From 5dd37847b4af726e92e5dbf63ec7982f23b5a9b8 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Tue, 12 Jan 2021 17:56:36 +0500 Subject: [PATCH] wp manager cmplt --- cloudAPI/cloudManager.py | 25 +++++++- cloudAPI/views.py | 2 + plogical/IncScheduler.py | 4 ++ plogical/applicationInstaller.py | 99 +++++++++++++++++++++----------- plogical/backupUtilities.py | 8 +++ websiteFunctions/StagingSetup.py | 2 +- 6 files changed, 103 insertions(+), 37 deletions(-) diff --git a/cloudAPI/cloudManager.py b/cloudAPI/cloudManager.py index bd306422c..5571d016b 100755 --- a/cloudAPI/cloudManager.py +++ b/cloudAPI/cloudManager.py @@ -1943,12 +1943,12 @@ class CloudManager: execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/applicationInstaller.py" execPath = execPath + " DeployWordPress --tempStatusPath %s --appsSet '%s' --domain '%s' --email '%s' --password '%s' " \ "--pluginUpdates '%s' --themeUpdates '%s' --title '%s' --updates '%s' --userName '%s' " \ - "--version '%s'" % ( + "--version '%s' --createSite %s" % ( tempStatusPath, self.data['appsSet'], self.data['domain'], self.data['email'], self.data['password'], self.data['pluginUpdates'], self.data['themeUpdates'], self.data['title'], self.data['updates'], - self.data['userName'], self.data['version']) + self.data['userName'], self.data['version'], str(self.data['createSite'])) try: execPath = '%s --path %s' % (execPath, self.data['path']) @@ -2485,6 +2485,27 @@ class CloudManager: final_json = json.dumps({'status': 1}) return HttpResponse(final_json) + except BaseException as msg: + final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + def WPScan(self): + try: + + path = '/home/%s/public_html' % (self.data['domainName']) + + command = 'wp core version --allow-root --path=%s' % (path) + result = ProcessUtilities.outputExecutioner(command) + + if result.find('Error:') > -1: + final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': 'This does not seem to be a WordPress installation'} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + else: + final_json = json.dumps({'status': 1}) + return HttpResponse(final_json) + except BaseException as msg: final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) diff --git a/cloudAPI/views.py b/cloudAPI/views.py index bf775fe63..4f756cd2f 100755 --- a/cloudAPI/views.py +++ b/cloudAPI/views.py @@ -97,6 +97,8 @@ def router(request): return cm.ChangeState() elif controller == 'saveWPSettings': return cm.saveWPSettings() + elif controller == 'WPScan': + return cm.WPScan() elif controller == 'getCurrentS3Backups': return cm.getCurrentS3Backups() elif controller == 'deleteS3Backup': diff --git a/plogical/IncScheduler.py b/plogical/IncScheduler.py index 0f3b4a2ef..f24a0d13e 100644 --- a/plogical/IncScheduler.py +++ b/plogical/IncScheduler.py @@ -683,6 +683,10 @@ Automatic backup failed for %s on %s. extraArgs['data'] = int(PlanConfig['data']) extraArgs['emails'] = int(PlanConfig['emails']) extraArgs['databases'] = int(PlanConfig['databases']) + extraArgs['port'] = '0' + extraArgs['ip'] = '0' + extraArgs['destinationDomain'] = 'None' + extraArgs['path'] = '/home/cyberpanel/backups/%s/backup-' % (items.domain) + items.domain + "-" + time.strftime("%m.%d.%Y_%H-%M-%S") bu = backupUtilities(extraArgs) result, fileName = bu.CloudBackups() diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index ad4039299..9b004bf3a 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -574,7 +574,10 @@ $parameters = array( except: command = "wp core download --allow-root --path=" + finalPath - ProcessUtilities.executioner(command, externalApp) + result = ProcessUtilities.outputExecutioner(command, externalApp) + + if result.find('Success:') == -1: + raise BaseException(result) ## @@ -583,7 +586,10 @@ $parameters = array( statusFile.close() command = "wp core config --dbname=" + dbName + " --dbuser=" + dbUser + " --dbpass=" + dbPassword + " --dbhost=%s --dbprefix=wp_ --allow-root --path=" % (ApplicationInstaller.LOCALHOST) + finalPath - ProcessUtilities.executioner(command, externalApp) + result = ProcessUtilities.outputExecutioner(command, externalApp) + + if result.find('Success:') == -1: + raise BaseException(result) if home == '0': path = self.extraArgs['path'] @@ -592,7 +598,10 @@ $parameters = array( finalURL = domainName command = 'wp core install --url="http://' + finalURL + '" --title="' + blogTitle + '" --admin_user="' + adminUser + '" --admin_password="' + adminPassword + '" --admin_email="' + adminEmail + '" --allow-root --path=' + finalPath - ProcessUtilities.executioner(command, externalApp) + result = ProcessUtilities.outputExecutioner(command, externalApp) + + if result.find('Success:') == -1: + raise BaseException(result) ## @@ -601,26 +610,43 @@ $parameters = array( statusFile.close() command = "wp plugin install litespeed-cache --allow-root --path=" + finalPath - ProcessUtilities.executioner(command, externalApp) + result = ProcessUtilities.outputExecutioner(command, externalApp) + + if result.find('Success:') == -1: + raise BaseException(result) statusFile = open(tempStatusPath, 'w') statusFile.writelines('Activating LSCache Plugin,90') statusFile.close() command = "wp plugin activate litespeed-cache --allow-root --path=" + finalPath - ProcessUtilities.executioner(command, externalApp) + result = ProcessUtilities.outputExecutioner(command, externalApp) - if self.extraArgs['updates']: + if result.find('Success:') == -1: + raise BaseException(result) - if self.extraArgs['updates'] == 'Disabled': - command = "wp config set WP_AUTO_UPDATE_CORE false --raw --allow-root --path=" + finalPath - ProcessUtilities.executioner(command, externalApp) - elif self.extraArgs['updates'] == 'Minor and Security Updates': - command = "wp config set WP_AUTO_UPDATE_CORE minor --allow-root --path=" + finalPath - ProcessUtilities.executioner(command, externalApp) - else: - command = "wp config set WP_AUTO_UPDATE_CORE true --raw --allow-root --path=" + finalPath - ProcessUtilities.executioner(command, externalApp) + try: + if self.extraArgs['updates']: + if self.extraArgs['updates'] == 'Disabled': + command = "wp config set WP_AUTO_UPDATE_CORE false --raw --allow-root --path=" + finalPath + result = ProcessUtilities.outputExecutioner(command, externalApp) + + if result.find('Success:') == -1: + raise BaseException(result) + elif self.extraArgs['updates'] == 'Minor and Security Updates': + command = "wp config set WP_AUTO_UPDATE_CORE minor --allow-root --path=" + finalPath + result = ProcessUtilities.outputExecutioner(command, externalApp) + + if result.find('Success:') == -1: + raise BaseException(result) + else: + command = "wp config set WP_AUTO_UPDATE_CORE true --raw --allow-root --path=" + finalPath + result = ProcessUtilities.outputExecutioner(command, externalApp) + + if result.find('Success:') == -1: + raise BaseException(result) + except: + pass ## @@ -1227,23 +1253,25 @@ $parameters = array( def DeployWordPress(self): try: - logging.statusWriter(self.extraArgs['tempStatusPath'], 'Creating this application..,10') - ## Create site + if self.extraArgs['createSite']: + logging.statusWriter(self.extraArgs['tempStatusPath'], 'Creating this application..,10') - import re - from plogical.virtualHostUtilities import virtualHostUtilities - tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999)) - externalApp = "".join(re.findall("[a-zA-Z]+", self.extraArgs['domain']))[:5] + str(randint(1000, 9999)) + ## Create site - virtualHostUtilities.createVirtualHost(self.extraArgs['domain'], self.extraArgs['email'], 'PHP 7.4', - externalApp, 0, 1, 0, - 'admin', 'Default', 0, tempStatusPath, - 0) - result = open(tempStatusPath, 'r').read() - if result.find('[404]') > -1: - logging.statusWriter(self.extraArgs['tempStatusPath'], 'Failed to create application. Error: %s [404]' % (result)) - return 0 + import re + from plogical.virtualHostUtilities import virtualHostUtilities + tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999)) + externalApp = "".join(re.findall("[a-zA-Z]+", self.extraArgs['domain']))[:5] + str(randint(1000, 9999)) + + virtualHostUtilities.createVirtualHost(self.extraArgs['domain'], self.extraArgs['email'], 'PHP 7.4', + externalApp, 1, 1, 0, + 'admin', 'Default', 0, tempStatusPath, + 0) + result = open(tempStatusPath, 'r').read() + if result.find('[404]') > -1: + logging.statusWriter(self.extraArgs['tempStatusPath'], 'Failed to create application. Error: %s [404]' % (result)) + return 0 ## Install WordPress @@ -1261,9 +1289,8 @@ $parameters = array( result = open(self.extraArgs['tempStatusPath'], 'r').read() if result.find('[404]') > -1: - logging.statusWriter(self.extraArgs['tempStatusPath'], - 'Failed to install WordPress. Error: %s [404]' % (result)) - return 0 + self.extraArgs['tempStatusPath'] = currentTemp + raise BaseException('Failed to install WordPress. Error: %s [404]' % (result)) self.extraArgs['tempStatusPath'] = currentTemp @@ -1306,9 +1333,11 @@ $parameters = array( writeToFile.write('0 12 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/WPAutoUpdates.py\n') writeToFile.close() - - except BaseException as msg: + self.extraArgs['websiteName'] = self.extraArgs['domain'] + from websiteFunctions.website import WebsiteManager + wm = WebsiteManager() + wm.submitWebsiteDeletion(1, self.extraArgs) logging.statusWriter(self.extraArgs['tempStatusPath'], '%s [404].' % (str(msg))) def main(): @@ -1326,6 +1355,7 @@ def main(): parser.add_argument('--userName', help='') parser.add_argument('--version', help='') parser.add_argument('--path', help='') + parser.add_argument('--createSite', help='') args = parser.parse_args() @@ -1344,6 +1374,7 @@ def main(): extraArgs['updates'] = args.updates extraArgs['userName'] = args.userName extraArgs['version'] = args.version + extraArgs['createSite'] = int(args.createSite) if args.path != None: extraArgs['path'] = args.path diff --git a/plogical/backupUtilities.py b/plogical/backupUtilities.py index e9ffd4c0f..1160e6631 100755 --- a/plogical/backupUtilities.py +++ b/plogical/backupUtilities.py @@ -1646,6 +1646,14 @@ class backupUtilities: command = "wp search-replace '%s' '%s' --path=%s --allow-root" % (self.extraArgs['sourceDomain'], self.extraArgs['domain'], path) ProcessUtilities.outputExecutioner(command) + command = "wp search-replace 'www.%s' '%s' --path=%s --allow-root" % ( + self.extraArgs['sourceDomain'], self.extraArgs['domain'], path) + ProcessUtilities.outputExecutioner(command) + + command = "wp search-replace 'www.%s' '%s' --path=%s --allow-root" % ( + self.extraArgs['domain'], self.extraArgs['domain'], path) + ProcessUtilities.outputExecutioner(command) + command = 'rm -rf %s' % (self.extractedPath) ProcessUtilities.executioner(command) diff --git a/websiteFunctions/StagingSetup.py b/websiteFunctions/StagingSetup.py index df6979ca6..9fe1c74b4 100644 --- a/websiteFunctions/StagingSetup.py +++ b/websiteFunctions/StagingSetup.py @@ -50,7 +50,7 @@ class StagingSetup(multi.Thread): execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" execPath = execPath + " createDomain --masterDomain " + masterDomain + " --virtualHostName " + domain + \ - " --phpVersion '" + phpSelection + "' --ssl 0 --dkimCheck 0 --openBasedir 0 --path " + path + ' --websiteOwner ' \ + " --phpVersion '" + phpSelection + "' --ssl 1 --dkimCheck 0 --openBasedir 0 --path " + path + ' --websiteOwner ' \ + admin.userName + ' --tempStatusPath %s' % (tempStatusPath + '1') + " --apache 0" ProcessUtilities.executioner(execPath)