From a5490854af2065fb093630b340d0b5eded2d164f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 25 Apr 2021 18:02:29 +0200 Subject: [PATCH 1/3] no return, send message --- server/server.py | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/server/server.py b/server/server.py index b4dba55..8b2ee3e 100644 --- a/server/server.py +++ b/server/server.py @@ -35,14 +35,14 @@ class Server: self.homeDirectory = "" self.executor.baseDir = Executor(self.homeDirectory) - def parseCommand(self, command: str) -> str: + def parseCommand(self, command: str) -> None: if command == "LINOK": - return "LINOK" + self.networkInstance.sendMessage("LINOK".encode('UTF-8')) elif command == "LINERROR": - return "LINERROR" + self.networkInstance.sendMessage("LINERROR".encode('UTF-8')) parsedCommand = command.split(" ") if len(parsedCommand) > 3: - return "ERROR" + self.networkInstance.sendMessage("ERROR".encode('UTF-8')) # TODO: Ez igy gecironda, ezt meg kene csinalni rendesen. elif len(parsedCommand) == 1: return self.execute(parsedCommand[0]) @@ -51,42 +51,48 @@ class Server: elif len(parsedCommand) == 3: return self.execute(parsedCommand[0], parsedCommand[1], parsedCommand[2]) - def execute(self, command: str, firstParam: str = "", secondParam: str = "") -> str: + def execute(self, command: str, firstParam: str = "", secondParam: str = "") -> None: if self.homeDirectory == "" or self.executor.currentDirectory == "" or self.executor.baseDir == "": raise Exception("Directories must not be empty string. Did the user log in?") if command == "MKD": if secondParam != "": - return "ERROR" + self.networkInstance.sendMessage("ERROR".encode('UTF-8')) else: - return self.executor.createDirectory(firstParam) + self.executor.createDirectory(firstParam) + self.networkInstance.sendMessage("OK".encode('UTF-8')) elif command == "RMD": if secondParam != "": - return "ERROR" + self.networkInstance.sendMessage("ERROR".encode('UTF-8')) else: - return self.executor.removeDirectory(firstParam) + self.executor.removeDirectory(firstParam) + self.networkInstance.sendMessage("OK".encode('UTF-8')) elif command == "GWD": if secondParam != "" or firstParam != "": - return "ERROR" + self.networkInstance.sendMessage("ERROR".encode('UTF-8')) else: - return self.executor.getCurrentDirectory() + self.executor.getCurrentDirectory() + self.networkInstance.sendMessage("OK".encode('UTF-8')) elif command == "CWD": if secondParam != "": - return "ERROR" + self.networkInstance.sendMessage("ERROR".encode('UTF-8')) else: - return self.executor.setCurrentDirectory(firstParam) + self.executor.setCurrentDirectory(firstParam) + self.networkInstance.sendMessage("OK".encode('UTF-8')) elif command == "LST": if secondParam != "" or firstParam != "": - return "ERROR" + self.networkInstance.sendMessage("ERROR".encode('UTF-8')) else: - return self.executor.listCurrentDirectoryContent() + self.executor.listCurrentDirectoryContent() + self.networkInstance.sendMessage("OK".encode('UTF-8')) elif command == "RMF": if secondParam != "": - return "ERROR" + self.networkInstance.sendMessage("ERROR".encode('UTF-8')) else: - return self.executor.removeFileInCurrentDirectory(firstParam) + self.executor.removeFileInCurrentDirectory(firstParam) + self.networkInstance.sendMessage("OK".encode('UTF-8')) elif command == "UPL": if secondParam != "": - return "ERROR" + self.networkInstance.sendMessage("ERROR".encode('UTF-8')) else: # TODO # Megkapod a filenevet argumentumneknt @@ -97,7 +103,7 @@ class Server: pass elif command == "DNL": if secondParam != "": - return "ERROR" + self.networkInstance.sendMessage("ERROR".encode('UTF-8')) else: # TODO # Megkapod a filenevet arguemntumkent @@ -107,7 +113,7 @@ class Server: # Ha sikeres, OK valaszt megkapod, kulonben ERROR valaszt megkapod pass else: - return "ERROR" + self.networkInstance.sendMessage("ERROR".encode('UTF-8')) def startServer(self): while True: From 621c59dce27b315935ce2af2e62a0674f861fae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 25 Apr 2021 18:05:49 +0200 Subject: [PATCH 2/3] fix decode --- server/authentication.py | 2 +- server/netwrapper.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/authentication.py b/server/authentication.py index dbc5e17..ee2e7f4 100644 --- a/server/authentication.py +++ b/server/authentication.py @@ -13,7 +13,7 @@ from Crypto.PublicKey import RSA from Crypto.PublicKey.RSA import RsaKey auth_logger = logging.getLogger('AUTH APPLICATION ') -auth_logger.root.setLevel(logging.INFO) +auth_logger.setLevel(logging.INFO) class Authetication: ABSOLUTE_PATH = os.path.abspath(os.path.dirname(sys.argv[0])) diff --git a/server/netwrapper.py b/server/netwrapper.py index cae72f6..d94b982 100644 --- a/server/netwrapper.py +++ b/server/netwrapper.py @@ -36,8 +36,8 @@ class NetWrapper: cipher = PKCS1_OAEP.new(self.currentClientPublicKey) identMsg = json.dumps( {'type': 'IDY', 'source': self.network.own_addr, - 'message': b64encode(cipher.encrypt(retmsg.encode('UTF-8')))}).decode( - 'ASCII') + 'message': b64encode(cipher.encrypt(retmsg.encode('UTF-8'))).decode('ASCII')}).encode( + 'UTF-8') self.network.send_msg(self.clientAddr, identMsg) def sendMessage(self, message: bytes) -> None: From 42fff36545032792c4223b0e834a5dc23d121845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 25 Apr 2021 18:08:21 +0200 Subject: [PATCH 3/3] unresolved reference --- server/authentication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/authentication.py b/server/authentication.py index ee2e7f4..fd9c159 100644 --- a/server/authentication.py +++ b/server/authentication.py @@ -121,7 +121,7 @@ class Authetication: with open(self.CONFIG_FILE_LOCATION) as json_file: data = json.load(json_file) - dictionary: dict + dictionary = dict() for user in data['user']: key = data['publicKey']