From 85037121bfbc78468086486b17ac0cce91989750 Mon Sep 17 00:00:00 2001 From: kitoy Date: Wed, 3 Jun 2026 12:24:24 +0200 Subject: [PATCH] Add test login to sftp/ftp repository --- app/models/sites.py | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/app/models/sites.py b/app/models/sites.py index 24f0444..dd646dd 100644 --- a/app/models/sites.py +++ b/app/models/sites.py @@ -127,6 +127,11 @@ class DataSite: self.datas['blocs']= blocs self.filej.write_text(json.dumps(self.datas, indent=5)) + def save_server_info(self, serverInfos=dict()): + self.datas['publish'] = serverInfos + self.filej.write_text(json.dumps(self.datas, indent=5)) + + def get_theme(self): return self.datas['config']['theme'] @@ -197,15 +202,30 @@ class DataSite: copytree(themesStaticFolder, publicStaticFolder) - def publish(self, user:str, password:str, serverAddress:str, serverPort:int, folder:str): - remote_directory = "/remote/dir" + def test_server_login(self, serverInfos: dict(), password:str()): + + test_connect = "lftp -u \"{}\",\"{}\" -p {} {} -e 'ls; bye;'".format(serverInfos['username'], + password, + serverInfos['Port'], + serverInfos['Address']) + test_login = subprocess.check_output(test_connect, shell=True, stderr=subprocess.STDOUT) + if "Login incorrect" in str(test_login) : + print ("Mauvais login") + return False + else: + return True + + + def publish(self, serverInfos=dict(), password=str()): userDir = Path(PurePosixPath(self.user_folder)) - command = "lftp -u \"{}\",\"{}\" -p {} {} -e ' mirror -R public {}; chmod -R o+rx ./; bye;'".format(user, + + command = "lftp -u \"{}\",\"{}\" -p {} {} -e ' mirror -R public {}; chmod -R o+rx ./; bye;'".format(serverInfos['username'], password, - serverPort, - serverAddress, - folder) + serverInfos['Port'], + serverInfos['Address'], + serverInfos['folder']) + try: subprocess.call(command, shell=True, cwd=str(userDir)) except ChildProcessError: @@ -213,15 +233,6 @@ class DataSite: return True - def emptyTrash(self): - for file in self.trash: - try: - remove(self.static_path+'img/portfolio/fullsize/'+file) - except FileNotFoundError: - print (f'Le fichier {file} n\'existe pas') - if path.exists((self.static_path+'img/portfolio/thumbnails/'+file)): - remove(self.static_path+'img/portfolio/thumbnails/'+file) - self.trash.clear()