示例#1
0
    def retrieve_json(self):
        """
		Retrieve a JSON payload from a given URL and parameter

		:return: Returns a JSON payload
		"""

        try:
            response = urllib.request.urlopen(self.url + self.param)
            payload = response.read()
            jsonPayload = json.loads(payload.decode('utf-8'))
            curlFeed = CurlFeed("App1", "Success",
                                "Retrieved JSON payload from URL")
            curlFeed.send()
            return jsonPayload
        except:
            # Catch all exceptions
            e = sys.exc_info()[0]
            print("Error:%s" % e)
            jsonPayload = {}
            logging.error(e)
            curlFeed = CurlFeed("App1", "Failed",
                                "Failed to retrieve JSON payload from URL")
            curlFeed.send()
            return jsonPayload
示例#2
0
    def send_payload(self, payload):
        """
		Sends JSON payload  to App2 using TLS

		:param payload: The JSON payload
		:return: Returns true if successful, false if failed
		"""

        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            ssl_sock = ssl.wrap_socket(s,
                                       ca_certs="server.crt",
                                       cert_reqs=ssl.CERT_REQUIRED)
            ssl_sock.connect(('localhost', 8080))
            curlFeed = CurlFeed("App1", "Success", "Sending Json Payload")
            curlFeed.send()
            ssl_sock.send((json.dumps(payload).encode()))
            ssl_sock.close()
            return True
        except:
            # Catch all exception
            e = sys.exc_info()[0]
            print("Error:%s" % e)
            logging.error(e)
            curlFeed = CurlFeed("App1", "Failed",
                                "Failed to send JSON payload")
            curlFeed.send()
            ssl_sock.close()
            return False
示例#3
0
    def send_payloadqueue(self, payload):
        """
		Makes connection to app3Pyro
		Pass the uri to app3
		Send payload to app1 via rabbitmq
		"""
        try:
            jsonPayload = format(payload)
            print(jsonPayload)
            print("Connecting to the localhost...")
            time.sleep(2)
            connection = pika.BlockingConnection(
                pika.ConnectionParameters(host='localhost'))
            channel = connection.channel()
            print("Successfully connected to the queue channel...")
            time.sleep(1)
            channel.queue_declare(queue='HelloTeam2!')
            channel.basic_publish(exchange='',
                                  routing_key='Hello',
                                  body=jsonPayload)
            print(" [x] Sent the payload back to app1.")
            curlFeed = CurlFeed("App4", "Success",
                                "Successfully Sent rabbitmq payload to  App1")
            curlFeed.send()
            connection.close()
        except Exception as e:
            print(e)
            curlFeed = CurlFeed("App4", "Failure",
                                "Failed to send rabbitmq payload to App1")
            curlFeed.send()
示例#4
0
文件: App3Main.py 项目: riz5034/PSU
def jasonRead():
    '''
    return the message 
    '''
    with open("json.txt", "r") as json_data:
        curlFeed = CurlFeed("App3", "Success", "Opened JSON file")
        curlFeed.send()
        message = json.load(json_data)
        print(type(message))
    return message
示例#5
0
	def send_SFTP(dataJSON):
		'''
		Sends the JSON Payload to APP3 using SFTP Security
		'''
		try:
			with pysftp.Connection(**cinfo) as sftp:
				print("Connection made")
				print("Sending JSON payload to App3")
				sftp.put('json.txt')
				curlFeed = CurlFeed("App2", "Success", "Sent JSON payload to App3")
				return True
		except:
			print("Log exception:", sys.exc_info()[0])
			curlFeed = CurlFeed("App2", "Failed", sys.exc_info()[0])
			curlFeed.send()
			return False
示例#6
0
文件: app3Pyro.py 项目: riz5034/PSU
	def pyro_payload(self,message):
		'''
		uri - The uri the user has to input from App4
		'''
		try:
			uri = input("Please enter the uri: ").strip()
			transformer = Pyro4.Proxy(uri)
			print("Sending JSON Payload to app4")
			transformer.send_pyro(message)
			transformer.shutdown()
			#print(transformer.get_payload(repr(message)))
			curlFeed = CurlFeed("App3", "Success", "Sent JSON payload to App4")
			curlFeed.send()
			return True
		except:
			print("Log exception",sys.exc_info()[0])
示例#7
0
文件: app2Sftp.py 项目: riz5034/PSU
	def send_SFTP(self):
		'''
		SFTP recieves payload
		'''
		try:
			with pysftp.Connection(**cinfo) as sftp:
				print("Connection made")
				print("Sending the JSON Payload to App3")
				sftp.put('json.txt')
				curlFeed = CurlFeed("App2", "Success", "Successfully Sent SFTP Payload to App3")
				curlFeed.send()
				return True
		except:
			print("Log exception:", sys.exc_info()[0])
			curlFeed = CurlFeed("App2", "Failure", "Failed to send SFTP Payload to App3")
			curlFeed.send()
示例#8
0
		def email_send(self):
			try:
				s = smtplib.SMTP_SSL('authsmtp.psu.edu', 465)
				s.sendmail(fromAddress,[toAddress1], msg.as_string())
				s.sendmail(fromAddress,[toAddress2], msg.as_string())
				s.sendmail(fromAddress,[toAddress3], msg.as_string())
				s.sendmail(fromAddress,[toAddress4], msg.as_string())
				s.sendmail(fromAddress,[toAddress5], msg.as_string())
				s.sendmail(fromAddress,[toAddress6], msg.as_string())
				curlFeed = CurlFeed("App3", "Success", "Sent JSON payload to email addresses")
				curlFeed.send()
			except exception as e:
				print("Log exception",sys.exc_info()[0])
				print("Error %s" %e.args[0])
				curlFeed = CurlFeed("App3", "Failed", e.args[0])
				curlFeed.send()
示例#9
0
文件: app4Pyro.py 项目: riz5034/PSU
				def shutdown(self):
					"""
					Shuts down the daemon passed
					"""
					try:
						print("Shutting down Pyro ORB...\n")
						self.daemon.shutdown()
						curlFeed = CurlFeed("App3", "Success", "Shutdown daemon")
						curlFeed.send()
						return True
					except:
						e = sys.exc_info()[0]
						print("Error:%s" %e)
						logging.error(e)
						curlFeed = CurlFeed("App3", "Failed", "Failed to shutdown daemon")
						curlFeed.send()
						return False
示例#10
0
文件: app4Pyro.py 项目: riz5034/PSU
				def send_pyro(self, payload):
					"""
					Appends a payload to the class
					:param payload: The payload to append
					:return: Returns true if successful and false if failed
					"""
					try:
						self.payload.append(payload)
						curlFeed = CurlFeed("App3", "Success", "Attached payload to send to App 4")
						curlFeed.send()
						return True
					except:
						e = sys.exc_info()[0]
						print("Error:%s" %e)
						logging.error(e)
						curlFeed = CurlFeed("App3", "Failed", "Failed to attach payload to send to App4")
						curlFeed.send()
						return False
示例#11
0
 def CompressFile(self):
     '''
     Compress the text file 
     '''
     try :
         with open(self.mlocation,'rb') as f_in:
             with gzip.open(self.olocation,'wb') as f_out:
                 print("Now compressing the JSON Payload")
                 shutil.copyfileobj(f_in, f_out)
                 print("The file has been compressed")
                 curlFeed = CurlFeed("App3", "Success", "Compressed JSON file")
                 curlFeed.send()
         return True
     except:
         e = sys.exc_info()[0]
         logging.error(e)
         curlFeed = CurlFeed("App3", "Failed", e)
         curlFeed.send()
         raise
示例#12
0
文件: app3Hash.py 项目: riz5034/PSU
 def messageEngrpt(self):
     '''
     Hash the message with the key and with sha256
    '''
     try:
         lkey = bytes(self.key, "UTF-8")
         lmessage = bytes(repr(self.message), "UTF-8")
         digester = hmac.new(lkey, lmessage, hashlib.sha256)
         print(digester)
         self.signature = digester.digest()
         curlFeed = CurlFeed("App3", "Success", "Hashed JSON data")
         curlFeed.send()
         print(self.signature)
         return True
     except:
         e = sys.exc_info()[0]
         logging.error(e)
         curlFeed = CurlFeed("App3", "Failed", e)
         curlFeed.send()
         raise
示例#13
0
    def save_payload(self, payload):
        """
		Writes JSON payload to text file
		:param payload: The JSON payload
		:return: Returns true if successful, false if failed
		"""
        try:
            with open('json.txt', 'w') as outFile:
                outFile.write(json.dumps(payload))
                curlFeed = CurlFeed("App1", "Success", "Saved Json payload")
                curlFeed.send()
                return True
        except:
            # Catch all exceptions
            e = sys.exc_info()[0]
            print("Error:%s" % e)
            logging.error(e)
            curlFeed = CurlFeed("App1", "Failed",
                                "Failed to save JSON payload")
            curlfeed.send()
            return False
