From 9ddf7f9378a52b8ee43c75343da22a23320e1f23 Mon Sep 17 00:00:00 2001 From: "usman@cyberpersons.com" Date: Sat, 15 Apr 2023 14:42:35 +0500 Subject: [PATCH] bug fix: ftp issue on ubuntu22 --- install/installCyberPanel.py | 8 ++++++++ plogical/ftpUtilities.py | 24 +++++++++++++++++------- plogical/processUtilities.py | 5 +++++ plogical/test.py | 5 +++++ plogical/upgrade.py | 13 +++++++++++++ 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/install/installCyberPanel.py b/install/installCyberPanel.py index da16aeda8..de4a993c9 100755 --- a/install/installCyberPanel.py +++ b/install/installCyberPanel.py @@ -504,6 +504,14 @@ class InstallCyberPanel: command = 'systemctl restart pure-ftpd-mysql.service' install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) + + if get_Ubuntu_release() > 20: + ### change mysql md5 to crypt + + command = "sed -i 's/MYSQLCrypt md5/MYSQLCrypt crypt/g' /etc/pure-ftpd/db/mysql.conf" + install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) + + InstallCyberPanel.stdOut("PureFTPD configured!", 1) except IOError as msg: diff --git a/plogical/ftpUtilities.py b/plogical/ftpUtilities.py index 4deee0b13..fa869cdf3 100755 --- a/plogical/ftpUtilities.py +++ b/plogical/ftpUtilities.py @@ -143,8 +143,13 @@ class FTPUtilities: print("0, %s file is symlinked." % (path)) return 0 - hash = hashlib.md5() - hash.update(password.encode('utf-8')) + if ProcessUtilities.ubuntu22Check == 1: + from crypt import crypt, METHOD_SHA512 + FTPPass = crypt(password, METHOD_SHA512) + else: + hash = hashlib.md5() + hash.update(password.encode('utf-8')) + FTPPass = hash.hexdigest() admin = Administrator.objects.get(userName=owner) @@ -153,7 +158,7 @@ class FTPUtilities: if website.package.ftpAccounts == 0: - user = Users(domain=website, user=userName, password=hash.hexdigest(), uid=uid, gid=gid, + user = Users(domain=website, user=userName, password=FTPPass, uid=uid, gid=gid, dir=path, quotasize=website.package.diskSpace, status="1", @@ -163,7 +168,7 @@ class FTPUtilities: user.save() elif website.users_set.all().count() < website.package.ftpAccounts: - user = Users(domain=website, user=userName, password=hash.hexdigest(), uid=uid, gid=gid, + user = Users(domain=website, user=userName, password=FTPPass, uid=uid, gid=gid, dir=path, quotasize=website.package.diskSpace, status="1", ulbandwidth=500000, @@ -195,11 +200,16 @@ class FTPUtilities: @staticmethod def changeFTPPassword(userName, password): try: - hash = hashlib.md5() - hash.update(password.encode('utf-8')) + if ProcessUtilities.ubuntu22Check == 1: + from crypt import crypt, METHOD_SHA512 + FTPPass = crypt(password, METHOD_SHA512) + else: + hash = hashlib.md5() + hash.update(password.encode('utf-8')) + FTPPass = hash.hexdigest() ftp = Users.objects.get(user=userName) - ftp.password = hash.hexdigest() + ftp.password = FTPPass ftp.save() return 1, None diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index e906d8ce9..2f33bbb68 100755 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -17,6 +17,7 @@ class ProcessUtilities(multi.Thread): cent8 = 2 ubuntu = 0 ubuntu20 = 3 + ubuntu22Check = 0 server_address = '/usr/local/lscpd/admin/comm.sock' token = "unset" portPath = '/usr/local/lscp/conf/bind.conf' @@ -166,6 +167,10 @@ class ProcessUtilities(multi.Thread): distroPath = '/etc/lsb-release' if os.path.exists(distroPath): + ## this is check only + if open(distroPath, 'r').read().find('22.04'): + ProcessUtilities.ubuntu22Check = 1 + if open(distroPath, 'r').read().find('20.04') > -1 or open(distroPath, 'r').read().find('22.04'): return ProcessUtilities.ubuntu20 return ProcessUtilities.ubuntu diff --git a/plogical/test.py b/plogical/test.py index e69de29bb..3886ae749 100644 --- a/plogical/test.py +++ b/plogical/test.py @@ -0,0 +1,5 @@ +import sys +from crypt import crypt, METHOD_SHA512 +from getpass import getpass + +print(crypt('hosting', METHOD_SHA512)) \ No newline at end of file diff --git a/plogical/upgrade.py b/plogical/upgrade.py index 2e5dd3547..efcdda86c 100755 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -1085,6 +1085,19 @@ $cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout'; except: pass + + ### update ftp issue for ubuntu 22 + + if Upgrade.FindOperatingSytem() == Ubuntu22: + + try: + cursor.execute('ALTER TABLE `users` CHANGE `Password` `Password` VARCHAR(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; ') + except: + pass + + command = "sed -i 's/MYSQLCrypt md5/MYSQLCrypt crypt/g' /etc/pure-ftpd/db/mysql.conf" + Upgrade.executioner(command, command, 1) + try: connection.close() except: