remote destinations fix for kimsufi

This commit is contained in:
usmannasir
2019-03-02 17:57:09 +05:00
parent fe09a0d1b7
commit 975fa95d47
3 changed files with 72 additions and 24 deletions

View File

@@ -63,8 +63,7 @@
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<div class="col-sm-12">
<div ng-hide="connectionFailed" class="alert alert-danger">
<p>{% trans "Connection to" %} {$ IPAddress $} {% trans "failed. Please delete and re-add. " %} {$ errorMessage $} </p>
</div>

View File

@@ -386,12 +386,6 @@ class BackupManager:
ipAddress = data['IPAddress']
password = data['password']
port = "22"
try:
port = data['backupSSHPort']
except:
pass
if dest.objects.all().count() == 2:
final_dic = {'destStatus': 0,
@@ -404,10 +398,19 @@ class BackupManager:
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except:
setupKeys = backupUtil.backupUtilities.setupSSHKeys(ipAddress, password, port)
if setupKeys[0] == 1:
backupUtil.backupUtilities.createBackupDir(ipAddress, port)
try:
port = data['backupSSHPort']
except:
port = "22"
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
execPath = execPath + " submitDestinationCreation --ipAddress " + ipAddress + " --password " \
+ password + " --port " + port
output = subprocess.check_output(shlex.split(execPath))
if output.find('1,') > -1:
try:
writeToFile = open(destinations, "w")
writeToFile.writelines(ipAddress + "\n")
@@ -427,7 +430,7 @@ class BackupManager:
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
else:
final_dic = {'destStatus': 0, 'error_message': setupKeys[1]}
final_dic = {'destStatus': 0, 'error_message': output}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
@@ -480,16 +483,20 @@ class BackupManager:
ipAddress = data['IPAddress']
checkCon = backupUtil.backupUtilities.checkConnection(ipAddress)
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
execPath = execPath + " getConnectionStatus --ipAddress " + ipAddress
if checkCon[0] == 1:
output = subprocess.check_output(shlex.split(execPath))
if output.find('1,') > -1:
final_dic = {'connStatus': 1, 'error_message': "None"}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
else:
final_dic = {'connStatus': 0, 'error_message': checkCon[1]}
final_dic = {'connStatus': 0, 'error_message': output}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException, msg:
final_dic = {'connStatus': 1, 'error_message': str(msg)}
final_json = json.dumps(final_dic)

View File

@@ -644,7 +644,7 @@ class backupUtilities:
expectation.append("Password:")
expectation.append("Permission denied")
command = "sudo 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 root@" + IPAddress + ":/root/.ssh/authorized_keys"
setupKeys = pexpect.spawn(command, timeout=3)
index = setupKeys.expect(expectation)
@@ -653,8 +653,12 @@ class backupUtilities:
if index == 0:
setupKeys.sendline(password)
setupKeys.expect("100%")
setupKeys.wait()
elif index == 1:
setupKeys.sendline(password)
setupKeys.expect("100%")
setupKeys.wait()
elif index == 2:
return [0, 'Please enable password authentication on your remote server.']
else:
@@ -690,8 +694,7 @@ class backupUtilities:
expectation.append("Password:")
expectation.append("Permission denied")
command = "sudo ssh -o StrictHostKeyChecking=no -p "+ port +" root@"+IPAddress+" mkdir /root/.ssh"
logging.CyberCPLogFileWriter.writeToFile(command)
command = "ssh -o StrictHostKeyChecking=no -p "+ port +" root@"+IPAddress+" mkdir /root/.ssh"
setupKeys = pexpect.spawn(command, timeout=3)
@@ -712,6 +715,7 @@ class backupUtilities:
expectation = []
expectation.append("please try again.")
expectation.append("Password:")
expectation.append(pexpect.EOF)
index = setupKeys.expect(expectation)
@@ -719,6 +723,8 @@ class backupUtilities:
if index == 0:
return [0,"Wrong Password!"]
elif index == 1:
return [0, "Wrong Password!"]
elif index == 2:
setupKeys.wait()
sendKey = backupUtilities.sendKey(IPAddress, password, port)
@@ -730,10 +736,8 @@ class backupUtilities:
except pexpect.TIMEOUT, msg:
logging.CyberCPLogFileWriter.writeToFile(setupKeys.before + " " + str(msg) + " [setupSSHKeys]")
return [0, str(msg) + " [TIMEOUT setupSSHKeys]"]
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(setupKeys.before + " " + str(msg) + " [setupSSHKeys]")
return [0, str(msg) + " [setupSSHKeys]"]
@staticmethod
@@ -759,6 +763,7 @@ class backupUtilities:
expectation = []
expectation.append("password:")
expectation.append("Password:")
expectation.append("Last login")
expectation.append(pexpect.EOF)
expectation.append(pexpect.TIMEOUT)
@@ -771,9 +776,14 @@ class backupUtilities:
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."]
elif index == 1:
subprocess.call(['kill', str(checkConn.pid)])
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."]
elif index == 2:
subprocess.call(['kill', str(checkConn.pid)])
return [1, "None"]
elif index == 3:
elif index == 4:
subprocess.call(['kill', str(checkConn.pid)])
return [1, "None"]
else:
@@ -968,6 +978,28 @@ def submitRestore(backupFile,dir):
str(msg) + " [cancelBackupCreation]")
print "0,"+str(msg)
def submitDestinationCreation(ipAddress, password, port):
setupKeys = backupUtilities.setupSSHKeys(ipAddress, password, port)
if setupKeys[0] == 1:
backupUtilities.createBackupDir(ipAddress, port)
print "1,None"
else:
print setupKeys[1]
def getConnectionStatus(ipAddress):
try:
checkCon = backupUtilities.checkConnection(ipAddress)
if checkCon[0] == 1:
print "1,None"
else:
print checkCon[1]
except BaseException, msg:
print str(msg)
def main():
parser = argparse.ArgumentParser(description='CyberPanel Installer')
@@ -978,6 +1010,12 @@ def main():
parser.add_argument('--backupDomain', help='')
parser.add_argument('--metaPath', help='')
## Destination Creation
parser.add_argument('--ipAddress', help='')
parser.add_argument('--password', help='')
parser.add_argument('--port', help='')
## backup cancellation arguments
parser.add_argument('--backupCancellationDomain', help='')
@@ -999,6 +1037,10 @@ def main():
cancelBackupCreation(args.backupCancellationDomain,args.fileName)
elif args.function == "submitRestore":
submitRestore(args.backupFile,args.dir)
elif args.function == "submitDestinationCreation":
submitDestinationCreation(args.ipAddress, args.password, args.port)
elif args.function == "getConnectionStatus":
getConnectionStatus(args.ipAddress)
if __name__ == "__main__":
main()