Skip to content

Commit 96a90f0

Browse files
committed
feature: finish initial wp manager
1 parent 7f8a36f commit 96a90f0

File tree

6 files changed

+171
-33
lines changed

6 files changed

+171
-33
lines changed

cloudAPI/cloudManager.py

Lines changed: 90 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,12 +1659,31 @@ def SubmitCloudBackup(self):
16591659
except:
16601660
databases = '0'
16611661

1662+
try:
1663+
port = str(self.data['port'])
1664+
except:
1665+
port = '0'
1666+
1667+
try:
1668+
ip = str(self.data['ip'])
1669+
except:
1670+
ip = '0'
1671+
1672+
try:
1673+
destinationDomain = self.data['destinationDomain']
1674+
except:
1675+
destinationDomain = ''
1676+
1677+
import time
1678+
BackupPath = '/home/cyberpanel/backups/%s/backup-' % (self.data['domain']) + self.data['domain'] + "-" + time.strftime("%m.%d.%Y_%H-%M-%S")
1679+
16621680
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
1663-
execPath = execPath + " CloudBackup --backupDomain %s --data %s --emails %s --databases %s --tempStoragePath %s" % (
1664-
self.data['domain'], data, emails, databases, tempStatusPath)
1681+
execPath = execPath + " CloudBackup --backupDomain %s --data %s --emails %s --databases %s --tempStoragePath %s " \
1682+
"--path %s --port %s --ip %s --destinationDomain %s" % (
1683+
self.data['domain'], data, emails, databases, tempStatusPath, BackupPath, port, ip, destinationDomain)
16651684
ProcessUtilities.popenExecutioner(execPath)
16661685

1667-
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
1686+
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath, 'path': '%s.tar.gz' % (BackupPath)}
16681687
final_json = json.dumps(final_dic)
16691688
return HttpResponse(final_json)
16701689

@@ -1774,9 +1793,14 @@ def SubmitCloudBackupRestore(self):
17741793
writeToFile.write('Starting..,0')
17751794
writeToFile.close()
17761795

1796+
try:
1797+
sourceDomain = self.data['sourceDomain']
1798+
except:
1799+
sourceDomain = 'None'
1800+
17771801
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
1778-
execPath = execPath + " SubmitCloudBackupRestore --backupDomain %s --backupFile %s --tempStoragePath %s" % (
1779-
self.data['domain'], self.data['backupFile'], tempStatusPath)
1802+
execPath = execPath + " SubmitCloudBackupRestore --backupDomain %s --backupFile %s --sourceDomain %s --tempStoragePath %s" % (
1803+
self.data['domain'], self.data['backupFile'],sourceDomain, tempStatusPath)
17801804
ProcessUtilities.popenExecutioner(execPath)
17811805

17821806
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
@@ -1993,11 +2017,8 @@ def FetchWordPressDetails(self):
19932017

19942018
## Get title
19952019

1996-
from cloudAPI.models import WPDeployments
1997-
import json
1998-
wpd = WPDeployments.objects.get(owner=website)
1999-
config = json.loads(wpd.config)
2000-
finalDic['title'] = config['title']
2020+
command = 'wp option get blogname --path=/home/%s/public_html' % (domain)
2021+
finalDic['title'] = ProcessUtilities.outputExecutioner(command, website.externalApp)
20012022

20022023
##
20032024

@@ -2320,4 +2341,62 @@ def DeleteThemes(self):
23202341
except BaseException as msg:
23212342
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
23222343
final_json = json.dumps(final_dic)
2323-
return HttpResponse(final_json)
2344+
return HttpResponse(final_json)
2345+
2346+
def GetServerPublicSSHkey(self):
2347+
try:
2348+
2349+
path = '/root/.ssh/cyberpanel.pub'
2350+
command = 'cat %s' % (path)
2351+
key = ProcessUtilities.outputExecutioner(command)
2352+
2353+
final_dic = {'status': 1, 'key': key}
2354+
final_json = json.dumps(final_dic)
2355+
return HttpResponse(final_json)
2356+
2357+
except BaseException as msg:
2358+
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
2359+
final_json = json.dumps(final_dic)
2360+
return HttpResponse(final_json)
2361+
2362+
def SubmitPublicKey(self):
2363+
try:
2364+
2365+
fm = FirewallManager()
2366+
fm.addSSHKey(self.admin.pk, self.data)
2367+
2368+
## Create backup path so that file can be sent here later.
2369+
2370+
BackupPath = '/home/cyberpanel/backups/%s' % (self.data['domain'])
2371+
command = 'mkdir -p %s' % (BackupPath)
2372+
ProcessUtilities.executioner(command, 'cyberpanel')
2373+
2374+
###
2375+
2376+
from WebTerminal.CPWebSocket import SSHServer
2377+
SSHServer.findSSHPort()
2378+
2379+
final_dic = {'status': 1, 'port': SSHServer.DEFAULT_PORT}
2380+
final_json = json.dumps(final_dic)
2381+
return HttpResponse(final_json)
2382+
2383+
except BaseException as msg:
2384+
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
2385+
final_json = json.dumps(final_dic)
2386+
return HttpResponse(final_json)
2387+
2388+
def CreateStaging(self, request):
2389+
try:
2390+
request.session['userID'] = self.admin.pk
2391+
wm = WebsiteManager()
2392+
return wm.startCloning(self.admin.pk, self.data)
2393+
except BaseException as msg:
2394+
return self.ajaxPre(0, str(msg))
2395+
2396+
def startSync(self, request):
2397+
try:
2398+
request.session['userID'] = self.admin.pk
2399+
wm = WebsiteManager()
2400+
return wm.startSync(self.admin.pk, self.data)
2401+
except BaseException as msg:
2402+
return self.ajaxPre(0, str(msg))

