diff --git a/cloudAPI/cloudManager.py b/cloudAPI/cloudManager.py index 1f38b74a8..bd306422c 100755 --- a/cloudAPI/cloudManager.py +++ b/cloudAPI/cloudManager.py @@ -1672,7 +1672,7 @@ class CloudManager: try: destinationDomain = self.data['destinationDomain'] except: - destinationDomain = '' + destinationDomain = 'None' import time BackupPath = '/home/cyberpanel/backups/%s/backup-' % (self.data['domain']) + self.data['domain'] + "-" + time.strftime("%m.%d.%Y_%H-%M-%S") @@ -2399,4 +2399,93 @@ class CloudManager: wm = WebsiteManager() return wm.startSync(self.admin.pk, self.data) except BaseException as msg: - return self.ajaxPre(0, str(msg)) \ No newline at end of file + return self.ajaxPre(0, str(msg)) + + def SaveAutoUpdateSettings(self): + try: + website = Websites.objects.get(domain=self.data['domainName']) + domainName = self.data['domainName'] + from cloudAPI.models import WPDeployments + wpd = WPDeployments.objects.get(owner=website) + config = json.loads(wpd.config) + config['updates'] = self.data['wpCore'] + config['pluginUpdates'] = self.data['plugins'] + config['themeUpdates'] = self.data['themes'] + wpd.config = json.dumps(config) + wpd.save() + + if self.data['wpCore'] == 'Disabled': + command = "wp config set WP_AUTO_UPDATE_CORE false --raw --path=/home/%s/public_html" % (domainName) + ProcessUtilities.executioner(command, website.externalApp) + elif self.data['wpCore'] == 'Minor and Security Updates': + command = "wp config set WP_AUTO_UPDATE_CORE minor --allow-root --path=/home/%s/public_html" % (domainName) + ProcessUtilities.executioner(command, website.externalApp) + else: + command = "wp config set WP_AUTO_UPDATE_CORE true --raw --allow-root --path=/home/%s/public_html" % (domainName) + ProcessUtilities.executioner(command, website.externalApp) + + final_json = json.dumps( + {'status': 1, 'message': "Autoupdates configured."}) + 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 fetchWPSettings(self): + try: + + cliVersion = ProcessUtilities.outputExecutioner('wp --version --allow-root') + + if cliVersion.find('not found') > -1: + cliVersion = 'WP CLI Not installed.' + + if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + localCronPath = "/var/spool/cron/root" + else: + localCronPath = "/var/spool/cron/crontabs/root" + + cronData = ProcessUtilities.outputExecutioner('cat %s' % (localCronPath)).split('\n') + + finalCron = '' + for cronLine in cronData: + if cronLine.find('WPAutoUpdates.py') > -1: + finalCron = cronLine + + + if finalCron.find('WPAutoUpdates.py') == -1: + finalCron = 'Not Set' + + final_json = json.dumps( + {'status': 1, 'cliVersion': cliVersion, 'finalCron': finalCron}) + 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 updateWPCLI(self): + try: + + command = 'wp cli update' + ProcessUtilities.executioner(command) + 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 saveWPSettings(self): + try: + + command = 'wp cli update' + ProcessUtilities.executioner(command) + 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) \ No newline at end of file diff --git a/cloudAPI/views.py b/cloudAPI/views.py index a866f308d..bf775fe63 100755 --- a/cloudAPI/views.py +++ b/cloudAPI/views.py @@ -14,10 +14,14 @@ def router(request): controller = data['controller'] serverUserName = data['serverUserName'] + admin = Administrator.objects.get(userName=serverUserName) cm = CloudManager(data, admin) + if serverUserName != 'admin': + return cm.ajaxPre(0, 'Only administrator can access API.') + if admin.api == 0: return cm.ajaxPre(0, 'API Access Disabled.') @@ -91,6 +95,8 @@ def router(request): return cm.UpdatePlugins() elif controller == 'ChangeState': return cm.ChangeState() + elif controller == 'saveWPSettings': + return cm.saveWPSettings() elif controller == 'getCurrentS3Backups': return cm.getCurrentS3Backups() elif controller == 'deleteS3Backup': @@ -237,6 +243,12 @@ def router(request): return cm.CreateStaging(request) elif controller == 'startSync': return cm.startSync(request) + elif controller == 'SaveAutoUpdateSettings': + return cm.SaveAutoUpdateSettings() + elif controller == 'fetchWPSettings': + return cm.fetchWPSettings() + elif controller == 'updateWPCLI': + return cm.updateWPCLI() elif controller == 'setupNode': return cm.setupManager(request) elif controller == 'fetchManagerTokens': diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index 82b3dd2f2..ad4039299 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -610,6 +610,18 @@ $parameters = array( command = "wp plugin activate litespeed-cache --allow-root --path=" + finalPath ProcessUtilities.executioner(command, externalApp) + if self.extraArgs['updates']: + + 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) + ## @@ -1280,6 +1292,22 @@ $parameters = array( except: pass + ## Set up cron if missing + + if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + localCronPath = "/var/spool/cron/root" + else: + localCronPath = "/var/spool/cron/crontabs/root" + + cronData = open(localCronPath, 'r').read() + + if cronData.find('WPAutoUpdates.py') == -1: + writeToFile = open(localCronPath, 'a') + writeToFile.write('0 12 * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/WPAutoUpdates.py\n') + writeToFile.close() + + + except BaseException as msg: logging.statusWriter(self.extraArgs['tempStatusPath'], '%s [404].' % (str(msg))) diff --git a/websiteFunctions/templates/websiteFunctions/listWebsites.html b/websiteFunctions/templates/websiteFunctions/listWebsites.html index 29ac71118..8fd9a21dd 100755 --- a/websiteFunctions/templates/websiteFunctions/listWebsites.html +++ b/websiteFunctions/templates/websiteFunctions/listWebsites.html @@ -57,7 +57,7 @@

-- - /home/{$ web.domain $}/public_html + File Manager