diff --git a/backup/backupManager.py b/backup/backupManager.py index 161a645ad..f7181f4ca 100755 --- a/backup/backupManager.py +++ b/backup/backupManager.py @@ -407,46 +407,65 @@ class BackupManager: destinations = backupUtil.backupUtilities.destinationsPath - ipAddress = data['IPAddress'] - password = data['password'] + finalDic = {} + + 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: + final_dic = {'destStatus': 0, 'error_message': "Currently only one remote destination is allowed."} final_json = json.dumps(final_dic) return HttpResponse(final_json) + 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_json = json.dumps(final_dic) return HttpResponse(final_json) except: - try: - port = data['backupSSHPort'] - except: - port = "22" - execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py" - execPath = execPath + " submitDestinationCreation --ipAddress " + ipAddress + " --password " \ - + password + " --port " + port + execPath = execPath + " submitDestinationCreation --ipAddress " + finalDic['ipAddress'] + " --password " \ + + finalDic['password'] + " --port " + finalDic['port'] + ' --user %s' % (finalDic['user']) + + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(execPath) output = ProcessUtilities.outputExecutioner(execPath) + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(output) + + if output.find('1,') > -1: try: writeToFile = open(destinations, "w") - writeToFile.writelines(ipAddress + "\n") - writeToFile.writelines(data['backupSSHPort'] + "\n") + writeToFile.write(json.dumps(finalDic)) writeToFile.close() - newDest = dest(destLoc=ipAddress) + newDest = dest(destLoc=finalDic['ipAddress']) newDest.save() + + final_dic = {'destStatus': 1, 'error_message': "None"} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) except: writeToFile = open(destinations, "w") - writeToFile.writelines(ipAddress + "\n") - writeToFile.writelines("22" + "\n") + writeToFile.write(json.dumps(finalDic)) writeToFile.close() - newDest = dest(destLoc=ipAddress) + + newDest = dest(destLoc=finalDic['ipAddress']) newDest.save() final_dic = {'destStatus': 1, 'error_message': "None"} diff --git a/backup/templates/backup/backupDestinations.html b/backup/templates/backup/backupDestinations.html index 9667803ed..5ab7e5ad9 100755 --- a/backup/templates/backup/backupDestinations.html +++ b/backup/templates/backup/backupDestinations.html @@ -33,6 +33,13 @@ +
+ +
+ +
+
+
@@ -48,13 +55,6 @@
-
- -
- -
-
-
diff --git a/plogical/backupUtilities.py b/plogical/backupUtilities.py index 886e0f67f..a017d410a 100755 --- a/plogical/backupUtilities.py +++ b/plogical/backupUtilities.py @@ -928,6 +928,9 @@ class backupUtilities: command = "scp -o StrictHostKeyChecking=no -P " + port + " /root/.ssh/cyberpanel.pub " + user + "@" + IPAddress + ":~/.ssh/authorized_keys" setupKeys = pexpect.spawn(command, timeout=3) + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(command) + index = setupKeys.expect(expectation) ## 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"' setupKeys = pexpect.spawn(command, timeout=3) + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(command) + index = setupKeys.expect(expectation) ## on first login attempt send password @@ -1040,10 +1046,11 @@ class backupUtilities: try: try: + import json destinations = backupUtilities.destinationsPath - data = open(destinations, 'r').readlines() - port = data[1].strip("\n") - user = data[2].strip("\n") + data = json.loads(open(destinations, 'r').read()) + port = data['port'] + user = data['user'] except: port = "22" @@ -1160,12 +1167,24 @@ class backupUtilities: try: 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)) 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)) 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)) except BaseException as msg: