Bug fix to Backups!

This commit is contained in:
usmannasir
2018-02-19 23:42:57 +05:00
parent 84a2575abb
commit fcaf433cc6
11 changed files with 63 additions and 93 deletions

View File

@@ -45,7 +45,6 @@ def loadBackupHome(request):
except KeyError:
return redirect(loadLoginPage)
def restoreSite(request):
try:
val = request.session['userID']
@@ -123,7 +122,6 @@ def backupSite(request):
except KeyError:
return redirect(loadLoginPage)
def getCurrentBackups(request):
try:
val = request.session['userID']
@@ -190,9 +188,7 @@ def submitBackupCreation(request):
## /home/example.com/backup
backupPath = os.path.join("/home",backupDomain,"backup/")
domainUser = website.externalApp
backupName = 'backup-' + domainUser + "-" + time.strftime("%I-%M-%S-%a-%b-%Y")
## /home/example.com/backup/backup-example-06-50-03-Thu-Feb-2018
@@ -200,7 +196,7 @@ def submitBackupCreation(request):
## Generating meta
## xml generation
## XML Generation
metaFileXML = Element('metaFile')
@@ -218,7 +214,7 @@ def submitBackupCreation(request):
databases = website.databases_set.all()
## child domains xml
## Child domains XML
childDomainsXML = Element('ChildDomains')
@@ -238,7 +234,7 @@ def submitBackupCreation(request):
metaFileXML.append(childDomainsXML)
## Databases
## Databases XML
databasesXML = Element('Databases')
@@ -258,7 +254,7 @@ def submitBackupCreation(request):
metaFileXML.append(databasesXML)
## DNS Records
## DNS Records XML
try:
dnsRecordsXML = Element("dnsrecords")
@@ -284,7 +280,7 @@ def submitBackupCreation(request):
except BaseException,msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg))
## email accounts
## Email accounts XML
try:
emailRecordsXML = Element('emails')
@@ -309,8 +305,6 @@ def submitBackupCreation(request):
## Email meta generated!
def prettify(elem):
"""Return a pretty-printed XML string for the Element.
"""
@@ -373,7 +367,7 @@ def backupStatus(request):
command = "sudo cat " + status
status = subprocess.check_output(shlex.split(command))
if status.find("completed")> -1:
if status.find("Completed")> -1:
command = 'sudo rm -f ' + status
subprocess.call(shlex.split(command))
@@ -502,7 +496,6 @@ def deleteBackup(request):
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def submitRestore(request):
try:
if request.method == 'POST':
@@ -590,14 +583,13 @@ def restoreStatus(request):
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def backupDestinations(request):
try:
val = request.session['userID']
admin = Administrator.objects.get(pk=val)
if admin.type==1:
if admin.type == 1:
return render(request, 'backup/backupDestinations.html', {})
else:
return HttpResponse("You should be admin to add backup destinations.")
@@ -609,13 +601,13 @@ def submitDestinationCreation(request):
try:
if request.method == 'POST':
destinations = backupUtil.backupUtilities.destinationsPath
data = json.loads(request.body)
ipAddress = data['IPAddress']
password = data['password']
port = "22"
try:
port = data['backupSSHPort']
except:
@@ -632,8 +624,9 @@ def submitDestinationCreation(request):
return HttpResponse(final_json)
except:
setupKeys = backupUtil.backupUtilities.setupSSHKeys(ipAddress,password,port)
if setupKeys[0] == 1:
backupUtil.backupUtilities.initiateBackupDirCreation(ipAddress,port)
backupUtil.backupUtilities.createBackupDir(ipAddress,port)
try:
writeToFile = open(destinations, "w")
writeToFile.writelines(ipAddress + "\n")

File diff suppressed because one or more lines are too long

View File

@@ -129,4 +129,9 @@ h1, h2, h3, h4, h5, h6,
}
#page-sidebar.font-inverse #sidebar-menu li .sidebar-submenu ul li a:hover {
background: rgba(255,255,255,0.05);
}
}
/* Admin responsive */
@media only screen and (min-width:20em){#header-logo,#theme-options{display:none}#page-sidebar{transform:translateX(0);-ms-transform:translateX(0);-o-transform:translateX(0);-webkit-transform:translateX(0);visibility:hidden}#page-content{margin-left:0}}@media only screen and (min-width:56.25em){#header-logo,#page-sidebar.collapse,#theme-options{display:block}#mobile-navigation{display:none}#page-sidebar{transform:translateX(0);-ms-transform:translateX(0);-o-transform:translateX(0);-webkit-transform:translateX(0);visibility:visible}#page-content{margin-left:260px}}@media only screen and (max-width:760px){#cloud-btn,#header-nav-right #fullscreen-btn{display:none}}@media only screen and (max-width:630px){#page-header .user-account-btn>a.user-profile span{display:none}#page-header .user-account-btn .dropdown-menu:after,#page-header .user-account-btn .dropdown-menu:before{left:56px}}@media only screen and (max-width:545px){#header-nav-right #chatbox-btn{display:none}}@media only screen and (max-width:520px){#dashnav-btn,#page-header .user-account-btn>a.user-profile span{display:none}.popover{width:100%;border-radius:0}.box-md{width:auto}}@media only screen and (max-width:460px){.box-sm,.timeline-box .popover{width:auto}#page-content{padding:10px}#page-title{padding:10px 0 15px;text-align:center}.col-lg-1,.col-lg-10,.col-lg-11,.col-lg-12,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-md-1,.col-md-10,.col-md-11,.col-md-12,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,.col-md-7,.col-md-8,.col-md-9,.col-sm-1,.col-sm-10,.col-sm-11,.col-sm-12,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9,.col-xs-1,.col-xs-10,.col-xs-11,.col-xs-12,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9{margin-bottom:20px}.content-box{margin-top:0!important}.row.mrg20B{margin-bottom:0!important}#page-title p,#progress-btn,.dashboard-box .list-grade,.header-buttons-separator,.todo-box .bs-label,.todo-box .btn,.tooltip .tooltip-arrow{display:none}}@media only screen and (max-width:410px){#header-nav-right #logout-btn,#notifications-btn{display:none}#header-nav-left{float:right}#header-nav-right{margin-right:0;margin-left:15px;float:left}.dropdown-menu{position:fixed;left:0!important;width:100%;border-radius:0}#page-header .user-account-btn .dropdown-menu{top:65px}#page-header .user-account-btn .dropdown-menu:after,#page-header .user-account-btn .dropdown-menu:before{left:auto;right:24px}}

View File

@@ -19,15 +19,9 @@
<!-- Favicons -->
{% load static %}
<script src = "https://code.angularjs.org/1.6.5/angular.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<!-- HELPERS -->
<link rel="stylesheet" type="text/css" href="{% static 'baseTemplate/assets/finalBase/finalBase.css' %}">
@@ -41,7 +35,6 @@
<!-- SNIPPETS -->
<!-- APPLICATIONS -->
<!-- Admin theme -->
<link rel="stylesheet" type="text/css" href="{% static 'baseTemplate/assets/finalBase/finalBaseTheme.css' %}">
@@ -49,7 +42,8 @@
<link rel="stylesheet" type="text/css" href="/static/baseTemplate/assets/themes/admin/layout.css">
<link rel="stylesheet" type="text/css" href="/static/baseTemplate/assets/themes/admin/color-schemes/default.css">
<!-- Components theme -->
<!-- Components theme, component below was above three CSS files. -->
<!-- Admin responsive -->

View File

@@ -32,7 +32,9 @@ class backupSchedule:
time.sleep(2)
data = json.loads(r.text)
if data['status'] == 0:
if data['backupStatus'] == 0:
break
elif data['abort'] == 1:
break
writeToFile.writelines("[" + time.strftime(
@@ -61,10 +63,8 @@ class backupSchedule:
@staticmethod
def sendBackup(backupPath, IPAddress, writeToFile,port):
try:
command = 'rsync -avz -e "ssh -i /root/.ssh/cyberpanel -o StrictHostKeyChecking=no -p '+port+'" ' + backupPath + ' root@' + IPAddress + ':/home/backup/' + time.strftime(
"%a-%b") + "/"
command = "sudo scp -P "+port+" -i /root/.ssh/cyberpanel " + backupPath + " root@"+IPAddress+":/home/backup/"+ time.strftime("%a-%b") + "/"
subprocess.call(shlex.split(command), stdout=writeToFile)
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]")
@@ -75,8 +75,6 @@ class backupSchedule:
backupLogPath = "/usr/local/lscp/logs/backup_log."+time.strftime("%I-%M-%S-%a-%b-%Y")
writeToFile = open(backupLogPath,"a")
writeToFile.writelines("#################################################\n")
@@ -99,6 +97,11 @@ class backupSchedule:
"%I-%M-%S-%a-%b-%Y") + "]" + " Connection to:" + ipAddress+" Failed, please resetup this destination from CyberPanel, aborting." + "\n")
return 0
else:
## Create backup dir on remote server
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel root@" + ipAddress + " mkdir /home/backup/" + time.strftime("%a-%b")
subprocess.call(shlex.split(command))
pass
else:
writeToFile.writelines("[" + time.strftime(

View File

@@ -16,6 +16,7 @@ import argparse
from shutil import move,copy
import sys
from xml.etree import ElementTree
import time
@@ -82,7 +83,7 @@ class backupUtilities:
rmtree(tempStoragePath)
status = open(os.path.join(backupPath,'status'), "w")
status.write("completed\n")
status.write("Completed\n")
status.close()
@@ -144,12 +145,11 @@ class backupUtilities:
status = open(os.path.join(completPath,'status'), "w")
status.write("Extracting Main Archive")
status.write("Extracting Main Archive!")
status.close()
## Converting /home/backup/backup-example-06-50-03-Thu-Feb-2018.tar.gz -> /home/backup/backup-example-06-50-03-Thu-Feb-2018
tar = tarfile.open(originalFile)
tar.extractall(completPath)
tar.close()
@@ -157,7 +157,7 @@ class backupUtilities:
status = open(os.path.join(completPath,'status'), "w")
status.write("Creating Account and databases!")
status.write("Creating Accounts,Databases and DNS records!")
status.close()
## creating website and its dabases
@@ -171,13 +171,12 @@ class backupUtilities:
pass
else:
status = open(os.path.join(completPath,'status'), "w")
status.write("Error Message: " + data['error_message'] +". Not able to create Account and Databases, aborting. [5009]")
status.write("Error Message: " + data['error_message'] +". Not able to create Account, Databasesand DNS Records, aborting. [5009]")
status.close()
logging.CyberCPLogFileWriter.writeToFile(r.text)
return 0
except BaseException,msg:
status = open(os.path.join(completPath,'status'), "w")
status.write("Error Message: " + str(msg) +". Not able to create Account and databases, aborting. [5009]")
status.write("Error Message: " + str(msg) +". Not able to create Account, Databasesand DNS Records, aborting. [5009]")
status.close()
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]")
return 0
@@ -234,7 +233,6 @@ class backupUtilities:
## Restoring email accounts
status = open(os.path.join(completPath, 'status'), "w")
status.write("Restoring email accounts!")
status.close()
@@ -314,20 +312,21 @@ class backupUtilities:
## emails extracted
## change permissions
## Change permissions
command = "chmod -r vmail:vmail " + emailHome
subprocess.call(shlex.split(command))
##
status = open(os.path.join(completPath,'status'), "w")
status.write("Done")
status.close()
installUtilities.reStartLiteSpeed()
command = "chown -R " + externalApp + ":" + externalApp + " " + websiteHome
cmd = shlex.split(command)
subprocess.call(cmd)
except BaseException, msg:
@@ -384,7 +383,6 @@ class backupUtilities:
expectation = "password:"
command = "ssh -o StrictHostKeyChecking=no -p "+ port +" root@"+IPAddress+" mkdir /root/.ssh"
setupKeys = pexpect.spawn(command,timeout=3)
@@ -404,7 +402,7 @@ class backupUtilities:
index = setupKeys.expect(expectation)
if index == 0:
return [0,"Wrong Password"]
return [0,"Wrong Password!"]
elif index == 1:
setupKeys.wait()
@@ -547,32 +545,17 @@ class backupUtilities:
def createBackupDir(IPAddress,port):
try:
command = "ssh -o StrictHostKeyChecking=no -p "+ port +" -i /home/cyberpanel/.ssh/cyberpanel cyberpanel@"+IPAddress+" mkdir /home/backup"
shlex.split(command)
command = "sudo ssh -o StrictHostKeyChecking=no -p "+ port +" -i /root/.ssh/cyberpanel root@"+IPAddress+" mkdir /home/backup"
subprocess.call(shlex.split(command))
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createBackupDir]")
return 0
@staticmethod
def initiateBackupDirCreation(IPAddress,port):
try:
thread.start_new_thread(backupUtilities.createBackupDir, (IPAddress,port))
except BaseException,msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateBackupDirCreation]")
@staticmethod
def host_key_verification(IPAddress):
try:
command = 'sudo ssh-keygen -R '+IPAddress
shlex.split(command)
subprocess.call(shlex.split(command))
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [host_key_verification]")
return 0
@@ -597,7 +580,7 @@ def submitBackupCreation(tempStoragePath,backupName,backupPath,metaPath):
p = Process(target=backupUtilities.startBackup, args=(tempStoragePath, backupName, backupPath,))
p.start()
pid = open(backupPath + 'pid', "w")
pid = open(os.path.join(backupPath,'pid'), "w")
pid.write(str(p.pid))
pid.close()
@@ -687,6 +670,4 @@ def main():
submitRestore(args.backupFile,args.dir)
if __name__ == "__main__":
main()
main()

