mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 13:56:01 +01:00
feature: finish wp manager
This commit is contained in:
@@ -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")
|
||||
@@ -2400,3 +2400,92 @@ class CloudManager:
|
||||
return wm.startSync(self.admin.pk, self.data)
|
||||
except BaseException as msg:
|
||||
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)
|
||||
@@ -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':
|
||||
|
||||
@@ -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)))
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
<h2 style="display: inline; color: #414C59;" ng-bind="web.domain"></h2>
|
||||
</a>
|
||||
<a target="_blank" href="/filemanager/{$ web.domain $}" title="Open File Manager"> --
|
||||
/home/{$ web.domain $}/public_html</a>
|
||||
File Manager</a>
|
||||
</div>
|
||||
<div class="col-md-2 content-box-header" style="text-transform: none;">
|
||||
<a href="/websites/{$ web.domain $}" target="_blank" title="Manage Website">
|
||||
|
||||
Reference in New Issue
Block a user