cloudAPI/views.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def router(request):
7979
return cm.ChangeStateThemes()
8080
elif controller == 'DeleteThemes':
8181
return cm.DeleteThemes()
82+
elif controller == 'GetServerPublicSSHkey':
83+
return cm.GetServerPublicSSHkey()
84+
elif controller == 'SubmitPublicKey':
85+
return cm.SubmitPublicKey()
8286
elif controller == 'UpdateWPSettings':
8387
return cm.UpdateWPSettings()
8488
elif controller == 'GetCurrentPlugins':
@@ -229,6 +233,10 @@ def router(request):
229233
return cm.getLogsFromFile(request)
230234
elif controller == 'serverSSL':
231235
return cm.serverSSL(request)
236+
elif controller == 'CreateStaging':
237+
return cm.CreateStaging(request)
238+
elif controller == 'startSync':
239+
return cm.startSync(request)
232240
elif controller == 'setupNode':
233241
return cm.setupManager(request)
234242
elif controller == 'fetchManagerTokens':
@@ -372,7 +380,6 @@ def router(request):
372380
cm = CloudManager(None)
373381
return cm.ajaxPre(0, str(msg))
374382

375-
@csrf_exempt
376383
def access(request):
377384
try:
378385
serverUserName = request.GET.get('serverUserName')
@@ -385,6 +392,10 @@ def access(request):
385392
return HttpResponse('API Access Disabled.')
386393

387394
if token == admin.token.lstrip('Basic ').rstrip('='):
395+
try:
396+
del request.session['userID']
397+
except:
398+
pass
388399
request.session['userID'] = admin.pk
389400
from django.shortcuts import redirect
390401
from baseTemplate.views import renderBase

filemanager/filemanager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ def fixPermissions(self, domainName):
711711
else:
712712
groupName = 'nogroup'
713713

714+
command = 'chown %s:%s /home/%s' % (website.externalApp, website.externalApp, domainName)
715+
ProcessUtilities.popenExecutioner(command)
716+
714717
command = 'chown -R %s:%s /home/%s/public_html/*' % (externalApp, externalApp, domainName)
715718
ProcessUtilities.popenExecutioner(command)
716719

plogical/applicationInstaller.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,27 +1255,31 @@ def DeployWordPress(self):
12551255

12561256
self.extraArgs['tempStatusPath'] = currentTemp
12571257

1258-
### Save config in db
1259-
1260-
from cloudAPI.models import WPDeployments
1261-
from websiteFunctions.models import Websites
1262-
import json
1263-
1264-
website = Websites.objects.get(domain = self.extraArgs['domain'])
1265-
1266-
del self.extraArgs['adminPassword']
1267-
del self.extraArgs['password']
1268-
del self.extraArgs['tempStatusPath']
1269-
del self.extraArgs['domain']
1270-
del self.extraArgs['adminEmail']
1271-
del self.extraArgs['adminUser']
1272-
del self.extraArgs['blogTitle']
1273-
1274-
wpDeploy = WPDeployments(owner=website, config=json.dumps(self.extraArgs))
1275-
wpDeploy.save()
12761258

12771259
logging.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].')
12781260

1261+
try:
1262+
### Save config in db
1263+
1264+
from cloudAPI.models import WPDeployments
1265+
from websiteFunctions.models import Websites
1266+
import json
1267+
1268+
website = Websites.objects.get(domain=self.extraArgs['domain'])
1269+
del self.extraArgs['adminPassword']
1270+
del self.extraArgs['password']
1271+
del self.extraArgs['tempStatusPath']
1272+
del self.extraArgs['domain']
1273+
del self.extraArgs['adminEmail']
1274+
del self.extraArgs['adminUser']
1275+
del self.extraArgs['blogTitle']
1276+
del self.extraArgs['appsSet']
1277+
1278+
wpDeploy = WPDeployments(owner=website, config=json.dumps(self.extraArgs))
1279+
wpDeploy.save()
1280+
except:
1281+
pass
1282+
12791283
except BaseException as msg:
12801284
logging.statusWriter(self.extraArgs['tempStatusPath'], '%s [404].' % (str(msg)))
12811285

plogical/backupUtilities.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ def CloudBackups(self):
14251425
self.cpu = backupUtilities.CPUDefault
14261426
self.time = int(backupUtilities.time)
14271427

