backuprestore

This commit is contained in:
Hassan Hashmi
2022-06-11 13:39:48 +05:00
parent 27c6d2e6c3
commit 0007406871
7 changed files with 718 additions and 9 deletions

View File

@@ -80,6 +80,8 @@ class ApplicationInstaller(multi.Thread):
self.DeploytoProduction() self.DeploytoProduction()
elif self.installApp == 'WPCreateBackup': elif self.installApp == 'WPCreateBackup':
self.WPCreateBackup() self.WPCreateBackup()
elif self.installApp == 'RestoreWPbackupNow':
self.RestoreWPbackupNow()
except BaseException as msg: except BaseException as msg:
logging.writeToFile(str(msg) + ' [ApplicationInstaller.run]') logging.writeToFile(str(msg) + ' [ApplicationInstaller.run]')
@@ -738,9 +740,6 @@ $parameters = array(
############## Install Save Plugin Buckets ############## Install Save Plugin Buckets
try: try:
logging.writeToFile("plugin bucket list start")
logging.writeToFile("plugin bucket list: %s" % str(self.extraArgs['AllPluginsList']))
logging.writeToFile("plugin bucket saved: %s" % str(self.extraArgs['SavedPlugins']))
if self.extraArgs['SavedPlugins'] == True: if self.extraArgs['SavedPlugins'] == True:
AllPluginList= self.extraArgs['AllPluginsList'] AllPluginList= self.extraArgs['AllPluginsList']
for i in range(len(AllPluginList)): for i in range(len(AllPluginList)):
@@ -1683,6 +1682,7 @@ $parameters = array(
DataToPass = {} DataToPass = {}
currentTemp = self.extraArgs['tempStatusPath'] currentTemp = self.extraArgs['tempStatusPath']
DataToPass['domainName'] = self.data['domainName'] DataToPass['domainName'] = self.data['domainName']
DataToPass['adminEmail'] = self.data['adminEmail'] DataToPass['adminEmail'] = self.data['adminEmail']
DataToPass['phpSelection'] = "PHP 7.4" DataToPass['phpSelection'] = "PHP 7.4"
@@ -1745,11 +1745,9 @@ $parameters = array(
for i in range(len(pluginlistt)): for i in range(len(pluginlistt)):
AllPluginsList.append(pluginlistt[i]) AllPluginsList.append(pluginlistt[i])
except BaseException as msg: except BaseException as msg:
logging.writeToFile("Error in Get save plugin ....... %s" % str(msg))
pass pass
logging.writeToFile("AllPluginsList 1 ....... %s" % str(AllPluginsList))
logging.writeToFile("SavedPlugins 1 ....... %s" % str(SavedPlugins))
currentTemp = self.extraArgs['tempStatusPath'] currentTemp = self.extraArgs['tempStatusPath']
self.extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) self.extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999))
@@ -2410,6 +2408,301 @@ $parameters = array(
logging.statusWriter(self.tempStatusPath, str(msg)) logging.statusWriter(self.tempStatusPath, str(msg))
return 0, str(msg) return 0, str(msg)
def RestoreWPbackupNow(self):
try:
import json
from managePHP.phpManager import PHPManager
from websiteFunctions.website import WebsiteManager
from packages.models import Package
self.tempStatusPath = self.extraArgs['tempStatusPath']
logging.statusWriter(self.tempStatusPath, 'Restoring BackUp...,10')
DesSiteID = self.extraArgs['DesSiteID']
backupid = self.extraArgs['backupid']
DomainName = self.extraArgs['Domain']
userID = self.extraArgs['adminID']
#### First get BAckup file from backupobj
backupobj = WPSitesBackup.objects.get(pk=backupid)
config = json.loads(backupobj.config)
BackUpFileName = config['name']
oldtemppath = config['RandomPath']
DatabaseNameold = config['DatabaseName']
DumpFileName = DatabaseNameold+".sql"
oldurl = config['WPFinalURL']
packgobj = Package.objects.get(pk=config['Webpackage_id'])
packegs = packgobj.packageName
WebOwnerobj = Administrator.objects.get(pk=config['Webadmin_id'])
WebOwner = WebOwnerobj.userName
#### Methode of Restoring
############## Existing site
if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1):
wpsite = WPSites.objects.get(pk=DesSiteID)
VHuser = wpsite.owner.externalApp
PhpVersion = wpsite.owner.phpSelection
newWPpath = wpsite.path
newurl = wpsite.FinalURL
### get WPsite Database name and usr
php = PHPManager.getPHPString(PhpVersion)
FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php)
######Get DBname
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % (VHuser, FinalPHPPath, newWPpath)
stdout = ProcessUtilities.outputExecutioner(command)
Finaldbname = stdout.rstrip("\n")
######Get DBuser
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % (VHuser, FinalPHPPath, newWPpath)
stdout = ProcessUtilities.outputExecutioner(command)
Finaldbuser = stdout.rstrip("\n")
#####Get DBpsswd
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % (VHuser, FinalPHPPath, newWPpath)
stdout = ProcessUtilities.outputExecutioner(command)
Finaldbpasswd = stdout.rstrip("\n")
### Create secure folder
ACLManager.CreateSecureDir()
RandomPath = str(randint(1000, 9999))
self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath)
command = f'mkdir -p {self.tempPath}'
ProcessUtilities.executioner(command)
command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}'
ProcessUtilities.executioner(command)
logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30')
###First copy backup file to temp and then Unzip
command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath)
ProcessUtilities.executioner(command)
#### Make temp dir ab for unzip
command ="sudo -u %s mkdir %s/ab"%(VHuser,self.tempPath)
ProcessUtilities.executioner(command)
command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % (VHuser, self.tempPath, BackUpFileName, self.tempPath)
ProcessUtilities.outputExecutioner(command)
###first empty the Existing site phblichtml folder
command = "sudo -u %s rm -r %s/*"%(VHuser, newWPpath)
result = ProcessUtilities.outputExecutioner(command)
logging.statusWriter(self.tempStatusPath, 'Copying Data File...,50')
###Copy backup content to newsite
unzippath ="%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/"%(self.tempPath, oldtemppath)
command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath)
result = ProcessUtilities.outputExecutioner(command)
#dump Mysql file in unzippath path
unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % (self.tempPath, oldtemppath, DumpFileName)
command = "mysql -u root %s < %s" % (Finaldbname, unzippath2)
ProcessUtilities.outputExecutioner(command)
logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70')
#####SetUp DataBase Settings
##set DBName
command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % (VHuser, FinalPHPPath, Finaldbname, newWPpath)
ProcessUtilities.outputExecutioner(command)
##set DBuser
command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % (VHuser, FinalPHPPath, Finaldbuser, newWPpath)
ProcessUtilities.outputExecutioner(command)
##set DBpasswd
command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % (VHuser, FinalPHPPath, Finaldbpasswd, newWPpath)
ProcessUtilities.outputExecutioner(command)
logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90')
########Now Replace URL's
command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % (VHuser, newWPpath, oldurl, newurl)
ProcessUtilities.outputExecutioner(command)
command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % (VHuser, newWPpath, newurl, newurl)
ProcessUtilities.outputExecutioner(command)
##Remove temppath
command = f'rm -rf {self.tempPath}'
ProcessUtilities.executioner(command)
###Restart Server
from plogical.installUtilities import installUtilities
installUtilities.reStartLiteSpeed()
############## New Site
elif(DomainName != "" and int(self.extraArgs['DesSiteID']) == -1):
###############Create New WordPressSite First
# logging.writeToFile("New Website Domain ....... %s" % str(DomainName))
DataToPass = {}
DataToPass['title'] = config['WPtitle']
DataToPass['domain'] = DomainName
DataToPass['WPVersion'] = "6.0"
DataToPass['adminUser'] = config['WebVHuser']
DataToPass['Email'] = config['WebadminEmail']
DataToPass['PasswordByPass'] = config['DatabaseUser']
DataToPass['AutomaticUpdates'] = config['WPAutoUpdates']
DataToPass['Plugins'] = config['WPPluginUpdates']
DataToPass['Themes'] = config['WPThemeUpdates']
DataToPass['websiteOwner'] = WebOwner
DataToPass['package'] = packegs
try:
website = Websites.objects.get(domain=DomainName)
logging.statusWriter(self.tempStatusPath, 'Web Site Already Exist.[404]')
except:
ab = WebsiteManager()
coreResult = ab.submitWorpressCreation(userID, DataToPass)
coreResult1 = json.loads((coreResult).content)
logging.writeToFile("WP Creating website result....%s" % coreResult1)
reutrntempath = coreResult1['tempStatusPath']
while (1):
lastLine = open(reutrntempath, 'r').read()
logging.writeToFile("Error WP creating lastline ....... %s" % lastLine)
if lastLine.find('[200]') > -1:
break
elif lastLine.find('[404]') > -1:
logging.statusWriter(self.tempStatusPath, 'Failed to WordPress: error: %s. [404]'% lastLine)
return 0
else:
logging.statusWriter(self.tempStatusPath, 'Creating WordPress....,20')
time.sleep(2)
logging.statusWriter(self.tempStatusPath, 'Restoring site ....,30')
NewWPsite =WPSites.objects.get(FinalURL=DomainName)
VHuser = NewWPsite.owner.externalApp
PhpVersion = NewWPsite.owner.phpSelection
newWPpath = NewWPsite.path
newurl = NewWPsite.FinalURL
###### Same code already used in Existing site
### get WPsite Database name and usr
php = PHPManager.getPHPString(PhpVersion)
FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php)
######Get DBname
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % (
VHuser, FinalPHPPath, newWPpath)
stdout = ProcessUtilities.outputExecutioner(command)
Finaldbname = stdout.rstrip("\n")
######Get DBuser
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % (
VHuser, FinalPHPPath, newWPpath)
stdout = ProcessUtilities.outputExecutioner(command)
Finaldbuser = stdout.rstrip("\n")
#####Get DBpsswd
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % (
VHuser, FinalPHPPath, newWPpath)
stdout = ProcessUtilities.outputExecutioner(command)
Finaldbpasswd = stdout.rstrip("\n")
### Create secure folder
ACLManager.CreateSecureDir()
RandomPath = str(randint(1000, 9999))
self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath)
command = f'mkdir -p {self.tempPath}'
ProcessUtilities.executioner(command)
command = f'chown -R {NewWPsite.owner.externalApp}:{NewWPsite.owner.externalApp} {self.tempPath}'
ProcessUtilities.executioner(command)
logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,40')
###First copy backup file to temp and then Unzip
command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath)
ProcessUtilities.executioner(command)
#### Make temp dir ab for unzip
command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath)
ProcessUtilities.executioner(command)
command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % (
VHuser, self.tempPath, BackUpFileName, self.tempPath)
ProcessUtilities.outputExecutioner(command)
###first empty the Existing site phblichtml folder
command = "sudo -u %s rm -r %s/*" % (VHuser, newWPpath)
result = ProcessUtilities.outputExecutioner(command)
logging.statusWriter(self.tempStatusPath, 'Copying Data File...,60')
###Copy backup content to newsite
unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/" % (self.tempPath, oldtemppath)
command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath)
result = ProcessUtilities.outputExecutioner(command)
# dump Mysql file in unzippath path
unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % (self.tempPath, oldtemppath, DumpFileName)
command = "mysql -u root %s < %s" % (Finaldbname, unzippath2)
ProcessUtilities.outputExecutioner(command)
logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,80')
#####SetUp DataBase Settings
##set DBName
command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % (
VHuser, FinalPHPPath, Finaldbname, newWPpath)
ProcessUtilities.outputExecutioner(command)
##set DBuser
command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % (
VHuser, FinalPHPPath, Finaldbuser, newWPpath)
ProcessUtilities.outputExecutioner(command)
##set DBpasswd
command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % (
VHuser, FinalPHPPath, Finaldbpasswd, newWPpath)
ProcessUtilities.outputExecutioner(command)
logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90')
########Now Replace URL's
command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % (
VHuser, newWPpath, oldurl, newurl)
ProcessUtilities.outputExecutioner(command)
command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % (
VHuser, newWPpath, newurl, newurl)
ProcessUtilities.outputExecutioner(command)
##Remove temppath
command = f'rm -rf {self.tempPath}'
ProcessUtilities.executioner(command)
###Restart Server
from plogical.installUtilities import installUtilities
installUtilities.reStartLiteSpeed()
logging.statusWriter(self.tempStatusPath, 'Completed.[200]')
except BaseException as msg:
logging.writeToFile("Error RestoreWPbackupNow ....... %s" % str(msg))
command = f'rm -rf {self.tempPath}'
ProcessUtilities.executioner(command)
logging.statusWriter(self.tempStatusPath, str(msg))
return 0, str(msg)
def main(): def main():

