mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-12 16:26:12 +01:00
Add remote backup user support for non root user. This is experimental patch to hopefully solve https://github.com/usmannasir/cyberpanel/issues/165
This commit is contained in:
@@ -48,6 +48,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-3 control-label">{% trans "User" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<input placeholder="{% trans "Backup server SSH User, leave empty for root." %}" type="text" class="form-control" ng-model="backupSSHPort" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-sm-3 control-label"></label>
|
<label class="col-sm-3 control-label"></label>
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ class backupSchedule:
|
|||||||
return 0, str(msg)
|
return 0, str(msg)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def createBackup(virtualHost, ipAddress, backupLogPath , port):
|
def createBackup(virtualHost, ipAddress, backupLogPath , port='22', user='root'):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
backupSchedule.remoteBackupLogging(backupLogPath, "Preparing to create backup for: " + virtualHost)
|
backupSchedule.remoteBackupLogging(backupLogPath, "Preparing to create backup for: " + virtualHost)
|
||||||
@@ -152,7 +152,7 @@ class backupSchedule:
|
|||||||
|
|
||||||
backupSchedule.remoteBackupLogging(backupLogPath, "Preparing to send backup for: " + virtualHost +" to " + ipAddress)
|
backupSchedule.remoteBackupLogging(backupLogPath, "Preparing to send backup for: " + virtualHost +" to " + ipAddress)
|
||||||
|
|
||||||
backupSchedule.sendBackup(backupPath+".tar.gz", ipAddress, backupLogPath, port)
|
backupSchedule.sendBackup(backupPath+".tar.gz", ipAddress, backupLogPath, port, user)
|
||||||
|
|
||||||
backupSchedule.remoteBackupLogging(backupLogPath, "Backup for: " + virtualHost + " is sent to " + ipAddress)
|
backupSchedule.remoteBackupLogging(backupLogPath, "Backup for: " + virtualHost + " is sent to " + ipAddress)
|
||||||
|
|
||||||
@@ -180,7 +180,7 @@ class backupSchedule:
|
|||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [backupSchedule.createBackup]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [backupSchedule.createBackup]")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def sendBackup(backupPath, IPAddress, backupLogPath , port):
|
def sendBackup(backupPath, IPAddress, backupLogPath , port='22', user='root'):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
## IPAddress of local server
|
## IPAddress of local server
|
||||||
@@ -193,7 +193,7 @@ class backupSchedule:
|
|||||||
##
|
##
|
||||||
|
|
||||||
writeToFile = open(backupLogPath, "a")
|
writeToFile = open(backupLogPath, "a")
|
||||||
command = "sudo scp -o StrictHostKeyChecking=no -P "+port+" -i /root/.ssh/cyberpanel " + backupPath + " root@"+IPAddress+":/home/backup/" + ipAddressLocal + "/" + time.strftime("%a-%b") + "/"
|
command = "sudo scp -o StrictHostKeyChecking=no -P "+port+" -i /root/.ssh/cyberpanel " + backupPath + " " + user + "@" + IPAddress+":~/backup/" + ipAddressLocal + "/" + time.strftime("%a-%b") + "/"
|
||||||
subprocess.call(shlex.split(command), stdout=writeToFile)
|
subprocess.call(shlex.split(command), stdout=writeToFile)
|
||||||
|
|
||||||
## Remove backups already sent to remote destinations
|
## Remove backups already sent to remote destinations
|
||||||
@@ -222,6 +222,10 @@ class backupSchedule:
|
|||||||
data = open(destinations,'r').readlines()
|
data = open(destinations,'r').readlines()
|
||||||
ipAddress = data[0].strip("\n")
|
ipAddress = data[0].strip("\n")
|
||||||
port = data[1].strip("\n")
|
port = data[1].strip("\n")
|
||||||
|
user = data[2].strip("\n")
|
||||||
|
|
||||||
|
# Set the user to root if not specified aka empty
|
||||||
|
user = user if bool(user) is not False else 'root'
|
||||||
|
|
||||||
## IPAddress of local server
|
## IPAddress of local server
|
||||||
|
|
||||||
@@ -241,16 +245,16 @@ class backupSchedule:
|
|||||||
"Connection to: " + ipAddress + " Failed, please resetup this destination from CyberPanel, aborting.")
|
"Connection to: " + ipAddress + " Failed, please resetup this destination from CyberPanel, aborting.")
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
## Create backup dir on remote server
|
## Create backup dir on remote server in ~/backup
|
||||||
|
|
||||||
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel root@" + ipAddress + " mkdir -p /home/backup/" + ipAddressLocal + "/" + time.strftime(
|
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel " + user + "@" + ipAddress + " mkdir -p ~/backup/" + ipAddressLocal + "/" + time.strftime(
|
||||||
"%a-%b")
|
"%a-%b")
|
||||||
subprocess.call(shlex.split(command))
|
subprocess.call(shlex.split(command))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for virtualHost in os.listdir("/home"):
|
for virtualHost in os.listdir("/home"):
|
||||||
if match(r'^[a-zA-Z0-9-]*[a-zA-Z0-9-]{0,61}[a-zA-Z0-9-](?:\.[a-zA-Z0-9-]{2,})+$', virtualHost, M | I):
|
if match(r'^[a-zA-Z0-9-]*[a-zA-Z0-9-]{0,61}[a-zA-Z0-9-](?:\.[a-zA-Z0-9-]{2,})+$', virtualHost, M | I):
|
||||||
backupSchedule.createBackup(virtualHost, ipAddress, backupLogPath, port)
|
backupSchedule.createBackup(virtualHost, ipAddress, backupLogPath, port, user)
|
||||||
|
|
||||||
|
|
||||||
backupSchedule.remoteBackupLogging(backupLogPath, "Remote backup job completed.\n")
|
backupSchedule.remoteBackupLogging(backupLogPath, "Remote backup job completed.\n")
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import os,sys
|
import os, sys
|
||||||
|
|
||||||
sys.path.append('/usr/local/CyberCP')
|
sys.path.append('/usr/local/CyberCP')
|
||||||
import django
|
import django
|
||||||
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||||
try:
|
try:
|
||||||
django.setup()
|
django.setup()
|
||||||
@@ -10,13 +12,14 @@ import pexpect
|
|||||||
from plogical import CyberCPLogFileWriter as logging
|
from plogical import CyberCPLogFileWriter as logging
|
||||||
import subprocess
|
import subprocess
|
||||||
import shlex
|
import shlex
|
||||||
from shutil import make_archive,rmtree
|
from shutil import make_archive, rmtree
|
||||||
from plogical import mysqlUtilities
|
from plogical import mysqlUtilities
|
||||||
import tarfile
|
import tarfile
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
import signal
|
import signal
|
||||||
from plogical.installUtilities import installUtilities
|
from plogical.installUtilities import installUtilities
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from plogical.virtualHostUtilities import virtualHostUtilities
|
from plogical.virtualHostUtilities import virtualHostUtilities
|
||||||
from plogical.sslUtilities import sslUtilities
|
from plogical.sslUtilities import sslUtilities
|
||||||
@@ -32,6 +35,7 @@ from shutil import copy
|
|||||||
from distutils.dir_util import copy_tree
|
from distutils.dir_util import copy_tree
|
||||||
from random import randint
|
from random import randint
|
||||||
from plogical.processUtilities import ProcessUtilities
|
from plogical.processUtilities import ProcessUtilities
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from websiteFunctions.models import Websites, ChildDomains, Backups
|
from websiteFunctions.models import Websites, ChildDomains, Backups
|
||||||
from databases.models import Databases
|
from databases.models import Databases
|
||||||
@@ -45,12 +49,13 @@ except:
|
|||||||
VERSION = '2.0'
|
VERSION = '2.0'
|
||||||
BUILD = 1
|
BUILD = 1
|
||||||
|
|
||||||
|
|
||||||
## I am not the monster that you think I am..
|
## I am not the monster that you think I am..
|
||||||
|
|
||||||
class backupUtilities:
|
class backupUtilities:
|
||||||
Server_root = "/usr/local/lsws"
|
Server_root = "/usr/local/lsws"
|
||||||
|
|
||||||
completeKeyPath = "/home/cyberpanel/.ssh"
|
completeKeyPath = "/home/cyberpanel/.ssh"
|
||||||
destinationsPath = "/home/cyberpanel/destinations"
|
destinationsPath = "/home/cyberpanel/destinations"
|
||||||
licenseKey = '/usr/local/lsws/conf/license.key'
|
licenseKey = '/usr/local/lsws/conf/license.key'
|
||||||
|
|
||||||
@@ -190,11 +195,9 @@ class backupUtilities:
|
|||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(
|
logging.CyberCPLogFileWriter.writeToFile(
|
||||||
'While creating backup for %s, we failed to backup database %s. Error message: %s' % (
|
'While creating backup for %s, we failed to backup database %s. Error message: %s' % (
|
||||||
backupDomain, items.dbName, str(msg)))
|
backupDomain, items.dbName, str(msg)))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
databaseXML = Element('database')
|
databaseXML = Element('database')
|
||||||
|
|
||||||
child = SubElement(databaseXML, 'dbName')
|
child = SubElement(databaseXML, 'dbName')
|
||||||
@@ -276,7 +279,6 @@ class backupUtilities:
|
|||||||
|
|
||||||
## Email meta generated!
|
## Email meta generated!
|
||||||
|
|
||||||
|
|
||||||
def prettify(elem):
|
def prettify(elem):
|
||||||
"""Return a pretty-printed XML string for the Element.
|
"""Return a pretty-printed XML string for the Element.
|
||||||
"""
|
"""
|
||||||
@@ -284,8 +286,6 @@ class backupUtilities:
|
|||||||
reparsed = minidom.parseString(rough_string)
|
reparsed = minidom.parseString(rough_string)
|
||||||
return reparsed.toprettyxml(indent=" ")
|
return reparsed.toprettyxml(indent=" ")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## /home/example.com/backup/backup-example.com-02.13.2018_10-24-52/meta.xml -- metaPath
|
## /home/example.com/backup/backup-example.com-02.13.2018_10-24-52/meta.xml -- metaPath
|
||||||
|
|
||||||
metaPath = '/tmp/%s' % (str(randint(1000, 9999)))
|
metaPath = '/tmp/%s' % (str(randint(1000, 9999)))
|
||||||
@@ -298,22 +298,21 @@ class backupUtilities:
|
|||||||
|
|
||||||
## meta generated
|
## meta generated
|
||||||
|
|
||||||
|
|
||||||
newBackup = Backups(website=website, fileName=backupName, date=time.strftime("%m.%d.%Y_%H-%M-%S"),
|
newBackup = Backups(website=website, fileName=backupName, date=time.strftime("%m.%d.%Y_%H-%M-%S"),
|
||||||
size=0, status=1)
|
size=0, status=1)
|
||||||
newBackup.save()
|
newBackup.save()
|
||||||
|
|
||||||
logging.CyberCPLogFileWriter.statusWriter(status, 'Meta data is ready..')
|
logging.CyberCPLogFileWriter.statusWriter(status, 'Meta data is ready..')
|
||||||
|
|
||||||
return 1,'None', metaPath
|
return 1, 'None', metaPath
|
||||||
|
|
||||||
|
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.CyberCPLogFileWriter.statusWriter(status, "%s [207][5009]" % (str(msg)))
|
logging.CyberCPLogFileWriter.statusWriter(status, "%s [207][5009]" % (str(msg)))
|
||||||
return 0,str(msg)
|
return 0, str(msg)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def startBackup(tempStoragePath, backupName, backupPath, metaPath = None):
|
def startBackup(tempStoragePath, backupName, backupPath, metaPath=None):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
## /home/example.com/backup/backup-example.com-02.13.2018_10-24-52 -- tempStoragePath
|
## /home/example.com/backup/backup-example.com-02.13.2018_10-24-52 -- tempStoragePath
|
||||||
@@ -327,12 +326,12 @@ class backupUtilities:
|
|||||||
writeToFile.writelines(str(os.getpid()))
|
writeToFile.writelines(str(os.getpid()))
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
|
|
||||||
backupFileNamePath = os.path.join(backupPath,"backupFileName")
|
backupFileNamePath = os.path.join(backupPath, "backupFileName")
|
||||||
logging.CyberCPLogFileWriter.statusWriter(backupFileNamePath, backupName)
|
logging.CyberCPLogFileWriter.statusWriter(backupFileNamePath, backupName)
|
||||||
|
|
||||||
#####
|
#####
|
||||||
|
|
||||||
status = os.path.join(backupPath,'status')
|
status = os.path.join(backupPath, 'status')
|
||||||
|
|
||||||
logging.CyberCPLogFileWriter.statusWriter(status, "Making archive of home directory.\n")
|
logging.CyberCPLogFileWriter.statusWriter(status, "Making archive of home directory.\n")
|
||||||
|
|
||||||
@@ -340,7 +339,7 @@ class backupUtilities:
|
|||||||
|
|
||||||
## /home/example.com/backup/backup-example.com-02.13.2018_10-24-52 -- tempStoragePath
|
## /home/example.com/backup/backup-example.com-02.13.2018_10-24-52 -- tempStoragePath
|
||||||
|
|
||||||
metaPathInBackup = os.path.join(tempStoragePath,'meta.xml')
|
metaPathInBackup = os.path.join(tempStoragePath, 'meta.xml')
|
||||||
|
|
||||||
if metaPath != None:
|
if metaPath != None:
|
||||||
writeToFile = open(metaPathInBackup, 'w')
|
writeToFile = open(metaPathInBackup, 'w')
|
||||||
@@ -349,7 +348,6 @@ class backupUtilities:
|
|||||||
|
|
||||||
backupMetaData = ElementTree.parse(metaPathInBackup)
|
backupMetaData = ElementTree.parse(metaPathInBackup)
|
||||||
|
|
||||||
|
|
||||||
##### Making archive of home directory
|
##### Making archive of home directory
|
||||||
|
|
||||||
domainName = backupMetaData.find('masterDomain').text
|
domainName = backupMetaData.find('masterDomain').text
|
||||||
@@ -366,10 +364,9 @@ class backupUtilities:
|
|||||||
|
|
||||||
## Stop making archive of document_root and copy instead
|
## Stop making archive of document_root and copy instead
|
||||||
|
|
||||||
|
|
||||||
copy_tree('/home/%s/public_html' % domainName, '%s/%s' % (tempStoragePath, 'public_html'))
|
copy_tree('/home/%s/public_html' % domainName, '%s/%s' % (tempStoragePath, 'public_html'))
|
||||||
|
|
||||||
#make_archive(os.path.join(tempStoragePath,"public_html"), 'gztar', os.path.join("/home",domainName,"public_html"))
|
# make_archive(os.path.join(tempStoragePath,"public_html"), 'gztar', os.path.join("/home",domainName,"public_html"))
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
@@ -378,7 +375,7 @@ class backupUtilities:
|
|||||||
|
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
try:
|
try:
|
||||||
os.remove(os.path.join(backupPath,backupName+".tar.gz"))
|
os.remove(os.path.join(backupPath, backupName + ".tar.gz"))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -388,8 +385,8 @@ class backupUtilities:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
status = os.path.join(backupPath, 'status')
|
status = os.path.join(backupPath, 'status')
|
||||||
logging.CyberCPLogFileWriter.statusWriter(status, "Aborted, "+ str(msg) + ".[365] [5009]")
|
logging.CyberCPLogFileWriter.statusWriter(status, "Aborted, " + str(msg) + ".[365] [5009]")
|
||||||
print(("Aborted, "+ str(msg) + ".[365] [5009]"))
|
print(("Aborted, " + str(msg) + ".[365] [5009]"))
|
||||||
|
|
||||||
os.remove(pidFile)
|
os.remove(pidFile)
|
||||||
|
|
||||||
@@ -462,7 +459,8 @@ class backupUtilities:
|
|||||||
|
|
||||||
domainName = backupMetaData.find('masterDomain').text
|
domainName = backupMetaData.find('masterDomain').text
|
||||||
|
|
||||||
if os.path.islink(status) or os.path.islink(tempStoragePath or os.path.islink(backupPath)) or os.path.islink(metaPath):
|
if os.path.islink(status) or os.path.islink(tempStoragePath or os.path.islink(backupPath)) or os.path.islink(
|
||||||
|
metaPath):
|
||||||
logging.CyberCPLogFileWriter.writeToFile('symlinked.')
|
logging.CyberCPLogFileWriter.writeToFile('symlinked.')
|
||||||
logging.CyberCPLogFileWriter.statusWriter(status, 'Symlink attack. [365][5009]')
|
logging.CyberCPLogFileWriter.statusWriter(status, 'Symlink attack. [365][5009]')
|
||||||
return 0
|
return 0
|
||||||
@@ -482,7 +480,7 @@ class backupUtilities:
|
|||||||
rmtree(tempStoragePath)
|
rmtree(tempStoragePath)
|
||||||
|
|
||||||
###
|
###
|
||||||
backupFileNamePath = os.path.join(backupPath,"backupFileName")
|
backupFileNamePath = os.path.join(backupPath, "backupFileName")
|
||||||
fileName = open(backupFileNamePath, 'r').read()
|
fileName = open(backupFileNamePath, 'r').read()
|
||||||
|
|
||||||
backupObs = Backups.objects.filter(fileName=fileName)
|
backupObs = Backups.objects.filter(fileName=fileName)
|
||||||
@@ -492,27 +490,27 @@ class backupUtilities:
|
|||||||
for items in backupObs:
|
for items in backupObs:
|
||||||
items.status = 1
|
items.status = 1
|
||||||
items.size = str(int(float(
|
items.size = str(int(float(
|
||||||
os.path.getsize(os.path.join(backupPath,backupName+".tar.gz"))) / (
|
os.path.getsize(os.path.join(backupPath, backupName + ".tar.gz"))) / (
|
||||||
1024.0 * 1024.0))) + "MB"
|
1024.0 * 1024.0))) + "MB"
|
||||||
items.save()
|
items.save()
|
||||||
except:
|
except:
|
||||||
for items in backupObs:
|
for items in backupObs:
|
||||||
items.status = 1
|
items.status = 1
|
||||||
items.size = str(int(float(
|
items.size = str(int(float(
|
||||||
os.path.getsize(os.path.join(backupPath,backupName+".tar.gz"))) / (
|
os.path.getsize(os.path.join(backupPath, backupName + ".tar.gz"))) / (
|
||||||
1024.0 * 1024.0))) + "MB"
|
1024.0 * 1024.0))) + "MB"
|
||||||
items.save()
|
items.save()
|
||||||
|
|
||||||
command = 'chmod 600 %s' % (os.path.join(backupPath,backupName+".tar.gz"))
|
command = 'chmod 600 %s' % (os.path.join(backupPath, backupName + ".tar.gz"))
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
logging.CyberCPLogFileWriter.statusWriter(status, "Completed\n")
|
logging.CyberCPLogFileWriter.statusWriter(status, "Completed\n")
|
||||||
os.remove(pidFile)
|
os.remove(pidFile)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def initiateBackup(tempStoragePath,backupName,backupPath):
|
def initiateBackup(tempStoragePath, backupName, backupPath):
|
||||||
try:
|
try:
|
||||||
p = Process(target=backupUtilities.startBackup, args=(tempStoragePath,backupName,backupPath,))
|
p = Process(target=backupUtilities.startBackup, args=(tempStoragePath, backupName, backupPath,))
|
||||||
p.start()
|
p.start()
|
||||||
pid = open(backupPath + 'pid', "w")
|
pid = open(backupPath + 'pid', "w")
|
||||||
pid.write(str(p.pid))
|
pid.write(str(p.pid))
|
||||||
@@ -581,14 +579,11 @@ class backupUtilities:
|
|||||||
if Websites.objects.filter(domain=domain).count() > 0:
|
if Websites.objects.filter(domain=domain).count() > 0:
|
||||||
raise BaseException('This website already exists.')
|
raise BaseException('This website already exists.')
|
||||||
|
|
||||||
|
|
||||||
if ChildDomains.objects.filter(domain=domain).count() > 0:
|
if ChildDomains.objects.filter(domain=domain).count() > 0:
|
||||||
raise BaseException("This website already exists as child domain.")
|
raise BaseException("This website already exists as child domain.")
|
||||||
|
|
||||||
|
|
||||||
####### Pre-creation checks ends
|
####### Pre-creation checks ends
|
||||||
|
|
||||||
|
|
||||||
## Create Configurations
|
## Create Configurations
|
||||||
|
|
||||||
result = virtualHostUtilities.createVirtualHost(domain, siteUser.email, phpSelection, externalApp, 0, 1, 0,
|
result = virtualHostUtilities.createVirtualHost(domain, siteUser.email, phpSelection, externalApp, 0, 1, 0,
|
||||||
@@ -623,7 +618,6 @@ class backupUtilities:
|
|||||||
zone = DNS.getZoneObject(domain)
|
zone = DNS.getZoneObject(domain)
|
||||||
|
|
||||||
for dnsrecord in dnsrecords:
|
for dnsrecord in dnsrecords:
|
||||||
|
|
||||||
recordType = dnsrecord.find('type').text
|
recordType = dnsrecord.find('type').text
|
||||||
value = dnsrecord.find('name').text
|
value = dnsrecord.find('name').text
|
||||||
content = dnsrecord.find('content').text
|
content = dnsrecord.find('content').text
|
||||||
@@ -631,8 +625,7 @@ class backupUtilities:
|
|||||||
|
|
||||||
DNS.createDNSRecord(zone, value, recordType, content, prio, 3600)
|
DNS.createDNSRecord(zone, value, recordType, content, prio, 3600)
|
||||||
|
|
||||||
|
return 1, 'None'
|
||||||
return 1,'None'
|
|
||||||
|
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
return 0, str(msg)
|
return 0, str(msg)
|
||||||
@@ -643,28 +636,28 @@ class backupUtilities:
|
|||||||
|
|
||||||
if dir == "CyberPanelRestore":
|
if dir == "CyberPanelRestore":
|
||||||
backupFileName = backupName.strip(".tar.gz")
|
backupFileName = backupName.strip(".tar.gz")
|
||||||
completPath = os.path.join("/home","backup",backupFileName) ## without extension
|
completPath = os.path.join("/home", "backup", backupFileName) ## without extension
|
||||||
originalFile = os.path.join("/home","backup",backupName) ## with extension
|
originalFile = os.path.join("/home", "backup", backupName) ## with extension
|
||||||
elif dir == 'CLI':
|
elif dir == 'CLI':
|
||||||
completPath = backupName.strip(".tar.gz") ## without extension
|
completPath = backupName.strip(".tar.gz") ## without extension
|
||||||
originalFile = backupName ## with extension
|
originalFile = backupName ## with extension
|
||||||
else:
|
else:
|
||||||
backupFileName = backupName.strip(".tar.gz")
|
backupFileName = backupName.strip(".tar.gz")
|
||||||
completPath = "/home/backup/transfer-"+str(dir)+"/"+backupFileName ## without extension
|
completPath = "/home/backup/transfer-" + str(dir) + "/" + backupFileName ## without extension
|
||||||
originalFile = "/home/backup/transfer-"+str(dir)+"/"+backupName ## with extension
|
originalFile = "/home/backup/transfer-" + str(dir) + "/" + backupName ## with extension
|
||||||
|
|
||||||
pathToCompressedHome = os.path.join(completPath,"public_html.tar.gz")
|
pathToCompressedHome = os.path.join(completPath, "public_html.tar.gz")
|
||||||
|
|
||||||
if not os.path.exists(completPath):
|
if not os.path.exists(completPath):
|
||||||
os.mkdir(completPath)
|
os.mkdir(completPath)
|
||||||
|
|
||||||
## Writing pid of restore process
|
## Writing pid of restore process
|
||||||
|
|
||||||
pid = os.path.join(completPath,'pid')
|
pid = os.path.join(completPath, 'pid')
|
||||||
|
|
||||||
logging.CyberCPLogFileWriter.statusWriter(pid, str(os.getpid()))
|
logging.CyberCPLogFileWriter.statusWriter(pid, str(os.getpid()))
|
||||||
|
|
||||||
status = os.path.join(completPath,'status')
|
status = os.path.join(completPath, 'status')
|
||||||
logging.CyberCPLogFileWriter.statusWriter(status, "Extracting Main Archive!")
|
logging.CyberCPLogFileWriter.statusWriter(status, "Extracting Main Archive!")
|
||||||
|
|
||||||
## Converting /home/backup/backup-example.com-02.13.2018_10-24-52.tar.gz -> /home/backup/backup-example.com-02.13.2018_10-24-52
|
## Converting /home/backup/backup-example.com-02.13.2018_10-24-52.tar.gz -> /home/backup/backup-example.com-02.13.2018_10-24-52
|
||||||
@@ -681,7 +674,6 @@ class backupUtilities:
|
|||||||
backupMetaData = ElementTree.parse(os.path.join(completPath, "meta.xml"))
|
backupMetaData = ElementTree.parse(os.path.join(completPath, "meta.xml"))
|
||||||
masterDomain = backupMetaData.find('masterDomain').text
|
masterDomain = backupMetaData.find('masterDomain').text
|
||||||
|
|
||||||
|
|
||||||
twoPointO = 0
|
twoPointO = 0
|
||||||
try:
|
try:
|
||||||
version = backupMetaData.find('VERSION').text
|
version = backupMetaData.find('VERSION').text
|
||||||
@@ -713,10 +705,10 @@ class backupUtilities:
|
|||||||
logging.CyberCPLogFileWriter.writeToFile('%s. [555:startRestore]' % (str(msg)))
|
logging.CyberCPLogFileWriter.writeToFile('%s. [555:startRestore]' % (str(msg)))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.CyberCPLogFileWriter.statusWriter(status, "Error Message: " + result[1] + ". Not able to create Account, Databases and DNS Records, aborting. [575][5009]")
|
logging.CyberCPLogFileWriter.statusWriter(status, "Error Message: " + result[
|
||||||
|
1] + ". Not able to create Account, Databases and DNS Records, aborting. [575][5009]")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
########### Creating child/sub/addon/parked domains
|
########### Creating child/sub/addon/parked domains
|
||||||
|
|
||||||
logging.CyberCPLogFileWriter.statusWriter(status, "Creating Child Domains!")
|
logging.CyberCPLogFileWriter.statusWriter(status, "Creating Child Domains!")
|
||||||
@@ -724,7 +716,7 @@ class backupUtilities:
|
|||||||
## Reading meta file to create subdomains
|
## Reading meta file to create subdomains
|
||||||
|
|
||||||
externalApp = backupMetaData.find('externalApp').text
|
externalApp = backupMetaData.find('externalApp').text
|
||||||
websiteHome = os.path.join("/home",masterDomain,"public_html")
|
websiteHome = os.path.join("/home", masterDomain, "public_html")
|
||||||
|
|
||||||
### Restoring Child Domains if any.
|
### Restoring Child Domains if any.
|
||||||
|
|
||||||
@@ -747,7 +739,8 @@ class backupUtilities:
|
|||||||
phpSelection = childDomain.find('phpSelection').text
|
phpSelection = childDomain.find('phpSelection').text
|
||||||
path = childDomain.find('path').text
|
path = childDomain.find('path').text
|
||||||
|
|
||||||
retValues = virtualHostUtilities.createDomain(masterDomain, domain, phpSelection, path, 0, 0, 0, 'admin', 0)
|
retValues = virtualHostUtilities.createDomain(masterDomain, domain, phpSelection, path, 0, 0, 0,
|
||||||
|
'admin', 0)
|
||||||
|
|
||||||
if retValues[0] == 1:
|
if retValues[0] == 1:
|
||||||
if os.path.exists(websiteHome):
|
if os.path.exists(websiteHome):
|
||||||
@@ -780,7 +773,8 @@ class backupUtilities:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
logging.CyberCPLogFileWriter.writeToFile('While restoring backup we had minor issues for rebuilding vhost conf for: ' + domain + '. However this will be auto healed.')
|
logging.CyberCPLogFileWriter.writeToFile(
|
||||||
|
'While restoring backup we had minor issues for rebuilding vhost conf for: ' + domain + '. However this will be auto healed.')
|
||||||
|
|
||||||
if float(version) > 2.0 or float(build) > 0:
|
if float(version) > 2.0 or float(build) > 0:
|
||||||
if path.find('/home/%s/public_html' % masterDomain) == -1:
|
if path.find('/home/%s/public_html' % masterDomain) == -1:
|
||||||
@@ -789,11 +783,12 @@ class backupUtilities:
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
logging.CyberCPLogFileWriter.writeToFile('Error domain %s' % (domain))
|
logging.CyberCPLogFileWriter.writeToFile('Error domain %s' % (domain))
|
||||||
logging.CyberCPLogFileWriter.statusWriter(status, "Error Message: " + retValues[1] + ". Not able to create child domains, aborting. [635][5009]")
|
logging.CyberCPLogFileWriter.statusWriter(status, "Error Message: " + retValues[
|
||||||
|
1] + ". Not able to create child domains, aborting. [635][5009]")
|
||||||
return 0
|
return 0
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
status = open(os.path.join(completPath,'status'), "w")
|
status = open(os.path.join(completPath, 'status'), "w")
|
||||||
status.write("Error Message: " + str(msg) +". Not able to create child domains, aborting. [638][5009]")
|
status.write("Error Message: " + str(msg) + ". Not able to create child domains, aborting. [638][5009]")
|
||||||
status.close()
|
status.close()
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]")
|
||||||
return 0
|
return 0
|
||||||
@@ -824,7 +819,8 @@ class backupUtilities:
|
|||||||
if result[0] == 0:
|
if result[0] == 0:
|
||||||
raise BaseException(result[1])
|
raise BaseException(result[1])
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.CyberCPLogFileWriter.statusWriter(status, "Error Message: " + str(msg) +". Not able to create email accounts, aborting. [671][5009]")
|
logging.CyberCPLogFileWriter.statusWriter(status, "Error Message: " + str(
|
||||||
|
msg) + ". Not able to create email accounts, aborting. [671][5009]")
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -865,7 +861,7 @@ class backupUtilities:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
pathToCompressedEmails = os.path.join(completPath, masterDomain + ".tar.gz")
|
pathToCompressedEmails = os.path.join(completPath, masterDomain + ".tar.gz")
|
||||||
emailHome = os.path.join("/home","vmail",masterDomain)
|
emailHome = os.path.join("/home", "vmail", masterDomain)
|
||||||
|
|
||||||
tar = tarfile.open(pathToCompressedEmails)
|
tar = tarfile.open(pathToCompressedEmails)
|
||||||
tar.extractall(emailHome)
|
tar.extractall(emailHome)
|
||||||
@@ -912,7 +908,7 @@ class backupUtilities:
|
|||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def initiateRestore(backupName,dir):
|
def initiateRestore(backupName, dir):
|
||||||
try:
|
try:
|
||||||
p = Process(target=backupUtilities.startRestore, args=(backupName, dir,))
|
p = Process(target=backupUtilities.startRestore, args=(backupName, dir,))
|
||||||
p.start()
|
p.start()
|
||||||
@@ -920,7 +916,7 @@ class backupUtilities:
|
|||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateRestore]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateRestore]")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def sendKey(IPAddress, password,port):
|
def sendKey(IPAddress, password, port='22', user='root'):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
expectation = []
|
expectation = []
|
||||||
@@ -929,7 +925,7 @@ class backupUtilities:
|
|||||||
expectation.append("Permission denied")
|
expectation.append("Permission denied")
|
||||||
expectation.append("100%")
|
expectation.append("100%")
|
||||||
|
|
||||||
command = "scp -o StrictHostKeyChecking=no -P "+ port +" /root/.ssh/cyberpanel.pub root@" + IPAddress + ":/root/.ssh/authorized_keys"
|
command = "scp -o StrictHostKeyChecking=no -P " + port + " /root/.ssh/cyberpanel.pub " + user + "@" + IPAddress + ":~/.ssh/authorized_keys"
|
||||||
setupKeys = pexpect.spawn(command, timeout=3)
|
setupKeys = pexpect.spawn(command, timeout=3)
|
||||||
|
|
||||||
index = setupKeys.expect(expectation)
|
index = setupKeys.expect(expectation)
|
||||||
@@ -958,13 +954,13 @@ class backupUtilities:
|
|||||||
return [0, "TIMEOUT [sendKey]"]
|
return [0, "TIMEOUT [sendKey]"]
|
||||||
except pexpect.EOF as msg:
|
except pexpect.EOF as msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [sendKey]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [sendKey]")
|
||||||
return [0, "EOF [sendKey]"]
|
return [0, "EOF [sendKey]"]
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [sendKey]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [sendKey]")
|
||||||
return [0, str(msg) + " [sendKey]"]
|
return [0, str(msg) + " [sendKey]"]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def setupSSHKeys(IPAddress, password,port):
|
def setupSSHKeys(IPAddress, password, port='22', user='root'):
|
||||||
try:
|
try:
|
||||||
## Checking for host verification
|
## Checking for host verification
|
||||||
|
|
||||||
@@ -974,7 +970,7 @@ class backupUtilities:
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
logging.CyberCPLogFileWriter.writeToFile("Host is Down.")
|
logging.CyberCPLogFileWriter.writeToFile("Host is Down.")
|
||||||
#return [0,"Host is Down."]
|
# return [0,"Host is Down."]
|
||||||
|
|
||||||
expectation = []
|
expectation = []
|
||||||
expectation.append("password:")
|
expectation.append("password:")
|
||||||
@@ -982,7 +978,7 @@ class backupUtilities:
|
|||||||
expectation.append("Permission denied")
|
expectation.append("Permission denied")
|
||||||
expectation.append("File exists")
|
expectation.append("File exists")
|
||||||
|
|
||||||
command = "ssh -o StrictHostKeyChecking=no -p "+ port +" root@"+IPAddress+' "mkdir /root/.ssh || rm -f /root/.ssh/temp && rm -f /root/.ssh/authorized_temp && cp /root/.ssh/authorized_keys /root/.ssh/temp"'
|
command = "ssh -o StrictHostKeyChecking=no -p " + port + user + "@" + IPAddress + ' "mkdir ~/.ssh || rm -f ~/.ssh/temp && rm -f ~/.ssh/authorized_temp && cp ~/.ssh/authorized_keys ~/.ssh/temp"'
|
||||||
setupKeys = pexpect.spawn(command, timeout=3)
|
setupKeys = pexpect.spawn(command, timeout=3)
|
||||||
|
|
||||||
index = setupKeys.expect(expectation)
|
index = setupKeys.expect(expectation)
|
||||||
@@ -1010,18 +1006,18 @@ class backupUtilities:
|
|||||||
index = setupKeys.expect(expectation)
|
index = setupKeys.expect(expectation)
|
||||||
|
|
||||||
if index == 0:
|
if index == 0:
|
||||||
return [0,"Wrong Password!"]
|
return [0, "Wrong Password!"]
|
||||||
elif index == 1:
|
elif index == 1:
|
||||||
return [0, "Wrong Password!"]
|
return [0, "Wrong Password!"]
|
||||||
elif index == 2:
|
elif index == 2:
|
||||||
setupKeys.wait()
|
setupKeys.wait()
|
||||||
|
|
||||||
sendKey = backupUtilities.sendKey(IPAddress, password, port)
|
sendKey = backupUtilities.sendKey(IPAddress, password, port, user)
|
||||||
|
|
||||||
if sendKey[0] == 1:
|
if sendKey[0] == 1:
|
||||||
return [1, "None"]
|
return [1, "None"]
|
||||||
else:
|
else:
|
||||||
return [0,sendKey[1]]
|
return [0, sendKey[1]]
|
||||||
|
|
||||||
|
|
||||||
except pexpect.TIMEOUT as msg:
|
except pexpect.TIMEOUT as msg:
|
||||||
@@ -1040,7 +1036,7 @@ class backupUtilities:
|
|||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[checkIfHostIsUp]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[checkIfHostIsUp]")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def checkConnection(IPAddress):
|
def checkConnection(IPAddress, password, port='22', user='root'):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -1057,13 +1053,16 @@ class backupUtilities:
|
|||||||
expectation.append(pexpect.EOF)
|
expectation.append(pexpect.EOF)
|
||||||
expectation.append(pexpect.TIMEOUT)
|
expectation.append(pexpect.TIMEOUT)
|
||||||
|
|
||||||
checkConn = pexpect.spawn("sudo ssh -i /root/.ssh/cyberpanel -o StrictHostKeyChecking=no -p "+ port+" root@"+IPAddress, timeout=3)
|
checkConn = pexpect.spawn(
|
||||||
|
"sudo ssh -i /root/.ssh/cyberpanel -o StrictHostKeyChecking=no -p " + port + user + "@" + IPAddress,
|
||||||
|
timeout=3)
|
||||||
index = checkConn.expect(expectation)
|
index = checkConn.expect(expectation)
|
||||||
|
|
||||||
if index == 0:
|
if index == 0:
|
||||||
subprocess.call(['kill', str(checkConn.pid)])
|
subprocess.call(['kill', str(checkConn.pid)])
|
||||||
logging.CyberCPLogFileWriter.writeToFile("Remote Server is not able to authenticate for transfer to initiate, IP Address:" + IPAddress)
|
logging.CyberCPLogFileWriter.writeToFile(
|
||||||
return [0,"Remote Server is not able to authenticate for transfer to initiate."]
|
"Remote Server is not able to authenticate for transfer to initiate, IP Address:" + IPAddress)
|
||||||
|
return [0, "Remote Server is not able to authenticate for transfer to initiate."]
|
||||||
elif index == 1:
|
elif index == 1:
|
||||||
subprocess.call(['kill', str(checkConn.pid)])
|
subprocess.call(['kill', str(checkConn.pid)])
|
||||||
logging.CyberCPLogFileWriter.writeToFile(
|
logging.CyberCPLogFileWriter.writeToFile(
|
||||||
@@ -1080,13 +1079,13 @@ class backupUtilities:
|
|||||||
return [1, "None"]
|
return [1, "None"]
|
||||||
|
|
||||||
except pexpect.TIMEOUT as msg:
|
except pexpect.TIMEOUT as msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile("Timeout "+IPAddress+ " [checkConnection]")
|
logging.CyberCPLogFileWriter.writeToFile("Timeout " + IPAddress + " [checkConnection]")
|
||||||
return [0, "371 Timeout while making connection to this server [checkConnection]"]
|
return [0, "371 Timeout while making connection to this server [checkConnection]"]
|
||||||
except pexpect.EOF as msg:
|
except pexpect.EOF as msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile("EOF "+IPAddress+ "[checkConnection]")
|
logging.CyberCPLogFileWriter.writeToFile("EOF " + IPAddress + "[checkConnection]")
|
||||||
return [0, "374 Remote Server is not able to authenticate for transfer to initiate. [checkConnection]"]
|
return [0, "374 Remote Server is not able to authenticate for transfer to initiate. [checkConnection]"]
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg)+" " +IPAddress+ " [checkConnection]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " " + IPAddress + " [checkConnection]")
|
||||||
return [0, "377 Remote Server is not able to authenticate for transfer to initiate. [checkConnection]"]
|
return [0, "377 Remote Server is not able to authenticate for transfer to initiate. [checkConnection]"]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -1094,7 +1093,7 @@ class backupUtilities:
|
|||||||
try:
|
try:
|
||||||
backupUtilities.host_key_verification(IPAddress)
|
backupUtilities.host_key_verification(IPAddress)
|
||||||
|
|
||||||
password = "hello" ## dumb password, not used anywhere.
|
password = "hello" ## dumb password, not used anywhere.
|
||||||
|
|
||||||
expectation = []
|
expectation = []
|
||||||
|
|
||||||
@@ -1116,7 +1115,6 @@ class backupUtilities:
|
|||||||
expectation.append("password:")
|
expectation.append("password:")
|
||||||
expectation.append(pexpect.EOF)
|
expectation.append(pexpect.EOF)
|
||||||
|
|
||||||
|
|
||||||
innerIndex = setupSSHKeys.expect(expectation)
|
innerIndex = setupSSHKeys.expect(expectation)
|
||||||
|
|
||||||
if innerIndex == 0:
|
if innerIndex == 0:
|
||||||
@@ -1148,25 +1146,25 @@ class backupUtilities:
|
|||||||
|
|
||||||
except pexpect.TIMEOUT as msg:
|
except pexpect.TIMEOUT as msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile("Timeout [verifyHostKey]")
|
logging.CyberCPLogFileWriter.writeToFile("Timeout [verifyHostKey]")
|
||||||
return [0,"Timeout [verifyHostKey]"]
|
return [0, "Timeout [verifyHostKey]"]
|
||||||
except pexpect.EOF as msg:
|
except pexpect.EOF as msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile("EOF [verifyHostKey]")
|
logging.CyberCPLogFileWriter.writeToFile("EOF [verifyHostKey]")
|
||||||
return [0,"EOF [verifyHostKey]"]
|
return [0, "EOF [verifyHostKey]"]
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [verifyHostKey]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [verifyHostKey]")
|
||||||
return [0,str(msg)+" [verifyHostKey]"]
|
return [0, str(msg) + " [verifyHostKey]"]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def createBackupDir(IPAddress,port):
|
def createBackupDir(IPAddress, port='22', user='root'):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
command = "sudo ssh -o StrictHostKeyChecking=no -p "+ port +" -i /root/.ssh/cyberpanel root@"+IPAddress+" mkdir /home/backup"
|
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel " + user + "@" + IPAddress + " mkdir /home/backup"
|
||||||
subprocess.call(shlex.split(command))
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel root@" + IPAddress + ' "cat /root/.ssh/authorized_keys /root/.ssh/temp > /root/.ssh/authorized_temp"'
|
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel " + user + "@" + IPAddress + ' "cat ~/.ssh/authorized_keys ~/.ssh/temp > ~/.ssh/authorized_temp"'
|
||||||
subprocess.call(shlex.split(command))
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel root@" + IPAddress + ' "cat /root/.ssh/authorized_temp > /root/.ssh/authorized_keys"'
|
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel " + user + "@" + IPAddress + ' "cat ~/.ssh/authorized_temp > ~/.ssh/authorized_keys"'
|
||||||
subprocess.call(shlex.split(command))
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
@@ -1271,10 +1269,8 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
|
|||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
result = backupUtilities.prepareBackupMeta(backupDomain, backupName, tempStoragePath, backupPath)
|
result = backupUtilities.prepareBackupMeta(backupDomain, backupName, tempStoragePath, backupPath)
|
||||||
|
|
||||||
|
|
||||||
if result[0] == 0:
|
if result[0] == 0:
|
||||||
writeToFile = open(schedulerPath, 'w')
|
writeToFile = open(schedulerPath, 'w')
|
||||||
writeToFile.writelines('error')
|
writeToFile.writelines('error')
|
||||||
@@ -1287,7 +1283,8 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
|
|||||||
|
|
||||||
execPath = "sudo nice -n 10 /usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
|
execPath = "sudo nice -n 10 /usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
|
||||||
execPath = execPath + " startBackup --tempStoragePath " + tempStoragePath + " --backupName " \
|
execPath = execPath + " startBackup --tempStoragePath " + tempStoragePath + " --backupName " \
|
||||||
+ backupName + " --backupPath " + backupPath + ' --backupDomain ' + backupDomain + ' --metaPath %s' % (result[2])
|
+ backupName + " --backupPath " + backupPath + ' --backupDomain ' + backupDomain + ' --metaPath %s' % (
|
||||||
|
result[2])
|
||||||
|
|
||||||
output = ProcessUtilities.outputExecutioner(execPath, website.externalApp)
|
output = ProcessUtilities.outputExecutioner(execPath, website.externalApp)
|
||||||
if output.find('[5009') > -1:
|
if output.find('[5009') > -1:
|
||||||
@@ -1324,7 +1321,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
|
|||||||
execPath = "sudo nice -n 10 /usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
|
execPath = "sudo nice -n 10 /usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
|
||||||
execPath = execPath + " BackupRoot --tempStoragePath " + tempStoragePath + " --backupName " \
|
execPath = execPath + " BackupRoot --tempStoragePath " + tempStoragePath + " --backupName " \
|
||||||
+ backupName + " --backupPath " + backupPath + ' --backupDomain ' + backupDomain + ' --metaPath %s' % (
|
+ backupName + " --backupPath " + backupPath + ' --backupDomain ' + backupDomain + ' --metaPath %s' % (
|
||||||
result[2])
|
result[2])
|
||||||
|
|
||||||
ProcessUtilities.executioner(execPath, 'root')
|
ProcessUtilities.executioner(execPath, 'root')
|
||||||
else:
|
else:
|
||||||
@@ -1340,7 +1337,8 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
|
|||||||
logging.CyberCPLogFileWriter.writeToFile(
|
logging.CyberCPLogFileWriter.writeToFile(
|
||||||
str(msg) + " [submitBackupCreation]")
|
str(msg) + " [submitBackupCreation]")
|
||||||
|
|
||||||
def cancelBackupCreation(backupCancellationDomain,fileName):
|
|
||||||
|
def cancelBackupCreation(backupCancellationDomain, fileName):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
path = "/home/" + backupCancellationDomain + "/backup/pid"
|
path = "/home/" + backupCancellationDomain + "/backup/pid"
|
||||||
@@ -1372,9 +1370,10 @@ def cancelBackupCreation(backupCancellationDomain,fileName):
|
|||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(
|
logging.CyberCPLogFileWriter.writeToFile(
|
||||||
str(msg) + " [cancelBackupCreation]")
|
str(msg) + " [cancelBackupCreation]")
|
||||||
print("0,"+str(msg))
|
print("0," + str(msg))
|
||||||
|
|
||||||
def submitRestore(backupFile,dir):
|
|
||||||
|
def submitRestore(backupFile, dir):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
p = Process(target=backupUtilities.startRestore, args=(backupFile, dir,))
|
p = Process(target=backupUtilities.startRestore, args=(backupFile, dir,))
|
||||||
@@ -1385,13 +1384,14 @@ def submitRestore(backupFile,dir):
|
|||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(
|
logging.CyberCPLogFileWriter.writeToFile(
|
||||||
str(msg) + " [cancelBackupCreation]")
|
str(msg) + " [cancelBackupCreation]")
|
||||||
print("0,"+str(msg))
|
print("0," + str(msg))
|
||||||
|
|
||||||
def submitDestinationCreation(ipAddress, password, port):
|
|
||||||
setupKeys = backupUtilities.setupSSHKeys(ipAddress, password, port)
|
def submitDestinationCreation(ipAddress, password, port='22', user='root'):
|
||||||
|
setupKeys = backupUtilities.setupSSHKeys(ipAddress, password, port, user)
|
||||||
|
|
||||||
if setupKeys[0] == 1:
|
if setupKeys[0] == 1:
|
||||||
backupUtilities.createBackupDir(ipAddress, port)
|
backupUtilities.createBackupDir(ipAddress, port, user)
|
||||||
print("1,None")
|
print("1,None")
|
||||||
else:
|
else:
|
||||||
print(setupKeys[1])
|
print(setupKeys[1])
|
||||||
@@ -1409,8 +1409,8 @@ def getConnectionStatus(ipAddress):
|
|||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
print(str(msg))
|
print(str(msg))
|
||||||
|
|
||||||
def main():
|
|
||||||
|
|
||||||
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
||||||
parser.add_argument('function', help='Specific a function to call!')
|
parser.add_argument('function', help='Specific a function to call!')
|
||||||
parser.add_argument('--tempStoragePath', help='')
|
parser.add_argument('--tempStoragePath', help='')
|
||||||
@@ -1424,6 +1424,7 @@ def main():
|
|||||||
parser.add_argument('--ipAddress', help='')
|
parser.add_argument('--ipAddress', help='')
|
||||||
parser.add_argument('--password', help='')
|
parser.add_argument('--password', help='')
|
||||||
parser.add_argument('--port', help='')
|
parser.add_argument('--port', help='')
|
||||||
|
parser.add_argument('--user', help='')
|
||||||
|
|
||||||
## backup cancellation arguments
|
## backup cancellation arguments
|
||||||
|
|
||||||
@@ -1435,19 +1436,16 @@ def main():
|
|||||||
parser.add_argument('--backupFile', help='')
|
parser.add_argument('--backupFile', help='')
|
||||||
parser.add_argument('--dir', help='')
|
parser.add_argument('--dir', help='')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.function == "submitBackupCreation":
|
if args.function == "submitBackupCreation":
|
||||||
submitBackupCreation(args.tempStoragePath,args.backupName,args.backupPath, args.backupDomain)
|
submitBackupCreation(args.tempStoragePath, args.backupName, args.backupPath, args.backupDomain)
|
||||||
elif args.function == "cancelBackupCreation":
|
elif args.function == "cancelBackupCreation":
|
||||||
cancelBackupCreation(args.backupCancellationDomain,args.fileName)
|
cancelBackupCreation(args.backupCancellationDomain, args.fileName)
|
||||||
elif args.function == "submitRestore":
|
elif args.function == "submitRestore":
|
||||||
submitRestore(args.backupFile,args.dir)
|
submitRestore(args.backupFile, args.dir)
|
||||||
elif args.function == "submitDestinationCreation":
|
elif args.function == "submitDestinationCreation":
|
||||||
submitDestinationCreation(args.ipAddress, args.password, args.port)
|
submitDestinationCreation(args.ipAddress, args.password, args.port, args.user)
|
||||||
elif args.function == "getConnectionStatus":
|
elif args.function == "getConnectionStatus":
|
||||||
getConnectionStatus(args.ipAddress)
|
getConnectionStatus(args.ipAddress)
|
||||||
elif args.function == "startBackup":
|
elif args.function == "startBackup":
|
||||||
@@ -1455,5 +1453,6 @@ def main():
|
|||||||
elif args.function == "BackupRoot":
|
elif args.function == "BackupRoot":
|
||||||
backupUtilities.BackupRoot(args.tempStoragePath, args.backupName, args.backupPath, args.metaPath)
|
backupUtilities.BackupRoot(args.tempStoragePath, args.backupName, args.backupPath, args.metaPath)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user