Skip to content

Commit

Permalink
cli utility to convert old alias to new alias
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Sep 25, 2024
1 parent 2b71d76 commit c9f4272
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
7 changes: 5 additions & 2 deletions plogical/IncScheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
76 changes: 76 additions & 0 deletions plogical/SwitchOldAliasToNew.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion plogical/virtualHostUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down

0 comments on commit c9f4272

Please sign in to comment.