View File

@@ -1162,8 +1162,6 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo
$timeout.cancel(); $timeout.cancel();
} else { } else {
$scope.wordpresshomeloading = true; $scope.wordpresshomeloading = true;
@@ -1182,7 +1180,6 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo
$scope.goBackDisable = false; $scope.goBackDisable = false;
} }
} else { } else {
@@ -1503,6 +1500,222 @@ function AppendToTable(table, markup) {
} }
//..................Restore Backup Home
app.controller('RestoreWPBackup', function ($scope, $http, $timeout, $window) {
$scope.wordpresshomeloading = true;
$scope.stagingDetailsForm = false;
$scope.installationProgress = true;
$scope.errorMessageBox = true;
$scope.success = true;
$scope.couldNotConnect = true;
$scope.goBackDisable = true;
$scope.checkmethode = function () {
var val = $('#RestoreMethode').children("option:selected").val();
if (val == 1) {
$('#Newsitediv').show();
$('#exinstingsitediv').hide();
} else if (val == 0) {
$('#exinstingsitediv').show();
$('#Newsitediv').hide();
} else {
}
};
$scope.RestoreWPbackupNow = 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 = "Start Restoring WordPress..";
var url = "/websites/RestoreWPbackupNow";
var data = {
backupid: $('#backupid').html(),
DesSite: $('#DesSite').children("option:selected").val(),
Domain: $("input[name=Newdomain]").val()
}
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
// console.log(data)
var d = $('#DesSite').children("option:selected").val();
var c = $("input[name=Newdomain]").val();
if( d == -1 && c == "")
{
alert("Please Select Method of Backup Restore");
}
else {
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
}
function ListInitialDatas(response) {
wordpresshomeloading = true;
$('#wordpresshomeloading').hide();
if (response.data.status === 1) {
new PNotify({
title: 'Success!',
text: 'Restoring process starts!.',
type: 'success'
});
statusFile = response.data.tempStatusPath;
getCreationStatus();
} else {
$('#wordpresshomeloading').hide();
$scope.wordpresshomeloading = true;
$scope.installationDetailsForm = true;
$scope.installationProgress = false;
$scope.errorMessageBox = false;
$scope.success = true;
$scope.couldNotConnect = true;
$scope.goBackDisable = false;
$scope.errorMessage = response.data.error_message;
}
}
function cantLoadInitialDatas(response) {
$('#wordpresshomeloading').hide();
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
}
function getCreationStatus() {
$('#wordpresshomeloading').show();
url = "/websites/installWordpressStatus";
var data = {
statusFile: statusFile
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$('#wordpresshomeloading').hide();
if (response.data.abort === 1) {
if (response.data.installStatus === 1) {
$scope.wordpresshomeloading = true;
$scope.stagingDetailsForm = true;
$scope.installationProgress = false;
$scope.errorMessageBox = true;
$scope.success = false;
$scope.couldNotConnect = true;
$scope.goBackDisable = false;
$("#installProgress").css("width", "100%");
$("#installProgressbackup").css("width", "100%");
$scope.installPercentage = "100";
$scope.currentStatus = response.data.currentStatus;
$timeout.cancel();
} else {
$scope.wordpresshomeloading = true;
$scope.stagingDetailsForm = true;
$scope.installationProgress = false;
$scope.errorMessageBox = false;
$scope.success = true;
$scope.couldNotConnect = true;
$scope.goBackDisable = false;
$scope.errorMessage = response.data.error_message;
$("#installProgress").css("width", "0%");
$("#installProgressbackup").css("width", "0%");
$scope.installPercentage = "0";
$scope.goBackDisable = false;
}
} else {
$("#installProgress").css("width", response.data.installationProgress + "%");
$("#installProgressbackup").css("width", response.data.installationProgress + "%");
$scope.installPercentage = response.data.installationProgress;
$scope.currentStatus = response.data.currentStatus;
$timeout(getCreationStatus, 1000);
}
}
function cantLoadInitialDatas(response) {
$('#wordpresshomeloading').hide();
$scope.wordpresshomeloading = true;
$scope.stagingDetailsForm = true;
$scope.installationProgress = false;
$scope.errorMessageBox = true;
$scope.success = true;
$scope.couldNotConnect = false;
$scope.goBackDisable = false;
}
}
$scope.goBack = function () {
$('#wordpresshomeloading').hide();
$scope.wordpresshomeloading = true;
$scope.stagingDetailsForm = false;
$scope.installationProgress = true;
$scope.errorMessageBox = true;
$scope.success = true;
$scope.couldNotConnect = true;
$scope.goBackDisable = true;
$("#installProgress").css("width", "0%");
};
});
/* Java script code to create account */ /* Java script code to create account */
app.controller('createWebsite', function ($scope, $http, $timeout, $window) { app.controller('createWebsite', function ($scope, $http, $timeout, $window) {

View File

@@ -121,6 +121,12 @@
</td> </td>
<td style="padding: 13px;"> <td style="padding: 13px;">
<a href="{% url 'RestoreHome' %}?BackupID={{ sub.id }}"
aria-label=""
type="button" class="btn btn-border btn-alt border-green btn-link font-green">
Restore
</a>
<button <button
data-toggle="modal" data-toggle="modal"
@@ -129,6 +135,7 @@
type="button" class="btn btn-border btn-alt border-red btn-link font-red"> type="button" class="btn btn-border btn-alt border-red btn-link font-red">
Delete Delete
</button> </button>
<div id="DeleteMember" class="modal fade" role="dialog"> <div id="DeleteMember" class="modal fade" role="dialog">
<div class="modal-dialog"> <div class="modal-dialog">
<!-- Modal content--> <!-- Modal content-->

View File

@@ -0,0 +1,112 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Restore Backpus - CyberPanel" %}{% endblock %}
{% block content %}
{% load static %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->
<div ng-controller="RestoreWPBackup" class="container">
<div id="page-title">
<h2 id="domainNamePage">{% trans "Restore Backups " %}
</h2>
<p>{% trans "On this page you can Restore, list, modify and delete Backups Wordpress Sites from your server." %}</p>
</div>
<div class="panel">
<div class="panel-body">
<h2 > {{ FileName }}</h2>
<span id="backupid" style="display: none">{{ backupobj.id }}</span>
<img id="wordpresshomeloading" style="display: none" src="{% static 'images/loading.gif' %}">
<div ng-hide="installationDetailsForm" style="margin-top: 1%" class="form-group">
<label class="col-sm-2 control-label">{% trans "Choose Restronig Method " %}</label>
<div class="col-sm-10">
<select ng-click="checkmethode()" id="RestoreMethode" class="form-control" required>
<option value="-1">Selecte Methode</option>
<option value="1">Restore to New Site</option>
<option value="0">Restore to Existing Site</option>
</select>
</div>
</div>
<div id="exinstingsitediv" ng-hide="installationDetailsForm" style="margin-top: 4%; display: none"
class="form-group">
<label class="col-sm-2 control-label">{% trans "Choose WPsite Restore Destination " %}</label>
<div class="col-sm-10">
<select id="DesSite" class="form-control" required>
<option value="-1">Select WordPress Site</option>
{% for i in WPsites %}
<option value="{{ i.id }}">{{ i.FinalURL }}</option>
{% endfor %}
</select>
</div>
</div>
<div id="Newsitediv" ng-hide="installationDetailsForm" style="margin-top: 4%; display: none" class="form-group">
<label class="col-sm-2 control-label">{% trans "Website Domain" %}</label>
<div class="col-sm-10">
<input name="Newdomain" id="Newdomain" type="url" placeholder="Enter New Website Domain for Restoring Website "
class="form-control" required>
</div>
</div>
<div ng-model="installationDetailsForm" class="col-sm-12 center-div" style="margin-top: 7%">
<button id="RestoreWPbackupNow" type="button"
ng-click="RestoreWPbackupNow()"
class="btn btn-primary btn-lg center-div">{% trans "Restore Backup Now" %}</button>
</div>
<div style="margin-top: 1%" ng-hide="installationProgress" class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-7">
<div class="alert alert-success text-center">
<h2>{$ currentStatus $}</h2>
</div>
<div class="progress">
<div id="installProgressbackup" class="progress-bar"
role="progressbar" aria-valuenow="70"
aria-valuemin="0" aria-valuemax="100"
style="width:0%">
<span class="sr-only">70% Complete</span>
</div>
</div>
<div ng-hide="errorMessageBox" class="alert alert-danger">
<p>{% trans "Error message:" %} {$ errorMessage $}</p>
</div>
<div ng-hide="success" class="alert alert-success">
<p>{% trans "Backup succesfully created." %}</p>
</div>
<div ng-hide="couldNotConnect" class="alert alert-danger">
<p>{% trans "Could not connect to server. Please refresh this page." %}</p>
</div>
</div>
</div>
<div ng-hide="installationProgress" class="form-group center-div">
<div class="col-sm-12">
<button type="button" ng-disabled="goBackDisable"
ng-click="goBack()"
class="btn btn-primary btn-lg center-div">{% trans "Go Back" %}</button>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -21,6 +21,7 @@ urlpatterns = [
url(r'^ListWPSites$', views.ListWPSites, name='ListWPSites'), url(r'^ListWPSites$', views.ListWPSites, name='ListWPSites'),
url(r'^WPHome$', views.WPHome, name='WPHome'), url(r'^WPHome$', views.WPHome, name='WPHome'),
url(r'^RestoreBackups$', views.RestoreBackups, name='RestoreBackups'), url(r'^RestoreBackups$', views.RestoreBackups, name='RestoreBackups'),
url(r'^RestoreHome$', views.RestoreHome, name='RestoreHome'),
url(r'^AutoLogin$', views.AutoLogin, name='AutoLogin'), url(r'^AutoLogin$', views.AutoLogin, name='AutoLogin'),
@@ -41,6 +42,7 @@ urlpatterns = [
url(r'^SaveUpdateConfig', views.SaveUpdateConfig, name='SaveUpdateConfig'), url(r'^SaveUpdateConfig', views.SaveUpdateConfig, name='SaveUpdateConfig'),
url(r'^DeploytoProduction', views.DeploytoProduction, name='DeploytoProduction'), url(r'^DeploytoProduction', views.DeploytoProduction, name='DeploytoProduction'),
url(r'^WPCreateBackup', views.WPCreateBackup, name='WPCreateBackup'), url(r'^WPCreateBackup', views.WPCreateBackup, name='WPCreateBackup'),
url(r'^RestoreWPbackupNow', views.RestoreWPbackupNow, name='RestoreWPbackupNow'),

View File

@@ -56,6 +56,15 @@ def WPHome(request):
return wm.WPHome(request, userID, WPid, DeleteID) return wm.WPHome(request, userID, WPid, DeleteID)
except KeyError: except KeyError:
return redirect(loadLoginPage) return redirect(loadLoginPage)
def RestoreHome(request):
try:
userID = request.session['userID']
BackupID = request.GET.get('BackupID')
wm = WebsiteManager()
return wm.RestoreHome(request, userID, BackupID)
except KeyError:
return redirect(loadLoginPage)
def RestoreBackups(request): def RestoreBackups(request):
try: try:
userID = request.session['userID'] userID = request.session['userID']
@@ -355,6 +364,29 @@ def WPCreateBackup(request):
def RestoreWPbackupNow(request):
try:
userID = request.session['userID']
result = pluginManager.preWebsiteCreation(request)
if result != 200:
return result
wm = WebsiteManager()
coreResult = wm.RestoreWPbackupNow(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): def GetCurrentThemes(request):
try: try:
userID = request.session['userID'] userID = request.session['userID']

View File

@@ -142,6 +142,20 @@ class WebsiteManager:
Data, 'createWebsite') Data, 'createWebsite')
return proc.render() return proc.render()
def RestoreHome(self, request=None, userID=None, BackupID=None ):
Data = {}
currentACL = ACLManager.loadedACL(userID)
Data['backupobj'] = WPSitesBackup.objects.get(pk=BackupID)
config = json.loads(Data['backupobj'].config)
Data['FileName']= config['name']
Data['WPsites'] = ACLManager.GetALLWPObjects(currentACL, userID)
proc = httpProc(request, 'websiteFunctions/WPRestoreHome.html',
Data, 'createWebsite')
return proc.render()
def RestoreBackups(self, request=None, userID=None, DeleteID=None): def RestoreBackups(self, request=None, userID=None, DeleteID=None):
Data = {} Data = {}
currentACL = ACLManager.loadedACL(userID) currentACL = ACLManager.loadedACL(userID)
@@ -768,6 +782,41 @@ class WebsiteManager:
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
def RestoreWPbackupNow(self, userID=None, data=None):
try:
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID)
backupid = data['backupid']
DesSiteID = data['DesSite']
Domain = data['Domain']
extraArgs = {}
extraArgs['adminID'] = admin.pk
extraArgs['backupid'] = backupid
extraArgs['DesSiteID'] = DesSiteID
extraArgs['Domain'] = Domain
extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999))
background = ApplicationInstaller('RestoreWPbackupNow', extraArgs)
background.start()
time.sleep(2)
data_ret = {'status': 1, 'installStatus': 1, 'error_message': 'None',
'tempStatusPath': extraArgs['tempStatusPath']}
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): def UpdatePlugins(self, userID=None, data=None):
try: try:
@@ -1223,6 +1272,7 @@ class WebsiteManager:
currentACL = ACLManager.loadedACL(userID) currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID) admin = Administrator.objects.get(pk=userID)
extraArgs = {} extraArgs = {}
extraArgs['currentACL'] = currentACL extraArgs['currentACL'] = currentACL
extraArgs['adminID'] = admin.pk extraArgs['adminID'] = admin.pk