From c9f42728b2fa2e4b6fdf0df7cac05f3adee66d35 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Wed, 25 Sep 2024 11:57:28 +0500 Subject: [PATCH] cli utility to convert old alias to new alias --- plogical/IncScheduler.py | 7 ++- plogical/SwitchOldAliasToNew.py | 76 ++++++++++++++++++++++++++++++++ plogical/virtualHostUtilities.py | 2 +- 3 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 plogical/SwitchOldAliasToNew.py diff --git a/plogical/IncScheduler.py b/plogical/IncScheduler.py index 39daf9504..91f1eae4f 100644 --- a/plogical/IncScheduler.py +++ b/plogical/IncScheduler.py @@ -618,8 +618,11 @@ def startNormalBackups(type): domain, time.strftime("%m.%d.%Y_%H-%M-%S"))).save() jobConfig = json.loads(backupjob.config) - if jobConfig['pid']: - del jobConfig['pid'] + try: + if jobConfig['pid']: + del jobConfig['pid'] + except: + pass jobConfig[IncScheduler.currentStatus] = 'Not running' backupjob.config = json.dumps(jobConfig) backupjob.save() diff --git a/plogical/SwitchOldAliasToNew.py b/plogical/SwitchOldAliasToNew.py new file mode 100644 index 000000000..8d79d8c0a --- /dev/null +++ b/plogical/SwitchOldAliasToNew.py @@ -0,0 +1,76 @@ +import os,sys +import shutil + +sys.path.append('/usr/local/CyberCP') +import django +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") +try: + django.setup() +except: + pass +import subprocess +from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging + + + +class SwitchOldAliasToNew: + + def __init__(self): + pass + + def Rebuild(self): + try: + message = 'We will convert old Domain Aliases to new Domain Aliases' + logging.writeToFile(message) + + origConf = "/usr/local/lsws/conf/httpd_config.conf" + origConfBack = "/usr/local/lsws/conf/httpd_config.conf" + + if not os.path.exists(origConf): + shutil.copy(origConf, origConfBack) + + from websiteFunctions.models import aliasDomains + from plogical.virtualHostUtilities import virtualHostUtilities + from plogical.processUtilities import ProcessUtilities + + for alias in aliasDomains.objects.all(): + message = f"{alias.aliasDomain} was alias of {alias.master.domain}. Conversions started.." + logging.writeToFile(message) + + path = f'/home/{alias.master.domain}/public_html' + + result = virtualHostUtilities.createDomain(alias.master.domain, alias.aliasDomain, alias.master.phpSelection, path, 1, 0, + 0, 'admin', 0,'/home/cyberpanel/fakePath', 1, 1) + + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(str(result)) + + data = open(origConf, 'r').readlines() + writeToFile = open(origConf, 'w') + for line in data: + if line.find(alias.master.domain) > -1: + line = line.replace(f',{alias.aliasDomain},', '') + line = line.replace(f', {alias.aliasDomain}', '') + writeToFile.write(line) + else: + writeToFile.write(line) + writeToFile.close() + + message = f"{alias.aliasDomain} is converted to new Domain Aliase." + logging.writeToFile(message) + + message = f"Conversion successfully completed." + logging.writeToFile(message) + + except: + pass + +def main(): + + rbQ = SwitchOldAliasToNew() + rbQ.Rebuild() + + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index 02a94fefe..c63ce0bf8 100644 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -1316,7 +1316,7 @@ def createDomain(masterDomain, virtualHostName, phpVersion, path, ssl, dkimCheck if vhost.checkIfAliasExists(virtualHostName) == 1: logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'This domain exists as Alias. [404]') - return 0, "This domain exists as Alias." + #return 0, "This domain exists as Alias." logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'DKIM Setup..,30')