From: lionel Date: Tue, 13 Sep 2016 16:16:12 +0000 (+0200) Subject: Added : working (almost) remus daemon (only HB) X-Git-Url: http://gitweb.enneade.fdn.org/?a=commitdiff_plain;h=85255b6ec46c77e892db381496172e1ba9174371;p=rome.git Added : working (almost) remus daemon (only HB) --- diff --git a/remus b/remus index 2972770..d21d728 100755 --- a/remus +++ b/remus @@ -32,7 +32,7 @@ class App(): self.stdin_path = "/dev/null" self.stdout_path = "/home/lionel/work/python/rome/log/stdout.log" self.stderr_path = "/home/lionel/work/python/rome/log/stderr.log" - self.pidfile_path = "/home/lionel/work/python/rome/pid/romulus.pid" + self.pidfile_path = "/home/lionel/work/python/rome/pid/remus.pid" self.pidfile_timeout = 5 def run(self): @@ -41,46 +41,46 @@ class App(): def heartbeat(void): # Heartbeat is also responsible of verifying the network link between the two #seconds = int(min) * 60 - MY_TCP_IP = '192.168.0.250' - MY_TCP_PORT = 5005 + DEST_TCP_IP = '212.37.5.93' + DEST_TCP_PORT = 5005 MY_BUFFER_SIZE = 1024 + MESSAGE = bytes("HB", 'UTF-8') + k = pyDes.des(b"DEADJACK", pyDes.CBC, b"\2\2\2\2\2\2\2\2", pad=None, padmode=2) + MESSAGE = k.encrypt(MESSAGE) + logger.info("HB : loop started") - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.bind((MY_TCP_IP, MY_TCP_PORT)) - s.listen(1) while True: - time.sleep(3) - conn, addr = s.accept() - if not conn: break - data = conn.recv(MY_BUFFER_SIZE) - if not data: break - logger.info("Received HB from " + str(addr) + " : " + str(data)) - k = pyDes.des(b"DEADJACK", pyDes.CBC, b"\2\2\2\2\2\2\2\2", pad=None, padmode=2) + time.sleep(30) + logger.info("HB : challenge starting") + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((DEST_TCP_IP, DEST_TCP_PORT)) + s.send(MESSAGE) + logger.info("HB : waiting for the reply packet ...") + data = s.recv(MY_BUFFER_SIZE) + #data = s.recv(BUFFER_SIZE).decode('UTF-8') + logger.info("HB : reply packet received") + s.close() try: - #logger.info("HB packet content is : " + str(data)) - #logger.info("decrypting") - data = k.decrypt(data) - #logger.info("HB packet content is : " + str(data)) - data = data.decode('UTF-8') - #logger.info("decode from UTF-8") - #logger.info("HB packet content is : " + str(data)) - if data == "HB": - DEST_MESSAGE = bytes("Received", 'UTF-8') - DEST_MESSAGE = k.encrypt(DEST_MESSAGE) - # Sending - conn.send(DEST_MESSAGE) - logger.info("HB packet sent back : Received") - conn.close() + logger.info("HB : trying to decrypt data : " + str(data)) + data = k.decrypt(data).decode('UTF-8') + logger.info("HB : received data:" + str(data)) + #data = k.decrypt(data) + #data = data.decode('UTF-8') + if data == "Received": + logger.info("HB : OK") + else: + logger.warn("HB : Error") except: logger.info("Received an invalid HB packet") time.sleep(1) + logger.error("I am out of the infinit HB loop !") - return False + return True # All functions definitions took place above if __name__ == '__main__': - logger.info("Romulus (test version) started") + logger.info("Remus (test version) started") ''' Launching the heartbeat function @@ -107,7 +107,7 @@ class App(): # Means : if it's working : DON'T TOUCH ANYTHING if __name__ == "__main__": app = App() - logger = logging.getLogger("romulus") + logger = logging.getLogger("remus") loglevel = "debug" if (loglevel=="DEBUG") or (loglevel=="debug"): logger.setLevel(logging.DEBUG) @@ -120,7 +120,7 @@ if __name__ == "__main__": else: logger.setLevel(logging.DEBUG) formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") - handler = logging.FileHandler("log/romulus.log") + handler = logging.FileHandler("log/remus.log") handler.setFormatter(formatter) logger.addHandler(handler)