示例#14
0
    def send_payload(self, payload):
        """
		Sends JSON payload  to App2 using TLS
		:param payload: The JSON payload
		:return: Returns true if successful, false if failed
		"""
        try:
            self.socket.send((json.dumps(payload).encode()))
            curlFeed = CurlFeed("App1", "Success", "Sent payload to App 2")
            self.socket.close()
            return True
        except:
            # Catch all exceptions
            e = sys.exc_info()[0]
            print("Error:%s" % e)
            logging.error(e)
            curlFeed = CurlFeed("App1", "Failed",
                                "Failed to send JSON payload")
            curlFeed.send()
            self.socket.close()
            return False
示例#15
0
    def receive_payloadqueue(self):
        '''
		Receives paylaod from queue 
		Return true when it receives the payload
		Return false when payload is not received
		'''
        try:
            connection = pika.BlockingConnection(
                pika.ConnectionParameters(host=settings.HOSTNAME))
            channel = connection.channel()
            channel.queue_declare(queue='Team2')
            curlFeed = CurlFeed(
                "App1", "Success",
                "Successfully receiving rabbitmq payload from app4")
            curlFeed.send()

            def callback(ch, method, properties, body):
                print("Received %r \n" % body)
                channel.stop_consuming()

            channel.basic_consume(callback, queue='Team2', no_ack=True)
            channel.start_consuming()
            curlFeed = CurlFeed(
                "App1", "Success",
                "Successfully receiving rabbitmq payload from app4")
            curlFeed.send()
            return True
        except Exception as e:
            print(e)
            curlFeed = CurlFeed(
                "App1", "Failure",
                "Failed to receive rabbitmq payload from  App4")
            curlFeed.send()
            return False
示例#16
0
文件: App2Main.py 项目: riz5034/PSU
    def get_connection():
        try:
            '''
			SFTP getting connection
			'''
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            ssl_sock = ssl.wrap_socket(s,
                                       server_side=True,
                                       certfile="server.crt",
                                       keyfile="server.key")
            ssl_sock.bind(('localhost', 8080))
            ssl_sock.listen(5)
            curlFeed = CurlFeed("App2", "Success", "Started server")
            curlFeed.send()
            print("ciphers:" + str(ssl_sock.cipher()))
            while True:
                print("Accept SSL Connections from the outside")
                (clientsocket, address) = ssl_sock.accept()
                data = clientsocket.recv(1024)
                dataJSON = json.loads(data.decode('utf-8'))
                print(json.dumps(dataJSON))
                curlFeed = CurlFeed("App2", "Success", "Recieved JSON payload")
                curlFeed.send()
                return dataJSON
        except:
            print("Log exception:", sys.exc_info()[0])
            curlFeed = CurlFeed("App2", "Failed", sys.exc_info()[0])
            curlFeed.send()
示例#17
0
	def hash(dataJSON):
		'''
		Hashes the JSON Payload
		'''
		try:
			key = "This is a key"
			print(key)
			key = bytes(key, 'UTF-8')
			dataJSON_bytes = bytes(json.dumps(dataJSON), 'UTF-8')
			sha256_digester = hmac.new(key, dataJSON_bytes, hashlib.sha256)
			print(sha256_digester)
			sha256_signature = sha256_digester.digest()
			print("Hashing JSON Payload")
			print(sha256_signature)
			curlFeed = CurlFeed("App2", "Success", "Hashed JSON Payload")
			curlFeed.send()
			return True
		except:
			print("Log exception:", sys.exc_info()[0])
			curlFeed = CurlFeed("App2", "Failed", sys.exc_info()[0])
			curlFeed.send()
			return False
示例#18
0
    def setup_connection(self):
        """
		Setup connection for TLS
		:return: Returns true if successful, false if failed
		"""
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.socket = ssl.wrap_socket(s,
                                          ca_certs=settings.CERT,
                                          cert_reqs=ssl.CERT_REQUIRED)
            self.socket.connect((settings.HOSTNAME, settings.PORT_NUMBER))
            curlFeed = CurlFeed("App1", "Success", "Connected to server")
            curlFeed.send()
            return True
        except:
            # Catch all exceptions
            e = sys.exc_info()[0]
            print("Error:%s" % e)
            logging.error(e)
            curlFeed = CurlFeed("App1", "Failed",
                                "Failed to connect to server")
            curlFeed.send()
            return False
