minor fix to backup destinations

This commit is contained in:
usmannasir
2019-03-01 20:20:44 +05:00
parent a2adeff09b
commit fe09a0d1b7
2 changed files with 24 additions and 9 deletions

View File

@@ -639,15 +639,26 @@ class backupUtilities:
def sendKey(IPAddress, password,port): def sendKey(IPAddress, password,port):
try: try:
expectation = []
expectation.append("password:")
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 = "sudo scp -o StrictHostKeyChecking=no -P "+ port +" /root/.ssh/cyberpanel.pub root@" + IPAddress + ":/root/.ssh/authorized_keys"
setupKeys = pexpect.spawn(command, timeout=3)
sendKeyProc = pexpect.spawn(command,timeout=3) index = setupKeys.expect(expectation)
sendKeyProc.expect("password:")
sendKeyProc.sendline(password) ## on first login attempt send password
sendKeyProc.expect("100%")
sendKeyProc.wait() if index == 0:
setupKeys.sendline(password)
elif index == 1:
setupKeys.sendline(password)
elif index == 2:
return [0, 'Please enable password authentication on your remote server.']
else:
raise BaseException
return [1, "None"] return [1, "None"]
@@ -671,13 +682,16 @@ class backupUtilities:
if backupUtilities.checkIfHostIsUp(IPAddress) == 1: if backupUtilities.checkIfHostIsUp(IPAddress) == 1:
pass pass
else: else:
return [0,"Host is Down."] logging.CyberCPLogFileWriter.writeToFile("Host is Down.")
#return [0,"Host is Down."]
expectation = [] expectation = []
expectation.append("password:") expectation.append("password:")
expectation.append("Password:")
expectation.append("Permission denied") expectation.append("Permission denied")
command = "sudo ssh -o StrictHostKeyChecking=no -p "+ port +" root@"+IPAddress+" mkdir /root/.ssh" command = "sudo ssh -o StrictHostKeyChecking=no -p "+ port +" root@"+IPAddress+" mkdir /root/.ssh"
logging.CyberCPLogFileWriter.writeToFile(command)
setupKeys = pexpect.spawn(command, timeout=3) setupKeys = pexpect.spawn(command, timeout=3)
@@ -688,6 +702,8 @@ class backupUtilities:
if index == 0: if index == 0:
setupKeys.sendline(password) setupKeys.sendline(password)
elif index == 1: elif index == 1:
setupKeys.sendline(password)
elif index == 2:
return [0, 'Please enable password authentication on your remote server.'] return [0, 'Please enable password authentication on your remote server.']
else: else:
raise BaseException raise BaseException

View File

@@ -29,7 +29,6 @@ class remoteBackup:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [getKey]") logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [getKey]")
return [0,"Not able to fetch key from remote server, Error Message:" + str(msg)] return [0,"Not able to fetch key from remote server, Error Message:" + str(msg)]
@staticmethod @staticmethod
def startRestore(backupDir,backupLogPath,dir): def startRestore(backupDir,backupLogPath,dir):
try: try: