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:
Michael Ramsey
2020-04-24 13:25:49 -04:00
parent e7e3f2b863
commit 39ee501fda
3 changed files with 117 additions and 108 deletions

View File

@@ -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>

View File

@@ -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")

View File

@@ -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()
@@ -17,6 +19,7 @@ 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,6 +49,7 @@ 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:
@@ -193,8 +198,6 @@ class backupUtilities:
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,7 +298,6 @@ 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()
@@ -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,7 +364,6 @@ 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"))
@@ -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
@@ -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,7 +625,6 @@ 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:
@@ -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!")
@@ -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,7 +783,8 @@ 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")
@@ -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
@@ -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)
@@ -964,7 +960,7 @@ class backupUtilities:
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
@@ -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)
@@ -1016,7 +1012,7 @@ class backupUtilities:
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"]
@@ -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,12 +1053,15 @@ 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(
"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."] 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)])
@@ -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:
@@ -1157,16 +1155,16 @@ class backupUtilities:
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:
@@ -1340,6 +1337,7 @@ 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:
@@ -1374,6 +1372,7 @@ def cancelBackupCreation(backupCancellationDomain,fileName):
str(msg) + " [cancelBackupCreation]") str(msg) + " [cancelBackupCreation]")
print("0," + str(msg)) print("0," + str(msg))
def submitRestore(backupFile, dir): def submitRestore(backupFile, dir):
try: try:
@@ -1387,11 +1386,12 @@ def submitRestore(backupFile,dir):
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,9 +1436,6 @@ 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":
@@ -1447,7 +1445,7 @@ def main():
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()