mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-08 06:16:08 +01:00
feature: finish initial wp manager
This commit is contained in:
@@ -1659,12 +1659,31 @@ class CloudManager:
|
||||
except:
|
||||
databases = '0'
|
||||
|
||||
try:
|
||||
port = str(self.data['port'])
|
||||
except:
|
||||
port = '0'
|
||||
|
||||
try:
|
||||
ip = str(self.data['ip'])
|
||||
except:
|
||||
ip = '0'
|
||||
|
||||
try:
|
||||
destinationDomain = self.data['destinationDomain']
|
||||
except:
|
||||
destinationDomain = ''
|
||||
|
||||
import time
|
||||
BackupPath = '/home/cyberpanel/backups/%s/backup-' % (self.data['domain']) + self.data['domain'] + "-" + time.strftime("%m.%d.%Y_%H-%M-%S")
|
||||
|
||||
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
|
||||
execPath = execPath + " CloudBackup --backupDomain %s --data %s --emails %s --databases %s --tempStoragePath %s" % (
|
||||
self.data['domain'], data, emails, databases, tempStatusPath)
|
||||
execPath = execPath + " CloudBackup --backupDomain %s --data %s --emails %s --databases %s --tempStoragePath %s " \
|
||||
"--path %s --port %s --ip %s --destinationDomain %s" % (
|
||||
self.data['domain'], data, emails, databases, tempStatusPath, BackupPath, port, ip, destinationDomain)
|
||||
ProcessUtilities.popenExecutioner(execPath)
|
||||
|
||||
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
|
||||
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath, 'path': '%s.tar.gz' % (BackupPath)}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
@@ -1774,9 +1793,14 @@ class CloudManager:
|
||||
writeToFile.write('Starting..,0')
|
||||
writeToFile.close()
|
||||
|
||||
try:
|
||||
sourceDomain = self.data['sourceDomain']
|
||||
except:
|
||||
sourceDomain = 'None'
|
||||
|
||||
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
|
||||
execPath = execPath + " SubmitCloudBackupRestore --backupDomain %s --backupFile %s --tempStoragePath %s" % (
|
||||
self.data['domain'], self.data['backupFile'], tempStatusPath)
|
||||
execPath = execPath + " SubmitCloudBackupRestore --backupDomain %s --backupFile %s --sourceDomain %s --tempStoragePath %s" % (
|
||||
self.data['domain'], self.data['backupFile'],sourceDomain, tempStatusPath)
|
||||
ProcessUtilities.popenExecutioner(execPath)
|
||||
|
||||
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
|
||||
@@ -1993,11 +2017,8 @@ class CloudManager:
|
||||
|
||||
## Get title
|
||||
|
||||
from cloudAPI.models import WPDeployments
|
||||
import json
|
||||
wpd = WPDeployments.objects.get(owner=website)
|
||||
config = json.loads(wpd.config)
|
||||
finalDic['title'] = config['title']
|
||||
command = 'wp option get blogname --path=/home/%s/public_html' % (domain)
|
||||
finalDic['title'] = ProcessUtilities.outputExecutioner(command, website.externalApp)
|
||||
|
||||
##
|
||||
|
||||
@@ -2321,3 +2342,61 @@ class CloudManager:
|
||||
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def GetServerPublicSSHkey(self):
|
||||
try:
|
||||
|
||||
path = '/root/.ssh/cyberpanel.pub'
|
||||
command = 'cat %s' % (path)
|
||||
key = ProcessUtilities.outputExecutioner(command)
|
||||
|
||||
final_dic = {'status': 1, 'key': key}
|
||||
final_json = json.dumps(final_dic)
|
||||
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 SubmitPublicKey(self):
|
||||
try:
|
||||
|
||||
fm = FirewallManager()
|
||||
fm.addSSHKey(self.admin.pk, self.data)
|
||||
|
||||
## Create backup path so that file can be sent here later.
|
||||
|
||||
BackupPath = '/home/cyberpanel/backups/%s' % (self.data['domain'])
|
||||
command = 'mkdir -p %s' % (BackupPath)
|
||||
ProcessUtilities.executioner(command, 'cyberpanel')
|
||||
|
||||
###
|
||||
|
||||
from WebTerminal.CPWebSocket import SSHServer
|
||||
SSHServer.findSSHPort()
|
||||
|
||||
final_dic = {'status': 1, 'port': SSHServer.DEFAULT_PORT}
|
||||
final_json = json.dumps(final_dic)
|
||||
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 CreateStaging(self, request):
|
||||
try:
|
||||
request.session['userID'] = self.admin.pk
|
||||
wm = WebsiteManager()
|
||||
return wm.startCloning(self.admin.pk, self.data)
|
||||
except BaseException as msg:
|
||||
return self.ajaxPre(0, str(msg))
|
||||
|
||||
def startSync(self, request):
|
||||
try:
|
||||
request.session['userID'] = self.admin.pk
|
||||
wm = WebsiteManager()
|
||||
return wm.startSync(self.admin.pk, self.data)
|
||||
except BaseException as msg:
|
||||
return self.ajaxPre(0, str(msg))
|
||||
@@ -79,6 +79,10 @@ def router(request):
|
||||
return cm.ChangeStateThemes()
|
||||
elif controller == 'DeleteThemes':
|
||||
return cm.DeleteThemes()
|
||||
elif controller == 'GetServerPublicSSHkey':
|
||||
return cm.GetServerPublicSSHkey()
|
||||
elif controller == 'SubmitPublicKey':
|
||||
return cm.SubmitPublicKey()
|
||||
elif controller == 'UpdateWPSettings':
|
||||
return cm.UpdateWPSettings()
|
||||
elif controller == 'GetCurrentPlugins':
|
||||
@@ -229,6 +233,10 @@ def router(request):
|
||||
return cm.getLogsFromFile(request)
|
||||
elif controller == 'serverSSL':
|
||||
return cm.serverSSL(request)
|
||||
elif controller == 'CreateStaging':
|
||||
return cm.CreateStaging(request)
|
||||
elif controller == 'startSync':
|
||||
return cm.startSync(request)
|
||||
elif controller == 'setupNode':
|
||||
return cm.setupManager(request)
|
||||
elif controller == 'fetchManagerTokens':
|
||||
@@ -372,7 +380,6 @@ def router(request):
|
||||
cm = CloudManager(None)
|
||||
return cm.ajaxPre(0, str(msg))
|
||||
|
||||
@csrf_exempt
|
||||
def access(request):
|
||||
try:
|
||||
serverUserName = request.GET.get('serverUserName')
|
||||
@@ -385,6 +392,10 @@ def access(request):
|
||||
return HttpResponse('API Access Disabled.')
|
||||
|
||||
if token == admin.token.lstrip('Basic ').rstrip('='):
|
||||
try:
|
||||
del request.session['userID']
|
||||
except:
|
||||
pass
|
||||
request.session['userID'] = admin.pk
|
||||
from django.shortcuts import redirect
|
||||
from baseTemplate.views import renderBase
|
||||
|
||||
@@ -711,6 +711,9 @@ class FileManager:
|
||||
else:
|
||||
groupName = 'nogroup'
|
||||
|
||||
command = 'chown %s:%s /home/%s' % (website.externalApp, website.externalApp, domainName)
|
||||
ProcessUtilities.popenExecutioner(command)
|
||||
|
||||
command = 'chown -R %s:%s /home/%s/public_html/*' % (externalApp, externalApp, domainName)
|
||||
ProcessUtilities.popenExecutioner(command)
|
||||
|
||||
|
||||
@@ -1255,14 +1255,17 @@ $parameters = array(
|
||||
|
||||
self.extraArgs['tempStatusPath'] = currentTemp
|
||||
|
||||
|
||||
logging.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].')
|
||||
|
||||
try:
|
||||
### Save config in db
|
||||
|
||||
from cloudAPI.models import WPDeployments
|
||||
from websiteFunctions.models import Websites
|
||||
import json
|
||||
|
||||
website = Websites.objects.get(domain = self.extraArgs['domain'])
|
||||
|
||||
website = Websites.objects.get(domain=self.extraArgs['domain'])
|
||||
del self.extraArgs['adminPassword']
|
||||
del self.extraArgs['password']
|
||||
del self.extraArgs['tempStatusPath']
|
||||
@@ -1270,11 +1273,12 @@ $parameters = array(
|
||||
del self.extraArgs['adminEmail']
|
||||
del self.extraArgs['adminUser']
|
||||
del self.extraArgs['blogTitle']
|
||||
del self.extraArgs['appsSet']
|
||||
|
||||
wpDeploy = WPDeployments(owner=website, config=json.dumps(self.extraArgs))
|
||||
wpDeploy.save()
|
||||
|
||||
logging.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].')
|
||||
except:
|
||||
pass
|
||||
|
||||
except BaseException as msg:
|
||||
logging.statusWriter(self.extraArgs['tempStatusPath'], '%s [404].' % (str(msg)))
|
||||
|
||||
@@ -1425,7 +1425,7 @@ class backupUtilities:
|
||||
self.cpu = backupUtilities.CPUDefault
|
||||
self.time = int(backupUtilities.time)
|
||||
|
||||
self.BackupPath = '/home/cyberpanel/backups/%s/backup-' % (self.extraArgs['domain']) + self.extraArgs['domain'] + "-" + time.strftime("%m.%d.%Y_%H-%M-%S")
|
||||
self.BackupPath = self.extraArgs['path']
|
||||
self.website = Websites.objects.get(domain=self.extraArgs['domain'])
|
||||
|
||||
command = 'mkdir -p %s' % (self.BackupPath)
|
||||
@@ -1486,6 +1486,13 @@ class backupUtilities:
|
||||
command = 'chmod 600:600 %s' % (finalPath)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
if self.extraArgs['port'] != 0:
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'Sending file to destination server..,90')
|
||||
|
||||
command = "scp -o StrictHostKeyChecking=no -P %s -i /root/.ssh/cyberpanel %s root@%s:/home/cyberpanel/backups/%s/" % (self.extraArgs['port'], finalPath, self.extraArgs['ip'], self.extraArgs['destinationDomain'])
|
||||
ProcessUtilities.outputExecutioner(command)
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].')
|
||||
|
||||
return 1, self.BackupPath + '.tar.gz'
|
||||
@@ -1548,9 +1555,14 @@ class backupUtilities:
|
||||
command = 'rm -rf %s' % (homePath)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
if self.extraArgs['sourceDomain'] == 'None':
|
||||
command = 'mv %s/%s %s' % (self.dataPath, self.website.domain, '/home')
|
||||
else:
|
||||
command = 'mv %s/%s %s/%s' % (self.dataPath, self.extraArgs['sourceDomain'], '/home', self.extraArgs['domain'])
|
||||
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
|
||||
from filemanager.filemanager import FileManager
|
||||
|
||||
fm = FileManager(None, None)
|
||||
@@ -1614,6 +1626,26 @@ class backupUtilities:
|
||||
|
||||
mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(db['databaseName'], self.databasesPath, db['password'])
|
||||
|
||||
if self.extraArgs['sourceDomain'] != 'None':
|
||||
if self.extraArgs['sourceDomain'] != self.extraArgs['domain']:
|
||||
|
||||
try:
|
||||
command = 'wp --info'
|
||||
outout = ProcessUtilities.outputExecutioner(command)
|
||||
|
||||
if not outout.find('WP-CLI root dir:') > -1:
|
||||
from plogical.applicationInstaller import ApplicationInstaller
|
||||
ai = ApplicationInstaller(None, None)
|
||||
ai.installWPCLI()
|
||||
except subprocess.CalledProcessError:
|
||||
from plogical.applicationInstaller import ApplicationInstaller
|
||||
ai = ApplicationInstaller(None, None)
|
||||
ai.installWPCLI()
|
||||
|
||||
path = '/home/%s/public_html' % (self.extraArgs['domain'])
|
||||
command = "wp search-replace '%s' '%s' --path=%s --allow-root" % (self.extraArgs['sourceDomain'], self.extraArgs['domain'], path)
|
||||
ProcessUtilities.outputExecutioner(command)
|
||||
|
||||
|
||||
command = 'rm -rf %s' % (self.extractedPath)
|
||||
ProcessUtilities.executioner(command)
|
||||
@@ -2038,6 +2070,10 @@ def main():
|
||||
parser.add_argument('--data', help='')
|
||||
parser.add_argument('--emails', help='')
|
||||
parser.add_argument('--databases', help='')
|
||||
parser.add_argument('--path', help='')
|
||||
parser.add_argument('--ip', help='')
|
||||
parser.add_argument('--sourceDomain', help='')
|
||||
parser.add_argument('--destinationDomain', help='')
|
||||
|
||||
## FOR S3
|
||||
|
||||
@@ -2067,13 +2103,19 @@ def main():
|
||||
extraArgs['data'] = int(args.data)
|
||||
extraArgs['emails'] = int(args.emails)
|
||||
extraArgs['databases'] = int(args.databases)
|
||||
extraArgs['path'] = args.path
|
||||
extraArgs['port'] = args.port
|
||||
extraArgs['ip'] = args.ip
|
||||
extraArgs['destinationDomain'] = args.destinationDomain
|
||||
bu = backupUtilities(extraArgs)
|
||||
bu.CloudBackups()
|
||||
|
||||
elif args.function == 'SubmitCloudBackupRestore':
|
||||
extraArgs = {}
|
||||
extraArgs['domain'] = args.backupDomain
|
||||
extraArgs['tempStatusPath'] = args.tempStoragePath
|
||||
extraArgs['backupFile'] = args.backupFile
|
||||
extraArgs['sourceDomain'] = args.sourceDomain
|
||||
bu = backupUtilities(extraArgs)
|
||||
bu.SubmitCloudBackupRestore()
|
||||
elif args.function == 'SubmitS3BackupRestore':
|
||||
|
||||
@@ -2712,7 +2712,6 @@ StrictHostKeyChecking no
|
||||
|
||||
self.domain = data['masterDomain']
|
||||
|
||||
|
||||
if not validators.domain(self.domain):
|
||||
data_ret = {'status': 0, 'createWebSiteStatus': 0, 'error_message': "Invalid domain."}
|
||||
json_data = json.dumps(data_ret)
|
||||
|
||||
Reference in New Issue
Block a user