diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index 527f04581..f7a8c16f6 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -1,6 +1,7 @@ #!/usr/local/CyberCP/bin/python import argparse import os, sys +import shutil import time from loginSystem.models import Administrator @@ -75,6 +76,8 @@ class ApplicationInstaller(multi.Thread): self.ChangeStatusThemes() elif self.installApp == 'CreateStagingNow': self.CreateStagingNow() + elif self.installApp == 'DeploytoProduction': + self.DeploytoProduction() elif self.installApp == 'WPCreateBackup': self.WPCreateBackup() @@ -1985,8 +1988,10 @@ $parameters = array( ab = WebsiteManager() coreResult = ab.submitWebsiteCreation(UserID, DataToPass) coreResult1 = json.loads((coreResult).content) + if os.path.exists('/usr/local/CyberCP/debug'): logging.writeToFile("Creating website result....%s" % coreResult1) + reutrntempath = coreResult1['tempStatusPath'] while (1): @@ -2006,7 +2011,7 @@ $parameters = array( time.sleep(2) statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Installing WordPress....') + statusFile.writelines('Installing WordPress....,30') statusFile.close() ####No crreating DataBAse............. @@ -2033,20 +2038,18 @@ $parameters = array( FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) ## Staging site + StagingPath = f'/home/{website.domain}/public_html' command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp core download --path={StagingPath}' - ProcessUtilities.executioner(command, website.externalApp) + + if ProcessUtilities.executioner(command, website.externalApp) == 0: + raise BaseException('Failed to download wp core. [404]') command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp core config --dbname={dbNameRestore} --dbuser={dbUser} --dbpass={dbPassword} --dbhost={ApplicationInstaller.LOCALHOST}:{ApplicationInstaller.PORT} --path={StagingPath}' - ProcessUtilities.executioner(command, website.externalApp) + if ProcessUtilities.executioner(command, website.externalApp) == 0: + raise BaseException('WP Core congiruations failed. [404]') - try: - masterPath = '/home/%s/public_html/%s' % (masterDomain, path) - replaceDomain = '%s/%s' % (masterDomain, path) - except: - masterPath = '/home/%s/public_html' % (masterDomain) - replaceDomain = masterDomain ### Get table prefix of master site @@ -2056,7 +2059,8 @@ $parameters = array( ## Export database from master site command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp --allow-root --skip-plugins --skip-themes --path={path} db export {tempPath}/dbexport-stage.sql' - ProcessUtilities.executioner(command, wpobj.owner.externalApp) + if ProcessUtilities.executioner(command, wpobj.owner.externalApp) == 0: + raise BaseException('Failed to export database from master site. [404]') ## Copy wp content folder to securey path @@ -2064,15 +2068,19 @@ $parameters = array( WpContentPath = ProcessUtilities.outputExecutioner(command, wpobj.owner.externalApp).splitlines()[-1].replace('themes', '') command = f'cp -R {WpContentPath} {tempPath}/' - ProcessUtilities.executioner(command, wpobj.owner.externalApp) + if ProcessUtilities.executioner(command, wpobj.owner.externalApp) == 0: + raise BaseException('Failed to copy wp-content from master to temp folder. [404]') command = f'cp -f {path}/.htaccess {tempPath}/' - ProcessUtilities.executioner(command, wpobj.owner.externalApp) + + if ProcessUtilities.executioner(command, wpobj.owner.externalApp) == 0: + logging.writeToFile('While staging creation .htaccess file did not copy') ### Set table prefix command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp config set table_prefix {TablePrefix} --path={StagingPath}' - ProcessUtilities.executioner(command, website.externalApp) + if ProcessUtilities.executioner(command, website.externalApp) == 0: + raise BaseException('Failed to set table prefix on staging site. [404]') ### Change permissions of temp folder to staging site @@ -2083,7 +2091,8 @@ $parameters = array( ## Import Database command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp --allow-root --skip-plugins --skip-themes --path={StagingPath} --quiet db import {tempPath}/dbexport-stage.sql' - ProcessUtilities.executioner(command, website.externalApp) + if ProcessUtilities.executioner(command, website.externalApp) ==0: + raise BaseException('Failed to import database on staging site. [404]') try: command = 'rm -f %s/dbexport-stage.sql' % (tempPath) @@ -2097,28 +2106,32 @@ $parameters = array( ProcessUtilities.executioner(command, website.externalApp) command = f'mv {tempPath}/wp-content {StagingPath}/' - ProcessUtilities.executioner(command, website.externalApp) + if ProcessUtilities.executioner(command, website.externalApp) == 0: + raise BaseException('Failed to copy wp-content from temp to staging site. [404]') ## Copy htaccess command = f'cp -f {tempPath}/.htaccess {StagingPath}/' - ProcessUtilities.executioner(command, wpobj.owner.externalApp) + if ProcessUtilities.executioner(command, wpobj.owner.externalApp) == 0: + logging.writeToFile('While staging creation .htaccess file did not copy') ## Search and replace url - command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path={StagingPath} "{replaceDomain}" "{domain}"' - ProcessUtilities.executioner(command, website.externalApp) + command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path={StagingPath} "{masterDomain}" "{domain}"' + if ProcessUtilities.executioner(command, website.externalApp) == 0: + raise BaseException('search-replace failed 1. [404]') - command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path={StagingPath} "www.{replaceDomain}" "{domain}"' - ProcessUtilities.executioner(command,website.externalApp) + command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path={StagingPath} "www.{masterDomain}" "{domain}"' + if ProcessUtilities.executioner(command,website.externalApp) == 0: + raise BaseException('search-replace failed 2. [404]') command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path={StagingPath} "https://{domain}" "http://{domain}"' - ProcessUtilities.executioner(command,website.externalApp) + if ProcessUtilities.executioner(command,website.externalApp) == 0: + raise BaseException('search-replace failed 3. [404]') from plogical.installUtilities import installUtilities installUtilities.reStartLiteSpeed() - wpsite = WPSites(owner=website, title=self.data['StagingName'], path ="/home/%s/public_html"%(self.extraArgs['StagingDomain']), FinalURL='%s' % (self.data['StagingDomain'])) @@ -2128,20 +2141,123 @@ $parameters = array( ProcessUtilities.executioner(command) WPStaging(wpsite=wpsite, owner=wpobj).save() + + statusFile = open(currentTemp, 'w') statusFile.writelines('Staging site created,[200]') statusFile.close() - except BaseException as msg: command = f'rm -rf {self.tempPath}' ProcessUtilities.executioner(command) statusFile = open(self.tempStatusPath, 'w') statusFile.writelines(f'{str(msg)}[404]') statusFile.close() - logging.writeToFile("Error WP ChangeStatusThemes ....... %s" % str(msg)) return 0 + + def DeploytoProduction(self): + + try: + self.tempStatusPath = self.extraArgs['tempStatusPath'] + self.statgingID = self.extraArgs['statgingID'] + self.WPid = self.extraArgs['WPid'] + + StagingSite = WPSites.objects.get(pk=self.statgingID) + WPSite = WPSites.objects.get(pk=self.WPid) + + ### Create secure folder + ACLManager.CreateSecureDir() + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', str(randint(1000, 9999))) + + command = f'mkdir -p {self.tempPath}' + ProcessUtilities.executioner(command) + + command = f'chown -R {StagingSite.owner.externalApp}:{StagingSite.owner.externalApp} {self.tempPath}' + ProcessUtilities.executioner(command) + + + from managePHP.phpManager import PHPManager + php = PHPManager.getPHPString(StagingSite.owner.phpSelection) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + ## Restore db + + logging.statusWriter(self.tempStatusPath, 'Creating database backup..,10') + + command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp --allow-root --skip-plugins --skip-themes --path={StagingSite.path} db export {self.tempPath}/dbexport-stage.sql' + if ProcessUtilities.executioner(command) == 0: + raise BaseException('Failed to create database backup of staging site. [404]') + + command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp theme path --skip-plugins --skip-themes --allow-root --path={WPSite.path}' + WpContentPath = ProcessUtilities.outputExecutioner(command, StagingSite.owner.externalApp).splitlines()[-1].replace('themes', '') + + logging.statusWriter(self.tempStatusPath, 'Moving staging site content..,20') + + command = f'cp -R {StagingSite.path}/wp-content/ {self.tempPath}/' + if ProcessUtilities.executioner(command, StagingSite.owner.externalApp) ==0: + raise BaseException('Failed copy wp-content from staging to temp folder. [404]') + + command = f'cp -f {StagingSite.path}/.htaccess {self.tempPath}/' + ProcessUtilities.executioner(command, StagingSite.owner.externalApp) + + ### First import db backup to main site + + command = f'chown -R {WPSite.owner.externalApp}:{WPSite.owner.externalApp} {self.tempPath}' + ProcessUtilities.executioner(command) + + ## Import Database + + logging.statusWriter(self.tempStatusPath, 'Importing database..,60') + + command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp --allow-root --skip-plugins --skip-themes --path={WPSite.path} --quiet db import {self.tempPath}/dbexport-stage.sql' + if ProcessUtilities.executioner(command, WPSite.owner.externalApp) == 0: + raise BaseException('Failed to import database backup into master site. [404]') + + try: + command = 'rm -f %s/dbexport-stage.sql' % (self.tempPath) + ProcessUtilities.executioner(command) + except: + pass + + logging.statusWriter(self.tempStatusPath, 'Moving content..,80') + + + command = f'cp -R {self.tempPath}/wp-content/* {WpContentPath}' + if ProcessUtilities.executioner(command, WPSite.owner.externalApp) == 0: + raise BaseException('Failed to copy wp-content to master site. [404]') + + ## Search and replace url + + command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path={WPSite.path} "{StagingSite.FinalURL}" "{WPSite.FinalURL}"' + if ProcessUtilities.executioner(command, WPSite.owner.externalApp) == 0: + raise BaseException('search-replace failed 1. [404]') + + command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path={WPSite.path} "www.{StagingSite.FinalURL}" "{WPSite.FinalURL}"' + if ProcessUtilities.executioner(command, WPSite.owner.externalApp) == 0: + raise BaseException('search-replace failed 2. [404]') + + command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path={WPSite.path} "https://{WPSite.FinalURL}" "http://{WPSite.FinalURL}"' + if ProcessUtilities.executioner(command, WPSite.owner.externalApp) == 0: + raise BaseException('search-replace failed 3. [404]') + + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() + + + command = f'rm -rf {self.tempPath}' + ProcessUtilities.executioner(command) + + + logging.statusWriter(self.tempStatusPath, 'Completed.[200]') + + return 0 + except BaseException as msg: + command = f'rm -rf {self.tempPath}' + ProcessUtilities.executioner(command) + mesg = '%s. [404]' % (str(msg)) + logging.statusWriter(self.tempStatusPath, mesg) + def WPCreateBackup(self): try: from managePHP.phpManager import PHPManager @@ -2303,6 +2419,7 @@ $parameters = array( return 0 + def main(): parser = argparse.ArgumentParser(description='CyberPanel Application Installer') parser.add_argument('function', help='Specify a function to call!') diff --git a/plogical/upgrade.py b/plogical/upgrade.py index 7cccd7b32..2f2709862 100755 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -905,6 +905,16 @@ autocreate_system_folders = On except: pass + try: + cursor.execute("CREATE TABLE `websiteFunctions_wpsitesbackup` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `WPSiteID` integer NOT NULL, `WebsiteID` integer NOT NULL, `config` longtext NOT NULL, `owner_id` integer NOT NULL); ") + except: + pass + + try: + cursor.execute("ALTER TABLE `websiteFunctions_wpsitesbackup` ADD CONSTRAINT `websiteFunctions_wps_owner_id_8a8dd0c5_fk_loginSyst` FOREIGN KEY (`owner_id`) REFERENCES `loginSystem_administrator` (`id`); ") + except: + pass + try: connection.close() except: diff --git a/websiteFunctions/models.py b/websiteFunctions/models.py index c799a29bd..34647f3e1 100755 --- a/websiteFunctions/models.py +++ b/websiteFunctions/models.py @@ -122,3 +122,9 @@ class WPSites(models.Model): class WPStaging(models.Model): owner = models.ForeignKey(WPSites, on_delete=models.CASCADE) wpsite = models.ForeignKey(WPSites, on_delete=models.CASCADE, related_name='actual_wpsite') + +class WPSitesBackup(models.Model): + owner = models.ForeignKey(Administrator, on_delete=models.CASCADE) + WPSiteID = models.IntegerField(default=-1) + WebsiteID = models.IntegerField(default=-1) + config = models.TextField() diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 7f7eb881d..bbfd4fcce 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -444,6 +444,12 @@ function FinalDeleteWPNow() { window.location.href = FurlDeleteWP; } +var DeploytoProductionID; + +function DeployToProductionInitial(vall) { + DeploytoProductionID = vall; +} + app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $window) { $scope.wordpresshomeloading = true; @@ -1322,19 +1328,33 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo } }; - var DeploytoProductionID; - - function DeployToProductionInitial(vall) { - DeploytoProductionID = vall; + function AddStagings(value, index, array) { + var FinalMarkup = '