示例#19
0
文件: App3Main.py 项目: riz5034/PSU
def Emailsent(message):
    '''
    Create email to sent
    '''
    fromAddress = '*****@*****.**'
    toAddress1 = '*****@*****.**'
    toAddress2 = '*****@*****.**'
    toAddress3 = '*****@*****.**'
    toAddress4 = '*****@*****.**'
    toAddress5 = '*****@*****.**'
    toAddress6 = '*****@*****.**'
    subject = "Hey Team"
    msg = MIMEText(repr(message))
    msg['Subject'] = 'Subject'
    msg['From'] = fromAddress
    msg['To Brian'] = toAddress1
    msg['To Zach'] = toAddress2
    msg['To Bijal'] = toAddress3
    msg['To Francheska'] = toAddress4
    msg['To Rachel'] = toAddress5
    msg['To Ricky'] = toAddress6
    try:
        s = smtplib.SMTP_SSL('authsmtp.psu.edu',465)
        s.sendmail(fromAddress,[toAddress1], msg.as_string())
        s.sendmail(fromAddress,[toAddress2], msg.as_string())
        s.sendmail(fromAddress,[toAddress3], msg.as_string())
        s.sendmail(fromAddress,[toAddress4], msg.as_string())
        s.sendmail(fromAddress,[toAddress5], msg.as_string())
        s.sendmail(fromAddress,[toAddress6], msg.as_string())
        curlFeed = CurlFeed("App3", "Success", "Sent JSON payload to email addresses")
        curlFeed.send()
        return True
    except exception as e:
        print("Error %s" %e.args[0])
        curlFeed = CurlFeed("App3", "Failed", e.args[0])
        curlFeed.send()
        return False
示例#20
0
		def pyro_payload(self):
			try:
				uri = input("Please enter the uri: ").strip()
				transformer = Pyro4.Proxy(uri)
				print("Sending JSON Payload to app4")
				print(transformer.get_payload(repr(message)))
				curlFeed = CurlFeed("App3", "Success", "Sent JSON payload to App4")
				curlFeed.send()
			except:
				print("Log exception",sys.exc_info()[0])

				try:
					with open('json.txt', 'rb') as f_in:
						try:
							with gzip.open('json.txt.gz', 'wb') as f_out:
								print("Now compressing the JSON Payload")
								shutil.copyfileobj(f_in, f_out)
								print("The file has been compressed")
								curlFeed = CurlFeed("App3", "Success", "Compressed JSON file")
								curlFeed.send()
						except:
							print("Log exception 1:", sys.exc_info()[0])
				except:
					print("Log exception 2:", sys.exc_info()[0])
示例#21
0
文件: testcurl.py 项目: riz5034/PSU
'''
Test this file
'''
from App5.curlfeed import CurlFeed
test = CurlFeed("APP5 Test", "Failed", "WHYY ")
test.getApp()
test.getStatus()
test.getInfo()
test.send()
示例#22
0
文件: app4Pyro.py 项目: riz5034/PSU
	def sendURI(self):
		"""
		Sends a URI to an application to recieve a PayloadSender object
		:return: Returns true if successful, false if failed
		"""
		try:
			@Pyro4.expose
			class PayloadSender(object):
				"""
				Contains methods to attach a payload and close the daemon attached
				"""
				def __init__(self, daemon, payload):
					self.daemon = daemon
					self.payload = payload
				def send_pyro(self, payload):
					"""
					Appends a payload to the class
					:param payload: The payload to append
					:return: Returns true if successful and false if failed
					"""
					try:
						self.payload.append(payload)
						curlFeed = CurlFeed("App3", "Success", "Attached payload to send to App 4")
						curlFeed.send()
						return True
					except:
						e = sys.exc_info()[0]
						print("Error:%s" %e)
						logging.error(e)
						curlFeed = CurlFeed("App3", "Failed", "Failed to attach payload to send to App4")
						curlFeed.send()
						return False

				@Pyro4.oneway # in case call returns later than daemon.shutdown
				def shutdown(self):
					"""
					Shuts down the daemon passed
					"""
					try:
						print("Shutting down Pyro ORB...\n")
						self.daemon.shutdown()
						curlFeed = CurlFeed("App3", "Success", "Shutdown daemon")
						curlFeed.send()
						return True
					except:
						e = sys.exc_info()[0]
						print("Error:%s" %e)
						logging.error(e)
						curlFeed = CurlFeed("App3", "Failed", "Failed to shutdown daemon")
						curlFeed.send()
						return False

			daemon = Pyro4.Daemon()
			uri = daemon.register(PayloadSender(daemon, self.payload))
			print("Ready... Object uri =", uri)
			print("Ready to send object using pyro")
			daemon.requestLoop()
			daemon.close()
			print("Daemon closed.\n")
			print("Here's the payload:")
			print(self.payload[0])
			print("")
			curlFeed = CurlFeed("App4", "Success", "Retrieved payload with Pyro object")
			curlFeed.send()
			return True
		except:
			e = sys.exc_info()[0]
			print("Error:%s" %e)
			logging.error(e)
			curlFeed = CurlFeed("App3", "Failed", "Failed to retrieve payload with Pyro object")
			curlFeed.send()
			return False
