mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-06 21:35:55 +01:00
minor fix for custom backup user
This commit is contained in:
@@ -407,46 +407,65 @@ class BackupManager:
|
|||||||
|
|
||||||
destinations = backupUtil.backupUtilities.destinationsPath
|
destinations = backupUtil.backupUtilities.destinationsPath
|
||||||
|
|
||||||
ipAddress = data['IPAddress']
|
finalDic = {}
|
||||||
password = data['password']
|
|
||||||
|
finalDic['ipAddress'] = data['IPAddress']
|
||||||
|
finalDic['password'] = data['password']
|
||||||
|
|
||||||
|
try:
|
||||||
|
finalDic['port'] = data['backupSSHPort']
|
||||||
|
except:
|
||||||
|
finalDic['port'] = "22"
|
||||||
|
|
||||||
|
try:
|
||||||
|
finalDic['user'] = data['user']
|
||||||
|
except:
|
||||||
|
finalDic['user'] = "root"
|
||||||
|
|
||||||
if dest.objects.all().count() == 2:
|
if dest.objects.all().count() == 2:
|
||||||
|
|
||||||
final_dic = {'destStatus': 0,
|
final_dic = {'destStatus': 0,
|
||||||
'error_message': "Currently only one remote destination is allowed."}
|
'error_message': "Currently only one remote destination is allowed."}
|
||||||
final_json = json.dumps(final_dic)
|
final_json = json.dumps(final_dic)
|
||||||
return HttpResponse(final_json)
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
d = dest.objects.get(destLoc=ipAddress)
|
d = dest.objects.get(destLoc=finalDic['password'])
|
||||||
final_dic = {'destStatus': 0, 'error_message': "This destination already exists."}
|
final_dic = {'destStatus': 0, 'error_message': "This destination already exists."}
|
||||||
final_json = json.dumps(final_dic)
|
final_json = json.dumps(final_dic)
|
||||||
return HttpResponse(final_json)
|
return HttpResponse(final_json)
|
||||||
except:
|
except:
|
||||||
|
|
||||||
try:
|
|
||||||
port = data['backupSSHPort']
|
|
||||||
except:
|
|
||||||
port = "22"
|
|
||||||
|
|
||||||
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
|
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
|
||||||
execPath = execPath + " submitDestinationCreation --ipAddress " + ipAddress + " --password " \
|
execPath = execPath + " submitDestinationCreation --ipAddress " + finalDic['ipAddress'] + " --password " \
|
||||||
+ password + " --port " + port
|
+ finalDic['password'] + " --port " + finalDic['port'] + ' --user %s' % (finalDic['user'])
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(execPath)
|
||||||
|
|
||||||
output = ProcessUtilities.outputExecutioner(execPath)
|
output = ProcessUtilities.outputExecutioner(execPath)
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(output)
|
||||||
|
|
||||||
|
|
||||||
if output.find('1,') > -1:
|
if output.find('1,') > -1:
|
||||||
try:
|
try:
|
||||||
writeToFile = open(destinations, "w")
|
writeToFile = open(destinations, "w")
|
||||||
writeToFile.writelines(ipAddress + "\n")
|
writeToFile.write(json.dumps(finalDic))
|
||||||
writeToFile.writelines(data['backupSSHPort'] + "\n")
|
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
newDest = dest(destLoc=ipAddress)
|
newDest = dest(destLoc=finalDic['ipAddress'])
|
||||||
newDest.save()
|
newDest.save()
|
||||||
|
|
||||||
|
final_dic = {'destStatus': 1, 'error_message': "None"}
|
||||||
|
final_json = json.dumps(final_dic)
|
||||||
|
return HttpResponse(final_json)
|
||||||
except:
|
except:
|
||||||
writeToFile = open(destinations, "w")
|
writeToFile = open(destinations, "w")
|
||||||
writeToFile.writelines(ipAddress + "\n")
|
writeToFile.write(json.dumps(finalDic))
|
||||||
writeToFile.writelines("22" + "\n")
|
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
newDest = dest(destLoc=ipAddress)
|
|
||||||
|
newDest = dest(destLoc=finalDic['ipAddress'])
|
||||||
newDest.save()
|
newDest.save()
|
||||||
|
|
||||||
final_dic = {'destStatus': 1, 'error_message': "None"}
|
final_dic = {'destStatus': 1, 'error_message': "None"}
|
||||||
|
|||||||
@@ -33,6 +33,13 @@
|
|||||||
</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="user" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-sm-3 control-label">{% trans "Password" %}</label>
|
<label class="col-sm-3 control-label">{% trans "Password" %}</label>
|
||||||
@@ -48,13 +55,6 @@
|
|||||||
</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="user" 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>
|
||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
|
|||||||
@@ -928,6 +928,9 @@ class backupUtilities:
|
|||||||
command = "scp -o StrictHostKeyChecking=no -P " + port + " /root/.ssh/cyberpanel.pub " + user + "@" + IPAddress + ":~/.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)
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(command)
|
||||||
|
|
||||||
index = setupKeys.expect(expectation)
|
index = setupKeys.expect(expectation)
|
||||||
|
|
||||||
## on first login attempt send password
|
## on first login attempt send password
|
||||||
@@ -981,6 +984,9 @@ class backupUtilities:
|
|||||||
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"'
|
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)
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(command)
|
||||||
|
|
||||||
index = setupKeys.expect(expectation)
|
index = setupKeys.expect(expectation)
|
||||||
|
|
||||||
## on first login attempt send password
|
## on first login attempt send password
|
||||||
@@ -1040,10 +1046,11 @@ class backupUtilities:
|
|||||||
try:
|
try:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
import json
|
||||||
destinations = backupUtilities.destinationsPath
|
destinations = backupUtilities.destinationsPath
|
||||||
data = open(destinations, 'r').readlines()
|
data = json.loads(open(destinations, 'r').read())
|
||||||
port = data[1].strip("\n")
|
port = data['port']
|
||||||
user = data[2].strip("\n")
|
user = data['user']
|
||||||
except:
|
except:
|
||||||
port = "22"
|
port = "22"
|
||||||
|
|
||||||
@@ -1160,12 +1167,24 @@ class backupUtilities:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel " + user + "@" + IPAddress + " mkdir ~/backup"
|
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel " + user + "@" + IPAddress + " mkdir ~/backup"
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(command)
|
||||||
|
|
||||||
subprocess.call(shlex.split(command))
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel " + user + "@" + IPAddress + ' "cat ~/.ssh/authorized_keys ~/.ssh/temp > ~/.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"'
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(command)
|
||||||
|
|
||||||
subprocess.call(shlex.split(command))
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel " + user + "@" + IPAddress + ' "cat ~/.ssh/authorized_temp > ~/.ssh/authorized_keys"'
|
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel " + user + "@" + IPAddress + ' "cat ~/.ssh/authorized_temp > ~/.ssh/authorized_keys"'
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(command)
|
||||||
|
|
||||||
subprocess.call(shlex.split(command))
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
|
|||||||
Reference in New Issue
Block a user