1428-
self.BackupPath = '/home/cyberpanel/backups/%s/backup-' % (self.extraArgs['domain']) + self.extraArgs['domain'] + "-" + time.strftime("%m.%d.%Y_%H-%M-%S")
1428+
self.BackupPath = self.extraArgs['path']
14291429
self.website = Websites.objects.get(domain=self.extraArgs['domain'])
14301430

14311431
command = 'mkdir -p %s' % (self.BackupPath)
@@ -1486,6 +1486,13 @@ def CloudBackups(self):
14861486
command = 'chmod 600:600 %s' % (finalPath)
14871487
ProcessUtilities.executioner(command)
14881488

1489+
if self.extraArgs['port'] != 0:
1490+
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
1491+
'Sending file to destination server..,90')
1492+
1493+
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'])
1494+
ProcessUtilities.outputExecutioner(command)
1495+
14891496
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].')
14901497

14911498
return 1, self.BackupPath + '.tar.gz'
@@ -1548,9 +1555,14 @@ def SubmitCloudBackupRestore(self):
15481555
command = 'rm -rf %s' % (homePath)
15491556
ProcessUtilities.executioner(command)
15501557

1551-
command = 'mv %s/%s %s' % (self.dataPath, self.website.domain, '/home')
1558+
if self.extraArgs['sourceDomain'] == 'None':
1559+
command = 'mv %s/%s %s' % (self.dataPath, self.website.domain, '/home')
1560+
else:
1561+
command = 'mv %s/%s %s/%s' % (self.dataPath, self.extraArgs['sourceDomain'], '/home', self.extraArgs['domain'])
1562+
15521563
ProcessUtilities.executioner(command)
15531564

1565+
15541566
from filemanager.filemanager import FileManager
15551567

15561568
fm = FileManager(None, None)
@@ -1614,6 +1626,26 @@ def SubmitCloudBackupRestore(self):
16141626

16151627
mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(db['databaseName'], self.databasesPath, db['password'])
16161628

1629+
if self.extraArgs['sourceDomain'] != 'None':
1630+
if self.extraArgs['sourceDomain'] != self.extraArgs['domain']:
1631+
1632+
try:
1633+
command = 'wp --info'
1634+
outout = ProcessUtilities.outputExecutioner(command)
1635+
1636+
if not outout.find('WP-CLI root dir:') > -1:
1637+
from plogical.applicationInstaller import ApplicationInstaller
1638+
ai = ApplicationInstaller(None, None)
1639+
ai.installWPCLI()
1640+
except subprocess.CalledProcessError:
1641+
from plogical.applicationInstaller import ApplicationInstaller
1642+
ai = ApplicationInstaller(None, None)
1643+
ai.installWPCLI()
1644+
1645+
path = '/home/%s/public_html' % (self.extraArgs['domain'])
1646+
command = "wp search-replace '%s' '%s' --path=%s --allow-root" % (self.extraArgs['sourceDomain'], self.extraArgs['domain'], path)
1647+
ProcessUtilities.outputExecutioner(command)
1648+
16171649

16181650
command = 'rm -rf %s' % (self.extractedPath)
16191651
ProcessUtilities.executioner(command)
@@ -2038,6 +2070,10 @@ def main():
20382070
parser.add_argument('--data', help='')
20392071
parser.add_argument('--emails', help='')
20402072
parser.add_argument('--databases', help='')
2073+
parser.add_argument('--path', help='')
2074+
parser.add_argument('--ip', help='')
2075+
parser.add_argument('--sourceDomain', help='')
2076+
parser.add_argument('--destinationDomain', help='')
20412077

20422078
## FOR S3
20432079

@@ -2067,13 +2103,19 @@ def main():
20672103
extraArgs['data'] = int(args.data)
20682104
extraArgs['emails'] = int(args.emails)
20692105
extraArgs['databases'] = int(args.databases)
2106+
extraArgs['path'] = args.path
2107+
extraArgs['port'] = args.port
2108+
extraArgs['ip'] = args.ip
2109+
extraArgs['destinationDomain'] = args.destinationDomain
20702110
bu = backupUtilities(extraArgs)
20712111
bu.CloudBackups()
2112+
20722113
elif args.function == 'SubmitCloudBackupRestore':
20732114
extraArgs = {}
20742115
extraArgs['domain'] = args.backupDomain
20752116
extraArgs['tempStatusPath'] = args.tempStoragePath
20762117
extraArgs['backupFile'] = args.backupFile
2118+
extraArgs['sourceDomain'] = args.sourceDomain
20772119
bu = backupUtilities(extraArgs)
20782120
bu.SubmitCloudBackupRestore()
20792121
elif args.function == 'SubmitS3BackupRestore':

websiteFunctions/website.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2712,7 +2712,6 @@ def startCloning(self, userID=None, data=None):
27122712

27132713
self.domain = data['masterDomain']
27142714

2715-
27162715
if not validators.domain(self.domain):
27172716
data_ret = {'status': 0, 'createWebSiteStatus': 0, 'error_message': "Invalid domain."}
27182717
json_data = json.dumps(data_ret)

0 commit comments

Comments
 (0)