示例#23
0
		def sftp(self):
			try:
				print("Recieving payload file")
				data = sftp.get("json.txt")
			except:
				print("Log exception",sys.exc_info()[0])

				with open("json.txt", "r") as json_data:
				curlFeed = CurlFeed("App3", "Success", "Opened JSON file")
				curlFeed.send()
				key = "This is a key"
				message = json.load(json_data)
				curlFeed = CurlFeed("App3", "Success", "Loaded JSON data")
				curlFeed.send()
				print(repr(message))
				key = bytes(key, "UTF-8")
				message = bytes(repr(message), "UTF-8")
				sha256_digester = hmac.new(key, message, hashlib.sha256)
				print(sha256_digester)
				sha256_signature = sha256_digester.digest()
				curlFeed = CurlFeed("App3", "Success", "Hashed JSON data")
				curlFeed.send()
				print(sha256_signature)

		''' Team2 email address'''
		def email_address(self):
			try:
				fromAddress = '*****@*****.**'
				toAddress1 = '*****@*****.**'
				toAddress2 = '*****@*****.**'
				toAddress3 = '*****@*****.**'
				toAddress4 = '*****@*****.**'
				toAddress5 = '*****@*****.**'
				toAddress6 = '*****@*****.**'
			except:
				print("Log exception:",sys.exc_info()[0])

		''' Subject that will be in the email adress'''
		def email_subjet(self):
			try:
				subject = "Hey Team"
				msg = MIMEText(repr(message))
			except:
				print("Log exception",sys.exc_info()[0])

		''' msg - The message that will be recieved in all the email'''
		def email_msg(self):
			try:
				msg['Subject'] = 'Subject'
				msg['From'] = fromAddress
				msg['To Brian'] = toAddress1
				msg['To Zach'] = toAddress2
				msg['To Bijal'] = toAddress3
				msg['To Francheska'] = toAddress4
				msg['To Rachel'] = toAddress5
				msg['To Ricky'] = toAddress6
			except:
				print("Log exception",sys.exc_info()[0])

		''' Sending the email'''
		def email_send(self):
			try:
				s = smtplib.SMTP_SSL('authsmtp.psu.edu', 465)
				s.sendmail(fromAddress,[toAddress1], msg.as_string())
				s.sendmail(fromAddress,[toAddress2], msg.as_string())
				s.sendmail(fromAddress,[toAddress3], msg.as_string())
				s.sendmail(fromAddress,[toAddress4], msg.as_string())
				s.sendmail(fromAddress,[toAddress5], msg.as_string())
				s.sendmail(fromAddress,[toAddress6], msg.as_string())
				curlFeed = CurlFeed("App3", "Success", "Sent JSON payload to email addresses")
				curlFeed.send()
			except exception as e:
				print("Log exception",sys.exc_info()[0])
				print("Error %s" %e.args[0])
				curlFeed = CurlFeed("App3", "Failed", e.args[0])
				curlFeed.send()

		''' uri-The uri the user has to iput from App4'''
		def pyro_payload(self):
			try:
				uri = input("Please enter the uri: ").strip()
				transformer = Pyro4.Proxy(uri)
				print("Sending JSON Payload to app4")
				print(transformer.get_payload(repr(message)))
				curlFeed = CurlFeed("App3", "Success", "Sent JSON payload to App4")
				curlFeed.send()
			except:
				print("Log exception",sys.exc_info()[0])

				try:
					with open('json.txt', 'rb') as f_in:
						try:
							with gzip.open('json.txt.gz', 'wb') as f_out:
								print("Now compressing the JSON Payload")
								shutil.copyfileobj(f_in, f_out)
								print("The file has been compressed")
								curlFeed = CurlFeed("App3", "Success", "Compressed JSON file")
								curlFeed.send()
						except:
							print("Log exception 1:", sys.exc_info()[0])
				except:
					print("Log exception 2:", sys.exc_info()[0])