mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 13:56:01 +01:00
resolve conflic
This commit is contained in:
@@ -78,6 +78,8 @@ class ApplicationInstaller(multi.Thread):
|
||||
self.CreateStagingNow()
|
||||
elif self.installApp == 'DeploytoProduction':
|
||||
self.DeploytoProduction()
|
||||
elif self.installApp == 'WPCreateBackup':
|
||||
self.WPCreateBackup()
|
||||
|
||||
except BaseException as msg:
|
||||
logging.writeToFile(str(msg) + ' [ApplicationInstaller.run]')
|
||||
@@ -2153,6 +2155,7 @@ $parameters = array(
|
||||
statusFile.close()
|
||||
return 0
|
||||
|
||||
|
||||
def DeploytoProduction(self):
|
||||
|
||||
try:
|
||||
@@ -2256,6 +2259,164 @@ $parameters = array(
|
||||
logging.statusWriter(self.tempStatusPath, mesg)
|
||||
|
||||
|
||||
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():
|
||||
parser = argparse.ArgumentParser(description='CyberPanel Application Installer')
|
||||
|
||||
@@ -1397,6 +1397,62 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo
|
||||
|
||||
};
|
||||
|
||||
|
||||
$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";
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
$('#wordpresshomeloading').hide();
|
||||
$('createbackupbutton').hide();
|
||||
if (response.data.status === 1) {
|
||||
new PNotify({
|
||||
title: 'Success!',
|
||||
text: 'Creating Backups!.',
|
||||
type: 'success'
|
||||
});
|
||||
statusFile = response.data.tempStatusPath;
|
||||
getCreationStatus();
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$('#wordpresshomeloading').hide();
|
||||
alert(response)
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@
|
||||
data-toggle="tab">Themes</a></li>
|
||||
<li><a href="#tab4" data-toggle="tab"
|
||||
ng-click="fetchstaging()">Staging</a></li>
|
||||
|
||||
</li>
|
||||
<li><a href="#tab5" data-toggle="tab"
|
||||
>Backups</a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active" id="tab1">
|
||||
@@ -362,6 +362,55 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="tab-pane" id="tab5">
|
||||
<h2>Create Backup Now</h2>
|
||||
<div class="col-sm-12" style="margin-top: 1%">
|
||||
<button id="createbackupbutton" type="button"
|
||||
ng-click="CreateBackup()"
|
||||
class="btn btn-primary btn-lg center-div">{% trans "Create Backup" %}</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="installProgress" 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>
|
||||
<hr>
|
||||
@@ -396,6 +445,7 @@
|
||||
</svg>
|
||||
Autoupdate Configurations
|
||||
</a>
|
||||
|
||||
<div id="autoUpdateConfig" class="modal fade" tabindex="-1" role="dialog"
|
||||
aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
|
||||
@@ -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'),
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -323,6 +323,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):
|
||||
|
||||
@@ -694,6 +694,45 @@ 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['WPid'] = WPManagerID
|
||||
extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||
|
||||
|
||||
|
||||
background = ApplicationInstaller('WPCreateBackup', 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):
|
||||
try:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user