diff --git a/api/views.py b/api/views.py index 1cabe9cc1..8780150a6 100644 --- a/api/views.py +++ b/api/views.py @@ -405,26 +405,20 @@ def remoteTransfer(request): dir = str(randint(1000, 9999)) ## - accountsToTransfer = ','.join(accountsToTransfer) execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/remoteTransferUtilities.py" - execPath = execPath + " remoteTransfer --ipAddress " + ipAddress + " --dir " + dir + " --accountsToTransfer " + accountsToTransfer - subprocess.Popen(shlex.split(execPath)) return HttpResponse(json.dumps({"transferStatus": 1, "dir": dir})) ## else: - data_ret = {'transferStatus': 0, 'error_message': "Invalid Credentials"} + data_ret = {'transferStatus': 0, 'error_message': "Could not authorize access to API."} json_data = json.dumps(data_ret) return HttpResponse(json_data) - - - except BaseException, msg: data = {'transferStatus': 0,'error_message': str(msg)} json_data = json.dumps(data) diff --git a/backup/static/backup/backup.js b/backup/static/backup/backup.js index eb78b0fb3..b83f9bcce 100644 --- a/backup/static/backup/backup.js +++ b/backup/static/backup/backup.js @@ -1149,7 +1149,6 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { // disable fetch accounts button $scope.fetchAccountsBtn = true; - $scope.backupLoading = false; var IPAddress = $scope.IPAddress; @@ -1174,7 +1173,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { function ListInitialDatas(response) { - if (response.data.remoteTransferStatus == 1) { + if (response.data.remoteTransferStatus === 1) { tempTransferDir = response.data.dir; $scope.accountsInRemoteServerTable = true; @@ -1235,8 +1234,6 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { }; - - function getBackupStatus(password) { url = "/backup/getRemoteTransferStatus"; @@ -1244,7 +1241,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { var data = { password : $scope.password, ipAddress: $scope.IPAddress, - dir: tempTransferDir, + dir: tempTransferDir }; var config = { @@ -1258,9 +1255,9 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { function ListInitialDatas(response) { - if (response.data.remoteTransferStatus == 1) { + if (response.data.remoteTransferStatus === 1) { - if(response.data.backupsSent == 0){ + if(response.data.backupsSent === 0){ $scope.backupStatus = false; $scope.requestData = response.data.status; $timeout(getBackupStatus, 2000); @@ -1271,7 +1268,6 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { // Start the restore of remote backups that are transferred to local server - remoteBackupRestore(); } } diff --git a/backup/views.py b/backup/views.py index 85e30391d..8e6ec1c2c 100644 --- a/backup/views.py +++ b/backup/views.py @@ -1320,7 +1320,7 @@ def submitRemoteBackups(request): return HttpResponse("This URL only accepts POST requests") except BaseException, msg: - final_json = json.dumps({'status': 0, 'type': 'exception', 'error_message': str(msg)}) + final_json = json.dumps({'status': 0, 'error_message': str(msg)}) return HttpResponse(final_json) def starRemoteTransfer(request): @@ -1336,7 +1336,7 @@ def starRemoteTransfer(request): try: - ipFile = "/etc/cyberpanel/machineIP" + ipFile = os.path.join("/etc","cyberpanel","machineIP") f = open(ipFile) ownIP = f.read() @@ -1351,6 +1351,14 @@ def starRemoteTransfer(request): if data['transferStatus'] == 1: + ## Create local backup dir + + localBackupDir = os.path.join("/home","backup") + + if not os.path.exists(localBackupDir): + command = "sudo mkdir " + localBackupDir + subprocess.call(shlex.split(command)) + ## create local directory that will host backups localStoragePath = "/home/backup/transfer-" + str(data['dir']) diff --git a/plogical/backupSchedule.py b/plogical/backupSchedule.py index d8100b3b1..26fcbaafc 100644 --- a/plogical/backupSchedule.py +++ b/plogical/backupSchedule.py @@ -63,7 +63,7 @@ class backupSchedule: @staticmethod def sendBackup(backupPath, IPAddress, writeToFile,port): try: - command = "sudo scp -P "+port+" -i /root/.ssh/cyberpanel " + backupPath + " root@"+IPAddress+":/home/backup/"+ time.strftime("%a-%b") + "/" + command = "sudo scp -o StrictHostKeyChecking=no -P "+port+" -i /root/.ssh/cyberpanel " + backupPath + " root@"+IPAddress+":/home/backup/"+ time.strftime("%a-%b") + "/" subprocess.call(shlex.split(command), stdout=writeToFile) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]") diff --git a/plogical/remoteTransferUtilities.py b/plogical/remoteTransferUtilities.py index fc491cad4..c68508015 100644 --- a/plogical/remoteTransferUtilities.py +++ b/plogical/remoteTransferUtilities.py @@ -16,7 +16,7 @@ class remoteTransferUtilities: @staticmethod def writeAuthKey(pathToKey): try: - authorized_keys = "/root/.ssh/authorized_keys" + authorized_keys = os.path.join("/root",".ssh","authorized_keys") presenseCheck = 0 try: @@ -209,7 +209,7 @@ class remoteTransferUtilities: try: ## complete path is a path to the file need to send - command = "sudo scp -i /root/.ssh/cyberpanel " + completedPathToSend + " root@" + IPAddress + ":/home/backup/transfer-" + folderNumber + "/" + command = "sudo scp -o StrictHostKeyChecking=no -i /root/.ssh/cyberpanel " + completedPathToSend + " root@" + IPAddress + ":/home/backup/transfer-" + folderNumber + "/" subprocess.call(shlex.split(command), stdout=writeToFile) except BaseException, msg: diff --git a/static/backup/backup.js b/static/backup/backup.js index 9242635ab..5f42d380a 100644 --- a/static/backup/backup.js +++ b/static/backup/backup.js @@ -1074,7 +1074,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { function ListInitialDatas(response) { - if (response.data.status == 1) { + if (response.data.status === 1) { $scope.records = JSON.parse(response.data.data); var parsed = JSON.parse(response.data.data); @@ -1149,7 +1149,6 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { // disable fetch accounts button $scope.fetchAccountsBtn = true; - $scope.backupLoading = false; var IPAddress = $scope.IPAddress; @@ -1174,7 +1173,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { function ListInitialDatas(response) { - if (response.data.remoteTransferStatus == 1) { + if (response.data.remoteTransferStatus === 1) { tempTransferDir = response.data.dir; $scope.accountsInRemoteServerTable = true; @@ -1235,8 +1234,6 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { }; - - function getBackupStatus(password) { url = "/backup/getRemoteTransferStatus"; @@ -1244,7 +1241,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { var data = { password : $scope.password, ipAddress: $scope.IPAddress, - dir: tempTransferDir, + dir: tempTransferDir }; var config = { @@ -1258,9 +1255,9 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { function ListInitialDatas(response) { - if (response.data.remoteTransferStatus == 1) { + if (response.data.remoteTransferStatus === 1) { - if(response.data.backupsSent == 0){ + if(response.data.backupsSent === 0){ $scope.backupStatus = false; $scope.requestData = response.data.status; $timeout(getBackupStatus, 2000); @@ -1268,7 +1265,9 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { else{ $scope.requestData = response.data.status; $timeout.cancel(); - $scope.backupLoading = true; + + // Start the restore of remote backups that are transferred to local server + remoteBackupRestore(); } } @@ -1318,7 +1317,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { function ListInitialDatas(response) { - if (response.data.remoteRestoreStatus == 1) { + if (response.data.remoteRestoreStatus === 1) { localRestoreStatus(); } } @@ -1330,6 +1329,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { $scope.errorMessage = true; $scope.accountsFetched = true; $scope.notificationsBox = false; + $scope.backupLoading = true; } /////////////// @@ -1357,9 +1357,9 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { function ListInitialDatas(response) { - if (response.data.remoteTransferStatus == 1) { + if (response.data.remoteTransferStatus === 1) { - if(response.data.complete == 0){ + if(response.data.complete === 0){ $scope.backupStatus = false; $scope.restoreData = response.data.status; $timeout(localRestoreStatus, 2000);