diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index c9a9ea604..f06143577 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -2307,16 +2307,25 @@ $parameters = array( self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) command = f'mkdir -p {self.tempPath}' - ProcessUtilities.executioner(command) + 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}' - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) ### Make directory for backup logging.statusWriter(self.tempStatusPath, 'Creating Backup Directory...,40') command = f"mkdir -p {self.tempPath}/public_html" - ProcessUtilities.executioner(command, VHuser) + result, stdout = ProcessUtilities.outputExecutioner(command, VHuser, None, None, 1) + + if result == 0: + raise BaseException(stdout) config = {} config['WPtitle']=wpsite.title @@ -2404,7 +2413,10 @@ $parameters = array( command = 'mkdir -p /home/backup/' - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) command = f"tar -czvf /home/backup/{config['name']}.tar.gz -P {self.tempPath}" retStatus, result = ProcessUtilities.outputExecutioner(command, None, None, None, 1) @@ -2420,7 +2432,10 @@ $parameters = array( backupobj.save() command = f'rm -rf {self.tempPath}' - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) logging.statusWriter(self.tempStatusPath, 'Completed.[200]') return 1, f"/home/backup/{config['name']}.tar.gz" @@ -2434,16 +2449,25 @@ $parameters = array( self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) command = f'mkdir -p {self.tempPath}' - ProcessUtilities.executioner(command) + 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}' - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) ### Make directory for backup logging.statusWriter(self.tempStatusPath, 'Creating Backup Directory...,40') command = f"mkdir -p {self.tempPath}/public_html" - ProcessUtilities.executioner(command, VHuser) + result, stdout = ProcessUtilities.outputExecutioner(command, VHuser, None, None, 1) + + if result == 0: + raise BaseException(stdout) config = {} config['WPtitle'] = wpsite.title @@ -2515,7 +2539,10 @@ $parameters = array( websitepath = "/home/%s" % websitedomain command = 'mkdir -p /home/backup/' - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) command = f"tar -czvf /home/backup/{config['name']}.tar.gz -P {self.tempPath}" retStatus, result = ProcessUtilities.outputExecutioner(command, None, None, None, 1) @@ -2530,7 +2557,10 @@ $parameters = array( logging.writeToFile(result) command = f'rm -rf {self.tempPath}' - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) logging.statusWriter(self.tempStatusPath, 'Completed.[200]') return 1, f"/home/backup/{config['name']}.tar.gz" @@ -2561,10 +2591,16 @@ $parameters = array( self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) command = f'mkdir -p {self.tempPath}' - ProcessUtilities.executioner(command) + 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}' - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) ### Make directory for backup logging.statusWriter(self.tempStatusPath, 'Creating Backup Directory...,40') @@ -2632,7 +2668,10 @@ $parameters = array( FinalZipPath = '%s/%s.zip' % (websitepath, RandomPath) command = 'mkdir -p /home/backup/' - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) command = f"tar -czvf /home/backup/{config['name']}.tar.gz -P {self.tempPath}" retStatus, result = ProcessUtilities.outputExecutioner(command, None, None, None, 1) @@ -2647,7 +2686,10 @@ $parameters = array( logging.writeToFile(result) command = f'rm -rf {self.tempPath}' - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) logging.statusWriter(self.tempStatusPath, 'Completed.[200]') return 1, f"/home/backup/{config['name']}.tar.gz" @@ -2668,9 +2710,11 @@ $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']) + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile("Error Restore WP backup Now ....... start:%s"% self.extraArgs['Domain']) + self.tempStatusPath = self.extraArgs['tempStatusPath'] - logging.statusWriter(self.tempStatusPath, 'Restoring BackUp...,10') + logging.statusWriter(self.tempStatusPath, 'Restoring backup...,10') DesSiteID = self.extraArgs['DesSiteID'] backupid = self.extraArgs['backupid'] DomainName = self.extraArgs['Domain'] @@ -2710,20 +2754,32 @@ $parameters = array( ######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") + 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) - stdout = ProcessUtilities.outputExecutioner(command) - Finaldbuser = stdout.rstrip("\n") + 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) - stdout = ProcessUtilities.outputExecutioner(command) - Finaldbpasswd = stdout.rstrip("\n") + 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 @@ -2732,60 +2788,97 @@ $parameters = array( self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) command = f'mkdir -p {self.tempPath}' - ProcessUtilities.executioner(command) + 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}' - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) # ##Remove temppath command = f'rm -rf {self.tempPath}' - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) ###Restart Server @@ -2819,24 +2912,39 @@ $parameters = array( self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) command = f'mkdir -p {self.tempPath}' - ProcessUtilities.executioner(command) + 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}' - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) logging.statusWriter(self.tempStatusPath, 'Copying Data File...,50') ###Copy backup content to newsite @@ -2858,14 +2966,20 @@ $parameters = array( b = newWPpath.rstrip('/') newwebpath = b.rstrip(newpathexta) command = "sudo -u %s mkdir %s%s" % (VHuser, newwebpath, pathexta) - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) Webnewpath = str(newwebpath) + str(pathexta) else: 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) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) Webnewpath = str(newWPpath) + str(pathexta) else: @@ -2874,22 +2988,32 @@ $parameters = array( Webnewpath = newWPpath command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, Webnewpath) - result = ProcessUtilities.outputExecutioner(command) + 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, Webnewpath) - result = ProcessUtilities.outputExecutioner(command) - + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) # ##Remove temppath command = f'rm -rf {self.tempPath}' @@ -2968,24 +3092,39 @@ $parameters = array( self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) command = f'mkdir -p {self.tempPath}' - ProcessUtilities.executioner(command) + 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}' - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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 @@ -2996,10 +3135,16 @@ $parameters = array( self.tempPath, oldtemppath) command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) - result = ProcessUtilities.outputExecutioner(command) + 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 = ProcessUtilities.outputExecutioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) @@ -3007,15 +3152,24 @@ $parameters = array( ########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) + 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) - ProcessUtilities.outputExecutioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) ##Remove temppath command = f'rm -rf {self.tempPath}' - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) ###Restart Server @@ -3044,9 +3198,6 @@ $parameters = array( 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) @@ -3054,19 +3205,35 @@ $parameters = array( ######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") + + 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) - stdout = ProcessUtilities.outputExecutioner(command) - Finaldbuser = stdout.rstrip("\n") + + + 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) - stdout = ProcessUtilities.outputExecutioner(command) - Finaldbpasswd = stdout.rstrip("\n") + + 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 @@ -3076,24 +3243,38 @@ $parameters = array( self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) command = f'mkdir -p {self.tempPath}' - ProcessUtilities.executioner(command) + 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}' - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise BaseException(stdout) logging.statusWriter(self.tempStatusPath, 'Copying Data File...,50') @@ -3116,14 +3297,20 @@ $parameters = array( b = newWPpath.rstrip('/') newwebpath = b.rstrip(newpathexta) command = "sudo -u %s mkdir %s%s" % (VHuser, newwebpath, pathexta) - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) Webnewpath = str(newwebpath) + str(pathexta) else: 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) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) Webnewpath = str(newWPpath) + str(pathexta) else: @@ -3133,42 +3320,69 @@ $parameters = array( command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, Webnewpath) - result = ProcessUtilities.outputExecutioner(command) + 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, Webnewpath) - result = ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) # ##Remove temppath command = f'rm -rf {self.tempPath}' - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) ###Restart Server @@ -3247,20 +3461,35 @@ $parameters = array( ######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") + + 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) - stdout = ProcessUtilities.outputExecutioner(command) - Finaldbuser = stdout.rstrip("\n") + + 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) - stdout = ProcessUtilities.outputExecutioner(command) - Finaldbpasswd = stdout.rstrip("\n") + + 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 @@ -3269,24 +3498,39 @@ $parameters = array( self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) command = f'mkdir -p {self.tempPath}' - ProcessUtilities.executioner(command) + 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}' - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.executioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) logging.statusWriter(self.tempStatusPath, 'Copying Data File...,60') @@ -3297,47 +3541,74 @@ $parameters = array( 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) + 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 = ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + 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) - ProcessUtilities.outputExecutioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) ##Remove temppath command = f'rm -rf {self.tempPath}' - ProcessUtilities.executioner(command) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if stdout.find('Error:') > -1: + raise BaseException(stdout) ###Restart Server diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index a8cd0a675..9b738ec59 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -165,11 +165,11 @@ class WebsiteManager: currentACL = ACLManager.loadedACL(userID) admin = Administrator.objects.get(pk=userID) - backobj = WPSitesBackup.objects.filter(owner=admin) + backobj = WPSitesBackup.objects.filter(owner=admin).order_by('-id') try: if DeleteID != None: - DeleteIDobj = WPSitesBackup.objects.get(pk=DeleteID) + DeleteIDobj = WPSitesBackup.objects.get(pk=DeleteID, owner=admin) config = DeleteIDobj.config conf = json.loads(config) FileName = conf['name']