diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py
index 456273364..2115cd4e3 100755
--- a/websiteFunctions/urls.py
+++ b/websiteFunctions/urls.py
@@ -39,6 +39,7 @@ urlpatterns = [
url(r'^fetchstaging', views.fetchstaging, name='fetchstaging'),
url(r'^SaveUpdateConfig', views.SaveUpdateConfig, name='SaveUpdateConfig'),
url(r'^DeploytoProduction', views.DeploytoProduction, name='DeploytoProduction'),
+ url(r'^WPCreateBackup', views.WPCreateBackup, name='WPCreateBackup'),
diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py
index 2c3f730d1..8ecd708c1 100755
--- a/websiteFunctions/views.py
+++ b/websiteFunctions/views.py
@@ -322,6 +322,27 @@ def DeploytoProduction(request):
except KeyError:
return redirect(loadLoginPage)
+def WPCreateBackup(request):
+ try:
+ userID = request.session['userID']
+
+ result = pluginManager.preWebsiteCreation(request)
+
+ if result != 200:
+ return result
+
+ wm = WebsiteManager()
+ coreResult = wm.WPCreateBackup(userID, json.loads(request.body))
+
+ result = pluginManager.postWebsiteCreation(request, coreResult)
+ if result != 200:
+ return result
+
+ return coreResult
+
+ except KeyError:
+ return redirect(loadLoginPage)
+
def GetCurrentThemes(request):
diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py
index d97e00370..25f5a5499 100755
--- a/websiteFunctions/website.py
+++ b/websiteFunctions/website.py
@@ -692,6 +692,46 @@ class WebsiteManager:
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
+
+ def WPCreateBackup(self, userID=None, data=None):
+ try:
+
+ currentACL = ACLManager.loadedACL(userID)
+ admin = Administrator.objects.get(pk=userID)
+
+ WPManagerID = data['WPid']
+
+ wpsite = WPSites.objects.get(pk=WPManagerID)
+
+
+ if ACLManager.checkOwnership(wpsite.owner.domain, admin, currentACL) == 1:
+ pass
+ else:
+ return ACLManager.loadError()
+
+ # extraArgs = {}
+ # extraArgs['adminID'] = admin.pk
+ # extraArgs['StagingDomain'] = StagingObj.FinalURL
+ # extraArgs['StagingName'] = StagingObj.title
+ # extraArgs['WPid'] = WPManagerID
+ # extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999))
+
+
+
+ # background = ApplicationInstaller('CreateStagingNow', extraArgs)
+ # background.start()
+
+ time.sleep(2)
+
+ data_ret = {'status': 1, 'installStatus': 1, 'error_message': 'None',}
+ json_data = json.dumps(data_ret)
+ return HttpResponse(json_data)
+
+ except BaseException as msg:
+ data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)}
+ json_data = json.dumps(data_ret)
+ return HttpResponse(json_data)
+
def UpdatePlugins(self, userID=None, data=None):
try:
From 3b06360da72e690082da7eea985e4a1141177ff2 Mon Sep 17 00:00:00 2001
From: Hassan Hashmi <75794688+habbi-hb@users.noreply.github.com>
Date: Tue, 7 Jun 2022 11:12:10 +0500
Subject: [PATCH 2/2] backupstartdone2
---
plogical/applicationInstaller.py | 158 ++++++++++++++++++
.../websiteFunctions/websiteFunctions.js | 22 ++-
.../websiteFunctions/WPsiteHome.html | 59 ++++++-
websiteFunctions/website.py | 17 +-
4 files changed, 235 insertions(+), 21 deletions(-)
diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py
index c3fe49d37..e76a518d9 100755
--- a/plogical/applicationInstaller.py
+++ b/plogical/applicationInstaller.py
@@ -75,6 +75,8 @@ class ApplicationInstaller(multi.Thread):
self.ChangeStatusThemes()
elif self.installApp == 'CreateStagingNow':
self.CreateStagingNow()
+ elif self.installApp == 'WPCreateBackup':
+ self.WPCreateBackup()
except BaseException as msg:
logging.writeToFile(str(msg) + ' [ApplicationInstaller.run]')
@@ -2140,6 +2142,162 @@ $parameters = array(
logging.writeToFile("Error WP ChangeStatusThemes ....... %s" % str(msg))
return 0
+ def WPCreateBackup(self):
+ try:
+ from managePHP.phpManager import PHPManager
+ import json
+ tempStatusPath = self.extraArgs['tempStatusPath']
+ statusFile = open(tempStatusPath, 'w')
+ statusFile.writelines('Creating BackUp...,10')
+ statusFile.close()
+
+ wpsite = WPSites.objects.get(pk=self.extraArgs['WPid'])
+
+ website =Websites.objects.get(pk=wpsite.owner_id)
+ PhpVersion = website.phpSelection
+ VHuser = website.externalApp
+ WPsitepath = wpsite.path
+ websitedomain = website.domain
+
+
+ php = PHPManager.getPHPString(PhpVersion)
+ FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php)
+ statusFile = open(tempStatusPath, 'w')
+ statusFile.writelines('Getting DataBase...,20')
+ statusFile.close()
+
+ command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % (VHuser, FinalPHPPath, WPsitepath)
+ stdoutput = ProcessUtilities.outputExecutioner(command)
+ DataBaseName = stdoutput.rstrip("\n")
+
+
+ command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % (
+ VHuser, FinalPHPPath, WPsitepath)
+ stdoutput = ProcessUtilities.outputExecutioner(command)
+ DataBaseUser = stdoutput.rstrip("\n")
+
+
+
+ ### Create secure folder
+ ACLManager.CreateSecureDir()
+ RandomPath = str(randint(1000, 9999))
+ tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath)
+ self.tempPath = tempPath
+
+ command = f'mkdir -p {tempPath}'
+ ProcessUtilities.executioner(command)
+
+ command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {tempPath}'
+ ProcessUtilities.executioner(command)
+
+ ### Make directory for backup
+ statusFile = open(tempStatusPath, 'w')
+ statusFile.writelines('Creating Backup Directory...,40')
+ statusFile.close()
+
+ command = "sudo -u %s mkdir -p %s/public_html" % (VHuser, tempPath)
+ ProcessUtilities.executioner(command)
+
+ config = {}
+ config['WPtitle']=wpsite.title
+ config['WPAutoUpdates']=wpsite.AutoUpdates
+ config['WPFinalURL']=wpsite.FinalURL
+ config['WPPluginUpdates']=wpsite.PluginUpdates
+ config['WPThemeUpdates']=wpsite.ThemeUpdates
+ config['WPowner_id']=wpsite.owner_id
+ config["WPsitepath"] = wpsite.path
+ config["DatabaseName"] = DataBaseName
+ config["DatabaseUser"] = DataBaseUser
+ config['RandomPath'] = RandomPath
+ config["WebDomain"] = websitedomain
+ config['WebadminEmail'] = website.adminEmail
+ config['WebphpSelection'] = website.phpSelection
+ config['Webssl'] = website.ssl
+ config['Webstate'] = website.state
+ config['WebVHuser'] = website.externalApp
+ config['Webpackage_id'] = website.package_id
+ config['Webadmin_id'] = website.admin_id
+
+ ###############Create config.Json file
+
+
+ command = "sudo -u %s touch /home/cyberpanel/config.json" % (VHuser)
+ ProcessUtilities.executioner(command)
+ ###### write into config
+ json_object = json.dumps(config, indent=4)
+ configPath = "/home/cyberpanel/config.json"
+ file = open(configPath, "w")
+ file.write(json_object)
+ file.close()
+
+ os.chmod(configPath, 0o600)
+
+ command ="sudo -u %s cp -R /home/cyberpanel/config.json %s"%(VHuser, tempPath)
+ ProcessUtilities.executioner(command)
+
+ command = "rm -r /home/cyberpanel/config.json"
+ ProcessUtilities.executioner(command)
+
+ statusFile = open(tempStatusPath, 'w')
+ statusFile.writelines('Copying website data.....,50')
+ statusFile.close()
+
+ ############## Copy Public_htnl to backup
+ command = "sudo -u %s cp -R %s* %s/public_html" % (VHuser, WPsitepath, tempPath)
+ result = ProcessUtilities.outputExecutioner(command)
+
+ if os.path.exists(ProcessUtilities.debugPath):
+ logging.writeToFile(result)
+
+ command = "sudo -u %s cp -R %s.[^.]* %s/public_html/" % (VHuser, WPsitepath, tempPath)
+ result = ProcessUtilities.outputExecutioner(command)
+
+ if os.path.exists(ProcessUtilities.debugPath):
+ logging.writeToFile(result)
+
+ statusFile = open(tempStatusPath, 'w')
+ statusFile.writelines('Copying DataBase.....,70')
+ statusFile.close()
+
+
+ ##### SQLDUMP database into new directory
+
+ command = "mysqldump %s --result-file %s/%s.sql" % (DataBaseName, tempPath, DataBaseName)
+ result = ProcessUtilities.outputExecutioner(command)
+
+ if os.path.exists(ProcessUtilities.debugPath):
+ logging.writeToFile(result)
+
+ ######## Zip backup directory
+ statusFile = open(tempStatusPath, 'w')
+ statusFile.writelines('Compressing backup files.....,90')
+ statusFile.close()
+
+ websitepath = "/home/%s"%websitedomain
+
+ FinalZipPath = '%s/%s.zip' % (websitepath, RandomPath)
+ command = "sudo -u %s tar -czvf %s -P %s" % (VHuser, FinalZipPath, tempPath)
+ result = ProcessUtilities.outputExecutioner(command)
+
+ if os.path.exists(ProcessUtilities.debugPath):
+ logging.writeToFile(result)
+
+ command = f'rm -rf {tempPath}'
+ ProcessUtilities.executioner(command)
+
+
+ statusFile = open(tempStatusPath, 'w')
+ statusFile.writelines("Successfully Created. [200]")
+ statusFile.close()
+ return 0
+
+
+ except BaseException as msg:
+ logging.writeToFile("Error WPCreateBackup ....... %s" % str(msg))
+ statusFile = open(self.tempStatusPath, 'w')
+ statusFile.writelines(str(msg) + " [404]")
+ statusFile.close()
+ return 0
def main():
diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js
index 4b7dc3d05..c8f8eb2b3 100755
--- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js
+++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js
@@ -1378,10 +1378,19 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo
}
- $scope.CreateBackup = function (){
- $('#wordpresshomeloading').show();
- var data = {
- WPid: $('#WPid').html(),
+ $scope.CreateBackup = function () {
+ $('#wordpresshomeloading').show();
+
+ $scope.wordpresshomeloading = false;
+ $scope.stagingDetailsForm = true;
+ $scope.installationProgress = false;
+ $scope.errorMessageBox = true;
+ $scope.success = true;
+ $scope.couldNotConnect = true;
+ $scope.goBackDisable = true;
+ $scope.currentStatus = "Starting creation Backups..";
+ var data = {
+ WPid: $('#WPid').html(),
}
var url = "/websites/WPCreateBackup";
@@ -1396,12 +1405,15 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo
function ListInitialDatas(response) {
$('#wordpresshomeloading').hide();
+ $('createbackupbutton').hide();
if (response.data.status === 1) {
new PNotify({
title: 'Success!',
- text: 'Backup Created!.',
+ text: 'Creating Backups!.',
type: 'success'
});
+ statusFile = response.data.tempStatusPath;
+ getCreationStatus();
} else {
new PNotify({
title: 'Operation Failed!',
diff --git a/websiteFunctions/templates/websiteFunctions/WPsiteHome.html b/websiteFunctions/templates/websiteFunctions/WPsiteHome.html
index 480902efa..3d6b21343 100644
--- a/websiteFunctions/templates/websiteFunctions/WPsiteHome.html
+++ b/websiteFunctions/templates/websiteFunctions/WPsiteHome.html
@@ -43,8 +43,8 @@
data-toggle="tab">Themes
Staging
-
-
+
Backups
+
+
Create Backup Now
+
+
+
+
+
+
+