diff --git a/CPScripts/mailscannerinstaller.sh b/CPScripts/mailscannerinstaller.sh index 6e324a22b..9175cd102 100644 --- a/CPScripts/mailscannerinstaller.sh +++ b/CPScripts/mailscannerinstaller.sh @@ -40,18 +40,42 @@ DIR=/etc/mail/spamassassin if [ -d "$DIR" ]; then sa-update else - echo "Please install spamassassin through the CyberPanel interface before proceeding" + echo "Please install SpamAssasin through the CyberPanel interface before proceeding" exit fi -if [ -f /etc/os-release ]; then - OS=$(head -1 /etc/os-release) - UBUNTUVERSION=$(sed '6q;d' /etc/os-release) - CENTOSVERSION=$(sed '5q;d' /etc/os-release) - CLNVERSION=$(sed '3q;d' /etc/os-release) +### OS Detection +Server_OS="" +Server_OS_Version="" +if grep -q -E "CentOS Linux 7|CentOS Linux 8" /etc/os-release ; then + Server_OS="CentOS" +elif grep -q "AlmaLinux-8" /etc/os-release ; then + Server_OS="AlmaLinux" +elif grep -q -E "CloudLinux 7|CloudLinux 8" /etc/os-release ; then + Server_OS="CloudLinux" +elif grep -q -E "Rocky Linux" /etc/os-release ; then + Server_OS="RockyLinux" +elif grep -q -E "Ubuntu 18.04|Ubuntu 20.04|Ubuntu 20.10|Ubuntu 22.04" /etc/os-release ; then + Server_OS="Ubuntu" +elif grep -q -E "openEuler 20.03|openEuler 22.03" /etc/os-release ; then + Server_OS="openEuler" +else + echo -e "Unable to detect your system..." + echo -e "\nCyberPanel is supported on x86_64 based Ubuntu 18.04, Ubuntu 20.04, Ubuntu 20.10, Ubuntu 22.04, CentOS 7, CentOS 8, AlmaLinux 8, RockyLinux 8, CloudLinux 7, CloudLinux 8, openEuler 20.03, openEuler 22.03...\n" + exit fi -if [ "$CENTOSVERSION" = "VERSION_ID=\"7\"" ]; then +Server_OS_Version=$(grep VERSION_ID /etc/os-release | awk -F[=,] '{print $2}' | tr -d \" | head -c2 | tr -d . ) + +echo -e "System: $Server_OS $Server_OS_Version detected...\n" + +if [[ $Server_OS = "CloudLinux" ]] || [[ "$Server_OS" = "AlmaLinux" ]] || [[ "$Server_OS" = "RockyLinux" ]] ; then + Server_OS="CentOS" + #CloudLinux gives version id like 7.8, 7.9, so cut it to show first number only + #treat CloudLinux, Rocky and Alma as CentOS +fi + +if [[ $Server_OS = "CentOS" ]] && [[ "$Server_OS_Version" = "7" ]] ; then setenforce 0 yum install -y perl yum-utils perl-CPAN @@ -68,7 +92,7 @@ if [ "$CENTOSVERSION" = "VERSION_ID=\"7\"" ]; then freshclam -v -elif [ "$CENTOSVERSION" = "VERSION_ID=\"8\"" ]; then +elif [[ $Server_OS = "CentOS" ]] && [[ "$Server_OS_Version" = "8" ]] ; then setenforce 0 yum install -y perl yum-utils perl-CPAN @@ -107,7 +131,7 @@ elif [ "$CLNVERSION" = "ID=\"cloudlinux\"" ]; then freshclam -v -elif [ "$OS" = "NAME=\"Ubuntu\"" ]; then +elif [[ $Server_OS = "Ubuntu" ]]; then apt-get install -y libmysqlclient-dev @@ -133,8 +157,8 @@ echo "/^Received:/ HOLD" >>/etc/postfix/header_checks systemctl restart postfix -if [ "$OS" = "NAME=\"Ubuntu\"" ]; then - wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.noarch.deb +if [[ $Server_OS = "Ubuntu" ]]; then + wget https://github.com/MailScanner/v5/releases/download/5.4.4-1/MailScanner-5.4.4-1.noarch.deb dpkg -i *.noarch.deb mkdir /var/run/MailScanner @@ -144,10 +168,9 @@ if [ "$OS" = "NAME=\"Ubuntu\"" ]; then chown -R postfix:postfix /var/lock/subsys/MailScanner chown -R postfix:postfix /var/spool/MailScanner -elif [ "$OS" = "NAME=\"CentOS Linux\"" ]; then - wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.rhel.noarch.rpm +elif [[ $Server_OS = "CentOS" ]]; then + wget https://github.com/MailScanner/v5/releases/download/5.4.4-1/MailScanner-5.4.4-1.rhel.noarch.rpm rpm -Uvh *.rhel.noarch.rpm - elif [ "$OS" = "NAME=\"CloudLinux\"" ]; then wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.rhel.noarch.rpm rpm -Uvh *.rhel.noarch.rpm diff --git a/CPScripts/mailscanneruninstaller.sh b/CPScripts/mailscanneruninstaller.sh index 8fc920677..2061fe9df 100644 --- a/CPScripts/mailscanneruninstaller.sh +++ b/CPScripts/mailscanneruninstaller.sh @@ -1,26 +1,52 @@ #!/bin/bash ## Uninstall Mailscanner CyberPanel -if [ -f /etc/os-release ]; then - OS=$(head -1 /etc/os-release) - UBUNTUVERSION=$(sed '6q;d' /etc/os-release) - CENTOSVERSION=$(sed '5q;d' /etc/os-release) - CLNVERSION=$(sed '3q;d' /etc/os-release) +### OS Detection +Server_OS="" +Server_OS_Version="" +if grep -q -E "CentOS Linux 7|CentOS Linux 8" /etc/os-release ; then + Server_OS="CentOS" +elif grep -q "AlmaLinux-8" /etc/os-release ; then + Server_OS="AlmaLinux" +elif grep -q -E "CloudLinux 7|CloudLinux 8" /etc/os-release ; then + Server_OS="CloudLinux" +elif grep -q -E "Rocky Linux" /etc/os-release ; then + Server_OS="RockyLinux" +elif grep -q -E "Ubuntu 18.04|Ubuntu 20.04|Ubuntu 20.10|Ubuntu 22.04" /etc/os-release ; then + Server_OS="Ubuntu" +elif grep -q -E "openEuler 20.03|openEuler 22.03" /etc/os-release ; then + Server_OS="openEuler" +else + echo -e "Unable to detect your system..." + echo -e "\nCyberPanel is supported on x86_64 based Ubuntu 18.04, Ubuntu 20.04, Ubuntu 20.10, Ubuntu 22.04, CentOS 7, CentOS 8, AlmaLinux 8, RockyLinux 8, CloudLinux 7, CloudLinux 8, openEuler 20.03, openEuler 22.03...\n" + exit +fi + +Server_OS_Version=$(grep VERSION_ID /etc/os-release | awk -F[=,] '{print $2}' | tr -d \" | head -c2 | tr -d . ) + +echo -e "System: $Server_OS $Server_OS_Version detected...\n" + +if [[ $Server_OS = "CloudLinux" ]] || [[ "$Server_OS" = "AlmaLinux" ]] || [[ "$Server_OS" = "RockyLinux" ]] ; then + Server_OS="CentOS" + #CloudLinux gives version id like 7.8, 7.9, so cut it to show first number only + #treat CloudLinux, Rocky and Alma as CentOS fi systemctl stop mailscanner -if [ "$OS" = "NAME=\"Ubuntu\"" ]; then - apt purge -y mailscanner -elif - [ "$OS" = "NAME=\"CentOS Linux\"" ] -then +if [[ $Server_OS = "CentOS" ]] && [[ "$Server_OS_Version" = "7" ]] ; then + yum remove -y MailScanner -elif [ "$OS" = "NAME=\"CloudLinux\"" ]; then +elif [[ $Server_OS = "CentOS" ]] && [[ "$Server_OS_Version" = "8" ]] ; then + yum remove -y MailScanner +elif [[ $Server_OS = "Ubuntu" ]]; then + + apt purge -y mailscanner + fi sed -i 's/\/^Received:\/ HOLD/\/^Received:\/ IGNORE/g' /etc/postfix/header_checks diff --git a/CyberCP/settings.py b/CyberCP/settings.py index f20c69b48..ef8b84ed8 100755 --- a/CyberCP/settings.py +++ b/CyberCP/settings.py @@ -24,7 +24,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = 'xr%j*p!*$0d%(-(e%@-*hyoz4$f%y77coq0u)6pwmjg4)q&19f' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False ALLOWED_HOSTS = ['*'] diff --git a/IncBackups/IncBackupsControl.py b/IncBackups/IncBackupsControl.py index 9d3509384..7c2f9e0b4 100644 --- a/IncBackups/IncBackupsControl.py +++ b/IncBackups/IncBackupsControl.py @@ -138,7 +138,7 @@ class IncJobs(multi.Thread): backupExcludesFile = '/home/%s/backup-exclude.conf' % (self.website.domain) resticBackupExcludeCMD = ' --exclude-file=%s' % (backupExcludesFile) - command = 'export AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s && restic -r s3:s3.amazonaws.com/%s backup %s --password-file %s --exclude /home/%s/backup --exclude /home/%s/incbackup' % ( + command = 'AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s restic -r s3:s3.amazonaws.com/%s backup %s --password-file %s --exclude /home/%s/backup --exclude /home/%s/incbackup' % ( key, secret, self.website.domain, backupPath, self.passwordFile, self.website.domain, self.website.domain) # If /home/%s/backup-exclude.conf file exists lets pass this to restic by appending the command to end. @@ -184,7 +184,7 @@ class IncJobs(multi.Thread): key, secret = self.getAWSData() - command = 'export AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s && restic -r s3:s3.amazonaws.com/%s forget %s --password-file %s' % ( + command = 'AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s restic -r s3:s3.amazonaws.com/%s forget %s --password-file %s' % ( key, secret, self.website, snapshotID, self.passwordFile) result = ProcessUtilities.outputExecutioner(command, self.externalApp) @@ -195,7 +195,7 @@ class IncJobs(multi.Thread): logging.statusWriter(self.statusPath, 'Failed: %s. [5009]' % (result), 1) return 0 - command = 'export AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s && restic -r s3:s3.amazonaws.com/%s prune --password-file %s' % ( + command = 'AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s restic -r s3:s3.amazonaws.com/%s prune --password-file %s' % ( key, secret, self.website, self.passwordFile) ProcessUtilities.outputExecutioner(command, self.externalApp) @@ -204,7 +204,7 @@ class IncJobs(multi.Thread): key, secret = self.getAWSData() - command = 'export AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s && restic -r s3:s3.amazonaws.com/%s restore %s --password-file %s --target %s' % ( + command = 'AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s restic -r s3:s3.amazonaws.com/%s restore %s --password-file %s --target %s' % ( key, secret, self.website, snapshotID, self.passwordFile, self.restoreTarget) result = ProcessUtilities.outputExecutioner(command, self.externalApp) @@ -764,7 +764,7 @@ class IncJobs(multi.Thread): logging.statusWriter(self.statusPath, result, 1) else: key, secret = self.getAWSData() - command = 'export AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s && restic -r s3:s3.amazonaws.com/%s init --password-file %s' % ( + command = 'AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s restic -r s3:s3.amazonaws.com/%s init --password-file %s' % ( key, secret, self.website.domain, self.passwordFile) result = ProcessUtilities.outputExecutioner(command, self.externalApp) diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index 82899a0bb..71787cc45 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -145,7 +145,7 @@
{% trans "On this page you can manage versions and or upgrade to latest version of CyberPanel" %}
-{% trans "Here you can manage versions and check for updates to CyberPanel" %}
+{% trans "Note: Latest commit does not match, please upgrade." %}
+{% trans "Note: Latest commit does not match, please upgrade CyberPanel." %}
{% trans "Email with id :" %} {$ createdID - $}{% trans " is successfully created." %}
+{% trans "Mailbox with username:" %} {$ createdID + $}{% trans " has been successfully created." %}
{% trans "Could not connect to server. Please refresh this page." %}
diff --git a/mailServer/templates/mailServer/deleteEmailAccount.html b/mailServer/templates/mailServer/deleteEmailAccount.html index 793bc0f40..942662540 100755 --- a/mailServer/templates/mailServer/deleteEmailAccount.html +++ b/mailServer/templates/mailServer/deleteEmailAccount.html @@ -92,7 +92,7 @@{% trans "Email with id : {$ deletedID $} is successfully deleted." %}
+{% trans "Mailbox with username: {$ deletedID $} has been successfully deleted." %}
{% trans "Could not connect to server. Please refresh this page." %}
diff --git a/plogical/IncScheduler.py b/plogical/IncScheduler.py index 8d1ef8da4..1ed92fdc1 100644 --- a/plogical/IncScheduler.py +++ b/plogical/IncScheduler.py @@ -1,9 +1,11 @@ #!/usr/local/CyberCP/bin/python import os.path import sys + sys.path.append('/usr/local/CyberCP') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") import django + django.setup() from IncBackups.IncBackupsControl import IncJobs from IncBackups.models import BackupJob @@ -22,6 +24,7 @@ import requests import socket from websiteFunctions.models import NormalBackupJobs, NormalBackupJobLogs from boto3.s3.transfer import TransferConfig + try: from s3Backups.models import BackupPlan, BackupLogs import boto3 @@ -63,7 +66,7 @@ class IncScheduler(multi.Thread): tempPath = "/home/cyberpanel/" + str(randint(1000, 9999)) for job in BackupJob.objects.all(): logging.statusWriter(IncScheduler.logPath, 'Job Description:\n\n Destination: %s, Frequency: %s.\n ' % ( - job.destination, job.frequency), 1) + job.destination, job.frequency), 1) if job.frequency == type: for web in job.jobsites_set.all(): logging.statusWriter(IncScheduler.logPath, 'Backing up %s.' % (web.website), 1) @@ -129,7 +132,7 @@ class IncScheduler(multi.Thread): web = Websites.objects.get(domain=website) message = '[%s Cron] Checking if %s has any pending commits on %s.' % ( - type, website, time.strftime("%m.%d.%Y_%H-%M-%S")) + type, website, time.strftime("%m.%d.%Y_%H-%M-%S")) finalText = '%s\n' % (message) GitLogs(owner=web, type='INFO', message=message).save() @@ -148,7 +151,7 @@ class IncScheduler(multi.Thread): data['domain'] = gitConf['domain'] data['folder'] = gitConf['folder'] data['commitMessage'] = 'Auto commit by CyberPanel %s cron on %s' % ( - type, time.strftime('%m-%d-%Y_%H-%M-%S')) + type, time.strftime('%m-%d-%Y_%H-%M-%S')) if gitConf['autoCommit'] == type: @@ -182,7 +185,7 @@ class IncScheduler(multi.Thread): finalText = '%s\n%s' % (finalText, message) message = '[%s Cron] Finished checking for %s on %s.' % ( - type, website, time.strftime("%m.%d.%Y_%H-%M-%S")) + type, website, time.strftime("%m.%d.%Y_%H-%M-%S")) finalText = '%s\n%s' % (finalText, message) logging.SendEmail(web.adminEmail, web.adminEmail, finalText, 'Git report for %s.' % (web.domain)) GitLogs(owner=web, type='INFO', message=message).save() @@ -333,7 +336,7 @@ class IncScheduler(multi.Thread): if retValues[0] == 0: GDriveJobLogs(owner=items, status=backupSchedule.ERROR, message='[ERROR] Backup failed for %s, error: %s moving on..' % ( - website.domain, retValues[1])).save() + website.domain, retValues[1])).save() continue completeFileToSend = retValues[1] + ".tar.gz" @@ -378,12 +381,9 @@ class IncScheduler(multi.Thread): GDriveJobLogs(owner=items, status=backupSchedule.INFO, message='Job Completed').save() - print("job com[leted") - #logging.writeToFile('job completed') - - + # logging.writeToFile('job completed') url = "https://platform.cyberpersons.com/CyberpanelAdOns/Adonpermission" data = { @@ -400,67 +400,67 @@ class IncScheduler(multi.Thread): page_token = None while True: - response = drive.files().list(q="name='%s-%s'" % (items.name,ipAddress), - spaces='drive', + response = drive.files().list(q="name='%s-%s'" % (items.name, ipAddress), + spaces='drive', fields='nextPageToken, files(id, name)', pageToken=page_token).execute() for file in response.get('files', []): # Process change - #print('Fetch Main folder ID: %s (%s)' % (file.get('name'), file.get('id'))) - #logging.writeToFile('Fetch Main folder ID: %s (%s)' % (file.get('name'), file.get('id'))) - mainfolder_id= file.get('id') + # print('Fetch Main folder ID: %s (%s)' % (file.get('name'), file.get('id'))) + # logging.writeToFile('Fetch Main folder ID: %s (%s)' % (file.get('name'), file.get('id'))) + mainfolder_id = file.get('id') page_token = response.get('nextPageToken', None) if page_token is None: break - #print("new job started ") + # print("new job started ") try: page_token = None while True: - response = drive.files().list(q="'%s' in parents"%(mainfolder_id), - spaces='drive', - fields='nextPageToken, files(id, name, createdTime)', - pageToken=page_token).execute() + response = drive.files().list(q="'%s' in parents" % (mainfolder_id), + spaces='drive', + fields='nextPageToken, files(id, name, createdTime)', + pageToken=page_token).execute() for file in response.get('files', []): # Process change - #print('Fetch all folders in main folder: %s (%s) time:-%s' % (file.get('name'), file.get('id'), file.get('createdTime'))) - #logging.writeToFile('Fetch all folders in main folder: %s (%s) time:-%s' % (file.get('name'), file.get('id'),file.get('createdTime'))) + # print('Fetch all folders in main folder: %s (%s) time:-%s' % (file.get('name'), file.get('id'), file.get('createdTime'))) + # logging.writeToFile('Fetch all folders in main folder: %s (%s) time:-%s' % (file.get('name'), file.get('id'),file.get('createdTime'))) ab = file.get('createdTime')[:10] filename = file.get('name') fileDeleteID = file.get('id') - timestamp = time.mktime(datetime.datetime.strptime(ab,"%Y-%m-%d").timetuple()) + timestamp = time.mktime(datetime.datetime.strptime(ab, "%Y-%m-%d").timetuple()) CUrrenttimestamp = time.time() timerrtention = gDriveData['FileRetentiontime'] - if(timerrtention == '1d'): + if (timerrtention == '1d'): new = CUrrenttimestamp - float(86400) - if(new>=timestamp): - resp=drive.files().delete(fileId=fileDeleteID).execute() - logging.writeToFile('Delete file %s '%filename) - elif(timerrtention == '1w'): + if (new >= timestamp): + resp = drive.files().delete(fileId=fileDeleteID).execute() + logging.writeToFile('Delete file %s ' % filename) + elif (timerrtention == '1w'): new = CUrrenttimestamp - float(604800) if (new >= timestamp): resp = drive.files().delete(fileId=fileDeleteID).execute() - logging.writeToFile('Delete file %s '%filename) + logging.writeToFile('Delete file %s ' % filename) elif (timerrtention == '1m'): new = CUrrenttimestamp - float(2592000) if (new >= timestamp): resp = drive.files().delete(fileId=fileDeleteID).execute() - logging.writeToFile('Delete file %s '%filename) + logging.writeToFile('Delete file %s ' % filename) elif (timerrtention == '6m'): new = CUrrenttimestamp - float(15552000) if (new >= timestamp): resp = drive.files().delete(fileId=fileDeleteID).execute() - logging.writeToFile('Delete file %s '%filename) + logging.writeToFile('Delete file %s ' % filename) page_token = response.get('nextPageToken', None) if page_token is None: break - # logging.writeToFile('Createtime list - %s'%Createtime) + # logging.writeToFile('Createtime list - %s'%Createtime) except BaseException as msg: - print('An error occurred fetch child: %s' % msg) - logging.writeToFile('An error occurred fetch child: %s' % msg) + print('An error occurred fetch child: %s' % msg) + logging.writeToFile('An error occurred fetch child: %s' % msg) except BaseException as msg: - logging.writeToFile('job not completed [ERROR:]..%s'%msg) + logging.writeToFile('job not completed [ERROR:]..%s' % msg) except BaseException as msg: GDriveJobLogs(owner=items, status=backupSchedule.ERROR, @@ -523,7 +523,7 @@ class IncScheduler(multi.Thread): NormalBackupJobLogs.objects.filter(owner=backupjob).delete() NormalBackupJobLogs(owner=backupjob, status=backupSchedule.INFO, message='Starting %s backup on %s..' % ( - type, time.strftime("%m.%d.%Y_%H-%M-%S"))).save() + type, time.strftime("%m.%d.%Y_%H-%M-%S"))).save() if oldJobContinue: NormalBackupJobLogs(owner=backupjob, status=backupSchedule.INFO, @@ -886,8 +886,7 @@ Automatic backup failed for %s on %s. emailPath = '/home/vmail/%s/%s' % (website.domain, email.email.split('@')[0]) email.DiskUsage = virtualHostUtilities.getDiskUsageofPath(emailPath) email.save() - print('Disk Usage of %s is %s' % (email.email,email.DiskUsage)) - + print('Disk Usage of %s is %s' % (email.email, email.DiskUsage)) config['DiskUsage'], config['DiskUsagePercentage'] = virtualHostUtilities.getDiskUsage( "/home/" + website.domain, website.package.diskSpace) @@ -947,19 +946,420 @@ Automatic backup failed for %s on %s. if config['pluginUpdates'] == 'Enabled': command = 'wp plugin update --all --minor --allow-root --path=/home/%s/public_html' % ( - config['domainName']) + config['domainName']) ProcessUtilities.executioner(command) ### Themes, for plugins we will do minor updates only. if config['themeUpdates'] == 'Enabled': command = 'wp theme update --all --minor --allow-root --path=/home/%s/public_html' % ( - config['domainName']) + config['domainName']) ProcessUtilities.executioner(command) except BaseException as msg: logging.writeToFile('%s. [WPUpdates:767]' % (str(msg))) + @staticmethod + def RemoteBackup(function): + try: + from websiteFunctions.models import RemoteBackupSchedule, RemoteBackupsites, WPSites + from loginSystem.models import Administrator + import json + import time + from plogical.applicationInstaller import ApplicationInstaller + for config in RemoteBackupSchedule.objects.all(): + try: + configbakup = json.loads(config.config) + backuptype = configbakup['BackupType'] + if backuptype == 'Only DataBase': + Backuptype = "3" + elif backuptype == 'Only Website': + Backuptype = "2" + else: + Backuptype = "1" + except: + continue + try: + allRemoteBackupsiteobj = RemoteBackupsites.objects.filter(owner=config.pk) + for i in allRemoteBackupsiteobj: + backupsiteID = i.WPsites + wpsite = WPSites.objects.get(pk=backupsiteID) + AdminID = wpsite.owner.admin_id + Admin = Administrator.objects.get(pk=AdminID) + + Lastrun = config.lastrun + Currenttime = float(time.time()) + + if config.timeintervel == function: + #al = float(Currenttime) - float(1800) + #if float(al) >= float(Lastrun): + #if 1 == 1: + + extraArgs = {} + extraArgs['adminID'] = Admin.pk + extraArgs['WPid'] = wpsite.pk + extraArgs['Backuptype'] = Backuptype + extraArgs['BackupDestination'] = config.RemoteBackupConfig.configtype + extraArgs['SFTPID'] = config.RemoteBackupConfig_id + + extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) + background = ApplicationInstaller('WPCreateBackup', extraArgs) + status, msg, backupID = background.WPCreateBackup() + if status == 1: + filename = msg + if config.RemoteBackupConfig.configtype == "SFTP": + IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id) + command = f"rm -r {filename}" + ProcessUtilities.executioner(command) + obj = RemoteBackupSchedule.objects.get(pk=config.id) + obj.lastrun = time.time() + obj.save() + elif config.RemoteBackupConfig.configtype == "S3": + IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID, + config.id) + command = f"rm -r {filename}" + ProcessUtilities.executioner(command) + obj = RemoteBackupSchedule.objects.get(pk=config.id) + obj.lastrun = time.time() + obj.save() + + elif config.timeintervel == function: + #al = float(Currenttime) - float(3600) + #if float(al) >= float(Lastrun): + # if 1 == 1: + + extraArgs = {} + extraArgs['adminID'] = Admin.pk + extraArgs['WPid'] = wpsite.pk + extraArgs['Backuptype'] = Backuptype + extraArgs['BackupDestination'] = config.RemoteBackupConfig.configtype + extraArgs['SFTPID'] = config.RemoteBackupConfig_id + + extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) + background = ApplicationInstaller('WPCreateBackup', extraArgs) + status, msg, backupID = background.WPCreateBackup() + if status == 1: + filename = msg + if config.RemoteBackupConfig.configtype == "SFTP": + IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id) + command = f"rm -r {filename}" + ProcessUtilities.executioner(command) + obj = RemoteBackupSchedule.objects.get(pk=config.id) + obj.lastrun = time.time() + obj.save() + elif config.RemoteBackupConfig.configtype == "S3": + IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID, + config.id) + command = f"rm -r {filename}" + ProcessUtilities.executioner(command) + obj = RemoteBackupSchedule.objects.get(pk=config.id) + obj.lastrun = time.time() + obj.save() + + elif config.timeintervel == function: + #al = float(Currenttime) - float(21600) + #if float(al) >= float(Lastrun): + + extraArgs = {} + extraArgs['adminID'] = Admin.pk + extraArgs['WPid'] = wpsite.pk + extraArgs['Backuptype'] = Backuptype + extraArgs['BackupDestination'] = "SFTP" + extraArgs['SFTPID'] = config.RemoteBackupConfig_id + + extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) + background = ApplicationInstaller('WPCreateBackup', extraArgs) + status, msg, backupID = background.WPCreateBackup() + if status == 1: + filename = msg + if config.RemoteBackupConfig.configtype == "SFTP": + IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id) + command = f"rm -r {filename}" + ProcessUtilities.executioner(command) + obj = RemoteBackupSchedule.objects.get(pk=config.id) + obj.lastrun = time.time() + obj.save() + elif config.RemoteBackupConfig.configtype == "S3": + IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID, + config.id) + command = f"rm -r {filename}" + ProcessUtilities.executioner(command) + obj = RemoteBackupSchedule.objects.get(pk=config.id) + obj.lastrun = time.time() + obj.save() + + elif config.timeintervel == function: + #al = float(Currenttime) - float(43200) + #if float(al) >= float(Lastrun): + extraArgs = {} + extraArgs['adminID'] = Admin.pk + extraArgs['WPid'] = wpsite.pk + extraArgs['Backuptype'] = Backuptype + extraArgs['BackupDestination'] = "SFTP" + extraArgs['SFTPID'] = config.RemoteBackupConfig_id + + extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) + background = ApplicationInstaller('WPCreateBackup', extraArgs) + status, msg, backupID = background.WPCreateBackup() + if status == 1: + filename = msg + if config.RemoteBackupConfig.configtype == "SFTP": + IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id) + command = f"rm -r {filename}" + ProcessUtilities.executioner(command) + obj = RemoteBackupSchedule.objects.get(pk=config.id) + obj.lastrun = time.time() + obj.save() + elif config.RemoteBackupConfig.configtype == "S3": + IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID, + config.id) + command = f"rm -r {filename}" + ProcessUtilities.executioner(command) + obj = RemoteBackupSchedule.objects.get(pk=config.id) + obj.lastrun = time.time() + obj.save() + + elif config.timeintervel == function: + #al = float(Currenttime) - float(86400) + #if float(al) >= float(Lastrun): + + extraArgs = {} + extraArgs['adminID'] = Admin.pk + extraArgs['WPid'] = wpsite.pk + extraArgs['Backuptype'] = Backuptype + extraArgs['BackupDestination'] = "SFTP" + extraArgs['SFTPID'] = config.RemoteBackupConfig_id + + extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) + background = ApplicationInstaller('WPCreateBackup', extraArgs) + status, msg, backupID = background.WPCreateBackup() + if status == 1: + filename = msg + if config.RemoteBackupConfig.configtype == "SFTP": + IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id) + command = f"rm -r {filename}" + ProcessUtilities.executioner(command) + obj = RemoteBackupSchedule.objects.get(pk=config.id) + obj.lastrun = time.time() + obj.save() + elif config.RemoteBackupConfig.configtype == "S3": + IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID, + config.id) + command = f"rm -r {filename}" + ProcessUtilities.executioner(command) + obj = RemoteBackupSchedule.objects.get(pk=config.id) + obj.lastrun = time.time() + obj.save() + + elif config.timeintervel == function: + #al = float(Currenttime) - float(259200) + #if float(al) >= float(Lastrun): + + extraArgs = {} + extraArgs['adminID'] = Admin.pk + extraArgs['WPid'] = wpsite.pk + extraArgs['Backuptype'] = Backuptype + extraArgs['BackupDestination'] = "SFTP" + extraArgs['SFTPID'] = config.RemoteBackupConfig_id + + extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) + background = ApplicationInstaller('WPCreateBackup', extraArgs) + status, msg, backupID = background.WPCreateBackup() + if status == 1: + filename = msg + if config.RemoteBackupConfig.configtype == "SFTP": + IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id) + command = f"rm -r {filename}" + ProcessUtilities.executioner(command) + obj = RemoteBackupSchedule.objects.get(pk=config.id) + obj.lastrun = time.time() + obj.save() + elif config.RemoteBackupConfig.configtype == "S3": + IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID, + config.id) + command = f"rm -r {filename}" + ProcessUtilities.executioner(command) + obj = RemoteBackupSchedule.objects.get(pk=config.id) + obj.lastrun = time.time() + obj.save() + + elif config.timeintervel == function: + #al = float(Currenttime) - float(604800) + #if float(al) >= float(Lastrun): + + extraArgs = {} + extraArgs['adminID'] = Admin.pk + extraArgs['WPid'] = wpsite.pk + extraArgs['Backuptype'] = Backuptype + extraArgs['BackupDestination'] = "SFTP" + extraArgs['SFTPID'] = config.RemoteBackupConfig_id + + extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) + background = ApplicationInstaller('WPCreateBackup', extraArgs) + status, msg, backupID = background.WPCreateBackup() + if status == 1: + filename = msg + if config.RemoteBackupConfig.configtype == "SFTP": + IncScheduler.SendTORemote(filename, config.RemoteBackupConfig_id) + command = f"rm -r {filename}" + ProcessUtilities.executioner(command) + obj = RemoteBackupSchedule.objects.get(pk=config.id) + obj.lastrun = time.time() + obj.save() + elif config.RemoteBackupConfig.configtype == "S3": + IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID, + config.id) + command = f"rm -r {filename}" + ProcessUtilities.executioner(command) + obj = RemoteBackupSchedule.objects.get(pk=config.id) + obj.lastrun = time.time() + obj.save() + + except BaseException as msg: + print("Error in Sites:%s" % str(msg)) + continue + except BaseException as msg: + print("Error: [RemoteBackup]: %s" % str(msg)) + logging.writeToFile('%s. [RemoteBackup]' % (str(msg))) + + @staticmethod + def SendTORemote(FileName, RemoteBackupID): + import pysftp + import json + import pysftp as sftp + from websiteFunctions.models import RemoteBackupConfig + + try: + RemoteBackupOBJ = RemoteBackupConfig.objects.get(pk=RemoteBackupID) + config = json.loads(RemoteBackupOBJ.config) + HostName = config['Hostname'] + Username = config['Username'] + Password = config['Password'] + Path = config['Path'] + + cnopts = sftp.CnOpts() + cnopts.hostkeys = None + + with pysftp.Connection(HostName, username=Username, password=Password, cnopts=cnopts) as sftp: + print("Connection succesfully stablished ... ") + + try: + with sftp.cd(Path): + sftp.put(FileName) + except: + sftp.mkdir(Path) + with sftp.cd(Path): + sftp.put(FileName) + + + + except BaseException as msg: + logging.writeToFile('%s. [SendTORemote]' % (str(msg))) + + @staticmethod + def SendToS3Cloud(FileName, RemoteBackupCofigID, backupID, scheduleID): + import boto3 + import json + import time + from websiteFunctions.models import RemoteBackupConfig, WPSitesBackup, RemoteBackupSchedule + import plogical.randomPassword as randomPassword + try: + print("UPloading to S3") + Backupobj = WPSitesBackup.objects.get(pk=backupID) + backupConfig = json.loads(Backupobj.config) + websitedomain = backupConfig['WebDomain'] + RemoteBackupOBJ = RemoteBackupConfig.objects.get(pk=RemoteBackupCofigID) + config = json.loads(RemoteBackupOBJ.config) + provider = config['Provider'] + if provider == "Backblaze": + EndURl = config['EndUrl'] + elif provider == "Amazon": + EndURl = "https://s3.us-east-1.amazonaws.com" + elif provider == "Wasabi": + EndURl = "https://s3.wasabisys.com" + + AccessKey = config['AccessKey'] + SecertKey = config['SecertKey'] + + session = boto3.session.Session() + + client = session.client( + 's3', + endpoint_url=EndURl, + aws_access_key_id=AccessKey, + aws_secret_access_key=SecertKey, + verify=False + ) + + # ############Creating Bucket + # BucketName = randomPassword.generate_pass().lower() + # print("BucketName...%s"%BucketName) + # + # try: + # client.create_bucket(Bucket=BucketName) + # except BaseException as msg: + # print("Error in Creating bucket...: %s" % str(msg)) + # logging.writeToFile("Create bucket error---%s:" % str(msg)) + + + ####getting Bucket from backup schedule + Scheduleobj = RemoteBackupSchedule.objects.get(pk=scheduleID) + Scheduleconfig = json.loads(Scheduleobj.config) + BucketName = Scheduleconfig['BucketName'] + #####Uploading File + + uploadfilename = 'backup-' + websitedomain + "-" + time.strftime("%m.%d.%Y_%H-%M-%S") + print("uploadfilename....%s"%uploadfilename) + + try: + res = client.upload_file(Filename=FileName, Bucket=BucketName, Key=uploadfilename) + print("res of Uploading...: %s" % res) + + except BaseException as msg: + print("Error in Uploading...: %s" % msg) + + ###################### version id, this only applied to blackbaze + try: + + s3 = boto3.resource( + 's3', + endpoint_url=EndURl, + aws_access_key_id=AccessKey, + aws_secret_access_key=SecertKey, + ) + + bucket = BucketName + key = uploadfilename + versions = s3.Bucket(bucket).object_versions.filter(Prefix=key) + data = {} + + for version in versions: + obj = version.get() + print("VersionId---%s:" % obj.get('VersionId')) + data['backupVersionId'] = obj.get('VersionId') + + ab = os.path.getsize(FileName) + filesize = float(ab) / 1024.0 + + backupConfig['uploadfilename'] = uploadfilename + backupConfig['backupVersionId'] = data['backupVersionId'] + backupConfig['BucketName'] = BucketName + backupConfig['Uplaodingfilesize'] = filesize + Backupobj.config = json.dumps(backupConfig) + Backupobj.save() + + except BaseException as msg: + print("Version ID Error: %s"%str(msg)) + + + + + + + except BaseException as msg: + print('%s. [SendToS3Cloud]' % (str(msg))) + logging.writeToFile('%s. [SendToS3Cloud]' % (str(msg))) + def main(): parser = argparse.ArgumentParser(description='CyberPanel Installer') @@ -967,6 +1367,10 @@ def main(): parser.add_argument('--planName', help='Plan name for AWS!') args = parser.parse_args() + if args.function == '30 Minutes' or args.function == '30 Minutes' or args.function == '1 Hour' or args.function == '6 Hours' or args.function == '12 Hours' or args.function == '1 Day' or args.function == '3 Days' or args.function == '1 Week': + IncScheduler.RemoteBackup(args.function) + return 0 + if args.function == 'forceRunAWSBackup': IncScheduler.forceRunAWSBackup(args.planName) return 0 @@ -979,10 +1383,10 @@ def main(): ib = IncScheduler('startBackup', {'freq': args.function}) ib.start() - ### IncScheduler.startBackup(args.function) + IncScheduler.runGoogleDriveBackups(args.function) IncScheduler.git(args.function) IncScheduler.checkDiskUsage() @@ -993,4 +1397,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index 2fcbe0a95..6ea2f6e88 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -15,7 +15,7 @@ django.setup() import threading as multi from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging import subprocess -from websiteFunctions.models import ChildDomains, Websites, WPSites, WPStaging, wpplugins, WPSitesBackup +from websiteFunctions.models import ChildDomains, Websites, WPSites, WPStaging, wpplugins, WPSitesBackup, RemoteBackupConfig from plogical import randomPassword from plogical.mysqlUtilities import mysqlUtilities from databases.models import Databases @@ -2261,7 +2261,12 @@ $parameters = array( wpsite = WPSites.objects.get(pk=self.extraArgs['WPid']) Adminobj = Administrator.objects.get(pk=self.extraArgs['adminID']) Backuptype = self.extraArgs['Backuptype'] - + try: + BackupDestination = self.extraArgs['BackupDestination'] + SFTP_ID = self.extraArgs['SFTPID'] + except: + BackupDestination = 'Local' + SFTP_ID = None website = wpsite.owner PhpVersion = website.phpSelection @@ -2272,12 +2277,16 @@ $parameters = array( php = PHPManager.getPHPString(PhpVersion) FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + ### Website and Database Both === 1 if Backuptype == "1": logging.statusWriter(self.tempStatusPath, 'Getting database...,20') - command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path={WPsitepath}' + command = f'sudo -u {VHuser} {FinalPHPPath} -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path={WPsitepath}' + print(command) retStatus, stdoutput = ProcessUtilities.outputExecutioner(command, VHuser, None, None, 1) + print(stdoutput) if stdoutput.find('Error:') == -1: DataBaseName = stdoutput.rstrip("\n") @@ -2285,7 +2294,7 @@ $parameters = array( raise BaseException(stdoutput) - command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path={WPsitepath}' + command = f'sudo -u {VHuser} {FinalPHPPath} -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path={WPsitepath}' retStatus, stdoutput = ProcessUtilities.outputExecutioner(command,VHuser, None, None, 1) if stdoutput.find('Error:') == -1: @@ -2314,7 +2323,7 @@ $parameters = array( ### Make directory for backup logging.statusWriter(self.tempStatusPath, 'Creating Backup Directory...,40') - command = f"mkdir -p {self.tempPath}/public_html" + command = f"sudo -u {VHuser} mkdir -p {self.tempPath}/public_html" result, stdout = ProcessUtilities.outputExecutioner(command, VHuser, None, None, 1) if result == 0: @@ -2341,6 +2350,8 @@ $parameters = array( config['Webadmin_id'] = website.admin_id config['name'] = 'backup-' + websitedomain + "-" + time.strftime("%m.%d.%Y_%H-%M-%S") config['Backuptype'] = "Both Website and DataBase" + config['BackupDestination'] = BackupDestination + config['SFTP_ID'] = SFTP_ID ###############Create config.Json file #command = "sudo -u %s touch /home/cyberpanel/config.json" % (VHuser) @@ -2355,7 +2366,7 @@ $parameters = array( os.chmod(configPath, 0o600) - command = f"cp -R {configPath} {self.tempPath}" + command = f"sudo -u {VHuser} cp -R {configPath} {self.tempPath}" retStatus, stdoutput = ProcessUtilities.outputExecutioner(command, VHuser, None, None, 1) if retStatus == 0: raise BaseException(stdoutput) @@ -2433,8 +2444,9 @@ $parameters = array( raise BaseException(stdout) logging.statusWriter(self.tempStatusPath, 'Completed.[200]') - return 1, f"/home/backup/{config['name']}.tar.gz" + return 1, f"/home/backup/{config['name']}.tar.gz", backupobj.id + #### Only Website Data === 2 elif Backuptype == "2": ###Onlye website data ### Create secure folder @@ -2485,6 +2497,8 @@ $parameters = array( config['Webadmin_id'] = website.admin_id config['name'] = 'backup-' + websitedomain + "-" + time.strftime("%m.%d.%Y_%H-%M-%S") config['Backuptype'] = "Website Backup" + config['BackupDestination'] = BackupDestination + config['SFTP_ID'] = SFTP_ID ###############Create config.Json file # command = "sudo -u %s touch /home/cyberpanel/config.json" % (VHuser) @@ -2562,7 +2576,9 @@ $parameters = array( raise BaseException(stdout) logging.statusWriter(self.tempStatusPath, 'Completed.[200]') - return 1, f"/home/backup/{config['name']}.tar.gz" + return 1, f"/home/backup/{config['name']}.tar.gz", backupobj.id + + #### Only Database === 3 else: ###only backup of data base logging.statusWriter(self.tempStatusPath, 'Getting database...,20') @@ -2626,6 +2642,8 @@ $parameters = array( config['Webadmin_id'] = website.admin_id config['name'] = 'backup-' + websitedomain + "-" + time.strftime("%m.%d.%Y_%H-%M-%S") config['Backuptype'] = "DataBase Backup" + config['BackupDestination'] = BackupDestination + config['SFTP_ID'] = SFTP_ID ###############Create config.Json file # command = "sudo -u %s touch /home/cyberpanel/config.json" % (VHuser) # ProcessUtilities.executioner(command) @@ -2687,7 +2705,7 @@ $parameters = array( raise BaseException(stdout) logging.statusWriter(self.tempStatusPath, 'Completed.[200]') - return 1, f"/home/backup/{config['name']}.tar.gz" + return 1, f"/home/backup/{config['name']}.tar.gz", backupobj.id except BaseException as msg: logging.writeToFile("Error WPCreateBackup ....... %s" % str(msg)) @@ -2697,7 +2715,7 @@ $parameters = array( except: pass logging.statusWriter(self.tempStatusPath, f'{str(msg)}. [404]') - return 0, str(msg) + return 0, str(msg), None def RestoreWPbackupNow(self): try: @@ -2705,7 +2723,9 @@ $parameters = array( from managePHP.phpManager import PHPManager from websiteFunctions.website import WebsiteManager from packages.models import Package - + import pysftp + import pysftp as sftp + import boto3 if os.path.exists(ProcessUtilities.debugPath): logging.writeToFile("Error Restore WP backup Now ....... start:%s"% self.extraArgs['Domain']) @@ -2733,177 +2753,75 @@ $parameters = array( #####Check Backup Type BackupType = config['Backuptype'] + BackupDestination = config['BackupDestination'] + RemoteBackupID = config['SFTP_ID'] - ##### CHeck if Backup type is Only Database - if BackupType == 'DataBase Backup': - if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): - wpsite = WPSites.objects.get(pk=DesSiteID) - VHuser = wpsite.owner.externalApp - PhpVersion = wpsite.owner.phpSelection - newWPpath = wpsite.path - newurl = wpsite.FinalURL - ## get WPsite Database name and usr - php = PHPManager.getPHPString(PhpVersion) - FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + #SFTPBackups + if BackupDestination == 'SFTP': + RemoteBackupOBJ = RemoteBackupConfig.objects.get(pk=RemoteBackupID) + RemoteBackupconf = json.loads(RemoteBackupOBJ.config) + HostName = RemoteBackupconf['Hostname'] + Username = RemoteBackupconf['Username'] + Password = RemoteBackupconf['Password'] + Path = RemoteBackupconf['Path'] + cnopts = sftp.CnOpts() + cnopts.hostkeys = None - #####Get DBname - command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( - VHuser, FinalPHPPath, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + with pysftp.Connection(HostName, username=Username, password=Password, cnopts=cnopts) as sftp: + logging.statusWriter(self.tempStatusPath, 'Downloading Backups...,15') + loaclpath = "/home/cyberpanel/%s.tar.gz" % BackUpFileName + remotepath = "%s/%s.tar.gz" % (Path, BackUpFileName) + logging.writeToFile("Downloading start") + sftp.get(str(remotepath), str(loaclpath)) - if stdout.find('Error:') == -1: - Finaldbname = stdout.rstrip("\n") - else: - raise BaseException(stdout) + command = "mv %s /home/backup"%loaclpath + ProcessUtilities.executioner(command) - #####Get DBuser - command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( - VHuser, FinalPHPPath, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if stdout.find('Error:') == -1: - Finaldbuser = stdout.rstrip("\n") - else: - raise BaseException(stdout) - - #####Get DBpsswd - command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( - VHuser, FinalPHPPath, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if stdout.find('Error:') == -1: - Finaldbpasswd = stdout.rstrip("\n") - else: - raise BaseException(stdout) - - ### ##Create secure folder - - ACLManager.CreateSecureDir() - RandomPath = str(randint(1000, 9999)) - self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) - - command = f'mkdir -p {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') - - #####First copy backup file to temp and then Unzip - command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - #### Make temp dir ab for unzip - command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( - VHuser, self.tempPath, BackUpFileName, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - # dump Mysql file in unzippath path - unzippathdb = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % (self.tempPath, oldtemppath, DumpFileName) - command = "mysql -u root %s < %s" % (Finaldbname, unzippathdb) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70') - #####SetUp DataBase Settings - ##set DBName - command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( - VHuser, FinalPHPPath, Finaldbname, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if stdout.find('Error:') > -1: - raise BaseException(stdout) - - ##set DBuser - command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( - VHuser, FinalPHPPath, Finaldbuser, newWPpath) - - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if stdout.find('Error:') > -1: - raise BaseException(stdout) - - ##set DBpasswd - command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( - VHuser, FinalPHPPath, Finaldbpasswd, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if stdout.find('Error:') > -1: - raise BaseException(stdout) - - logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') - ########Now Replace URL's - command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( - VHuser, newWPpath, oldurl, newurl) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if stdout.find('Error:') > -1: - raise BaseException(stdout) - - command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( - VHuser, newWPpath, newurl, newurl) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if stdout.find('Error:') > -1: - raise BaseException(stdout) - - command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' - ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - # ##Remove temppath - command = f'rm -rf {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - ###Restart Server - - from plogical.installUtilities import installUtilities - installUtilities.reStartLiteSpeed() - ####Check if BAckup type is Only Webdata - elif BackupType == 'Website Backup': - if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): - wpsite = WPSites.objects.get(pk=DesSiteID) - webobj = Websites.objects.get(pk=wpsite.owner_id) - ag = WPSites.objects.filter(owner=webobj).count() - if ag > 0: - ###Website found --> Wpsite Found - finalurl = "%s%s" % (webobj.domain, oldurl[oldurl.find('/'):]) - try: - WPobj = WPSites.objects.get(FinalURL=finalurl, owner=webobj) - ###Website found --> WPsite Found --> Final URL Match - #### Do not create Ne site - ### get WPsite Database name and usr + ##### CHeck if Backup type is Only Database + if BackupType == 'DataBase Backup': + if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): + wpsite = WPSites.objects.get(pk=DesSiteID) VHuser = wpsite.owner.externalApp - PhpVersion = WPobj.owner.phpSelection - newWPpath = WPobj.path + PhpVersion = wpsite.owner.phpSelection + newWPpath = wpsite.path + newurl = wpsite.FinalURL + + ## get WPsite Database name and usr php = PHPManager.getPHPString(PhpVersion) FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) - ### Create secure folder + #####Get DBname + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') == -1: + Finaldbname = stdout.rstrip("\n") + else: + raise BaseException(stdout) + + #####Get DBuser + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') == -1: + Finaldbuser = stdout.rstrip("\n") + else: + raise BaseException(stdout) + + #####Get DBpsswd + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') == -1: + Finaldbpasswd = stdout.rstrip("\n") + else: + raise BaseException(stdout) + + ### ##Create secure folder ACLManager.CreateSecureDir() RandomPath = str(randint(1000, 9999)) @@ -2923,6 +2841,371 @@ $parameters = array( logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') + #####First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + # dump Mysql file in unzippath path + unzippathdb = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % (self.tempPath, oldtemppath, DumpFileName) + command = "mysql -u root %s < %s" % (Finaldbname, unzippathdb) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70') + #####SetUp DataBase Settings + ##set DBName + command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbname, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBuser + command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbuser, newWPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBpasswd + command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbpasswd, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, newWPpath, oldurl, newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, newWPpath, newurl, newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + ###Restart Server + + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() + ####Check if BAckup type is Only Webdata + elif BackupType == 'Website Backup': + if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): + wpsite = WPSites.objects.get(pk=DesSiteID) + webobj = Websites.objects.get(pk=wpsite.owner_id) + ag = WPSites.objects.filter(owner=webobj).count() + if ag > 0: + ###Website found --> Wpsite Found + finalurl = "%s%s" % (webobj.domain, oldurl[oldurl.find('/'):]) + try: + WPobj = WPSites.objects.get(FinalURL=finalurl, owner=webobj) + ###Website found --> WPsite Found --> Final URL Match + #### Do not create Ne site + ### get WPsite Database name and usr + VHuser = wpsite.owner.externalApp + PhpVersion = WPobj.owner.phpSelection + newWPpath = WPobj.path + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, newWPpath, oldurl, finalurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, newWPpath, finalurl, finalurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + except: + ####Website found --> WPsite Found --> Final URL Not Match + ####Create new obj and call wordpressnew + Newurl = wpsite.FinalURL + WPpath = wpsite.path + VHuser = wpsite.owner.externalApp + PhpVersion = wpsite.owner.phpSelection + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % ( + VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, WPpath, oldurl, Newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, WPpath, Newurl, Newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={WPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + elif (DomainName != "" and int(self.extraArgs['DesSiteID']) == -1): + DataToPass = {} + + DataToPass['title'] = config['WPtitle'] + DataToPass['domain'] = DomainName + DataToPass['WPVersion'] = "6.0" + DataToPass['adminUser'] = config['WebVHuser'] + DataToPass['Email'] = config['WebadminEmail'] + DataToPass['PasswordByPass'] = config['DatabaseUser'] + DataToPass['AutomaticUpdates'] = config['WPAutoUpdates'] + DataToPass['Plugins'] = config['WPPluginUpdates'] + DataToPass['Themes'] = config['WPThemeUpdates'] + DataToPass['websiteOwner'] = WebOwner + DataToPass['package'] = packegs + try: + oldpath = config['WPsitepath'] + abc = oldpath.split("/") + newpath = abc[4] + oldhome = "0" + except BaseException as msg: + oldhome = "1" + + if self.extraArgs['path'] == '': + newurl = DomainName + else: + newurl = "%s/%s" % (DomainName, self.extraArgs['path']) + + DataToPass['path'] = self.extraArgs['path'] + + DataToPass['home'] = self.extraArgs['home'] + + ab = WebsiteManager() + coreResult = ab.submitWorpressCreation(userID, DataToPass) + coreResult1 = json.loads((coreResult).content) + logging.writeToFile("WP Creating website result....%s" % coreResult1) + reutrntempath = coreResult1['tempStatusPath'] + while (1): + lastLine = open(reutrntempath, 'r').read() + logging.writeToFile("Error WP creating lastline ....... %s" % lastLine) + if lastLine.find('[200]') > -1: + break + elif lastLine.find('[404]') > -1: + logging.statusWriter(self.tempStatusPath, + 'Failed to Create WordPress: error: %s. [404]' % lastLine) + return 0 + else: + logging.statusWriter(self.tempStatusPath, 'Creating WordPress....,20') + time.sleep(2) + + logging.statusWriter(self.tempStatusPath, 'Restoring site ....,30') + NewWPsite = WPSites.objects.get(FinalURL=newurl) + VHuser = NewWPsite.owner.externalApp + PhpVersion = NewWPsite.owner.phpSelection + newWPpath = NewWPsite.path + + ###### Same code already used in Existing site + + ### get WPsite Database name and usr + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {NewWPsite.owner.externalApp}:{NewWPsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,40') + ###First copy backup file to temp and then Unzip command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) @@ -2944,7 +3227,13 @@ $parameters = array( if result == 0: raise BaseException(stdout) - unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + logging.statusWriter(self.tempStatusPath, 'Copying Data File...,60') + ###Copy backup content to newsite + if oldhome == "0": + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + else: + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/" % ( + self.tempPath, oldtemppath) command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) @@ -2963,14 +3252,14 @@ $parameters = array( logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') ########Now Replace URL's command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( - VHuser, newWPpath, oldurl, finalurl) + VHuser, newWPpath, oldurl, newurl) result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) if stdout.find('Error:') > -1: raise BaseException(stdout) command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( - VHuser, newWPpath, finalurl, finalurl) + VHuser, newWPpath, newurl, newurl) result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) if stdout.find('Error:') > -1: @@ -2979,287 +3268,417 @@ $parameters = array( command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' ProcessUtilities.outputExecutioner(command, None, None, None, 1) - # ##Remove temppath + ##Remove temppath command = f'rm -rf {self.tempPath}' result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if result == 0: - raise BaseException(stdout) - - except: - ####Website found --> WPsite Found --> Final URL Not Match - ####Create new obj and call wordpressnew - Newurl = wpsite.FinalURL - WPpath = wpsite.path - VHuser = wpsite.owner.externalApp - PhpVersion = wpsite.owner.phpSelection - php = PHPManager.getPHPString(PhpVersion) - FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) - - - ### Create secure folder - - ACLManager.CreateSecureDir() - RandomPath = str(randint(1000, 9999)) - self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) - - command = f'mkdir -p {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') - - ###First copy backup file to temp and then Unzip - command = "sudo -u %s cp -R /home/backup/%s* %s" % ( - VHuser, BackUpFileName, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - #### Make temp dir ab for unzip - command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( - VHuser, self.tempPath, BackUpFileName, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) - - command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, WPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, WPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - - - logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') - ########Now Replace URL's - command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( - VHuser, WPpath, oldurl, Newurl) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: raise BaseException(stdout) - command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( - VHuser, WPpath, Newurl, Newurl) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + ###Restart Server - if stdout.find('Error:') > -1: - raise BaseException(stdout) + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() - command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={WPpath}' - ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - # ##Remove temppath - command = f'rm -rf {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - elif (DomainName != "" and int(self.extraArgs['DesSiteID']) == -1): - DataToPass = {} - - DataToPass['title'] = config['WPtitle'] - DataToPass['domain'] = DomainName - DataToPass['WPVersion'] = "6.0" - DataToPass['adminUser'] = config['WebVHuser'] - DataToPass['Email'] = config['WebadminEmail'] - DataToPass['PasswordByPass'] = config['DatabaseUser'] - DataToPass['AutomaticUpdates'] = config['WPAutoUpdates'] - DataToPass['Plugins'] = config['WPPluginUpdates'] - DataToPass['Themes'] = config['WPThemeUpdates'] - DataToPass['websiteOwner'] = WebOwner - DataToPass['package'] = packegs - try: - oldpath = config['WPsitepath'] - abc = oldpath.split("/") - newpath = abc[4] - oldhome = "0" - except BaseException as msg: - oldhome = "1" - - if self.extraArgs['path'] == '': - newurl = DomainName + ####Check if backup type is Both web and DB else: - newurl = "%s/%s" % (DomainName, self.extraArgs['path']) + ############## Existing site + if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): + wpsite = WPSites.objects.get(pk=DesSiteID) + webobj = Websites.objects.get(pk=wpsite.owner_id) + ag = WPSites.objects.filter(owner=webobj).count() + if ag > 0: + ###Website found --> Wpsite Found + finalurl = "%s%s" % (webobj.domain, oldurl[oldurl.find('/'):]) + try: + WPobj = WPSites.objects.get(FinalURL=finalurl, owner=webobj) + ###Website found --> WPsite Found --> Final URL Match + #### Do not create Ne site + ### get WPsite Database name and usr + VHuser = wpsite.owner.externalApp + PhpVersion = WPobj.owner.phpSelection + newWPpath = WPobj.path + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) - DataToPass['path'] = self.extraArgs['path'] + ######Get DBname + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) - DataToPass['home'] = self.extraArgs['home'] + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - ab = WebsiteManager() - coreResult = ab.submitWorpressCreation(userID, DataToPass) - coreResult1 = json.loads((coreResult).content) - logging.writeToFile("WP Creating website result....%s" % coreResult1) - reutrntempath = coreResult1['tempStatusPath'] - while (1): - lastLine = open(reutrntempath, 'r').read() - logging.writeToFile("Error WP creating lastline ....... %s" % lastLine) - if lastLine.find('[200]') > -1: - break - elif lastLine.find('[404]') > -1: - logging.statusWriter(self.tempStatusPath, - 'Failed to Create WordPress: error: %s. [404]' % lastLine) - return 0 - else: - logging.statusWriter(self.tempStatusPath, 'Creating WordPress....,20') - time.sleep(2) + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbname = stdout.rstrip("\n") - logging.statusWriter(self.tempStatusPath, 'Restoring site ....,30') - NewWPsite = WPSites.objects.get(FinalURL=newurl) - VHuser = NewWPsite.owner.externalApp - PhpVersion = NewWPsite.owner.phpSelection - newWPpath = NewWPsite.path + ######Get DBuser + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) - ###### Same code already used in Existing site + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - ### get WPsite Database name and usr - php = PHPManager.getPHPString(PhpVersion) - FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbuser = stdout.rstrip("\n") + #####Get DBpsswd + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) - ### Create secure folder + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - ACLManager.CreateSecureDir() - RandomPath = str(randint(1000, 9999)) - self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbpasswd = stdout.rstrip("\n") - command = f'mkdir -p {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + ### Create secure folder - if result == 0: - raise BaseException(stdout) + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) - command = f'chown -R {NewWPsite.owner.externalApp}:{NewWPsite.owner.externalApp} {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if result == 0: - raise BaseException(stdout) + if result == 0: + raise BaseException(stdout) - logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,40') + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - ###First copy backup file to temp and then Unzip - command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise BaseException(stdout) - if result == 0: - raise BaseException(stdout) + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') - #### Make temp dir ab for unzip - command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if result == 0: - raise BaseException(stdout) + if result == 0: + raise BaseException(stdout) - command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( - VHuser, self.tempPath, BackUpFileName, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if result == 0: - raise BaseException(stdout) + if result == 0: + raise BaseException(stdout) - logging.statusWriter(self.tempStatusPath, 'Copying Data File...,60') - ###Copy backup content to newsite - if oldhome == "0": - unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) - else: - unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/" % ( - self.tempPath, oldtemppath) + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise BaseException(stdout) - if result == 0: - raise BaseException(stdout) + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) - command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if result == 0: - raise BaseException(stdout) + if result == 0: + raise BaseException(stdout) + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise BaseException(stdout) - logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') - ########Now Replace URL's - command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( - VHuser, newWPpath, oldurl, newurl) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + # dump Mysql file in unzippath path + unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % ( + self.tempPath, oldtemppath, DumpFileName) + command = "mysql -u root %s < %s" % (Finaldbname, unzippath2) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + if result == 0: + raise BaseException(stdout) - command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( - VHuser, newWPpath, newurl, newurl) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70') + #####SetUp DataBase Settings + ##set DBName + command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbname, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + if stdout.find('Error:') > -1: + raise BaseException(stdout) - command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' - ProcessUtilities.outputExecutioner(command, None, None, None, 1) + ##set DBuser + command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbuser, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - ##Remove temppath - command = f'rm -rf {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if stdout.find('Error:') > -1: + raise BaseException(stdout) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + ##set DBpasswd + command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbpasswd, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - ###Restart Server + if stdout.find('Error:') > -1: + raise BaseException(stdout) - from plogical.installUtilities import installUtilities - installUtilities.reStartLiteSpeed() + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, newWPpath, oldurl, finalurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, newWPpath, finalurl, finalurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + except: + ####Website found --> WPsite Found --> Final URL Not Match + ####Create new obj and call wordpressnew + Newurl = wpsite.FinalURL + WPpath = wpsite.path + VHuser = wpsite.owner.externalApp + PhpVersion = wpsite.owner.phpSelection + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + ######Get DBname + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, WPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbname = stdout.rstrip("\n") + + ######Get DBuser + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, WPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbuser = stdout.rstrip("\n") + + #####Get DBpsswd + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, WPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbpasswd = stdout.rstrip("\n") + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % ( + VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + # dump Mysql file in unzippath path + unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % ( + self.tempPath, oldtemppath, DumpFileName) + command = "mysql -u root %s < %s" % (Finaldbname, unzippath2) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70') + #####SetUp DataBase Settings + ##set DBName + command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbname, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBuser + command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbuser, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBpasswd + command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbpasswd, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, WPpath, oldurl, Newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, WPpath, Newurl, Newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={WPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + ############## New Site + elif(DomainName != "" and int(self.extraArgs['DesSiteID']) == -1): + ###############Create New WordPressSite First + # logging.writeToFile("New Website Domain ....... %s" % str(DomainName)) + # logging.writeToFile("New Website Domain path....... %s" % str(self.extraArgs['path'])) + DataToPass = {} + + DataToPass['title'] = config['WPtitle'] + DataToPass['domain'] = DomainName + DataToPass['WPVersion'] = "6.0" + DataToPass['adminUser'] = config['WebVHuser'] + DataToPass['Email'] = config['WebadminEmail'] + DataToPass['PasswordByPass'] = config['DatabaseUser'] + DataToPass['AutomaticUpdates'] = config['WPAutoUpdates'] + DataToPass['Plugins'] = config['WPPluginUpdates'] + DataToPass['Themes'] = config['WPThemeUpdates'] + DataToPass['websiteOwner'] = WebOwner + DataToPass['package'] = packegs + try: + oldpath = config['WPsitepath'] + abc = oldpath.split("/") + newpath = abc[4] + oldhome = "0" + except BaseException as msg: + oldhome = "1" + + if self.extraArgs['path'] == '': + newurl = DomainName + else: + newurl = "%s/%s"%(DomainName, self.extraArgs['path']) + + DataToPass['path'] = self.extraArgs['path'] + + DataToPass['home'] = self.extraArgs['home'] + + ab = WebsiteManager() + coreResult = ab.submitWorpressCreation(userID, DataToPass) + coreResult1 = json.loads((coreResult).content) + logging.writeToFile("WP Creating website result....%s" % coreResult1) + reutrntempath = coreResult1['tempStatusPath'] + while (1): + lastLine = open(reutrntempath, 'r').read() + logging.writeToFile("Error WP creating lastline ....... %s" % lastLine) + if lastLine.find('[200]') > -1: + break + elif lastLine.find('[404]') > -1: + logging.statusWriter(self.tempStatusPath, + 'Failed to Create WordPress: error: %s. [404]' % lastLine) + return 0 + else: + logging.statusWriter(self.tempStatusPath, 'Creating WordPress....,20') + time.sleep(2) + + logging.statusWriter(self.tempStatusPath, 'Restoring site ....,30') + logging.writeToFile("Create site url =%s"%newurl) + NewWPsite = WPSites.objects.get(FinalURL=newurl) + VHuser = NewWPsite.owner.externalApp + PhpVersion = NewWPsite.owner.phpSelection + newWPpath = NewWPsite.path + + ###### Same code already used in Existing site - ####Check if backup type is Both web and DB - else: - ############## Existing site - if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): - wpsite = WPSites.objects.get(pk=DesSiteID) - webobj = Websites.objects.get(pk=wpsite.owner_id) - ag = WPSites.objects.filter(owner=webobj).count() - if ag > 0: - ###Website found --> Wpsite Found - finalurl = "%s%s" % (webobj.domain, oldurl[oldurl.find('/'):]) - try: - WPobj = WPSites.objects.get(FinalURL=finalurl, owner=webobj) - ###Website found --> WPsite Found --> Final URL Match - #### Do not create Ne site ### get WPsite Database name and usr - VHuser = wpsite.owner.externalApp - PhpVersion = WPobj.owner.phpSelection - newWPpath = WPobj.path php = PHPManager.getPHPString(PhpVersion) FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) ######Get DBname command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( - VHuser, FinalPHPPath, newWPpath) + VHuser, FinalPHPPath, newWPpath) result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) @@ -3270,7 +3689,7 @@ $parameters = array( ######Get DBuser command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( - VHuser, FinalPHPPath, newWPpath) + VHuser, FinalPHPPath, newWPpath) result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) @@ -3281,7 +3700,7 @@ $parameters = array( #####Get DBpsswd command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( - VHuser, FinalPHPPath, newWPpath) + VHuser, FinalPHPPath, newWPpath) result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) @@ -3302,13 +3721,13 @@ $parameters = array( if result == 0: raise BaseException(stdout) - command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + command = f'chown -R {NewWPsite.owner.externalApp}:{NewWPsite.owner.externalApp} {self.tempPath}' result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) if result == 0: raise BaseException(stdout) - logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,40') ###First copy backup file to temp and then Unzip command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) @@ -3325,474 +3744,2245 @@ $parameters = array( raise BaseException(stdout) command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Copying Data File...,60') + ###Copy backup content to newsite + if oldhome == "0": + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + else: + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/" % (self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + # dump Mysql file in unzippath path + unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % (self.tempPath, oldtemppath, DumpFileName) + command = "mysql -u root %s < %s" % (Finaldbname, unzippath2) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,80') + #####SetUp DataBase Settings + ##set DBName + command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbname, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBuser + command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbuser, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBpasswd + command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbpasswd, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, newWPpath, oldurl, newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, newWPpath, newurl, newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + + ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ###Restart Server + + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() + + + ###S#Backups + elif BackupDestination == 'S3': + uploadfilename = config['uploadfilename'] + BucketName = config['BucketName'] + RemoteBackupOBJ = RemoteBackupConfig.objects.get(pk=RemoteBackupID) + RemoteBackupconf = json.loads(RemoteBackupOBJ.config) + provider = RemoteBackupconf['Provider'] + if provider == "Backblaze": + EndURl = RemoteBackupconf['EndUrl'] + elif provider == "Amazon": + EndURl = "https://s3.us-east-1.amazonaws.com" + elif provider == "Wasabi": + EndURl = "https://s3.wasabisys.com" + AccessKey = RemoteBackupconf['AccessKey'] + SecertKey = RemoteBackupconf['SecertKey'] + + session = boto3.session.Session() + + client = session.client( + 's3', + endpoint_url=EndURl, + aws_access_key_id=AccessKey, + aws_secret_access_key=SecertKey, + verify=False + ) + + FinalZipPath = "/home/cyberpanel/%s.tar.gz" % (uploadfilename) + try: + client.download_file(BucketName, uploadfilename, FinalZipPath) + except BaseException as msg: + logging.writeToFile("Error in downloadfile: ..%s"%str(msg)) + + command = "mv %s /home/backup" % FinalZipPath + ProcessUtilities.executioner(command) + + ##### CHeck if Backup type is Only Database + if BackupType == 'DataBase Backup': + if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): + wpsite = WPSites.objects.get(pk=DesSiteID) + VHuser = wpsite.owner.externalApp + PhpVersion = wpsite.owner.phpSelection + newWPpath = wpsite.path + newurl = wpsite.FinalURL + + ## get WPsite Database name and usr + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + #####Get DBname + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') == -1: + Finaldbname = stdout.rstrip("\n") + else: + raise BaseException(stdout) + + #####Get DBuser + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') == -1: + Finaldbuser = stdout.rstrip("\n") + else: + raise BaseException(stdout) + + #####Get DBpsswd + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') == -1: + Finaldbpasswd = stdout.rstrip("\n") + else: + raise BaseException(stdout) + + ### ##Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') + + #####First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( VHuser, self.tempPath, BackUpFileName, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if result == 0: - raise BaseException(stdout) + if result == 0: + raise BaseException(stdout) - unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + # dump Mysql file in unzippath path + unzippathdb = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % (self.tempPath, oldtemppath, DumpFileName) + command = "mysql -u root %s < %s" % (Finaldbname, unzippathdb) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise BaseException(stdout) - if result == 0: - raise BaseException(stdout) - - command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - # dump Mysql file in unzippath path - unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % ( - self.tempPath, oldtemppath, DumpFileName) - command = "mysql -u root %s < %s" % (Finaldbname, unzippath2) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70') - #####SetUp DataBase Settings - ##set DBName - command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( + logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70') + #####SetUp DataBase Settings + ##set DBName + command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( VHuser, FinalPHPPath, Finaldbname, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + if stdout.find('Error:') > -1: + raise BaseException(stdout) - ##set DBuser - command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( + ##set DBuser + command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( VHuser, FinalPHPPath, Finaldbuser, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - ##set DBpasswd - command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBpasswd + command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( VHuser, FinalPHPPath, Finaldbpasswd, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + if stdout.find('Error:') > -1: + raise BaseException(stdout) - logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') - ########Now Replace URL's - command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( - VHuser, newWPpath, oldurl, finalurl) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, newWPpath, oldurl, newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + if stdout.find('Error:') > -1: + raise BaseException(stdout) - command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( - VHuser, newWPpath, finalurl, finalurl) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, newWPpath, newurl, newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + if stdout.find('Error:') > -1: + raise BaseException(stdout) - command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' - ProcessUtilities.outputExecutioner(command, None, None, None, 1) + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) - # ##Remove temppath - command = f'rm -rf {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if result == 0: - raise BaseException(stdout) + if result == 0: + raise BaseException(stdout) - except: - ####Website found --> WPsite Found --> Final URL Not Match - ####Create new obj and call wordpressnew - Newurl = wpsite.FinalURL - WPpath = wpsite.path - VHuser = wpsite.owner.externalApp - PhpVersion = wpsite.owner.phpSelection - php = PHPManager.getPHPString(PhpVersion) - FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + ###Restart Server - ######Get DBname - command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( - VHuser, FinalPHPPath, WPpath) + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() + ####Check if BAckup type is Only Webdata + elif BackupType == 'Website Backup': + if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): + wpsite = WPSites.objects.get(pk=DesSiteID) + webobj = Websites.objects.get(pk=wpsite.owner_id) + ag = WPSites.objects.filter(owner=webobj).count() + if ag > 0: + ###Website found --> Wpsite Found + finalurl = "%s%s" % (webobj.domain, oldurl[oldurl.find('/'):]) + try: + WPobj = WPSites.objects.get(FinalURL=finalurl, owner=webobj) + ###Website found --> WPsite Found --> Final URL Match + #### Do not create Ne site + ### get WPsite Database name and usr + VHuser = wpsite.owner.externalApp + PhpVersion = WPobj.owner.phpSelection + newWPpath = WPobj.path + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + ### Create secure folder - if stdout.find('Error:') > -1: - raise BaseException(stdout) - else: - Finaldbname = stdout.rstrip("\n") + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) - ######Get DBuser - command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( - VHuser, FinalPHPPath, WPpath) + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise BaseException(stdout) - if stdout.find('Error:') > -1: - raise BaseException(stdout) - else: - Finaldbuser = stdout.rstrip("\n") + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - #####Get DBpsswd - command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( - VHuser, FinalPHPPath, WPpath) + if result == 0: + raise BaseException(stdout) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') - if stdout.find('Error:') > -1: - raise BaseException(stdout) - else: - Finaldbpasswd = stdout.rstrip("\n") - - ### Create secure folder - - ACLManager.CreateSecureDir() - RandomPath = str(randint(1000, 9999)) - self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) - - command = f'mkdir -p {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') - - ###First copy backup file to temp and then Unzip - command = "sudo -u %s cp -R /home/backup/%s* %s" % ( + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % ( VHuser, BackUpFileName, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if result == 0: - raise BaseException(stdout) + if result == 0: + raise BaseException(stdout) - #### Make temp dir ab for unzip - command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if result == 0: - raise BaseException(stdout) + if result == 0: + raise BaseException(stdout) - command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( - VHuser, self.tempPath, BackUpFileName, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if result == 0: - raise BaseException(stdout) + if result == 0: + raise BaseException(stdout) - unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) - command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, WPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if result == 0: - raise BaseException(stdout) + if result == 0: + raise BaseException(stdout) - command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, WPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if result == 0: - raise BaseException(stdout) + if result == 0: + raise BaseException(stdout) - # dump Mysql file in unzippath path - unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % ( - self.tempPath, oldtemppath, DumpFileName) - command = "mysql -u root %s < %s" % (Finaldbname, unzippath2) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, newWPpath, oldurl, finalurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if result == 0: - raise BaseException(stdout) + if stdout.find('Error:') > -1: + raise BaseException(stdout) - logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70') - #####SetUp DataBase Settings - ##set DBName - command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( - VHuser, FinalPHPPath, Finaldbname, WPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, newWPpath, finalurl, finalurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + if stdout.find('Error:') > -1: + raise BaseException(stdout) - ##set DBuser - command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( - VHuser, FinalPHPPath, Finaldbuser, WPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - ##set DBpasswd - command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( - VHuser, FinalPHPPath, Finaldbpasswd, WPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise BaseException(stdout) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + except: + ####Website found --> WPsite Found --> Final URL Not Match + ####Create new obj and call wordpressnew + Newurl = wpsite.FinalURL + WPpath = wpsite.path + VHuser = wpsite.owner.externalApp + PhpVersion = wpsite.owner.phpSelection + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) - logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') - ########Now Replace URL's - command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( - VHuser, WPpath, oldurl, Newurl) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + ### Create secure folder - if stdout.find('Error:') > -1: - raise BaseException(stdout) + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) - command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( - VHuser, WPpath, Newurl, Newurl) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + if result == 0: + raise BaseException(stdout) - command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={WPpath}' - ProcessUtilities.outputExecutioner(command, None, None, None, 1) + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - # ##Remove temppath - command = f'rm -rf {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise BaseException(stdout) - if result == 0: - raise BaseException(stdout) + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') - ############## New Site - elif(DomainName != "" and int(self.extraArgs['DesSiteID']) == -1): - ###############Create New WordPressSite First - # logging.writeToFile("New Website Domain ....... %s" % str(DomainName)) - # logging.writeToFile("New Website Domain path....... %s" % str(self.extraArgs['path'])) - DataToPass = {} + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % ( + VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - DataToPass['title'] = config['WPtitle'] - DataToPass['domain'] = DomainName - DataToPass['WPVersion'] = "6.0" - DataToPass['adminUser'] = config['WebVHuser'] - DataToPass['Email'] = config['WebadminEmail'] - DataToPass['PasswordByPass'] = config['DatabaseUser'] - DataToPass['AutomaticUpdates'] = config['WPAutoUpdates'] - DataToPass['Plugins'] = config['WPPluginUpdates'] - DataToPass['Themes'] = config['WPThemeUpdates'] - DataToPass['websiteOwner'] = WebOwner - DataToPass['package'] = packegs - try: - oldpath = config['WPsitepath'] - abc = oldpath.split("/") - newpath = abc[4] - oldhome = "0" - except BaseException as msg: - oldhome = "1" + if result == 0: + raise BaseException(stdout) - if self.extraArgs['path'] == '': - newurl = DomainName - else: - newurl = "%s/%s"%(DomainName, self.extraArgs['path']) + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - DataToPass['path'] = self.extraArgs['path'] + if result == 0: + raise BaseException(stdout) - DataToPass['home'] = self.extraArgs['home'] + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - ab = WebsiteManager() - coreResult = ab.submitWorpressCreation(userID, DataToPass) - coreResult1 = json.loads((coreResult).content) - logging.writeToFile("WP Creating website result....%s" % coreResult1) - reutrntempath = coreResult1['tempStatusPath'] - while (1): - lastLine = open(reutrntempath, 'r').read() - logging.writeToFile("Error WP creating lastline ....... %s" % lastLine) - if lastLine.find('[200]') > -1: - break - elif lastLine.find('[404]') > -1: - logging.statusWriter(self.tempStatusPath, - 'Failed to Create WordPress: error: %s. [404]' % lastLine) - return 0 + if result == 0: + raise BaseException(stdout) + + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, WPpath, oldurl, Newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, WPpath, Newurl, Newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={WPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + elif (DomainName != "" and int(self.extraArgs['DesSiteID']) == -1): + DataToPass = {} + + DataToPass['title'] = config['WPtitle'] + DataToPass['domain'] = DomainName + DataToPass['WPVersion'] = "6.0" + DataToPass['adminUser'] = config['WebVHuser'] + DataToPass['Email'] = config['WebadminEmail'] + DataToPass['PasswordByPass'] = config['DatabaseUser'] + DataToPass['AutomaticUpdates'] = config['WPAutoUpdates'] + DataToPass['Plugins'] = config['WPPluginUpdates'] + DataToPass['Themes'] = config['WPThemeUpdates'] + DataToPass['websiteOwner'] = WebOwner + DataToPass['package'] = packegs + try: + oldpath = config['WPsitepath'] + abc = oldpath.split("/") + newpath = abc[4] + oldhome = "0" + except BaseException as msg: + oldhome = "1" + + if self.extraArgs['path'] == '': + newurl = DomainName else: - logging.statusWriter(self.tempStatusPath, 'Creating WordPress....,20') - time.sleep(2) + newurl = "%s/%s" % (DomainName, self.extraArgs['path']) - logging.statusWriter(self.tempStatusPath, 'Restoring site ....,30') - NewWPsite = WPSites.objects.get(FinalURL=newurl) - VHuser = NewWPsite.owner.externalApp - PhpVersion = NewWPsite.owner.phpSelection - newWPpath = NewWPsite.path + DataToPass['path'] = self.extraArgs['path'] - ###### Same code already used in Existing site + DataToPass['home'] = self.extraArgs['home'] - ### get WPsite Database name and usr - php = PHPManager.getPHPString(PhpVersion) - FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + ab = WebsiteManager() + coreResult = ab.submitWorpressCreation(userID, DataToPass) + coreResult1 = json.loads((coreResult).content) + logging.writeToFile("WP Creating website result....%s" % coreResult1) + reutrntempath = coreResult1['tempStatusPath'] + while (1): + lastLine = open(reutrntempath, 'r').read() + logging.writeToFile("Error WP creating lastline ....... %s" % lastLine) + if lastLine.find('[200]') > -1: + break + elif lastLine.find('[404]') > -1: + logging.statusWriter(self.tempStatusPath, + 'Failed to Create WordPress: error: %s. [404]' % lastLine) + return 0 + else: + logging.statusWriter(self.tempStatusPath, 'Creating WordPress....,20') + time.sleep(2) - ######Get DBname - command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( + logging.statusWriter(self.tempStatusPath, 'Restoring site ....,30') + NewWPsite = WPSites.objects.get(FinalURL=newurl) + VHuser = NewWPsite.owner.externalApp + PhpVersion = NewWPsite.owner.phpSelection + newWPpath = NewWPsite.path + + ###### Same code already used in Existing site + + ### get WPsite Database name and usr + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {NewWPsite.owner.externalApp}:{NewWPsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,40') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Copying Data File...,60') + ###Copy backup content to newsite + if oldhome == "0": + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + else: + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/" % ( + self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, newWPpath, oldurl, newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, newWPpath, newurl, newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ###Restart Server + + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() + + ####Check if backup type is Both web and DB + else: + ############## Existing site + if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): + wpsite = WPSites.objects.get(pk=DesSiteID) + webobj = Websites.objects.get(pk=wpsite.owner_id) + ag = WPSites.objects.filter(owner=webobj).count() + if ag > 0: + ###Website found --> Wpsite Found + finalurl = "%s%s" % (webobj.domain, oldurl[oldurl.find('/'):]) + try: + WPobj = WPSites.objects.get(FinalURL=finalurl, owner=webobj) + ###Website found --> WPsite Found --> Final URL Match + #### Do not create Ne site + ### get WPsite Database name and usr + VHuser = wpsite.owner.externalApp + PhpVersion = WPobj.owner.phpSelection + newWPpath = WPobj.path + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + ######Get DBname + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbname = stdout.rstrip("\n") + + ######Get DBuser + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbuser = stdout.rstrip("\n") + + #####Get DBpsswd + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbpasswd = stdout.rstrip("\n") + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % ( + VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + # dump Mysql file in unzippath path + unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % ( + self.tempPath, oldtemppath, DumpFileName) + command = "mysql -u root %s < %s" % (Finaldbname, unzippath2) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70') + #####SetUp DataBase Settings + ##set DBName + command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbname, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBuser + command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbuser, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBpasswd + command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbpasswd, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, newWPpath, oldurl, finalurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, newWPpath, finalurl, finalurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + except: + ####Website found --> WPsite Found --> Final URL Not Match + ####Create new obj and call wordpressnew + Newurl = wpsite.FinalURL + WPpath = wpsite.path + VHuser = wpsite.owner.externalApp + PhpVersion = wpsite.owner.phpSelection + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + ######Get DBname + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, WPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbname = stdout.rstrip("\n") + + ######Get DBuser + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, WPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbuser = stdout.rstrip("\n") + + #####Get DBpsswd + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, WPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbpasswd = stdout.rstrip("\n") + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % ( + VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + # dump Mysql file in unzippath path + unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % ( + self.tempPath, oldtemppath, DumpFileName) + command = "mysql -u root %s < %s" % (Finaldbname, unzippath2) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70') + #####SetUp DataBase Settings + ##set DBName + command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbname, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBuser + command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbuser, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBpasswd + command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbpasswd, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, WPpath, oldurl, Newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, WPpath, Newurl, Newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={WPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + ############## New Site + elif (DomainName != "" and int(self.extraArgs['DesSiteID']) == -1): + ###############Create New WordPressSite First + # logging.writeToFile("New Website Domain ....... %s" % str(DomainName)) + # logging.writeToFile("New Website Domain path....... %s" % str(self.extraArgs['path'])) + DataToPass = {} + + DataToPass['title'] = config['WPtitle'] + DataToPass['domain'] = DomainName + DataToPass['WPVersion'] = "6.0" + DataToPass['adminUser'] = config['WebVHuser'] + DataToPass['Email'] = config['WebadminEmail'] + DataToPass['PasswordByPass'] = config['DatabaseUser'] + DataToPass['AutomaticUpdates'] = config['WPAutoUpdates'] + DataToPass['Plugins'] = config['WPPluginUpdates'] + DataToPass['Themes'] = config['WPThemeUpdates'] + DataToPass['websiteOwner'] = WebOwner + DataToPass['package'] = packegs + try: + oldpath = config['WPsitepath'] + abc = oldpath.split("/") + newpath = abc[4] + oldhome = "0" + except BaseException as msg: + oldhome = "1" + + if self.extraArgs['path'] == '': + newurl = DomainName + else: + newurl = "%s/%s" % (DomainName, self.extraArgs['path']) + + DataToPass['path'] = self.extraArgs['path'] + + DataToPass['home'] = self.extraArgs['home'] + + ab = WebsiteManager() + coreResult = ab.submitWorpressCreation(userID, DataToPass) + coreResult1 = json.loads((coreResult).content) + logging.writeToFile("WP Creating website result....%s" % coreResult1) + reutrntempath = coreResult1['tempStatusPath'] + while (1): + lastLine = open(reutrntempath, 'r').read() + logging.writeToFile("Error WP creating lastline ....... %s" % lastLine) + if lastLine.find('[200]') > -1: + break + elif lastLine.find('[404]') > -1: + logging.statusWriter(self.tempStatusPath, + 'Failed to Create WordPress: error: %s. [404]' % lastLine) + return 0 + else: + logging.statusWriter(self.tempStatusPath, 'Creating WordPress....,20') + time.sleep(2) + + logging.statusWriter(self.tempStatusPath, 'Restoring site ....,30') + logging.writeToFile("Create site url =%s" % newurl) + NewWPsite = WPSites.objects.get(FinalURL=newurl) + VHuser = NewWPsite.owner.externalApp + PhpVersion = NewWPsite.owner.phpSelection + newWPpath = NewWPsite.path + + ###### Same code already used in Existing site + + ### get WPsite Database name and usr + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + ######Get DBname + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbname = stdout.rstrip("\n") + + ######Get DBuser + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbuser = stdout.rstrip("\n") + + #####Get DBpsswd + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbpasswd = stdout.rstrip("\n") + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {NewWPsite.owner.externalApp}:{NewWPsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,40') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Copying Data File...,60') + ###Copy backup content to newsite + if oldhome == "0": + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + else: + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/" % ( + self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + # dump Mysql file in unzippath path + unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % (self.tempPath, oldtemppath, DumpFileName) + command = "mysql -u root %s < %s" % (Finaldbname, unzippath2) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,80') + #####SetUp DataBase Settings + ##set DBName + command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbname, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBuser + command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbuser, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBpasswd + command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbpasswd, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, newWPpath, oldurl, newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, newWPpath, newurl, newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ###Restart Server + + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() + + #####Local BAckups + else: + ##### CHeck if Backup type is Only Database + if BackupType == 'DataBase Backup': + if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): + wpsite = WPSites.objects.get(pk=DesSiteID) + VHuser = wpsite.owner.externalApp + PhpVersion = wpsite.owner.phpSelection + newWPpath = wpsite.path + newurl = wpsite.FinalURL + + ## get WPsite Database name and usr + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + #####Get DBname + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( VHuser, FinalPHPPath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if stdout.find('Error:') == -1: + Finaldbname = stdout.rstrip("\n") + else: + raise BaseException(stdout) - if stdout.find('Error:') > -1: - raise BaseException(stdout) - else: - Finaldbname = stdout.rstrip("\n") - - ######Get DBuser - command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( + #####Get DBuser + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( VHuser, FinalPHPPath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if stdout.find('Error:') == -1: + Finaldbuser = stdout.rstrip("\n") + else: + raise BaseException(stdout) - if stdout.find('Error:') > -1: - raise BaseException(stdout) - else: - Finaldbuser = stdout.rstrip("\n") - - #####Get DBpsswd - command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( + #####Get DBpsswd + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( VHuser, FinalPHPPath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if stdout.find('Error:') == -1: + Finaldbpasswd = stdout.rstrip("\n") + else: + raise BaseException(stdout) - if stdout.find('Error:') > -1: - raise BaseException(stdout) - else: - Finaldbpasswd = stdout.rstrip("\n") + ### ##Create secure folder - ### Create secure folder + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) - ACLManager.CreateSecureDir() - RandomPath = str(randint(1000, 9999)) - self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - command = f'mkdir -p {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise BaseException(stdout) - if result == 0: - raise BaseException(stdout) + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - command = f'chown -R {NewWPsite.owner.externalApp}:{NewWPsite.owner.externalApp} {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise BaseException(stdout) - if result == 0: - raise BaseException(stdout) + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') - logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,40') + #####First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - ###First copy backup file to temp and then Unzip - command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise BaseException(stdout) - if result == 0: - raise BaseException(stdout) + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - #### Make temp dir ab for unzip - command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise BaseException(stdout) - if result == 0: - raise BaseException(stdout) - - command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( VHuser, self.tempPath, BackUpFileName, self.tempPath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if result == 0: - raise BaseException(stdout) + if result == 0: + raise BaseException(stdout) - logging.statusWriter(self.tempStatusPath, 'Copying Data File...,60') - ###Copy backup content to newsite - if oldhome == "0": - unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) - else: - unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/" % (self.tempPath, oldtemppath) + # dump Mysql file in unzippath path + unzippathdb = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % (self.tempPath, oldtemppath, DumpFileName) + command = "mysql -u root %s < %s" % (Finaldbname, unzippathdb) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise BaseException(stdout) - if result == 0: - raise BaseException(stdout) - - command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - raise BaseException(stdout) - - # dump Mysql file in unzippath path - unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % (self.tempPath, oldtemppath, DumpFileName) - command = "mysql -u root %s < %s" % (Finaldbname, unzippath2) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if stdout.find('Error:') > -1: - raise BaseException(stdout) - - logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,80') - #####SetUp DataBase Settings - ##set DBName - command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( + logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70') + #####SetUp DataBase Settings + ##set DBName + command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( VHuser, FinalPHPPath, Finaldbname, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + if stdout.find('Error:') > -1: + raise BaseException(stdout) - ##set DBuser - command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( + ##set DBuser + command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( VHuser, FinalPHPPath, Finaldbuser, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - ##set DBpasswd - command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBpasswd + command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( VHuser, FinalPHPPath, Finaldbpasswd, newWPpath) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + if stdout.find('Error:') > -1: + raise BaseException(stdout) - logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') - ########Now Replace URL's - command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( VHuser, newWPpath, oldurl, newurl) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + if stdout.find('Error:') > -1: + raise BaseException(stdout) - command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( VHuser, newWPpath, newurl, newurl) - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + if stdout.find('Error:') > -1: + raise BaseException(stdout) - command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' - ProcessUtilities.outputExecutioner(command, None, None, None, 1) + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + ###Restart Server + + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() + ####Check if BAckup type is Only Webdata + elif BackupType == 'Website Backup': + if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): + wpsite = WPSites.objects.get(pk=DesSiteID) + webobj = Websites.objects.get(pk=wpsite.owner_id) + ag = WPSites.objects.filter(owner=webobj).count() + if ag > 0: + ###Website found --> Wpsite Found + finalurl = "%s%s" % (webobj.domain, oldurl[oldurl.find('/'):]) + try: + WPobj = WPSites.objects.get(FinalURL=finalurl, owner=webobj) + ###Website found --> WPsite Found --> Final URL Match + #### Do not create Ne site + ### get WPsite Database name and usr + VHuser = wpsite.owner.externalApp + PhpVersion = WPobj.owner.phpSelection + newWPpath = WPobj.path + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) - ##Remove temppath - command = f'rm -rf {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if stdout.find('Error:') > -1: - raise BaseException(stdout) + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, newWPpath, oldurl, finalurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - ###Restart Server + if stdout.find('Error:') > -1: + raise BaseException(stdout) - from plogical.installUtilities import installUtilities - installUtilities.reStartLiteSpeed() + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, newWPpath, finalurl, finalurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + except: + ####Website found --> WPsite Found --> Final URL Not Match + ####Create new obj and call wordpressnew + Newurl = wpsite.FinalURL + WPpath = wpsite.path + VHuser = wpsite.owner.externalApp + PhpVersion = wpsite.owner.phpSelection + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % ( + VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, WPpath, oldurl, Newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, WPpath, Newurl, Newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={WPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + elif (DomainName != "" and int(self.extraArgs['DesSiteID']) == -1): + DataToPass = {} + + DataToPass['title'] = config['WPtitle'] + DataToPass['domain'] = DomainName + DataToPass['WPVersion'] = "6.0" + DataToPass['adminUser'] = config['WebVHuser'] + DataToPass['Email'] = config['WebadminEmail'] + DataToPass['PasswordByPass'] = config['DatabaseUser'] + DataToPass['AutomaticUpdates'] = config['WPAutoUpdates'] + DataToPass['Plugins'] = config['WPPluginUpdates'] + DataToPass['Themes'] = config['WPThemeUpdates'] + DataToPass['websiteOwner'] = WebOwner + DataToPass['package'] = packegs + try: + oldpath = config['WPsitepath'] + abc = oldpath.split("/") + newpath = abc[4] + oldhome = "0" + except BaseException as msg: + oldhome = "1" + + if self.extraArgs['path'] == '': + newurl = DomainName + else: + newurl = "%s/%s" % (DomainName, self.extraArgs['path']) + + DataToPass['path'] = self.extraArgs['path'] + + DataToPass['home'] = self.extraArgs['home'] + + ab = WebsiteManager() + coreResult = ab.submitWorpressCreation(userID, DataToPass) + coreResult1 = json.loads((coreResult).content) + logging.writeToFile("WP Creating website result....%s" % coreResult1) + reutrntempath = coreResult1['tempStatusPath'] + while (1): + lastLine = open(reutrntempath, 'r').read() + logging.writeToFile("Error WP creating lastline ....... %s" % lastLine) + if lastLine.find('[200]') > -1: + break + elif lastLine.find('[404]') > -1: + logging.statusWriter(self.tempStatusPath, + 'Failed to Create WordPress: error: %s. [404]' % lastLine) + return 0 + else: + logging.statusWriter(self.tempStatusPath, 'Creating WordPress....,20') + time.sleep(2) + + logging.statusWriter(self.tempStatusPath, 'Restoring site ....,30') + NewWPsite = WPSites.objects.get(FinalURL=newurl) + VHuser = NewWPsite.owner.externalApp + PhpVersion = NewWPsite.owner.phpSelection + newWPpath = NewWPsite.path + + ###### Same code already used in Existing site + + ### get WPsite Database name and usr + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {NewWPsite.owner.externalApp}:{NewWPsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,40') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Copying Data File...,60') + ###Copy backup content to newsite + if oldhome == "0": + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + else: + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/" % ( + self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, newWPpath, oldurl, newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, newWPpath, newurl, newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ###Restart Server + + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() + + ####Check if backup type is Both web and DB + else: + ############## Existing site + if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): + wpsite = WPSites.objects.get(pk=DesSiteID) + webobj = Websites.objects.get(pk=wpsite.owner_id) + ag = WPSites.objects.filter(owner=webobj).count() + if ag > 0: + ###Website found --> Wpsite Found + finalurl = "%s%s" % (webobj.domain, oldurl[oldurl.find('/'):]) + try: + WPobj = WPSites.objects.get(FinalURL=finalurl, owner=webobj) + ###Website found --> WPsite Found --> Final URL Match + #### Do not create Ne site + ### get WPsite Database name and usr + VHuser = wpsite.owner.externalApp + PhpVersion = WPobj.owner.phpSelection + newWPpath = WPobj.path + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + ######Get DBname + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbname = stdout.rstrip("\n") + + ######Get DBuser + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbuser = stdout.rstrip("\n") + + #####Get DBpsswd + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbpasswd = stdout.rstrip("\n") + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + # dump Mysql file in unzippath path + unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % ( + self.tempPath, oldtemppath, DumpFileName) + command = "mysql -u root %s < %s" % (Finaldbname, unzippath2) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70') + #####SetUp DataBase Settings + ##set DBName + command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbname, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBuser + command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbuser, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBpasswd + command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbpasswd, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, newWPpath, oldurl, finalurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, newWPpath, finalurl, finalurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + except: + ####Website found --> WPsite Found --> Final URL Not Match + ####Create new obj and call wordpressnew + Newurl = wpsite.FinalURL + WPpath = wpsite.path + VHuser = wpsite.owner.externalApp + PhpVersion = wpsite.owner.phpSelection + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + ######Get DBname + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, WPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbname = stdout.rstrip("\n") + + ######Get DBuser + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, WPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbuser = stdout.rstrip("\n") + + #####Get DBpsswd + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, WPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbpasswd = stdout.rstrip("\n") + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % ( + VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + # dump Mysql file in unzippath path + unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % ( + self.tempPath, oldtemppath, DumpFileName) + command = "mysql -u root %s < %s" % (Finaldbname, unzippath2) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70') + #####SetUp DataBase Settings + ##set DBName + command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbname, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBuser + command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbuser, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBpasswd + command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbpasswd, WPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, WPpath, oldurl, Newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, WPpath, Newurl, Newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={WPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + ############## New Site + elif(DomainName != "" and int(self.extraArgs['DesSiteID']) == -1): + ###############Create New WordPressSite First + # logging.writeToFile("New Website Domain ....... %s" % str(DomainName)) + # logging.writeToFile("New Website Domain path....... %s" % str(self.extraArgs['path'])) + DataToPass = {} + + DataToPass['title'] = config['WPtitle'] + DataToPass['domain'] = DomainName + DataToPass['WPVersion'] = "6.0" + DataToPass['adminUser'] = config['WebVHuser'] + DataToPass['Email'] = config['WebadminEmail'] + DataToPass['PasswordByPass'] = config['DatabaseUser'] + DataToPass['AutomaticUpdates'] = config['WPAutoUpdates'] + DataToPass['Plugins'] = config['WPPluginUpdates'] + DataToPass['Themes'] = config['WPThemeUpdates'] + DataToPass['websiteOwner'] = WebOwner + DataToPass['package'] = packegs + try: + oldpath = config['WPsitepath'] + abc = oldpath.split("/") + newpath = abc[4] + oldhome = "0" + except BaseException as msg: + oldhome = "1" + + if self.extraArgs['path'] == '': + newurl = DomainName + else: + newurl = "%s/%s"%(DomainName, self.extraArgs['path']) + + DataToPass['path'] = self.extraArgs['path'] + + DataToPass['home'] = self.extraArgs['home'] + + ab = WebsiteManager() + coreResult = ab.submitWorpressCreation(userID, DataToPass) + coreResult1 = json.loads((coreResult).content) + logging.writeToFile("WP Creating website result....%s" % coreResult1) + reutrntempath = coreResult1['tempStatusPath'] + while (1): + lastLine = open(reutrntempath, 'r').read() + logging.writeToFile("Error WP creating lastline ....... %s" % lastLine) + if lastLine.find('[200]') > -1: + break + elif lastLine.find('[404]') > -1: + logging.statusWriter(self.tempStatusPath, + 'Failed to Create WordPress: error: %s. [404]' % lastLine) + return 0 + else: + logging.statusWriter(self.tempStatusPath, 'Creating WordPress....,20') + time.sleep(2) + + logging.statusWriter(self.tempStatusPath, 'Restoring site ....,30') + NewWPsite = WPSites.objects.get(FinalURL=newurl) + VHuser = NewWPsite.owner.externalApp + PhpVersion = NewWPsite.owner.phpSelection + newWPpath = NewWPsite.path + + ###### Same code already used in Existing site + + ### get WPsite Database name and usr + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + ######Get DBname + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbname = stdout.rstrip("\n") + + ######Get DBuser + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbuser = stdout.rstrip("\n") + + #####Get DBpsswd + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + else: + Finaldbpasswd = stdout.rstrip("\n") + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = f'chown -R {NewWPsite.owner.externalApp}:{NewWPsite.owner.externalApp} {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,40') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Copying Data File...,60') + ###Copy backup content to newsite + if oldhome == "0": + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + else: + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/" % (self.tempPath, oldtemppath) + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) + + # dump Mysql file in unzippath path + unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % (self.tempPath, oldtemppath, DumpFileName) + command = "mysql -u root %s < %s" % (Finaldbname, unzippath2) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,80') + #####SetUp DataBase Settings + ##set DBName + command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbname, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBuser + command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbuser, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ##set DBpasswd + command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbpasswd, newWPpath) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, newWPpath, oldurl, newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, newWPpath, newurl, newurl) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + + ##Remove temppath + command = f'rm -rf {self.tempPath}' + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) + + ###Restart Server + + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() logging.statusWriter(self.tempStatusPath, 'Completed.[200]') + + except BaseException as msg: logging.writeToFile("Error RestoreWPbackupNow ....... %s" % str(msg)) try: diff --git a/plogical/backupUtilities.py b/plogical/backupUtilities.py index c94b18e44..a3f783cfd 100755 --- a/plogical/backupUtilities.py +++ b/plogical/backupUtilities.py @@ -360,8 +360,7 @@ class backupUtilities: completPathToConf = f'{backupUtilities.Server_root}/conf/vhosts/{domainName}/vhost.conf' - if os.path.exists(backupUtilities.licenseKey): - copy(completPathToConf, tempStoragePath + '/vhost.conf') + copy(completPathToConf, tempStoragePath + '/vhost.conf') ## /home/example.com/backup/backup-example.com-02.13.2018_10-24-52 -- tempStoragePath ## shutil.make_archive @@ -441,9 +440,9 @@ class backupUtilities: actualChildDomain = childDomain.find('domain').text childPath = childDomain.find('path').text - if os.path.exists(backupUtilities.licenseKey): - completPathToConf = f'{backupUtilities.Server_root}/conf/vhosts/{actualChildDomain}/vhost.conf' - copy(completPathToConf, f'{tempStoragePath}/{actualChildDomain}.vhost.conf') + + completPathToConf = f'{backupUtilities.Server_root}/conf/vhosts/{actualChildDomain}/vhost.conf' + copy(completPathToConf, f'{tempStoragePath}/{actualChildDomain}.vhost.conf') ### Storing SSL for child domainsa @@ -813,10 +812,9 @@ class backupUtilities: try: - if os.path.exists(backupUtilities.licenseKey): - if os.path.exists(completPath + '/' + domain + '.vhost.conf'): - completPathToConf = backupUtilities.Server_root + '/conf/vhosts/' + domain + '/vhost.conf' - copy(completPath + '/' + domain + '.vhost.conf', completPathToConf) + if os.path.exists(completPath + '/' + domain + '.vhost.conf'): + completPathToConf = backupUtilities.Server_root + '/conf/vhosts/' + domain + '/vhost.conf' + copy(completPath + '/' + domain + '.vhost.conf', completPathToConf) sslStoragePath = completPath + "/" + domain + ".cert.pem" @@ -1025,10 +1023,9 @@ class backupUtilities: ## emails extracted - if os.path.exists(backupUtilities.licenseKey): - completPathToConf = backupUtilities.Server_root + '/conf/vhosts/' + masterDomain + '/vhost.conf' - if os.path.exists(completPath + '/vhost.conf'): - copy(completPath + '/vhost.conf', completPathToConf) + completPathToConf = backupUtilities.Server_root + '/conf/vhosts/' + masterDomain + '/vhost.conf' + if os.path.exists(completPath + '/vhost.conf'): + copy(completPath + '/vhost.conf', completPathToConf) logging.CyberCPLogFileWriter.statusWriter(status, "Done") diff --git a/plogical/mysqlUtilities.py b/plogical/mysqlUtilities.py index 89153d5c5..9b2e1cb56 100755 --- a/plogical/mysqlUtilities.py +++ b/plogical/mysqlUtilities.py @@ -838,6 +838,7 @@ password=%s if connection == 0: return 0 + cursor.execute("use mysql") if host != None: @@ -855,11 +856,11 @@ password=%s else: query = "SET PASSWORD FOR '" + userName + "'@'%s' = '" % (LOCALHOST) + dbPassword + "'" - cursor.execute(query) - if os.path.exists(ProcessUtilities.debugPath): logging.CyberCPLogFileWriter.writeToFile(query) + cursor.execute(query) + connection.close() return 1 diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index 8d7467736..731e93841 100755 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -291,7 +291,6 @@ class ProcessUtilities(multi.Thread): @staticmethod def outputExecutioner(command, user=None, shell = None, dir = None, retRequired = None): try: - if getpass.getuser() == 'root': if os.path.exists(ProcessUtilities.debugPath): logging.writeToFile(command) @@ -299,7 +298,11 @@ class ProcessUtilities(multi.Thread): p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) else: p = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - return p.communicate()[0].decode("utf-8") + + if retRequired: + return 1, p.communicate()[0].decode("utf-8") + else: + return p.communicate()[0].decode("utf-8") if type(command) == list: command = " ".join(command) diff --git a/plogical/test.py b/plogical/test.py index e69de29bb..93258abd8 100644 --- a/plogical/test.py +++ b/plogical/test.py @@ -0,0 +1,9 @@ +config= { + "name": "habi", + "dev": "python" +} + +print(config) +config['klm'] ="tls" + +print(config) \ No newline at end of file diff --git a/plogical/upgrade.py b/plogical/upgrade.py index aba920c1d..439bcbec5 100755 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -287,7 +287,7 @@ class Upgrade: command = 'wget -O /usr/local/CyberCP/public/phpmyadmin.zip https://github.com/usmannasir/cyberpanel/raw/stable/phpmyadmin.zip' Upgrade.executioner(command, 0) - command = 'unzip /usr/local/CyberCP/public/phpmyadmin.zip -d /usr/local/CyberCP/public/' + command = 'unzip /usr/local/CyberCP/public/phpmyadmin.zip -d /usr/local/CyberCP/public/phpmyadmin' Upgrade.executioner(command, 0) command = 'mv /usr/local/CyberCP/public/phpMyAdmin-*-all-languages /usr/local/CyberCP/public/phpmyadmin' @@ -2566,6 +2566,22 @@ vmail writeToFile = open(cronPath, 'a') writeToFile.write(content) writeToFile.close() + + if data.find("IncScheduler.py '30 Minutes'") == -1: + content = """ +*/30 * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py '30 Minutes' +0 * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py '1 Hour' +0 */6 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py '6 Hours' +0 */12 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py '12 Hours' +0 1 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py '1 Day' +0 0 */3 * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py '3 Days' +0 0 * * 0 /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py '1 Week' +""" + writeToFile = open(cronPath, 'a') + writeToFile.write(content) + writeToFile.close() + + else: content = """ 0 * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/findBWUsage.py >/dev/null 2>&1 @@ -2786,7 +2802,7 @@ vmail command = execPath + " --function submitinstallImunifyAV" Upgrade.executioner(command, command, 1) - command = 'chmod +x /usr/local/CyberCP/bin/python /usr/local/CyberCP/CLManager/CageFS.py' + command = 'chmod +x /usr/local/CyberCP/public/imunifyav/bin/execute.py' Upgrade.executioner(command, command, 1) diff --git a/websiteFunctions/models.py b/websiteFunctions/models.py index 34647f3e1..c9b1a8640 100755 --- a/websiteFunctions/models.py +++ b/websiteFunctions/models.py @@ -128,3 +128,22 @@ class WPSitesBackup(models.Model): WPSiteID = models.IntegerField(default=-1) WebsiteID = models.IntegerField(default=-1) config = models.TextField() + + +class RemoteBackupConfig(models.Model): + owner = models.ForeignKey(Administrator, on_delete=models.CASCADE) + configtype = models.CharField(max_length=255, default='') + config = models.TextField() + +class RemoteBackupSchedule(models.Model): + RemoteBackupConfig = models.ForeignKey(RemoteBackupConfig, on_delete=models.CASCADE) + Name = models.CharField(max_length=255, default='') + timeintervel = models.CharField(max_length=200) + fileretention = models.CharField(max_length=200) + lastrun = models.CharField(max_length=200) + config = models.TextField() + +class RemoteBackupsites(models.Model): + owner = models.ForeignKey(RemoteBackupSchedule, on_delete=models.CASCADE) + WPsites = models.IntegerField(null=True) + database = models.IntegerField(null=True) diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 61b512882..7542b08a8 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -521,7 +521,7 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo if (response.data.ret_data.maintenanceMode === 1) { $('#maintenanceMode').prop('checked', true); } - if(response.data.ret_data.wpcron === 1) { + if (response.data.ret_data.wpcron === 1) { $('#wpcron').prop('checked', true); } if (response.data.ret_data.passwordprotection == 1) { @@ -589,8 +589,7 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo PPPassword: $scope.PPPassword, } - } - else { + } else { var data = { WPid: $('#WPid').html(), setting: setting, @@ -633,7 +632,7 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo text: 'Successfully Updated!.', type: 'success' }); - if (setting === "PasswordProtection"){ + if (setting === "PasswordProtection") { location.reload(); } } else { @@ -642,7 +641,7 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo text: response.data.error_message, type: 'error' }); - if (setting === "PasswordProtection"){ + if (setting === "PasswordProtection") { location.reload(); } @@ -1955,6 +1954,329 @@ app.controller('RestoreWPBackup', function ($scope, $http, $timeout, $window) { }); +//.......................................Remote Backup + +//........... delete DeleteBackupConfigNow + +function DeleteBackupConfigNow(url) { + window.location.href = url; +} + +function DeleteRemoteBackupsiteNow(url) { + window.location.href = url; +} + +function DeleteBackupfileConfigNow(url) { + window.location.href = url; +} + + +app.controller('RemoteBackupConfig', function ($scope, $http, $timeout, $window) { + $scope.RemoteBackupLoading = true; + $scope.SFTPBackUpdiv = true; + + $scope.EndpointURLdiv = true; + $scope.Selectprovider = true; + $scope.S3keyNamediv = true; + $scope.Accesskeydiv = true; + $scope.SecretKeydiv = true; + $scope.SelectRemoteBackuptype = function () { + var val = $scope.RemoteBackuptype; + if (val == "SFTP") { + $scope.SFTPBackUpdiv = false; + $scope.EndpointURLdiv = true; + $scope.Selectprovider = true; + $scope.S3keyNamediv = true; + $scope.Accesskeydiv = true; + $scope.SecretKeydiv = true; + } else if (val == "S3") { + $scope.EndpointURLdiv = true; + $scope.Selectprovider = false; + $scope.S3keyNamediv = false; + $scope.Accesskeydiv = false; + $scope.SecretKeydiv = false; + $scope.SFTPBackUpdiv = true; + } else { + $scope.RemoteBackupLoading = true; + $scope.SFTPBackUpdiv = true; + + $scope.EndpointURLdiv = true; + $scope.Selectprovider = true; + $scope.S3keyNamediv = true; + $scope.Accesskeydiv = true; + $scope.SecretKeydiv = true; + } + } + + $scope.SelectProvidertype = function () { + $scope.EndpointURLdiv = true; + var provider = $scope.Providervalue + if (provider == 'Backblaze') { + $scope.EndpointURLdiv = false; + } else { + $scope.EndpointURLdiv = true; + } + } + + $scope.SaveBackupConfig = function () { + $scope.RemoteBackupLoading = false; + var Hname = $scope.Hostname; + var Uname = $scope.Username; + var Passwd = $scope.Password; + var path = $scope.path; + var type = $scope.RemoteBackuptype; + var Providervalue = $scope.Providervalue; + var data; + if (type == "SFTP") { + + data = { + Hname: Hname, + Uname: Uname, + Passwd: Passwd, + path: path, + type: type + } + } else if (type == "S3") { + if (Providervalue == "Backblaze") { + data = { + S3keyname: $scope.S3keyName, + Provider: Providervalue, + AccessKey: $scope.Accesskey, + SecertKey: $scope.SecretKey, + EndUrl: $scope.EndpointURL, + type: type + } + } else { + data = { + S3keyname: $scope.S3keyName, + Provider: Providervalue, + AccessKey: $scope.Accesskey, + SecertKey: $scope.SecretKey, + type: type + } + + } + + } + var url = "/websites/SaveBackupConfig"; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.RemoteBackupLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Saved!.', + type: 'success' + }); + location.reload(); + + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.RemoteBackupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + + + } + +}); + +var UpdatescheduleID; +app.controller('BackupSchedule', function ($scope, $http, $timeout, $window) { + $scope.BackupScheduleLoading = true; + $scope.SaveBackupSchedule = function () { + $scope.RemoteBackupLoading = false; + var FileRetention = $scope.Fretention; + var Backfrequency = $scope.Bfrequency; + + + var data = { + FileRetention: FileRetention, + Backfrequency: Backfrequency, + ScheduleName: $scope.ScheduleName, + RemoteConfigID: $('#RemoteConfigID').html(), + BackupType: $scope.BackupType + } + var url = "/websites/SaveBackupSchedule"; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.RemoteBackupLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Saved!.', + type: 'success' + }); + location.reload(); + + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.RemoteBackupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + + + }; + + + $scope.getupdateid = function (ID) { + UpdatescheduleID = ID; + } + + $scope.UpdateRemoteschedules = function () { + $scope.RemoteBackupLoading = false; + var Frequency = $scope.RemoteFrequency; + var fretention = $scope.RemoteFileretention; + + var data = { + ScheduleID: UpdatescheduleID, + Frequency: Frequency, + FileRetention: fretention + } + var url = "/websites/UpdateRemoteschedules"; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.RemoteBackupLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Updated!.', + type: 'success' + }); + location.reload(); + + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.RemoteBackupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + }; + + $scope.AddWPsiteforRemoteBackup = function () { + $scope.RemoteBackupLoading = false; + + + var data = { + WpsiteID: $('#Wpsite').val(), + RemoteScheduleID: $('#RemoteScheduleID').html() + } + var url = "/websites/AddWPsiteforRemoteBackup"; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.RemoteBackupLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Saved!.', + type: 'success' + }); + location.reload(); + + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.RemoteBackupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + + + }; +}); /* Java script code to create account */ app.controller('createWebsite', function ($scope, $http, $timeout, $window) { diff --git a/websiteFunctions/templates/websiteFunctions/AddRemoteBackupSite.html b/websiteFunctions/templates/websiteFunctions/AddRemoteBackupSite.html new file mode 100644 index 000000000..583492b0a --- /dev/null +++ b/websiteFunctions/templates/websiteFunctions/AddRemoteBackupSite.html @@ -0,0 +1,87 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "Backup Sites Configurations - CyberPanel" %}{% endblock %} +{% block content %} + + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + + +
+ | ID | +WordPress Title | +Action | +
|---|---|---|
| {{ sub.id }} | +{{ sub.Title }} | ++ + + | +
+ | ID | +Schedule Name | +Backup Frequency | +Backup File Retention + | +Last Run | +Remote Configuration + | +Action | +
|---|---|---|---|---|---|---|
| {{ sub.id }} | +{{ sub.Name }} | +{{ sub.Frequency }} | +{{ sub.Retention }} | +{{ sub.LastRun }} | +{{ sub.RemoteConfiguration }} | ++ + + + Add WordPress Sites + + | +
+
+ | Backup Type | +HostName | +Path / Key Name | +Action | +
|---|---|---|---|
| {{ sub.Type }} | +{{ sub.HostName }} | +{{ sub.Path }} | ++ + + Schedule Backups + | +