View File

@@ -135,18 +135,22 @@ class sslUtilities:
# command = "sudo certbot certonly -n --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName
try:
serverIPAddress = requests.get('https://api.ipify.org').text
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
serverIPAddress = ipData.split('\n', 1)[0]
domainIP = socket.gethostbyname("www."+virtualHostName)
if serverIPAddress == domainIP:
command = "certbot certonly -n --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName + " -d www." + virtualHostName
else:
command = "certbot certonly -n --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName
logging.CyberCPLogFileWriter.writeToFile(
"SSL is issues without 'www' due to DNS error! for domain :" + virtualHostName)
"SSL is issued without 'www' due to DNS error! for domain :" + virtualHostName)
except:
command = "certbot certonly -n --agree-tos --email " + adminEmail + " --webroot -w " + sslpath + " -d " + virtualHostName
logging.CyberCPLogFileWriter.writeToFile("SSL is issues without 'www' due to DNS error! for domain : " + virtualHostName)
logging.CyberCPLogFileWriter.writeToFile("SSL is issued without 'www' due to DNS error! for domain : " + virtualHostName)
expectation = []

View File

@@ -36,7 +36,6 @@ app.controller('backupWebsiteControl', function($scope,$http,$timeout) {
};
$scope.fetchDetails = function () {
getBackupStatus();
populateCurrentRecords();
$scope.destination = false;
@@ -71,10 +70,9 @@ app.controller('backupWebsiteControl', function($scope,$http,$timeout) {
function ListInitialDatas(response) {
if(response.data.backupStatus == 1){
if(response.data.backupStatus === 1){
if(response.data.abort === 1){
$timeout.cancel();
$scope.backupLoadingBottom = true;
$scope.destination = false;
@@ -108,11 +106,7 @@ app.controller('backupWebsiteControl', function($scope,$http,$timeout) {
}
}
function cantLoadInitialDatas(response) {
}
function cantLoadInitialDatas(response) {}
};
@@ -147,22 +141,12 @@ app.controller('backupWebsiteControl', function($scope,$http,$timeout) {
if(response.data.fetchStatus == 1){
$scope.records = JSON.parse(response.data.data);
}
else{
}
}
function cantLoadInitialDatas(response) {
}
function cantLoadInitialDatas(response) {}
};
@@ -195,7 +179,7 @@ app.controller('backupWebsiteControl', function($scope,$http,$timeout) {
function ListInitialDatas(response) {
if(response.data.metaStatus == 1){
if(response.data.metaStatus === 1){
getBackupStatus();
}

File diff suppressed because one or more lines are too long

View File

@@ -129,4 +129,9 @@ h1, h2, h3, h4, h5, h6,
}
#page-sidebar.font-inverse #sidebar-menu li .sidebar-submenu ul li a:hover {
background: rgba(255,255,255,0.05);
}
}
/* Admin responsive */
@media only screen and (min-width:20em){#header-logo,#theme-options{display:none}#page-sidebar{transform:translateX(0);-ms-transform:translateX(0);-o-transform:translateX(0);-webkit-transform:translateX(0);visibility:hidden}#page-content{margin-left:0}}@media only screen and (min-width:56.25em){#header-logo,#page-sidebar.collapse,#theme-options{display:block}#mobile-navigation{display:none}#page-sidebar{transform:translateX(0);-ms-transform:translateX(0);-o-transform:translateX(0);-webkit-transform:translateX(0);visibility:visible}#page-content{margin-left:260px}}@media only screen and (max-width:760px){#cloud-btn,#header-nav-right #fullscreen-btn{display:none}}@media only screen and (max-width:630px){#page-header .user-account-btn>a.user-profile span{display:none}#page-header .user-account-btn .dropdown-menu:after,#page-header .user-account-btn .dropdown-menu:before{left:56px}}@media only screen and (max-width:545px){#header-nav-right #chatbox-btn{display:none}}@media only screen and (max-width:520px){#dashnav-btn,#page-header .user-account-btn>a.user-profile span{display:none}.popover{width:100%;border-radius:0}.box-md{width:auto}}@media only screen and (max-width:460px){.box-sm,.timeline-box .popover{width:auto}#page-content{padding:10px}#page-title{padding:10px 0 15px;text-align:center}.col-lg-1,.col-lg-10,.col-lg-11,.col-lg-12,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-md-1,.col-md-10,.col-md-11,.col-md-12,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,.col-md-7,.col-md-8,.col-md-9,.col-sm-1,.col-sm-10,.col-sm-11,.col-sm-12,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9,.col-xs-1,.col-xs-10,.col-xs-11,.col-xs-12,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9{margin-bottom:20px}.content-box{margin-top:0!important}.row.mrg20B{margin-bottom:0!important}#page-title p,#progress-btn,.dashboard-box .list-grade,.header-buttons-separator,.todo-box .bs-label,.todo-box .btn,.tooltip .tooltip-arrow{display:none}}@media only screen and (max-width:410px){#header-nav-right #logout-btn,#notifications-btn{display:none}#header-nav-left{float:right}#header-nav-right{margin-right:0;margin-left:15px;float:left}.dropdown-menu{position:fixed;left:0!important;width:100%;border-radius:0}#page-header .user-account-btn .dropdown-menu{top:65px}#page-header .user-account-btn .dropdown-menu:after,#page-header .user-account-btn .dropdown-menu:before{left:auto;right:24px}}

View File

@@ -648,8 +648,6 @@ def submitWebsiteDeletion(request):
execPath = execPath + " deleteVirtualHostConfigurations --virtualHostName "+ websiteName+" --numberOfSites "+numberOfWebsites
subprocess.check_output(shlex.split(execPath))
delWebsite = Websites.objects.get(domain=websiteName)
@@ -682,6 +680,11 @@ def submitWebsiteDeletion(request):
installUtilities.reStartLiteSpeed()
## Delete mail accounts
command = "sudo rm -rf /home/vmail/" + websiteName
subprocess.call(shlex.split(command))
data_ret = {'websiteDeleteStatus': 1,'error_message': "None"}
json_data = json.dumps(data_ret)