diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index f5019ded4..d501fcc46 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -2617,6 +2617,7 @@ $parameters = array( from managePHP.phpManager import PHPManager from websiteFunctions.website import WebsiteManager from packages.models import Package + logging.writeToFile("Error Restore WP backup Now ....... start:%s"% self.extraArgs['Domain']) self.tempStatusPath = self.extraArgs['tempStatusPath'] logging.statusWriter(self.tempStatusPath, 'Restoring BackUp...,10') DesSiteID = self.extraArgs['DesSiteID'] @@ -2643,12 +2644,329 @@ $parameters = array( #####Check Backup Type BackupType = config['Backuptype'] + ##### CHeck if Backup type is Only Database if BackupType == 'DataBase Backup': - pass + 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 + + #### Check If sub dir in web site + try: + oldpath = config['WPsitepath'] + abc = oldpath.split("/") + pathexta = abc[4] + if pathexta != "": + home = "0" + else: + home = "1" + except BaseException as msg: + home = "1" + + ### 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) + stdout = ProcessUtilities.outputExecutioner(command) + 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) + stdout = ProcessUtilities.outputExecutioner(command) + 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) + stdout = ProcessUtilities.outputExecutioner(command) + 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}' + ProcessUtilities.executioner(command) + + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + ProcessUtilities.executioner(command) + + 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) + ProcessUtilities.executioner(command) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + ProcessUtilities.executioner(command) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + ProcessUtilities.outputExecutioner(command) + + # 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) + ProcessUtilities.outputExecutioner(command) + + 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) + ProcessUtilities.outputExecutioner(command) + + ##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) + ProcessUtilities.outputExecutioner(command) + + ##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) + ProcessUtilities.outputExecutioner(command) + + 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) + ProcessUtilities.outputExecutioner(command) + + 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) + ProcessUtilities.outputExecutioner(command) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + ProcessUtilities.executioner(command) + + ###Restart Server + + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() + ####Check if BAckup type is Only Webdata elif BackupType == 'Website Backup': - pass + ############## Existing site + if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): + wpsite = WPSites.objects.get(pk=DesSiteID) + VHuser = wpsite.owner.externalApp + newWPpath = wpsite.path + newurl = wpsite.FinalURL + + #### Check If sub dir in web site + try: + oldpath = config['WPsitepath'] + abc = oldpath.split("/") + pathexta = abc[4] + if pathexta != "": + home = "0" + else: + home = "1" + except BaseException as msg: + home = "1" + + ### 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}' + ProcessUtilities.executioner(command) + + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + ProcessUtilities.executioner(command) + + 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) + ProcessUtilities.executioner(command) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + ProcessUtilities.executioner(command) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + ProcessUtilities.outputExecutioner(command) + + logging.statusWriter(self.tempStatusPath, 'Copying Data File...,50') + ###Copy backup content to newsite + if home == "0": + + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) + ###make dir of sub folder in existing site + command = "sudo -u %s mkdir %s%s" % (VHuser, newWPpath, pathexta) + ProcessUtilities.executioner(command) + Webnewpath = str(newWPpath) + str(pathexta) + else: + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % ( + self.tempPath, oldtemppath) + Webnewpath = newWPpath + + ###/usr/local/CyberCP/tmp/1755/ab/usr/local/CyberCP/tmp/8774/public_html + ###/usr/local/CyberCP/tmp/1755/ab/usr/local/CyberCP/tmp/8774/public_html/public_html/* + + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, Webnewpath) + result = ProcessUtilities.outputExecutioner(command) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, Webnewpath) + result = ProcessUtilities.outputExecutioner(command) + + + + 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) + ProcessUtilities.outputExecutioner(command) + + 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) + ProcessUtilities.outputExecutioner(command) + + # ##Remove temppath + command = f'rm -rf {self.tempPath}' + ProcessUtilities.executioner(command) + + ###Restart Server + + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() + ############## New Site + elif (DomainName != "" and int(self.extraArgs['DesSiteID']) == -1): + ###############Create New WordPressSite First + # logging.writeToFile("New Website Domain ....... %s" % str(DomainName)) + 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] + if newpath != "": + newurl = "%s/%s" % (DomainName, newpath) + else: + newurl = DomainName + home = "0" + except BaseException as msg: + newpath = "" + newurl = DomainName + home = "1" + + DataToPass['path'] = newpath + + DataToPass['home'] = home + + try: + website = Websites.objects.get(domain=DomainName) + logging.statusWriter(self.tempStatusPath, 'Web Site Already Exist.[404]') + except: + 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 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 + newWPpath = NewWPsite.path + + ### 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}' + ProcessUtilities.executioner(command) + + command = f'chown -R {NewWPsite.owner.externalApp}:{NewWPsite.owner.externalApp} {self.tempPath}' + ProcessUtilities.executioner(command) + + 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) + ProcessUtilities.executioner(command) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + ProcessUtilities.executioner(command) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + ProcessUtilities.outputExecutioner(command) + + logging.statusWriter(self.tempStatusPath, 'Copying Data File...,60') + ###Copy backup content to newsite + if home == "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 = ProcessUtilities.outputExecutioner(command) + + command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) + result = ProcessUtilities.outputExecutioner(command) + + + + 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) + ProcessUtilities.outputExecutioner(command) + + 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) + ProcessUtilities.outputExecutioner(command) + + ##Remove temppath + command = f'rm -rf {self.tempPath}' + ProcessUtilities.executioner(command) + + ###Restart Server + + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() + ####Check if backup type is Both web and DB else: - #### Methode of Restoring ############## Existing site if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): wpsite = WPSites.objects.get(pk=DesSiteID) @@ -2663,7 +2981,10 @@ $parameters = array( oldpath = config['WPsitepath'] abc = oldpath.split("/") pathexta = abc[4] - home = "0" + if pathexta != "": + home = "0" + else: + home = "1" except BaseException as msg: home = "1" @@ -2671,6 +2992,7 @@ $parameters = array( 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) stdout = ProcessUtilities.outputExecutioner(command) @@ -2725,6 +3047,7 @@ $parameters = array( ProcessUtilities.executioner(command) Webnewpath = str(newWPpath)+str(pathexta) else: + ##usr/local/CyberCP/tmp/4701/ab/usr/local/CyberCP/tmp/9507/public_html/public_html/ unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/" % (self.tempPath, oldtemppath) Webnewpath = newWPpath @@ -2792,7 +3115,10 @@ $parameters = array( oldpath = config['WPsitepath'] abc = oldpath.split("/") newpath = abc[4] - newurl = "%s/%s"%(DomainName,newpath) + if newpath != "": + newurl = "%s/%s"%(DomainName,newpath) + else: + newurl = DomainName home = "0" except BaseException as msg: newpath = "" @@ -2818,7 +3144,7 @@ $parameters = array( if lastLine.find('[200]') > -1: break elif lastLine.find('[404]') > -1: - logging.statusWriter(self.tempStatusPath, 'Failed to WordPress: error: %s. [404]'% lastLine) + logging.statusWriter(self.tempStatusPath, 'Failed to Create WordPress: error: %s. [404]'% lastLine) return 0 else: logging.statusWriter(self.tempStatusPath, 'Creating WordPress....,20') diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 6c791a50f..ea819f119 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -1550,16 +1550,26 @@ app.controller('RestoreWPBackup', function ($scope, $http, $timeout, $window) { $scope.goBackDisable = true; $scope.currentStatus = "Start Restoring WordPress.."; + var backuptype = $('#backuptype').html(); + var data; + if (backuptype == "DataBase Backup") { + data = { + backupid: $('#backupid').html(), + DesSite: $('#DesSite').children("option:selected").val(), + Domain: '' + } + } else { + data = { + backupid: $('#backupid').html(), + DesSite: $('#DesSite').children("option:selected").val(), + Domain: $("input[name=Newdomain]").val() + } + + } + var url = "/websites/RestoreWPbackupNow"; - - var data = { - backupid: $('#backupid').html(), - DesSite: $('#DesSite').children("option:selected").val(), - Domain: $("input[name=Newdomain]").val() - } - var config = { headers: { 'X-CSRFToken': getCookie('csrftoken') @@ -1570,16 +1580,11 @@ app.controller('RestoreWPBackup', function ($scope, $http, $timeout, $window) { var d = $('#DesSite').children("option:selected").val(); var c = $("input[name=Newdomain]").val(); - if( d == -1 && c == "") - { - alert("Please Select Method of Backup Restore"); - } - else { + // if (d == -1 || c == "") { + // alert("Please Select Method of Backup Restore"); + // } else { $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - } - - - + // } function ListInitialDatas(response) { diff --git a/websiteFunctions/templates/websiteFunctions/WPRestoreHome.html b/websiteFunctions/templates/websiteFunctions/WPRestoreHome.html index 9a6894547..4a9eaf450 100644 --- a/websiteFunctions/templates/websiteFunctions/WPRestoreHome.html +++ b/websiteFunctions/templates/websiteFunctions/WPRestoreHome.html @@ -18,9 +18,26 @@
-

{{ FileName }}

- - +

{{ FileName }}

+ + + + {% if Backuptype == "DataBase Backup" %} +
+ +
+ + +
+
+ {% else %}
@@ -53,6 +70,8 @@ class="form-control" required>
+ {% endif %} + diff --git a/websiteFunctions/tests.py b/websiteFunctions/tests.py index f868f45fc..31d9fc814 100755 --- a/websiteFunctions/tests.py +++ b/websiteFunctions/tests.py @@ -1,7 +1,11 @@ -a = "/home/newweb2.com/public_html/newweb2/" +a = "/home/habibackup.ml/public_html/////" DomainName ="newweb3.com" abc = a.split("/") wpexpath = abc[4] newpath = '/home/%s/public_html/%s' % (DomainName, wpexpath) -print(newpath) +if wpexpath != "": + home = "0" +else: + home = "1" +print(home) diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 36833ead6..a8cd0a675 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -151,6 +151,10 @@ class WebsiteManager: config = json.loads(Data['backupobj'].config) Data['FileName']= config['name'] + try: + Data['Backuptype']= config['Backuptype'] + except: + Data['Backuptype'] = None Data['WPsites'] = ACLManager.GetALLWPObjects(currentACL, userID) proc = httpProc(request, 'websiteFunctions/WPRestoreHome.html', Data, 'createWebsite') @@ -166,6 +170,11 @@ class WebsiteManager: try: if DeleteID != None: DeleteIDobj = WPSitesBackup.objects.get(pk=DeleteID) + config = DeleteIDobj.config + conf = json.loads(config) + FileName = conf['name'] + command = "rm -r /home/backup/%s.tar.gz"%FileName + ProcessUtilities.executioner(command) DeleteIDobj.delete() except BaseException as msg: @@ -800,8 +809,9 @@ class WebsiteManager: backupid = data['backupid'] DesSiteID = data['DesSite'] - Domain = data['Domain'] + logging.CyberCPLogFileWriter.writeToFile("Error WP ChangeStatusThemes ....... %s"%data) + Domain = data['Domain'] extraArgs = {} extraArgs['adminID'] = admin.pk