mirror of
				https://github.com/usmannasir/cyberpanel.git
				synced 2025-10-31 10:26:01 +01:00 
			
		
		
		
	Updates to Remote Backup Transfer
This commit is contained in:
		| @@ -15,4 +15,8 @@ urlpatterns = [ | |||||||
|     url(r'^fetchSSHkey', views.fetchSSHkey, name='fetchSSHkey'), |     url(r'^fetchSSHkey', views.fetchSSHkey, name='fetchSSHkey'), | ||||||
|     url(r'^remoteTransfer', views.remoteTransfer, name='remoteTransfer'), |     url(r'^remoteTransfer', views.remoteTransfer, name='remoteTransfer'), | ||||||
|     url(r'^fetchAccountsFromRemoteServer', views.fetchAccountsFromRemoteServer, name='fetchAccountsFromRemoteServer'), |     url(r'^fetchAccountsFromRemoteServer', views.fetchAccountsFromRemoteServer, name='fetchAccountsFromRemoteServer'), | ||||||
|  |     url(r'^FetchRemoteTransferStatus', views.FetchRemoteTransferStatus, name='FetchRemoteTransferStatus'), | ||||||
|  |  | ||||||
|  |     url(r'^cancelRemoteTransfer', views.cancelRemoteTransfer, name='cancelRemoteTransfer'), | ||||||
|  |  | ||||||
| ] | ] | ||||||
							
								
								
									
										80
									
								
								api/views.py
									
									
									
									
									
								
							
							
						
						
									
										80
									
								
								api/views.py
									
									
									
									
									
								
							| @@ -16,6 +16,10 @@ from baseTemplate.views import renderBase | |||||||
| from random import randint | from random import randint | ||||||
| import plogical.remoteBackup as rBackup | import plogical.remoteBackup as rBackup | ||||||
| from websiteFunctions.models import Websites | from websiteFunctions.models import Websites | ||||||
|  | import os | ||||||
|  | import signal | ||||||
|  | from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging | ||||||
|  | from shutil import rmtree | ||||||
| # Create your views here. | # Create your views here. | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -422,6 +426,80 @@ def fetchAccountsFromRemoteServer(request): | |||||||
|                 return HttpResponse(json_data) |                 return HttpResponse(json_data) | ||||||
|  |  | ||||||
|     except BaseException, msg: |     except BaseException, msg: | ||||||
|         data = {'transferStatus': 0,'error_message': str(msg)} |         data = {'fetchStatus': 0,'error_message': str(msg)} | ||||||
|         json_data = json.dumps(data) |         json_data = json.dumps(data) | ||||||
|         return HttpResponse(json_data) |         return HttpResponse(json_data) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def FetchRemoteTransferStatus(request): | ||||||
|  |     try: | ||||||
|  |         if request.method == "POST": | ||||||
|  |             data = json.loads(request.body) | ||||||
|  |             username = data['username'] | ||||||
|  |             password = data['password'] | ||||||
|  |             dir = "/home/backup/transfer-"+str(data['dir'])+"/backup_log" | ||||||
|  |  | ||||||
|  |             statusFile = open(dir,'r') | ||||||
|  |             status = statusFile.read() | ||||||
|  |             statusFile.close() | ||||||
|  |  | ||||||
|  |             admin = Administrator.objects.get(userName=username) | ||||||
|  |             if hashPassword.check_password(admin.password, password): | ||||||
|  |  | ||||||
|  |                 final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "status": status}) | ||||||
|  |  | ||||||
|  |                 return HttpResponse(final_json) | ||||||
|  |             else: | ||||||
|  |                 data_ret = {'fetchStatus': 0, 'error_message': "Invalid Credentials"} | ||||||
|  |                 json_data = json.dumps(data_ret) | ||||||
|  |                 return HttpResponse(json_data) | ||||||
|  |  | ||||||
|  |     except BaseException, msg: | ||||||
|  |         data = {'fetchStatus': 0,'error_message': str(msg)} | ||||||
|  |         json_data = json.dumps(data) | ||||||
|  |         return HttpResponse(json_data) | ||||||
|  |  | ||||||
|  | def cancelRemoteTransfer(request): | ||||||
|  |     try: | ||||||
|  |         if request.method == "POST": | ||||||
|  |             data = json.loads(request.body) | ||||||
|  |             username = data['username'] | ||||||
|  |             password = data['password'] | ||||||
|  |             dir = "/home/backup/transfer-"+str(data['dir']) | ||||||
|  |  | ||||||
|  |             admin = Administrator.objects.get(userName=username) | ||||||
|  |  | ||||||
|  |             if hashPassword.check_password(admin.password, password): | ||||||
|  |  | ||||||
|  |                 if os.path.exists(dir): | ||||||
|  |  | ||||||
|  |                     path = dir+"/pid" | ||||||
|  |  | ||||||
|  |                     pid = open(path, "r").readlines()[0] | ||||||
|  |  | ||||||
|  |                     try: | ||||||
|  |                         os.kill(int(pid), signal.SIGKILL) | ||||||
|  |                     except BaseException, msg: | ||||||
|  |                         logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [cancelRemoteTransfer]") | ||||||
|  |  | ||||||
|  |                     rmtree(dir) | ||||||
|  |  | ||||||
|  |                     data = {'cancelStatus': 1, 'error_message': "None"} | ||||||
|  |                     json_data = json.dumps(data) | ||||||
|  |                     return HttpResponse(json_data) | ||||||
|  |  | ||||||
|  |                 else: | ||||||
|  |                     data = {'cancelStatus': 1, 'error_message': "None"} | ||||||
|  |                     json_data = json.dumps(data) | ||||||
|  |                     return HttpResponse(json_data) | ||||||
|  |             else: | ||||||
|  |                 data_ret = {'cancelStatus': 0, 'error_message': "Invalid Credentials"} | ||||||
|  |                 json_data = json.dumps(data_ret) | ||||||
|  |                 return HttpResponse(json_data) | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     except BaseException, msg: | ||||||
|  |         data = {'cancelStatus': 1, 'error_message': str(msg)} | ||||||
|  |         json_data = json.dumps(data) | ||||||
|  |         return HttpResponse(json_data) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -396,7 +396,6 @@ app.controller('restoreWebsiteControl', function($scope,$http,$timeout) { | |||||||
|            }; |            }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     $scope.restoreBackup = function(){ |     $scope.restoreBackup = function(){ | ||||||
|         var backupFile = $scope.backupFile; |         var backupFile = $scope.backupFile; | ||||||
|  |  | ||||||
| @@ -1033,21 +1032,97 @@ app.controller('scheduleBackup', function($scope,$http,$timeout) { | |||||||
|  |  | ||||||
| //*** Remote Backup site ****// | //*** Remote Backup site ****// | ||||||
| app.controller('remoteBackupControl', function($scope, $http, $timeout) { | app.controller('remoteBackupControl', function($scope, $http, $timeout) { | ||||||
|  |  | ||||||
|     $scope.backupButton = true; |     $scope.backupButton = true; | ||||||
|  |  | ||||||
|     $scope.status_success = true; |  | ||||||
|     $scope.status_danger = true; |  | ||||||
|     $scope.status_info = true; |  | ||||||
|  |  | ||||||
|     $scope.backupLoading = true; |     $scope.backupLoading = true; | ||||||
|     $scope.request = true; |     $scope.request = true; | ||||||
|     $scope.requestData = ""; |     $scope.requestData = ""; | ||||||
|     $scope.submitDisable = false; |     $scope.submitDisable = false; | ||||||
|     $scope.startRestore = true; |     $scope.startRestore = true; | ||||||
|  |  | ||||||
|     $scope.accountsInRemoteServerTable = true; |     $scope.accountsInRemoteServerTable = true; | ||||||
|  |     $scope.transferBoxBtn = true; | ||||||
|  |     $scope.stopTransferbtn = true; | ||||||
|  |     $scope.fetchAccountsBtn = false; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     // notifications boxes | ||||||
|  |     $scope.notificationsBox = true; | ||||||
|  |     $scope.errorMessage = true; | ||||||
|  |     $scope.couldNotConnect = true; | ||||||
|  |     $scope.accountsFetched = true; | ||||||
|  |     $scope.backupProcessStarted = true; | ||||||
|  |     $scope.backupCancelled = true; | ||||||
|  |  | ||||||
|  |     // status box | ||||||
|  |  | ||||||
|  |     $scope.backupStatus = true; | ||||||
|  |  | ||||||
|  |     var websitesToBeBacked = []; | ||||||
|  |     var websitesToBeBackedTemp = []; | ||||||
|  |  | ||||||
|  |     var index = 0; | ||||||
|  |     var tempTransferDir = ""; | ||||||
|  |  | ||||||
|  |     $scope.passwordEnter = function() { | ||||||
|  |         $scope.backupButton = false; | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     $scope.addRemoveWebsite = function (website,websiteStatus) { | ||||||
|  |         if(websiteStatus==true) | ||||||
|  |         { | ||||||
|  |             var check = 1; | ||||||
|  |             for(var j = 0; j < websitesToBeBacked.length; j++){ | ||||||
|  |                     if (websitesToBeBacked[j] == website){ | ||||||
|  |                         check = 0; | ||||||
|  |                         break; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             if(check == 1) { | ||||||
|  |                 websitesToBeBacked.push(website); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |         else{ | ||||||
|  |  | ||||||
|  |             var tempArray = []; | ||||||
|  |  | ||||||
|  |             for(var j = 0; j < websitesToBeBacked.length; j++){ | ||||||
|  |                     if (websitesToBeBacked[j] != website){ | ||||||
|  |                         tempArray.push(websitesToBeBacked[j]); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             websitesToBeBacked = tempArray; | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     $scope.allChecked = function (webSiteStatus) { | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         if(webSiteStatus==true) { | ||||||
|  |  | ||||||
|  |             websitesToBeBacked = websitesToBeBackedTemp; | ||||||
|  |             $scope.webSiteStatus = true; | ||||||
|  |         } | ||||||
|  |         else{ | ||||||
|  |             websitesToBeBacked = []; | ||||||
|  |             $scope.webSiteStatus = false; | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     $scope.fetchAccountsFromRemoteServer = function () { |     $scope.fetchAccountsFromRemoteServer = function () { | ||||||
|  |  | ||||||
|  |         $scope.backupLoading = false; | ||||||
|  |  | ||||||
|  |         // notifications boxes | ||||||
|  |         $scope.notificationsBox = true; | ||||||
|  |         $scope.errorMessage = true; | ||||||
|  |         $scope.couldNotConnect = true; | ||||||
|  |         $scope.accountsFetched = true; | ||||||
|  |         $scope.backupProcessStarted = true; | ||||||
|  |         $scope.backupCancelled = true; | ||||||
|  |  | ||||||
|         var IPAddress = $scope.IPAddress; |         var IPAddress = $scope.IPAddress; | ||||||
|         var password = $scope.password; |         var password = $scope.password; | ||||||
|  |  | ||||||
| @@ -1071,112 +1146,87 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { | |||||||
|  |  | ||||||
|             if (response.data.status == 1) { |             if (response.data.status == 1) { | ||||||
|                 $scope.records = JSON.parse(response.data.data); |                 $scope.records = JSON.parse(response.data.data); | ||||||
|  |                 var parsed = JSON.parse(response.data.data); | ||||||
|  |  | ||||||
|  |                 for(var j = 0; j < parsed.length; j++){ | ||||||
|  |                     websitesToBeBackedTemp.push(parsed[j].website); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|                 $scope.accountsInRemoteServerTable = false; |                 $scope.accountsInRemoteServerTable = false; | ||||||
|  |                 $scope.backupLoading = true; | ||||||
|  |  | ||||||
|  |                 // enable the transfer/cancel btn | ||||||
|  |  | ||||||
|  |                 $scope.transferBoxBtn = false; | ||||||
|  |  | ||||||
|  |                 // notifications boxes | ||||||
|  |                 $scope.notificationsBox = false; | ||||||
|  |                 $scope.errorMessage = true; | ||||||
|  |                 $scope.couldNotConnect = true; | ||||||
|  |                 $scope.accountsFetched = false; | ||||||
|  |                 $scope.backupProcessStarted = true; | ||||||
|  |                 $scope.backupCancelled = true; | ||||||
|  |  | ||||||
|  |  | ||||||
|             } |             } | ||||||
|             else { |             else { | ||||||
|                 $scope.error_message = response.data.error_message; |                 $scope.error_message = response.data.error_message; | ||||||
|  |                 $scope.backupLoading = true; | ||||||
|  |  | ||||||
|  |                 // notifications boxes | ||||||
|  |                 $scope.notificationsBox = false; | ||||||
|  |                 $scope.errorMessage = false; | ||||||
|  |                 $scope.couldNotConnect = true; | ||||||
|  |                 $scope.accountsFetched = true; | ||||||
|  |                 $scope.backupProcessStarted = true; | ||||||
|  |                 $scope.backupCancelled = true; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         function cantLoadInitialDatas(response) { |         function cantLoadInitialDatas(response) { | ||||||
|  |  | ||||||
|         } |             // notifications boxes | ||||||
|  |  | ||||||
|     }; |             $scope.notificationsBox = false; | ||||||
|  |             $scope.errorMessage = true; | ||||||
|     $scope.passwordEnter = function() { |             $scope.couldNotConnect = false; | ||||||
|         $scope.backupButton = false; |             $scope.accountsFetched = true; | ||||||
|     }; |             $scope.backupProcessStarted = true; | ||||||
|  |             $scope.backupCancelled = true; | ||||||
|     var seek = 0; |  | ||||||
|     var backupDir; |  | ||||||
|     var username = "admin"; |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     function getBackupStatus(password) { |  | ||||||
|  |  | ||||||
|         url = "/backup/getRemoteTransferStatus"; |  | ||||||
|  |  | ||||||
|         var data = { |  | ||||||
|             ipAddress: $scope.IPAddress, |  | ||||||
|             seek: seek, |  | ||||||
|             backupDir: backupDir, |  | ||||||
|         }; |  | ||||||
|  |  | ||||||
|         var config = { |  | ||||||
|             headers: { |  | ||||||
|                 'X-CSRFToken': getCookie('csrftoken') |  | ||||||
|             } |  | ||||||
|         }; |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         console.log("Initiating Status with seek: " + seek) |  | ||||||
|  |  | ||||||
|         $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); |  | ||||||
|  |  | ||||||
|         function ListInitialDatas(response) { |  | ||||||
|             console.log(response.data) |  | ||||||
|  |  | ||||||
|             if (response.data.remoteTransferStatus == 1) { |  | ||||||
|                 seek = response.data.where; |  | ||||||
|                 if (response.data.complete == 1) { |  | ||||||
|                     $scope.submitDisable = false; |  | ||||||
|                     $scope.backupLoading = true; |  | ||||||
|  |  | ||||||
|                     $scope.status_danger = true; |  | ||||||
|                     $scope.status_info = true; |  | ||||||
|                     $scope.status_success = false; |  | ||||||
|                     $scope.startRestore = true; |  | ||||||
|                     $scope.statusBox = "Backup Files Transferred! Require Permission to restore backups"; |  | ||||||
|                     $scope.requestData = $scope.requestData + response.data.logs |  | ||||||
|                     seek = 0; |  | ||||||
|  |  | ||||||
|                     $scope.startRestore = false; |  | ||||||
|                 } else { |  | ||||||
|                     $scope.requestData = $scope.requestData + response.data.logs |  | ||||||
|                     $timeout(getBackupStatus(password), 5000); |  | ||||||
|                 } |  | ||||||
|             } else { |  | ||||||
|                 if (response.data.error_message == "list index out of range") { |  | ||||||
|                     $timeout(getBackupStatus(password), 5000); |  | ||||||
|                 } else { |  | ||||||
|                     $scope.submitDisable = false; |  | ||||||
|                     $scope.status_danger = false; |  | ||||||
|                     $scope.status_info = true; |  | ||||||
|                     $scope.status_success = true; |  | ||||||
|                     $scope.statusBox = "Unable to Transfer File: " + response.data.error_message; |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         function cantLoadInitialDatas(response) { |  | ||||||
|             $scope.status_danger = false; |  | ||||||
|             $scope.status_info = true; |  | ||||||
|             $scope.status_success = true; |  | ||||||
|             $scope.statusBox = "Unable to connect" |  | ||||||
|         } |  | ||||||
|     }; |     }; | ||||||
|  |      | ||||||
|  |     $scope.startTransfer = function () { | ||||||
|  |  | ||||||
|     $scope.submitRemoteBackup = function() { |         // notifications boxes | ||||||
|         $scope.requestData = ""; |         $scope.notificationsBox = true; | ||||||
|         $scope.status_success = true; |         $scope.errorMessage = true; | ||||||
|         $scope.status_danger = true; |         $scope.couldNotConnect = true; | ||||||
|         $scope.status_info = true; |         $scope.accountsFetched = true; | ||||||
|  |         $scope.backupProcessStarted = true; | ||||||
|  |         $scope.backupCancelled = true; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         if(websitesToBeBacked.length === 0){ | ||||||
|  |             alert("No websites selected for transfer.") | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $scope.fetchAccountsBtn = true; | ||||||
|  |  | ||||||
|         $scope.backupLoading = false; |         $scope.backupLoading = false; | ||||||
|         $scope.submitDisable = true; |  | ||||||
|         var IPAddress = $scope.IPAddress; |         var IPAddress = $scope.IPAddress; | ||||||
|         var password = $scope.password; |         var password = $scope.password; | ||||||
|  |  | ||||||
|         url = "/backup/submitRemoteBackups"; |         url = "/backup/starRemoteTransfer"; | ||||||
|  |  | ||||||
|         var data = { |         var data = { | ||||||
|             ipAddress: IPAddress, |             ipAddress: IPAddress, | ||||||
|             username: username, |  | ||||||
|             password: password, |             password: password, | ||||||
|         }; |         }; | ||||||
|  |  | ||||||
| @@ -1187,48 +1237,82 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { | |||||||
|         }; |         }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); |         $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); | ||||||
|  |  | ||||||
|  |  | ||||||
|         function ListInitialDatas(response) { |         function ListInitialDatas(response) { | ||||||
|             console.log(response.data) |  | ||||||
|  |  | ||||||
|             if (response.data.status == 1) { |             if (response.data.remoteTransferStatus == 1) { | ||||||
|                 $scope.request = false; |                     tempTransferDir = response.data.dir; | ||||||
|                 console.log("Backup generated!!") |                     $scope.accountsInRemoteServerTable = true; | ||||||
|                 backupDir = response.data.dir; |  | ||||||
|                 getBackupStatus(password); |                     // notifications boxes | ||||||
|             } else { |                     $scope.notificationsBox = false; | ||||||
|                 $scope.submitDisable = false; |                     $scope.errorMessage = true; | ||||||
|  |                     $scope.couldNotConnect = true; | ||||||
|  |                     $scope.accountsFetched = true; | ||||||
|  |                     $scope.backupProcessStarted = false; | ||||||
|  |                     $scope.backupCancelled = true; | ||||||
|  |  | ||||||
|  |                     // disable transfer button | ||||||
|  |  | ||||||
|  |                     $scope.startTransferbtn = true; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |                     // enable cancel button | ||||||
|  |  | ||||||
|  |                     $scope.stopTransferbtn = false; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |                     getBackupStatus(); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |             } | ||||||
|  |             else { | ||||||
|  |  | ||||||
|  |                 $scope.error_message = response.data.error_message; | ||||||
|                 $scope.backupLoading = true; |                 $scope.backupLoading = true; | ||||||
|  |  | ||||||
|                 $scope.status_danger = false; |                 // Notifications box settings | ||||||
|                 $scope.status_info = true; |  | ||||||
|                 $scope.status_success = true; |                 // notifications boxes | ||||||
|                 $scope.statusBox = "Unable to Transfer File: " + response.data.error_message; |                 $scope.notificationsBox = false; | ||||||
|  |                 $scope.errorMessage = false; | ||||||
|  |                 $scope.couldNotConnect = true; | ||||||
|  |                 $scope.accountsFetched = true; | ||||||
|  |                 $scope.backupProcessStarted = true; | ||||||
|  |                 $scope.backupCancelled = true; | ||||||
|  |  | ||||||
|             } |             } | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         function cantLoadInitialDatas(response) { |         function cantLoadInitialDatas(response) { | ||||||
|             $scope.status_danger = false; |  | ||||||
|             $scope.status_info = true; |                 // Notifications box settings | ||||||
|             $scope.status_success = true; |  | ||||||
|             $scope.statusBox = "Unable to connect" |                 // notifications boxes | ||||||
|  |                 $scope.notificationsBox = false; | ||||||
|  |                 $scope.errorMessage = true; | ||||||
|  |                 $scope.couldNotConnect = false; | ||||||
|  |                 $scope.accountsFetched = true; | ||||||
|  |                 $scope.backupProcessStarted = true; | ||||||
|  |                 $scope.backupCancelled = true; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     function getRestStatus() { |  | ||||||
|  |  | ||||||
|         url = "/backup/remoteRestoreStatus"; |  | ||||||
|  |     function getBackupStatus(password) { | ||||||
|  |  | ||||||
|  |         url = "/backup/getRemoteTransferStatus"; | ||||||
|  |  | ||||||
|         var data = { |         var data = { | ||||||
|             seek: seek, |             password : $scope.password, | ||||||
|             backupDir: backupDir, |             ipAddress: $scope.IPAddress, | ||||||
|  |             dir: tempTransferDir, | ||||||
|         }; |         }; | ||||||
|         console.log(data) |  | ||||||
|  |  | ||||||
|         var config = { |         var config = { | ||||||
|             headers: { |             headers: { | ||||||
| @@ -1237,69 +1321,58 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { | |||||||
|         }; |         }; | ||||||
|  |  | ||||||
|  |  | ||||||
|         console.log("Initiating Status with seek: " + seek) |  | ||||||
|  |  | ||||||
|         $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); |         $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); | ||||||
|  |  | ||||||
|         function ListInitialDatas(response) { |         function ListInitialDatas(response) { | ||||||
|             console.log(response.data) |  | ||||||
|  |  | ||||||
|             if (response.data.remoteRestoreStatus == 1) { |             if (response.data.remoteTransferStatus == 1) { | ||||||
|                 seek = response.data.where; |  | ||||||
|                 console.log(seek); |                 if(response.data.backupsSent == 0){ | ||||||
|                 if (response.data.complete == 1) { |                     $scope.backupStatus = false; | ||||||
|                     $scope.submitDisable = false; |                     $scope.requestData = response.data.status; | ||||||
|  |                     $timeout(getBackupStatus, 2000); | ||||||
|  |                 } | ||||||
|  |                 else{ | ||||||
|  |                     $scope.requestData = response.data.status; | ||||||
|  |                     $timeout.cancel(); | ||||||
|                     $scope.backupLoading = true; |                     $scope.backupLoading = true; | ||||||
|  |                     remoteBackupRestore(); | ||||||
|                     $scope.status_danger = true; |  | ||||||
|                     $scope.status_info = true; |  | ||||||
|                     $scope.status_success = false; |  | ||||||
|  |  | ||||||
|                     $scope.statusBox = "Backup Files Restored!"; |  | ||||||
|                     $scope.requestData = $scope.requestData + response.data.logs |  | ||||||
|                     $scope.startRestore = false; |  | ||||||
|                 } else { |  | ||||||
|                     $scope.requestData = $scope.requestData + response.data.logs |  | ||||||
|                     $timeout(getRestStatus(), 5000); |  | ||||||
|                 } |  | ||||||
|             } else { |  | ||||||
|                 if (response.data.error_message == "list index out of range") { |  | ||||||
|                     $timeout(getRestStatus(), 5000); |  | ||||||
|                 } else { |  | ||||||
|                     $scope.submitDisable = false; |  | ||||||
|                     $scope.status_danger = false; |  | ||||||
|                     $scope.status_info = true; |  | ||||||
|                     $scope.status_success = true; |  | ||||||
|                     $scope.statusBox = "Unable to Restore File: " + response.data.error_message; |  | ||||||
|                 } |                 } | ||||||
|  |             } | ||||||
|  |             else{ | ||||||
|  |  | ||||||
|  |                 $scope.error_message = response.data.error_message; | ||||||
|  |                 $scope.backupLoading = true; | ||||||
|  |                 $scope.couldNotConnect = true; | ||||||
|  |  | ||||||
|  |                 // Notifications box settings | ||||||
|  |  | ||||||
|  |                 $scope.couldNotConnect = true; | ||||||
|  |                 $scope.errorMessage = false; | ||||||
|  |                 $scope.accountsFetched = true; | ||||||
|  |                 $scope.notificationsBox = false; | ||||||
|  |                 $timeout.cancel(); | ||||||
|  |  | ||||||
|             } |             } | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         function cantLoadInitialDatas(response) { |         function cantLoadInitialDatas(response) { | ||||||
|             $scope.status_danger = false; |                  // Notifications box settings | ||||||
|             $scope.status_info = true; |  | ||||||
|             $scope.status_success = true; |                 $scope.couldNotConnect = false; | ||||||
|             $scope.statusBox = "Unable to connect" |                 $scope.errorMessage = true; | ||||||
|  |                 $scope.accountsFetched = true; | ||||||
|  |                 $scope.notificationsBox = false; | ||||||
|         } |         } | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     $scope.submitBackupRestore = function() { |     function remoteBackupRestore(){ | ||||||
|         $scope.status_success = true; |  | ||||||
|         $scope.status_danger = true; |  | ||||||
|         $scope.status_info = false; |  | ||||||
|         $scope.statusBox = "Restoring Backup"; |  | ||||||
|  |  | ||||||
|         $scope.backupLoading = false; |  | ||||||
|         $scope.submitDisable = true; |  | ||||||
|  |  | ||||||
|         url = "/backup/remoteBackupRestore"; |         url = "/backup/remoteBackupRestore"; | ||||||
|  |  | ||||||
|         var data = { |         var data = { | ||||||
|             backupDir: backupDir |             backupDir: tempTransferDir, | ||||||
|         }; |         }; | ||||||
|         console.log(data) |  | ||||||
|  |  | ||||||
|         var config = { |         var config = { | ||||||
|             headers: { |             headers: { | ||||||
| @@ -1307,42 +1380,241 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { | |||||||
|             } |             } | ||||||
|         }; |         }; | ||||||
|  |  | ||||||
|         seek = 0 |  | ||||||
|  |  | ||||||
|         $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); |         $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); | ||||||
|  |  | ||||||
|         function ListInitialDatas(response) { |         function ListInitialDatas(response) { | ||||||
|             console.log(response.data) |  | ||||||
|  |  | ||||||
|             if (response.data.remoteRestoreStatus == 1) { |             if (response.data.remoteRestoreStatus == 1) { | ||||||
|                 $scope.request = false; |                     localRestoreStatus(); | ||||||
|                 $scope.backupLoading = false; |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|                 $scope.status_danger = true; |         function cantLoadInitialDatas(response) { | ||||||
|                 $scope.status_info = true; |                  // Notifications box settings | ||||||
|                 $scope.status_success = false; |  | ||||||
|                 $scope.statusBox = "Restore in Progress, fetching details" |                 $scope.couldNotConnect = false; | ||||||
|                 getRestStatus(); |                 $scope.errorMessage = true; | ||||||
|             } else { |                 $scope.accountsFetched = true; | ||||||
|                 $scope.submitDisable = false; |                 $scope.notificationsBox = false; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /////////////// | ||||||
|  |  | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     function localRestoreStatus(password) { | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         url = "/backup/localRestoreStatus"; | ||||||
|  |  | ||||||
|  |         var data = { | ||||||
|  |             backupDir: tempTransferDir, | ||||||
|  |         }; | ||||||
|  |  | ||||||
|  |         var config = { | ||||||
|  |             headers: { | ||||||
|  |                 'X-CSRFToken': getCookie('csrftoken') | ||||||
|  |             } | ||||||
|  |         }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); | ||||||
|  |  | ||||||
|  |         function ListInitialDatas(response) { | ||||||
|  |  | ||||||
|  |             if (response.data.remoteTransferStatus == 1) { | ||||||
|  |  | ||||||
|  |                 if(response.data.complete == 0){ | ||||||
|  |                     $scope.backupStatus = false; | ||||||
|  |                     $scope.requestData = response.data.status; | ||||||
|  |                     $timeout(localRestoreStatus, 2000); | ||||||
|  |                 } | ||||||
|  |                 else{ | ||||||
|  |                     $scope.requestData = response.data.status; | ||||||
|  |                     $timeout.cancel(); | ||||||
|  |                     $scope.backupLoading = true; | ||||||
|  |                     $scope.startTransferbtn = false; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             else{ | ||||||
|  |  | ||||||
|  |                 $scope.error_message = response.data.error_message; | ||||||
|                 $scope.backupLoading = true; |                 $scope.backupLoading = true; | ||||||
|                 $scope.status_danger = false; |                 $scope.couldNotConnect = true; | ||||||
|                 $scope.status_info = true; |  | ||||||
|                 $scope.status_success = true; |                 // Notifications box settings | ||||||
|                 $scope.statusBox = "Unable to Restore Backups: " + response.data.error_message; |  | ||||||
|  |                 $scope.couldNotConnect = true; | ||||||
|  |                 $scope.errorMessage = false; | ||||||
|  |                 $scope.accountsFetched = true; | ||||||
|  |                 $scope.notificationsBox = false; | ||||||
|  |  | ||||||
|             } |             } | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         function cantLoadInitialDatas(response) { |         function cantLoadInitialDatas(response) { | ||||||
|             $scope.status_danger = false; |                  // Notifications box settings | ||||||
|             $scope.status_info = true; |  | ||||||
|             $scope.status_success = true; |                 $scope.couldNotConnect = false; | ||||||
|             $scope.statusBox = "Unable to connect"; |                 $scope.errorMessage = true; | ||||||
|  |                 $scope.accountsFetched = true; | ||||||
|  |                 $scope.notificationsBox = false; | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     function restoreAccounts() { | ||||||
|  |  | ||||||
|  |         url = "/backup/getRemoteTransferStatus"; | ||||||
|  |  | ||||||
|  |         var data = { | ||||||
|  |             password : $scope.password, | ||||||
|  |             ipAddress: $scope.IPAddress, | ||||||
|  |             dir: tempTransferDir, | ||||||
|  |         }; | ||||||
|  |  | ||||||
|  |         var config = { | ||||||
|  |             headers: { | ||||||
|  |                 'X-CSRFToken': getCookie('csrftoken') | ||||||
|  |             } | ||||||
|  |         }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); | ||||||
|  |  | ||||||
|  |         function ListInitialDatas(response) { | ||||||
|  |  | ||||||
|  |             if (response.data.remoteTransferStatus == 1) { | ||||||
|  |  | ||||||
|  |                 if(response.data.backupsSent == 0){ | ||||||
|  |                     $scope.backupStatus = false; | ||||||
|  |                     $scope.requestData = response.data.status; | ||||||
|  |                     $timeout(getBackupStatus, 2000); | ||||||
|  |                 } | ||||||
|  |                 else{ | ||||||
|  |                     $timeout.cancel(); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         function cantLoadInitialDatas(response) { | ||||||
|  |                  // Notifications box settings | ||||||
|  |  | ||||||
|  |                 $scope.couldNotConnect = false; | ||||||
|  |                 $scope.errorMessage = true; | ||||||
|  |                 $scope.accountsFetched = true; | ||||||
|  |                 $scope.notificationsBox = false; | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     $scope.cancelRemoteBackup = function () { | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         $scope.backupLoading = false; | ||||||
|  |  | ||||||
|  |         // notifications boxes | ||||||
|  |         $scope.notificationsBox = true; | ||||||
|  |         $scope.errorMessage = true; | ||||||
|  |         $scope.couldNotConnect = true; | ||||||
|  |         $scope.accountsFetched = true; | ||||||
|  |         $scope.backupProcessStarted = true; | ||||||
|  |         $scope.backupCancelled = true; | ||||||
|  |  | ||||||
|  |         var IPAddress = $scope.IPAddress; | ||||||
|  |         var password = $scope.password; | ||||||
|  |  | ||||||
|  |         url = "/backup/cancelRemoteBackup"; | ||||||
|  |  | ||||||
|  |         var data = { | ||||||
|  |             ipAddress: IPAddress, | ||||||
|  |             password: password, | ||||||
|  |             dir:tempTransferDir, | ||||||
|  |         }; | ||||||
|  |  | ||||||
|  |         var config = { | ||||||
|  |             headers: { | ||||||
|  |                 'X-CSRFToken': getCookie('csrftoken') | ||||||
|  |             } | ||||||
|  |         }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); | ||||||
|  |  | ||||||
|  |         function ListInitialDatas(response) { | ||||||
|  |  | ||||||
|  |             if (response.data.cancelStatus == 1) { | ||||||
|  |                     $scope.backupLoading = true; | ||||||
|  |  | ||||||
|  |                     // notifications boxes | ||||||
|  |                     $scope.notificationsBox = false; | ||||||
|  |                     $scope.errorMessage = true; | ||||||
|  |                     $scope.couldNotConnect = true; | ||||||
|  |                     $scope.accountsFetched = true; | ||||||
|  |                     $scope.backupProcessStarted = true; | ||||||
|  |                     $scope.backupCancelled = false; | ||||||
|  |  | ||||||
|  |                     // enable transfer button | ||||||
|  |  | ||||||
|  |                     $scope.startTransferbtn = false; | ||||||
|  |  | ||||||
|  |                     //disable cancel button | ||||||
|  |  | ||||||
|  |                     $scope.stopTransferbtn = true; | ||||||
|  |  | ||||||
|  |                     // hide status box | ||||||
|  |  | ||||||
|  |                     $scope.backupStatus = true; | ||||||
|  |  | ||||||
|  |                     // bring back websites table | ||||||
|  |  | ||||||
|  |                     $scope.accountsInRemoteServerTable = false; | ||||||
|  |  | ||||||
|  |                     // enable fetch button | ||||||
|  |  | ||||||
|  |                     $scope.fetchAccountsBtn = false; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |             } | ||||||
|  |             else { | ||||||
|  |  | ||||||
|  |                 $scope.error_message = response.data.error_message; | ||||||
|  |                 $scope.backupLoading = true; | ||||||
|  |  | ||||||
|  |                 // notifications boxes | ||||||
|  |  | ||||||
|  |                 $scope.notificationsBox = false; | ||||||
|  |                 $scope.errorMessage = false; | ||||||
|  |                 $scope.couldNotConnect = true; | ||||||
|  |                 $scope.accountsFetched = true; | ||||||
|  |                 $scope.backupProcessStarted = true; | ||||||
|  |                 $scope.backupCancelled = true; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         function cantLoadInitialDatas(response) { | ||||||
|  |  | ||||||
|  |                 // notifications boxes | ||||||
|  |  | ||||||
|  |                 $scope.notificationsBox = false; | ||||||
|  |                 $scope.errorMessage = true; | ||||||
|  |                 $scope.couldNotConnect = false; | ||||||
|  |                 $scope.accountsFetched = true; | ||||||
|  |                 $scope.backupProcessStarted = true; | ||||||
|  |                 $scope.backupCancelled = true; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|  |  | ||||||
| }); | }); | ||||||
|  |  | ||||||
| ///** Backup site ends **/// | ///** Backup site ends **/// | ||||||
| @@ -41,13 +41,60 @@ | |||||||
|                 <div ng-hide="backupButton" class="form-group"> |                 <div ng-hide="backupButton" 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"> | ||||||
|                          <button type="button" ng-disabled="submitDisable" ng-click="fetchAccountsFromRemoteServer()" class="btn btn-primary btn-lg btn-block">Fetch Accounts</button> |                          <button type="button" ng-disabled="fetchAccountsBtn" ng-click="fetchAccountsFromRemoteServer()" class="btn btn-primary btn-lg btn-block">Fetch Accounts</button> | ||||||
|                     </div> |                     </div> | ||||||
|             </div> |                 </div> | ||||||
|  |  | ||||||
|  |  | ||||||
|  |                 <div ng-hide="transferBoxBtn" class="form-group"> | ||||||
|  |  | ||||||
|  |                     <label class="col-sm-1 control-label"></label> | ||||||
|  |                     <div class="col-sm-4"> | ||||||
|  |                          <button type="button" ng-disabled="startTransferbtn" ng-click="startTransfer()" class="btn btn-primary btn-lg btn-block">Start Transfer</button> | ||||||
|  |                     </div> | ||||||
|  |  | ||||||
|  |                     <div class="col-sm-4"> | ||||||
|  |                          <button type="button" ng-disabled="stopTransferbtn" ng-click="cancelRemoteBackup()" class="btn btn-primary btn-lg btn-block">Cancel</button> | ||||||
|  |                     </div> | ||||||
|  |  | ||||||
|  |                 </div> | ||||||
|  |  | ||||||
|  |  | ||||||
|  |                 <div ng-hide="notificationsBox" class="form-group"> | ||||||
|  |                     <label class="col-sm-3 control-label"></label> | ||||||
|  |                     <div class="col-sm-4"> | ||||||
|  |                         <div ng-hide="errorMessage" class="alert alert-danger"> | ||||||
|  |                             <p>{$ error_message $}</p> | ||||||
|  |                         </div> | ||||||
|  |                         <div ng-hide="couldNotConnect" class="alert alert-danger"> | ||||||
|  |                             <p>Could not connect, please refresh this page.</p> | ||||||
|  |                         </div> | ||||||
|  |  | ||||||
|  |                         <div ng-hide="accountsFetched" class="alert alert-success"> | ||||||
|  |                             <p>Accounts Successfully Fetched from remote server.</p> | ||||||
|  |                         </div> | ||||||
|  |  | ||||||
|  |                         <div ng-hide="backupProcessStarted" class="alert alert-success"> | ||||||
|  |                             <p>Backup Process successfully started.</p> | ||||||
|  |                         </div> | ||||||
|  |  | ||||||
|  |                         <div ng-hide="backupCancelled" class="alert alert-success"> | ||||||
|  |                             <p>Backup successfully cancelled.</p> | ||||||
|  |                         </div> | ||||||
|  |  | ||||||
|  |                     </div> | ||||||
|  |                 </div> | ||||||
|  |  | ||||||
|  |  | ||||||
|                 <!------ List of Accounts in remote server ---------------> |                 <!------ List of Accounts in remote server ---------------> | ||||||
|  |  | ||||||
|  |                 <div ng-hide="accountsInRemoteServerTable" class="form-group"> | ||||||
|  |  | ||||||
|  |                     <div class="col-sm-12"> | ||||||
|  |                         <input type="text" ng-model="accountsSearch" placeholder="{% trans 'Search Accounts..' %}" class="form-control autocomplete-input"> | ||||||
|  |                     </div> | ||||||
|  |                  </div> | ||||||
|  |  | ||||||
|                 <div ng-hide="accountsInRemoteServerTable" class="form-group"> |                 <div ng-hide="accountsInRemoteServerTable" class="form-group"> | ||||||
|  |  | ||||||
|                     <div  class="col-sm-12"> |                     <div  class="col-sm-12"> | ||||||
| @@ -59,16 +106,16 @@ | |||||||
|                                 <th>{% trans "PHP" %}</th> |                                 <th>{% trans "PHP" %}</th> | ||||||
|                                 <th>{% trans "Package" %}</th> |                                 <th>{% trans "Package" %}</th> | ||||||
|                                 <th>{% trans "Email" %}</th> |                                 <th>{% trans "Email" %}</th> | ||||||
|                                 <th>{% trans "Transfer" %}</th> |                                 <th><input ng-model="webSiteStatus" ng-change="allChecked(webSiteStatus)" type="checkbox" value=""></th> | ||||||
|                             </tr> |                             </tr> | ||||||
|                             </thead> |                             </thead> | ||||||
|                             <tbody> |                             <tbody> | ||||||
|                             <tr ng-repeat="record in records track by $index"> |                             <tr ng-repeat="record in records | filter:accountsSearch"> | ||||||
|                                 <td ng-bind="record.website"></td> |                                 <td ng-bind="record.website"></td> | ||||||
|                                 <td ng-bind="record.php"></td> |                                 <td ng-bind="record.php"></td> | ||||||
|                                 <td ng-bind="record.package"></td> |                                 <td ng-bind="record.package"></td> | ||||||
|                                 <td ng-bind="record.email"></td> |                                 <td ng-bind="record.email"></td> | ||||||
|                                 <td ng-click=""><input ng-model="sslCheck" type="checkbox" value=""></td> |                                 <td ng-click=""><input ng-model="webSiteStatus" ng-change="addRemoveWebsite(record.website,webSiteStatus)" type="checkbox" value=""></td> | ||||||
|                             </tr> |                             </tr> | ||||||
|                             </tbody> |                             </tbody> | ||||||
|                         </table> |                         </table> | ||||||
| @@ -78,17 +125,12 @@ | |||||||
|             <!------ List of Accounts in remote server ---------------> |             <!------ List of Accounts in remote server ---------------> | ||||||
|  |  | ||||||
|             </form> |             </form> | ||||||
|             <div ng-hide="status_danger" class="alert alert-danger"> |  | ||||||
|                 <p>{$ error_message $}</p> |  | ||||||
|             </div> |  | ||||||
|             <div ng-hide="status_info" class="alert alert-info"> |  | ||||||
|                 <p>{$ statusBox $}</p> |  | ||||||
|             </div> |  | ||||||
|  |  | ||||||
|             <div ng-hide="request" class="form-group"> |  | ||||||
|  |  | ||||||
|  |             <div ng-hide="backupStatus" class="form-group"> | ||||||
|                 <div class="col-sm-12"> |                 <div class="col-sm-12"> | ||||||
|                     <button ng-disabled="startRestore" style="margin-bottom: 1%" type="button" ng-click="submitBackupRestore()" class="btn ra-100 btn-blue-alt">Start Restore</button> |                     <textarea ng-model="requestData" rows="15" class="form-control"></textarea> | ||||||
|                     <textarea ng-model="requestData" rows="15" class="form-control" readonly>{{ requestData }}</textarea> |  | ||||||
|                 </div> |                 </div> | ||||||
|             </div> |             </div> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -39,11 +39,12 @@ urlpatterns = [ | |||||||
|  |  | ||||||
|     url(r'^remoteBackups', views.remoteBackups, name='remoteBackups'), |     url(r'^remoteBackups', views.remoteBackups, name='remoteBackups'), | ||||||
|     url(r'^submitRemoteBackups', views.submitRemoteBackups, name='submitRemoteBackups'), |     url(r'^submitRemoteBackups', views.submitRemoteBackups, name='submitRemoteBackups'), | ||||||
|     url(r'^remoteTransferStatus', views.remoteTransferStatus, name='remoteTransferStatus'), |  | ||||||
|     url(r'^getRemoteTransferStatus', views.getRemoteTransferStatus, name='getRemoteTransferStatus'), |     url(r'^getRemoteTransferStatus', views.getRemoteTransferStatus, name='getRemoteTransferStatus'), | ||||||
|     url(r'^remoteBackupRestore', views.remoteBackupRestore, name='remoteBackupRestore'), |     url(r'^remoteBackupRestore', views.remoteBackupRestore, name='remoteBackupRestore'), | ||||||
|     url(r'^remoteRestoreStatus', views.remoteRestoreStatus, name='remoteRestoreStatus'), |     url(r'^starRemoteTransfer', views.starRemoteTransfer, name='starRemoteTransfer'), | ||||||
|  |     url(r'^localRestoreStatus', views.localRestoreStatus, name='localRestoreStatus'), | ||||||
|  |  | ||||||
|  |     url(r'^cancelRemoteBackup', views.cancelRemoteBackup, name='cancelRemoteBackup'), | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										395
									
								
								backup/views.py
									
									
									
									
									
								
							
							
						
						
									
										395
									
								
								backup/views.py
									
									
									
									
									
								
							| @@ -160,61 +160,55 @@ def getCurrentBackups(request): | |||||||
|  |  | ||||||
| def submitBackupCreation(request): | def submitBackupCreation(request): | ||||||
|     try: |     try: | ||||||
|         try: |         if request.method == 'POST': | ||||||
|             if request.method == 'POST': |  | ||||||
|  |  | ||||||
|                 data = json.loads(request.body) |             data = json.loads(request.body) | ||||||
|                 backupDomain = data['websiteToBeBacked'] |             backupDomain = data['websiteToBeBacked'] | ||||||
|  |  | ||||||
|                 website = Websites.objects.get(domain=backupDomain) |             website = Websites.objects.get(domain=backupDomain) | ||||||
|  |  | ||||||
|                 backupPath = "/home/"+backupDomain+"/backup/" |             backupPath = "/home/" + backupDomain + "/backup/" | ||||||
|  |  | ||||||
|                 if not os.path.exists(backupPath): |             if not os.path.exists(backupPath): | ||||||
|                     os.mkdir(backupPath) |                 os.mkdir(backupPath) | ||||||
|  |  | ||||||
|                 domainUser = backupDomain.split('.') |             domainUser = backupDomain.split('.') | ||||||
|  |  | ||||||
|                 backupName = 'backup-'+domainUser[0]+"-"+time.strftime("%I-%M-%S-%a-%b-%Y") |             backupName = 'backup-' + domainUser[0] + "-" + time.strftime("%I-%M-%S-%a-%b-%Y") | ||||||
|  |  | ||||||
|                 tempStoragePath = backupPath+backupName |             tempStoragePath = backupPath + backupName | ||||||
|  |  | ||||||
|                 if not os.path.exists(tempStoragePath): |             if not os.path.exists(tempStoragePath): | ||||||
|                     os.mkdir(tempStoragePath) |                 os.mkdir(tempStoragePath) | ||||||
|  |  | ||||||
|                 ## Generating meta |             ## Generating meta | ||||||
|  |  | ||||||
|                 meta = tempStoragePath+"/meta" |             meta = tempStoragePath + "/meta" | ||||||
|  |  | ||||||
|                 metaFile = open(meta,'w') |             metaFile = open(meta, 'w') | ||||||
|  |  | ||||||
|                 metaFile.write(backupDomain+"\n") |             metaFile.write(backupDomain + "\n") | ||||||
|  |  | ||||||
|                 databases = website.databases_set.all() |             databases = website.databases_set.all() | ||||||
|  |  | ||||||
|                 for items in databases: |             for items in databases: | ||||||
|                     dbuser = DBUsers.objects.get(user=items.dbUser) |                 dbuser = DBUsers.objects.get(user=items.dbUser) | ||||||
|                     metaFile.write(items.dbName + "-" + items.dbUser + "-"+dbuser.password + "\n") |                 metaFile.write(items.dbName + "-" + items.dbUser + "-" + dbuser.password + "\n") | ||||||
|                 metaFile.close() |             metaFile.close() | ||||||
|  |  | ||||||
|                 backupUtil.backupUtilities.initiateBackup(tempStoragePath,backupName,backupPath) |             backupUtil.backupUtilities.initiateBackup(tempStoragePath, backupName, backupPath) | ||||||
|  |  | ||||||
|                 newBackup = Backups(website=website,fileName=backupName,date=time.strftime("%I-%M-%S-%a-%b-%Y"), |             newBackup = Backups(website=website, fileName=backupName, date=time.strftime("%I-%M-%S-%a-%b-%Y"), | ||||||
|                                     size=0,status=0) |                                 size=0, status=0) | ||||||
|                 newBackup.save() |             newBackup.save() | ||||||
|  |  | ||||||
|  |  | ||||||
|                 final_json = json.dumps({'metaStatus': 1, 'error_message': "None",'tempStorage':tempStoragePath}) |  | ||||||
|                 return HttpResponse(final_json) |  | ||||||
|  |  | ||||||
|         except BaseException,msg: |  | ||||||
|             final_dic = {'metaStatus': 0, 'error_message': str(msg)} |  | ||||||
|             final_json = json.dumps(final_dic) |  | ||||||
|  |  | ||||||
|  |             final_json = json.dumps({'metaStatus': 1, 'error_message': "None", 'tempStorage': tempStoragePath}) | ||||||
|             return HttpResponse(final_json) |             return HttpResponse(final_json) | ||||||
|     except KeyError: |  | ||||||
|         final_dic = {'metaStatus': 0, 'error_message': "Not Logged In, please refresh the page or login again."} |     except BaseException, msg: | ||||||
|  |         final_dic = {'metaStatus': 0, 'error_message': str(msg)} | ||||||
|         final_json = json.dumps(final_dic) |         final_json = json.dumps(final_dic) | ||||||
|  |  | ||||||
|         return HttpResponse(final_json) |         return HttpResponse(final_json) | ||||||
|  |  | ||||||
| def backupStatus(request): | def backupStatus(request): | ||||||
| @@ -397,79 +391,78 @@ def deleteBackup(request): | |||||||
|  |  | ||||||
| def submitRestore(request): | def submitRestore(request): | ||||||
|     try: |     try: | ||||||
|         val = request.session['userID'] |         if request.method == 'POST': | ||||||
|         try: |  | ||||||
|             if request.method == 'POST': |  | ||||||
|  |  | ||||||
|  |             data = json.loads(request.body) | ||||||
|  |             backupFile = data['backupFile'] | ||||||
|  |  | ||||||
|                 data = json.loads(request.body) |             originalFile = "/home/backup/" + backupFile | ||||||
|                 backupFile = data['backupFile'] |  | ||||||
|  |  | ||||||
|                 backupUtil.backupUtilities.initiateRestore(backupFile) |             if not os.path.exists(originalFile): | ||||||
|  |                 dir = data['dir'] | ||||||
|  |             else: | ||||||
|  |                 dir = None | ||||||
|  |  | ||||||
|                 final_dic = {'restoreStatus': 1, 'error_message': "None"} |             backupUtil.backupUtilities.initiateRestore(backupFile, dir) | ||||||
|                 final_json = json.dumps(final_dic) |  | ||||||
|                 return HttpResponse(final_json) |  | ||||||
|  |  | ||||||
|         except BaseException,msg: |             final_dic = {'restoreStatus': 1, 'error_message': "None"} | ||||||
|             final_dic = {'restoreStatus': 0, 'error_message': str(msg)} |  | ||||||
|             final_json = json.dumps(final_dic) |             final_json = json.dumps(final_dic) | ||||||
|             return HttpResponse(final_json) |             return HttpResponse(final_json) | ||||||
|     except KeyError: |  | ||||||
|         final_dic = {'restoreStatus': 0, 'error_message': "Not Logged In, please refresh the page or login again."} |     except BaseException, msg: | ||||||
|  |         final_dic = {'restoreStatus': 0, 'error_message': str(msg)} | ||||||
|         final_json = json.dumps(final_dic) |         final_json = json.dumps(final_dic) | ||||||
|         return HttpResponse(final_json) |         return HttpResponse(final_json) | ||||||
|  |  | ||||||
|  |  | ||||||
| def restoreStatus(request): | def restoreStatus(request): | ||||||
|     try: |     try: | ||||||
|         val = request.session['userID'] |         if request.method == 'POST': | ||||||
|         try: |  | ||||||
|             if request.method == 'POST': |  | ||||||
|  |  | ||||||
|  |             data = json.loads(request.body) | ||||||
|  |             backupFile = data['backupFile'].strip(".tar.gz") | ||||||
|  |  | ||||||
|                 data = json.loads(request.body) |             path = "/home/backup/" + backupFile | ||||||
|                 backupFile = data['backupFile'].strip(".tar.gz") |  | ||||||
|  |  | ||||||
|                 path = "/home/backup/"+backupFile |             if os.path.exists(path): | ||||||
|  |                 pass | ||||||
|  |             else: | ||||||
|  |                 dir = data['dir'] | ||||||
|  |                 path = "/home/backup/transfer-" + str(dir) + "/" + backupFile | ||||||
|  |  | ||||||
|  |             if os.path.exists(path): | ||||||
|  |                 try: | ||||||
|  |                     status = open(path + '/status', 'r').readlines()[0] | ||||||
|  |                 except: | ||||||
|  |                     status = "Just Started" | ||||||
|  |  | ||||||
|                 if os.path.exists(path): |                 if status == "Done": | ||||||
|                     try: |                     rmtree(path) | ||||||
|                         status = open(path+'/status','r').readlines()[0] |                     final_json = json.dumps({'restoreStatus': 1, 'error_message': "None", "status": "Done"}) | ||||||
|                     except: |  | ||||||
|                         status = "Just Started" |  | ||||||
|  |  | ||||||
|                     if status == "Done": |  | ||||||
|                         rmtree(path) |  | ||||||
|                         final_json = json.dumps({'restoreStatus': 1, 'error_message': "None", "status": "Done"}) |  | ||||||
|                         return HttpResponse(final_json) |  | ||||||
|  |  | ||||||
|                     if status == "Website already exists": |  | ||||||
|                         rmtree(path) |  | ||||||
|                         final_json = json.dumps({'restoreStatus': 1, 'error_message': "Website already exists", "status": "Website already exists"}) |  | ||||||
|                         return HttpResponse(final_json) |  | ||||||
|  |  | ||||||
|                     if status.find("Not able to create Account and databases") > -1: |  | ||||||
|                         rmtree(path) |  | ||||||
|                         final_json = json.dumps({'restoreStatus': 1, 'error_message': "Not able to create Account and databases, aborting.", |  | ||||||
|                                                  "status": "Not able to create Account and databases, aborting."}) |  | ||||||
|                         return HttpResponse(final_json) |  | ||||||
|  |  | ||||||
|  |  | ||||||
|                     final_json = json.dumps({'restoreStatus': 1, 'error_message': "None", "status": status}) |  | ||||||
|                     return HttpResponse(final_json) |  | ||||||
|                 else: |  | ||||||
|                     final_json = json.dumps({'restoreStatus': 1, 'error_message': "None", "status": 0}) |  | ||||||
|                     return HttpResponse(final_json) |                     return HttpResponse(final_json) | ||||||
|  |  | ||||||
|  |                 if status == "Website already exists": | ||||||
|  |                     rmtree(path) | ||||||
|  |                     final_json = json.dumps({'restoreStatus': 1, 'error_message': "Website already exists", | ||||||
|  |                                              "status": "Website already exists"}) | ||||||
|  |                     return HttpResponse(final_json) | ||||||
|  |  | ||||||
|         except BaseException,msg: |                 if status.find("Not able to create Account and databases") > -1: | ||||||
|             final_dic = {'restoreStatus': 0, 'error_message': str(msg)} |                     rmtree(path) | ||||||
|             final_json = json.dumps(final_dic) |                     final_json = json.dumps( | ||||||
|             return HttpResponse(final_json) |                         {'restoreStatus': 1, 'error_message': "Not able to create Account and databases, aborting.", | ||||||
|     except KeyError: |                          "status": "Not able to create Account and databases, aborting."}) | ||||||
|         final_dic = {'restoreStatus': 0, 'error_message': "Not Logged In, please refresh the page or login again."} |                     return HttpResponse(final_json) | ||||||
|  |  | ||||||
|  |                 final_json = json.dumps({'restoreStatus': 1, 'error_message': "None", "status": status}) | ||||||
|  |                 return HttpResponse(final_json) | ||||||
|  |             else: | ||||||
|  |                 final_json = json.dumps({'restoreStatus': 1, 'error_message': "None", "status": 0}) | ||||||
|  |                 return HttpResponse(final_json) | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     except BaseException, msg: | ||||||
|  |         final_dic = {'restoreStatus': 0, 'error_message': str(msg)} | ||||||
|         final_json = json.dumps(final_dic) |         final_json = json.dumps(final_dic) | ||||||
|         return HttpResponse(final_json) |         return HttpResponse(final_json) | ||||||
|  |  | ||||||
| @@ -1063,10 +1056,6 @@ def submitRemoteBackups(request): | |||||||
|             pathToSSH = "/root/.ssh/authorized_keys" |             pathToSSH = "/root/.ssh/authorized_keys" | ||||||
|  |  | ||||||
|  |  | ||||||
|             sshFile = open(pathToSSH, 'a') |  | ||||||
|             sshFile.writelines("#Added by CyberPanel\n") |  | ||||||
|             sshFile.close() |  | ||||||
|  |  | ||||||
|  |  | ||||||
|             presenseCheck = 0 |             presenseCheck = 0 | ||||||
|  |  | ||||||
| @@ -1078,6 +1067,7 @@ def submitRemoteBackups(request): | |||||||
|  |  | ||||||
|             if presenseCheck == 0: |             if presenseCheck == 0: | ||||||
|                 writeToFile = open(pathToSSH, 'a') |                 writeToFile = open(pathToSSH, 'a') | ||||||
|  |                 writeToFile.writelines("#Added by CyberPanel\n") | ||||||
|                 writeToFile.writelines("\n") |                 writeToFile.writelines("\n") | ||||||
|                 writeToFile.writelines(sshkey) |                 writeToFile.writelines(sshkey) | ||||||
|                 writeToFile.writelines("\n") |                 writeToFile.writelines("\n") | ||||||
| @@ -1091,8 +1081,6 @@ def submitRemoteBackups(request): | |||||||
|  |  | ||||||
|             r = requests.post(url, data=finalData, verify=False) |             r = requests.post(url, data=finalData, verify=False) | ||||||
|  |  | ||||||
|             logging.CyberCPLogFileWriter.writeToFile(r.text) |  | ||||||
|  |  | ||||||
|             data = json.loads(r.text) |             data = json.loads(r.text) | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -1127,73 +1115,92 @@ def submitRemoteBackups(request): | |||||||
|         final_json = json.dumps({'status': 0, 'type':'exception', 'error_message': str(msg)}) |         final_json = json.dumps({'status': 0, 'type':'exception', 'error_message': str(msg)}) | ||||||
|         return HttpResponse(final_json) |         return HttpResponse(final_json) | ||||||
|  |  | ||||||
|  | def starRemoteTransfer(request): | ||||||
|  |  | ||||||
| def remoteTransferStatus(request): |  | ||||||
|     try: |     try: | ||||||
|         if request.method == "POST": |         val = request.session['userID'] | ||||||
|             data = json.loads(request.body) |         try: | ||||||
|             backupDir = data['backupDir'] |             if request.method == 'POST': | ||||||
|             seek = data['seek'] |                 data = json.loads(request.body) | ||||||
|  |  | ||||||
|             #admin = Administrator.objects.get(userName=username) |                 ipAddress = data['ipAddress'] | ||||||
|             if 1==1: |                 password = data['password'] | ||||||
|                 backupLogPath = "/home/backup/transfer-"+ backupDir +"/" + "backup_log" |  | ||||||
|                 print backupLogPath |  | ||||||
|  |  | ||||||
|                 if os.path.isfile(backupLogPath): |                 ownIP = requests.get('https://api.ipify.org').text | ||||||
|                     pass |  | ||||||
|  |                 finalData = json.dumps({'username': "admin", "password": password,"ipAddress": ownIP}) | ||||||
|  |  | ||||||
|  |                 url = "https://" + ipAddress + ":8090/api/remoteTransfer" | ||||||
|  |  | ||||||
|  |                 r = requests.post(url, data=finalData, verify=False) | ||||||
|  |  | ||||||
|  |                 data = json.loads(r.text) | ||||||
|  |  | ||||||
|  |                 localStoragePath = "/home/backup/transfer-"+str(data['dir']) | ||||||
|  |  | ||||||
|  |                 if not os.path.exists(localStoragePath): | ||||||
|  |                     os.makedirs(localStoragePath) | ||||||
|  |  | ||||||
|  |                 if data['transferStatus'] == 1: | ||||||
|  |                     final_json = json.dumps({'remoteTransferStatus': 1, 'error_message': "None","dir":data['dir']}) | ||||||
|  |                     return HttpResponse(final_json) | ||||||
|                 else: |                 else: | ||||||
|                     data_ret = {'remoteTransferStatus': 0, 'error_message': "No such log found"} |                     final_json = json.dumps({'remoteTransferStatus': 0, 'error_message': data['error_message']}) | ||||||
|                     json_data = json.dumps(data_ret) |                     return HttpResponse(final_json) | ||||||
|                     return HttpResponse(json_data) |  | ||||||
|  |  | ||||||
|                 last_line = "" |         except BaseException,msg: | ||||||
|                 with open(backupLogPath, 'r') as logfile: |             final_json = json.dumps({'remoteTransferStatus': 0, 'error_message': str(msg)}) | ||||||
|                     last_line = logfile.readlines()[-1] |             return HttpResponse(final_json) | ||||||
|                     logfile.seek(seek) |     except KeyError: | ||||||
|                     data = logfile.read() |         final_json = json.dumps({'remoteTransferStatus': 0, 'error_message': str(msg)}) | ||||||
|                     where = logfile.tell() |         return HttpResponse(final_json) | ||||||
|  |  | ||||||
|                 if 'success' in last_line: |  | ||||||
|                     data_ret = {'remoteTransferStatus': 1, "complete":1, 'error_message': "None","logs":data,"where":where} |  | ||||||
|                     json_data = json.dumps(data_ret) |  | ||||||
|                     return HttpResponse(json_data) |  | ||||||
|                 else: |  | ||||||
|  |  | ||||||
|                     data_ret = {'remoteTransferStatus': 1, "complete":0, 'error_message': "Backup In Progress","logs":data,"where":where} |  | ||||||
|                     json_data = json.dumps(data_ret) |  | ||||||
|                     return HttpResponse(json_data) |  | ||||||
|  |  | ||||||
|             else: |  | ||||||
|                 data_ret = {'remoteTransferStatus': 0, "complete":0, 'error_message': "Invalid Credentials"} |  | ||||||
|                 json_data = json.dumps(data_ret) |  | ||||||
|                 return HttpResponse(json_data) |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     except BaseException, msg: |  | ||||||
|         data = {'remoteTransferStatus': 0, 'error_message': str(msg)} |  | ||||||
|         json_data = json.dumps(data) |  | ||||||
|         return HttpResponse(json_data) |  | ||||||
|  |  | ||||||
| def getRemoteTransferStatus(request): | def getRemoteTransferStatus(request): | ||||||
|     try: |     try: | ||||||
|         if request.method == "POST": |         if request.method == "POST": | ||||||
|             data = json.loads(request.body) |             data = json.loads(request.body) | ||||||
|             ipAddress = data['ipAddress'] |             ipAddress = data['ipAddress'] | ||||||
|             backupDir = data['backupDir'] |             password = data['password'] | ||||||
|             seek = data['seek'] |             dir = data['dir'] | ||||||
|  |             username = "admin" | ||||||
|  |  | ||||||
|             finalData = json.dumps({'backupDir': backupDir, "seek":seek}) |             finalData = json.dumps({'dir': dir, "username":username,"password":password}) | ||||||
|             r = requests.post("https://"+ipAddress+":8090/backup/remoteTransferStatus", data=finalData) |             r = requests.post("https://"+ipAddress+":8090/api/FetchRemoteTransferStatus", data=finalData) | ||||||
|  |  | ||||||
|  |             data = json.loads(r.text) | ||||||
|  |  | ||||||
|  |             if data['fetchStatus'] == 1: | ||||||
|  |                 if data['status'].find("Backups are successfully generated and received on") > -1: | ||||||
|  |  | ||||||
|  |                     #try: | ||||||
|  |                         #finalData = json.dumps({"backupDir": dir}) | ||||||
|  |                         #r = requests.post("http://localhost:5003/backup/remoteBackupRestore", data=finalData) | ||||||
|  |                         #logging.CyberCPLogFileWriter.writeToFile(r.text) | ||||||
|  |                     #except BaseException,msg: | ||||||
|  |                     #    logging.CyberCPLogFileWriter.writeToFile("Something happened here:" +str(msg)) | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |                     data = {'remoteTransferStatus': 1, 'error_message': "None", "status": data['status'],'backupsSent': 1} | ||||||
|  |                     json_data = json.dumps(data) | ||||||
|  |                     return HttpResponse(json_data) | ||||||
|  |                 else: | ||||||
|  |                     data = {'remoteTransferStatus': 1, 'error_message': "None", "status": data['status'], | ||||||
|  |                             'backupsSent': 0} | ||||||
|  |                     json_data = json.dumps(data) | ||||||
|  |                     return HttpResponse(json_data) | ||||||
|  |             else: | ||||||
|  |                 data = {'remoteTransferStatus': 0, 'error_message': data['error_message'], | ||||||
|  |                         'backupsSent': 0} | ||||||
|  |                 json_data = json.dumps(data) | ||||||
|  |                 return HttpResponse(json_data) | ||||||
|  |  | ||||||
|             return HttpResponse(r.text) |  | ||||||
|  |  | ||||||
|     except BaseException, msg: |     except BaseException, msg: | ||||||
|         data = {'remoteTransferStatus': 0, 'error_message': str(msg)} |         data = {'remoteTransferStatus': 0, 'error_message': str(msg),'backupsSent': 0} | ||||||
|         json_data = json.dumps(data) |         json_data = json.dumps(data) | ||||||
|         return HttpResponse(json_data) |         return HttpResponse(json_data) | ||||||
|  |  | ||||||
|  |  | ||||||
| def remoteBackupRestore(request): | def remoteBackupRestore(request): | ||||||
|     try: |     try: | ||||||
|         val = request.session['userID'] |         val = request.session['userID'] | ||||||
| @@ -1202,11 +1209,10 @@ def remoteBackupRestore(request): | |||||||
|                 data = json.loads(request.body) |                 data = json.loads(request.body) | ||||||
|                 backupDir = data['backupDir'] |                 backupDir = data['backupDir'] | ||||||
|  |  | ||||||
|                 backupDir = "/home/backup/transfer-"+str(backupDir) |                 backupDirComplete = "/home/backup/transfer-"+str(backupDir) | ||||||
|                 admin = Administrator.objects.get(pk=val) |  | ||||||
|                 #adminEmail = admin.email |                 #adminEmail = admin.email | ||||||
|  |  | ||||||
|                 restoreRequest = rBackup.remoteBackup.remoteRestore(backupDir, admin) |                 restoreRequest = rBackup.remoteBackup.remoteRestore(backupDirComplete,str(backupDir)) | ||||||
|  |  | ||||||
|                 if restoreRequest[0] == 1: |                 if restoreRequest[0] == 1: | ||||||
|                     data = {'remoteRestoreStatus': 1, 'error_message': 'None'} |                     data = {'remoteRestoreStatus': 1, 'error_message': 'None'} | ||||||
| @@ -1227,50 +1233,93 @@ def remoteBackupRestore(request): | |||||||
|         json_data = json.dumps(data_ret) |         json_data = json.dumps(data_ret) | ||||||
|         return HttpResponse(json_data) |         return HttpResponse(json_data) | ||||||
|  |  | ||||||
|  | def localRestoreStatus(request): | ||||||
|  |  | ||||||
|  |  | ||||||
| def remoteRestoreStatus(request): |  | ||||||
|     try: |     try: | ||||||
|         if request.method == "POST": |         if request.method == "POST": | ||||||
|  |  | ||||||
|             data = json.loads(request.body) |             data = json.loads(request.body) | ||||||
|             backupDir = data['backupDir'] |             backupDir = data['backupDir'] | ||||||
|             seek = data['seek'] |  | ||||||
|  |  | ||||||
|             #admin = Administrator.objects.get(userName=username) |             #admin = Administrator.objects.get(userName=username) | ||||||
|             if 1==1: |             backupLogPath = "/home/backup/transfer-"+ backupDir +"/" + "backup_log" | ||||||
|                 backupLogPath = "/home/backup/transfer-"+ backupDir +"/" + "backup_log" |  | ||||||
|  |  | ||||||
|                 if os.path.isfile(backupLogPath): |             removalPath = "/home/backup/transfer-"+ str(backupDir) | ||||||
|                     pass |  | ||||||
|                 else: |  | ||||||
|                     data_ret = {'remoteRestoreStatus': 0, 'error_message': "No such log found"} |  | ||||||
|                     json_data = json.dumps(data_ret) |  | ||||||
|                     return HttpResponse(json_data) |  | ||||||
|  |  | ||||||
|                 last_line = "" |             if os.path.isfile(backupLogPath): | ||||||
|                 with open(backupLogPath, 'r') as logfile: |  | ||||||
|                     last_line = logfile.readlines()[-1] |  | ||||||
|                     logfile.seek(seek) |  | ||||||
|                     data = logfile.read() |  | ||||||
|                     where = logfile.tell() |  | ||||||
|  |  | ||||||
|                 if 'success' in last_line: |                 statusFile = open(backupLogPath,"r") | ||||||
|                     data_ret = {'remoteRestoreStatus': 1, "complete":1, 'error_message': "None","logs":data,"where":where} |                 status = statusFile.read() | ||||||
|  |                 statusFile.close() | ||||||
|  |  | ||||||
|  |                 if status.find("completed[success]")>-1: | ||||||
|  |                     rmtree(removalPath) | ||||||
|  |                     data_ret = {'remoteTransferStatus': 1, 'error_message': "None", "status": status, "complete": 1} | ||||||
|                     json_data = json.dumps(data_ret) |                     json_data = json.dumps(data_ret) | ||||||
|                     return HttpResponse(json_data) |                     return HttpResponse(json_data) | ||||||
|                 else: |                 else: | ||||||
|  |                     data_ret = {'remoteTransferStatus': 1, 'error_message': "None", "status": status, "complete": 0} | ||||||
|                     data_ret = {'remoteRestoreStatus': 1, "complete":0, 'error_message': "Backup In Progress","logs":data,"where":where} |  | ||||||
|                     json_data = json.dumps(data_ret) |                     json_data = json.dumps(data_ret) | ||||||
|                     return HttpResponse(json_data) |                     return HttpResponse(json_data) | ||||||
|  |  | ||||||
|             else: |             else: | ||||||
|                 data_ret = {'remoteRestoreStatus': 0, "complete":0, 'error_message': "Invalid Credentials"} |                 data_ret = {'remoteTransferStatus': 0, 'error_message': "No such log found","status":"None","complete":0} | ||||||
|                 json_data = json.dumps(data_ret) |                 json_data = json.dumps(data_ret) | ||||||
|                 return HttpResponse(json_data) |                 return HttpResponse(json_data) | ||||||
|  |  | ||||||
|  |  | ||||||
|     except BaseException, msg: |     except BaseException, msg: | ||||||
|         data = {'remoteRestoreStatus': 0, "complete":0, 'error_message': str(msg)} |         data = {'remoteTransferStatus': 0,'error_message': str(msg),"status":"None","complete":0} | ||||||
|         json_data = json.dumps(data) |         json_data = json.dumps(data) | ||||||
|         return HttpResponse(json_data) |         return HttpResponse(json_data) | ||||||
|  |  | ||||||
|  | def cancelRemoteBackup(request): | ||||||
|  |     try: | ||||||
|  |  | ||||||
|  |         if request.method == "POST": | ||||||
|  |  | ||||||
|  |             data = json.loads(request.body) | ||||||
|  |             ipAddress = data['ipAddress'] | ||||||
|  |             password = data['password'] | ||||||
|  |             dir = data['dir'] | ||||||
|  |             username = "admin" | ||||||
|  |  | ||||||
|  |  | ||||||
|  |             finalData = json.dumps({'dir': dir, "username":username,"password":password}) | ||||||
|  |             r = requests.post("https://"+ipAddress+":8090/api/cancelRemoteTransfer", data=finalData) | ||||||
|  |  | ||||||
|  |             data = json.loads(r.text) | ||||||
|  |  | ||||||
|  |             if data['cancelStatus'] == 1: | ||||||
|  |                 pass | ||||||
|  |             else: | ||||||
|  |                 logging.CyberCPLogFileWriter.writeToFile("Some error cancelling at remote server, see the log file for remote server.") | ||||||
|  |  | ||||||
|  |             path = "/home/backup/transfer-" + str(dir) | ||||||
|  |  | ||||||
|  |             if os.path.exists(path): | ||||||
|  |                 try: | ||||||
|  |                     pathpid = path + "/pid" | ||||||
|  |  | ||||||
|  |                     pid = open(pathpid, "r").readlines()[0] | ||||||
|  |  | ||||||
|  |                     try: | ||||||
|  |                         os.kill(int(pid), signal.SIGKILL) | ||||||
|  |                     except BaseException, msg: | ||||||
|  |                         logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [cancelRemoteBackup]") | ||||||
|  |  | ||||||
|  |                     rmtree(path) | ||||||
|  |                 except: | ||||||
|  |                     rmtree(path) | ||||||
|  |  | ||||||
|  |                 data = {'cancelStatus': 1, 'error_message': "None"} | ||||||
|  |                 json_data = json.dumps(data) | ||||||
|  |                 return HttpResponse(json_data) | ||||||
|  |             else: | ||||||
|  |                 data = {'cancelStatus': 1, 'error_message': "None"} | ||||||
|  |                 json_data = json.dumps(data) | ||||||
|  |                 return HttpResponse(json_data) | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     except BaseException, msg: | ||||||
|  |         data = {'cancelStatus': 0, 'error_message': str(msg)} | ||||||
|  |         json_data = json.dumps(data) | ||||||
|  |         return HttpResponse(json_data) | ||||||
|   | |||||||
										
											Binary file not shown.
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -127,6 +127,9 @@ def issueSSL(request): | |||||||
|                     website.ssl = 1 |                     website.ssl = 1 | ||||||
|                     website.save() |                     website.save() | ||||||
|  |  | ||||||
|  |                     sslUtilities.installSSLForDomain(virtualHost) | ||||||
|  |                     installUtilities.reStartLiteSpeed() | ||||||
|  |  | ||||||
|                     data_ret = {"SSL": 1, |                     data_ret = {"SSL": 1, | ||||||
|                                 'error_message': "None"} |                                 'error_message': "None"} | ||||||
|                     json_data = json.dumps(data_ret) |                     json_data = json.dumps(data_ret) | ||||||
|   | |||||||
| @@ -1,6 +0,0 @@ | |||||||
| from django.utils.translation import LANGUAGE_SESSION_KEY |  | ||||||
|  |  | ||||||
| class SetLanguage(object): |  | ||||||
|     def setUserLanguage(self,request,exception): |  | ||||||
|         request.session[LANGUAGE_SESSION_KEY] = "pt-pt" |  | ||||||
|         return "Hello" |  | ||||||
| @@ -76,18 +76,24 @@ class backupUtilities: | |||||||
|             p.start() |             p.start() | ||||||
|             pid = open(backupPath + 'pid', "w") |             pid = open(backupPath + 'pid', "w") | ||||||
|             pid.write(str(p.pid)) |             pid.write(str(p.pid)) | ||||||
|  |  | ||||||
|             pid.close() |             pid.close() | ||||||
|         except BaseException,msg: |         except BaseException,msg: | ||||||
|             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateBackup]") |             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateBackup]") | ||||||
|  |  | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def startRestore(backupName, backupNames): |     def startRestore(backupName, dir): | ||||||
|         try: |         try: | ||||||
|             backupFileName = backupName.strip(".tar.gz") |  | ||||||
|  |  | ||||||
|             completPath = "/home/backup/" + backupFileName |             if dir == None: | ||||||
|             originalFile = "/home/backup/" + backupName |                 backupFileName = backupName.strip(".tar.gz") | ||||||
|  |                 completPath = "/home/backup/" + backupFileName ## without extension | ||||||
|  |                 originalFile = "/home/backup/" + backupName ## with extension | ||||||
|  |             else: | ||||||
|  |                 backupFileName = backupName.strip(".tar.gz") | ||||||
|  |                 completPath = "/home/backup/transfer-"+str(dir)+"/"+backupFileName ## without extension | ||||||
|  |                 originalFile = "/home/backup/transfer-"+str(dir)+"/"+backupName ## with extension | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|             pathToCompressedHome = completPath + "/public_html.tar.gz" |             pathToCompressedHome = completPath + "/public_html.tar.gz" | ||||||
|  |  | ||||||
| @@ -115,7 +121,7 @@ class backupUtilities: | |||||||
|             ## creating website and its dabases |             ## creating website and its dabases | ||||||
|  |  | ||||||
|             try: |             try: | ||||||
|                 finalData = json.dumps({'backupFile': backupName}) |                 finalData = json.dumps({'backupFile': backupName,"dir":dir}) | ||||||
|                 r = requests.post("http://localhost:5003/websites/CreateWebsiteFromBackup", data=finalData) |                 r = requests.post("http://localhost:5003/websites/CreateWebsiteFromBackup", data=finalData) | ||||||
|                 data = json.loads(r.text) |                 data = json.loads(r.text) | ||||||
|  |  | ||||||
| @@ -183,9 +189,9 @@ class backupUtilities: | |||||||
|             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]") |             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]") | ||||||
|  |  | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def initiateRestore(backupName): |     def initiateRestore(backupName,dir): | ||||||
|         try: |         try: | ||||||
|             p = Process(target=backupUtilities.startRestore, args=(backupName, backupName,)) |             p = Process(target=backupUtilities.startRestore, args=(backupName, dir,)) | ||||||
|             p.start() |             p.start() | ||||||
|         except BaseException, msg: |         except BaseException, msg: | ||||||
|             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateRestore]") |             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateRestore]") | ||||||
| @@ -379,17 +385,16 @@ class backupUtilities: | |||||||
|             verifyHostKey.sendline("yes") |             verifyHostKey.sendline("yes") | ||||||
|  |  | ||||||
|         except pexpect.TIMEOUT, msg: |         except pexpect.TIMEOUT, msg: | ||||||
|             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [verifyHostKey]") |             logging.CyberCPLogFileWriter.writeToFile("Timeout [verifyHostKey]") | ||||||
|             return 0 |             return 0 | ||||||
|         except pexpect.EOF, msg: |         except pexpect.EOF, msg: | ||||||
|             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [verifyHostKey]") |             logging.CyberCPLogFileWriter.writeToFile("EOF [verifyHostKey]") | ||||||
|             return 0 |             return 0 | ||||||
|         except BaseException, msg: |         except BaseException, msg: | ||||||
|             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [verifyHostKey]") |             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [verifyHostKey]") | ||||||
|             return 0 |             return 0 | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def createBackupDir(IPAddress,IPAddressA): |     def createBackupDir(IPAddress,IPAddressA): | ||||||
|  |  | ||||||
|   | |||||||
| @@ -15,6 +15,8 @@ from websiteFunctions.models import Websites | |||||||
| from plogical.virtualHostUtilities import virtualHostUtilities | from plogical.virtualHostUtilities import virtualHostUtilities | ||||||
| from plogical.installUtilities import installUtilities | from plogical.installUtilities import installUtilities | ||||||
| from plogical.mysqlUtilities import mysqlUtilities | from plogical.mysqlUtilities import mysqlUtilities | ||||||
|  | from multiprocessing import Process | ||||||
|  | from shutil import move,rmtree | ||||||
|  |  | ||||||
| class remoteBackup: | class remoteBackup: | ||||||
|  |  | ||||||
| @@ -37,7 +39,7 @@ class remoteBackup: | |||||||
|             return [0, msg] |             return [0, msg] | ||||||
|  |  | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def startRestore(backupName, backupDir, admin, backupLogPath): |     def startRestoreTemp(backupName, backupDir, admin, backupLogPath): | ||||||
|         try: |         try: | ||||||
|             adminEmail = admin.email |             adminEmail = admin.email | ||||||
|  |  | ||||||
| @@ -189,13 +191,95 @@ class remoteBackup: | |||||||
|             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]") |             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]") | ||||||
|  |  | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def initiateRestore(backupDir, admin, backupLogPath): |     def startRestore(backupDir,backupLogPath,dir): | ||||||
|         try: |         try: | ||||||
|             ext = ".tar.gz" |             ext = ".tar.gz" | ||||||
|  |  | ||||||
|             for backup in os.listdir(backupDir): |             for backup in os.listdir(backupDir): | ||||||
|  |  | ||||||
|  |                 writeToFile = open(backupLogPath, "a") | ||||||
|  |  | ||||||
|  |                 writeToFile.writelines("\n") | ||||||
|  |                 writeToFile.writelines("\n") | ||||||
|  |                 writeToFile.writelines("[" + time.strftime( | ||||||
|  |                     "%I-%M-%S-%a-%b-%Y") + "]" + " Starting restore for: "+backup+".\n") | ||||||
|  |  | ||||||
|  |                 writeToFile.close() | ||||||
|  |  | ||||||
|                 if backup.endswith(ext): |                 if backup.endswith(ext): | ||||||
|                     remoteBackup.startRestore(backup, backupDir, admin, backupLogPath) |                     finalData = json.dumps({'backupFile': backup,"dir":dir}) | ||||||
|             installUtilities.reStartLiteSpeed() |                     r = requests.post("http://localhost:5003/backup/submitRestore", data=finalData) | ||||||
|  |                     data = json.loads(r.text) | ||||||
|  |  | ||||||
|  |                     logging.CyberCPLogFileWriter.writeToFile(r.text) | ||||||
|  |  | ||||||
|  |                     if data['restoreStatus'] == 1: | ||||||
|  |  | ||||||
|  |                         while (1): | ||||||
|  |                             finalData = json.dumps({'backupFile': backup, "dir": dir}) | ||||||
|  |                             r = requests.post("http://localhost:5003/backup/restoreStatus", data=finalData) | ||||||
|  |                             data = json.loads(r.text) | ||||||
|  |  | ||||||
|  |                             logging.CyberCPLogFileWriter.writeToFile(r.text) | ||||||
|  |  | ||||||
|  |                             if data['status'] == "Done": | ||||||
|  |                                 writeToFile = open(backupLogPath, "a") | ||||||
|  |                                 writeToFile.writelines("\n") | ||||||
|  |                                 writeToFile.writelines("\n") | ||||||
|  |                                 writeToFile.writelines("[" + time.strftime( | ||||||
|  |                                     "%I-%M-%S-%a-%b-%Y") + "]" + " Restore Completed.\n") | ||||||
|  |                                 writeToFile.writelines("[" + time.strftime( | ||||||
|  |                                     "%I-%M-%S-%a-%b-%Y") + "]" + " #########################################\n") | ||||||
|  |                                 writeToFile.close() | ||||||
|  |                                 break | ||||||
|  |                             elif data['status'] == "Website already exists": | ||||||
|  |                                 writeToFile = open(backupLogPath, "a") | ||||||
|  |                                 writeToFile.writelines("\n") | ||||||
|  |                                 writeToFile.writelines("\n") | ||||||
|  |                                 writeToFile.writelines("[" + time.strftime( | ||||||
|  |                                     "%I-%M-%S-%a-%b-%Y") + "]" + " Website associated with this backup already exists.\n") | ||||||
|  |                                 writeToFile.writelines("[" + time.strftime( | ||||||
|  |                                     "%I-%M-%S-%a-%b-%Y") + "]" + " #########################################\n") | ||||||
|  |                                 writeToFile.close() | ||||||
|  |                                 logging.CyberCPLogFileWriter.writeToFile( | ||||||
|  |                                     "Website associated with this backup already exists") | ||||||
|  |                                 break | ||||||
|  |                             elif data['status'] == 0: | ||||||
|  |                                 time.sleep(2) | ||||||
|  |  | ||||||
|  |                                 writeToFile = open(backupLogPath, "a") | ||||||
|  |                                 writeToFile.writelines("\n") | ||||||
|  |                                 writeToFile.writelines("\n") | ||||||
|  |                                 writeToFile.writelines("[" + time.strftime( | ||||||
|  |                                     "%I-%M-%S-%a-%b-%Y") + "]" + " Waiting for restore to complete.\n") | ||||||
|  |                                 writeToFile.close() | ||||||
|  |  | ||||||
|  |                                 pass | ||||||
|  |                             elif data['status'] == "Not able to create Account and databases, aborting.": | ||||||
|  |                                 writeToFile = open(backupLogPath, "a") | ||||||
|  |                                 writeToFile.writelines("\n") | ||||||
|  |                                 writeToFile.writelines("\n") | ||||||
|  |                                 writeToFile.writelines("[" + time.strftime( | ||||||
|  |                                     "%I-%M-%S-%a-%b-%Y") + "]" + " Not able to create Account and databases, aborting.\n") | ||||||
|  |                                 writeToFile.writelines("[" + time.strftime( | ||||||
|  |                                     "%I-%M-%S-%a-%b-%Y") + "]" + " #########################################\n") | ||||||
|  |                                 writeToFile.close() | ||||||
|  |                                 logging.CyberCPLogFileWriter.writeToFile( | ||||||
|  |                                     "Not able to create Account and databases, aborting.") | ||||||
|  |                                 break | ||||||
|  |                             else: | ||||||
|  |                                 time.sleep(3) | ||||||
|  |  | ||||||
|  |                                 writeToFile = open(backupLogPath, "a") | ||||||
|  |                                 writeToFile.writelines("\n") | ||||||
|  |                                 writeToFile.writelines("\n") | ||||||
|  |                                 writeToFile.writelines("[" + time.strftime( | ||||||
|  |                                     "%I-%M-%S-%a-%b-%Y") + "]" + " Waiting for restore to complete.\n") | ||||||
|  |                                 writeToFile.close() | ||||||
|  |  | ||||||
|  |                                 pass | ||||||
|  |                     else: | ||||||
|  |                         logging.CyberCPLogFileWriter.writeToFile("Could not start restore process for: "+backup) | ||||||
|  |  | ||||||
|             writeToFile = open(backupLogPath, "a") |             writeToFile = open(backupLogPath, "a") | ||||||
|  |  | ||||||
| @@ -210,8 +294,12 @@ class remoteBackup: | |||||||
|             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateRestore]") |             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateRestore]") | ||||||
|  |  | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def remoteRestore(backupDir, admin): |     def remoteRestore(backupDir, dir): | ||||||
|         try: |         try: | ||||||
|  |  | ||||||
|  |             ## dir is transfer-### | ||||||
|  |             # backupDir is /home/backup/transfer-### | ||||||
|  |  | ||||||
|             backupLogPath = backupDir + "/backup_log" |             backupLogPath = backupDir + "/backup_log" | ||||||
|  |  | ||||||
|             writeToFile = open(backupLogPath, "a+") |             writeToFile = open(backupLogPath, "a+") | ||||||
| @@ -224,6 +312,7 @@ class remoteBackup: | |||||||
|             writeToFile.writelines("############################\n") |             writeToFile.writelines("############################\n") | ||||||
|             writeToFile.writelines("\n") |             writeToFile.writelines("\n") | ||||||
|             writeToFile.writelines("\n") |             writeToFile.writelines("\n") | ||||||
|  |             writeToFile.close() | ||||||
|  |  | ||||||
|             if os.path.exists(backupDir): |             if os.path.exists(backupDir): | ||||||
|                 pass |                 pass | ||||||
| @@ -231,12 +320,17 @@ class remoteBackup: | |||||||
|                 return [0, 'No such directory found'] |                 return [0, 'No such directory found'] | ||||||
|  |  | ||||||
|  |  | ||||||
|             thread.start_new_thread(remoteBackup.initiateRestore, (backupDir, admin, backupLogPath)) |             p = Process(target=remoteBackup.startRestore, args=(backupDir, backupLogPath,dir,)) | ||||||
|  |             p.start() | ||||||
|  |  | ||||||
|             return [1, 'Started'] |             return [1, 'Started'] | ||||||
|  |  | ||||||
|  |             pid = open(destination + '/pid', "w") | ||||||
|  |             pid.write(str(p.pid)) | ||||||
|  |             pid.close() | ||||||
|  |  | ||||||
|         except BaseException, msg: |         except BaseException, msg: | ||||||
|             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [getKey]") |             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [remoteRestore]") | ||||||
|             return [0, msg] |             return [0, msg] | ||||||
|  |  | ||||||
|     @staticmethod |     @staticmethod | ||||||
| @@ -306,27 +400,98 @@ class remoteBackup: | |||||||
|  |  | ||||||
|  |  | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def sendBackup(backupPath, IPAddress, writeToFile, dir): |     def sendBackup(completedPathToSend, IPAddress, folderNumber,writeToFile): | ||||||
|         try: |         try: | ||||||
|             command = 'rsync -avz -e "ssh  -i /root/.ssh/cyberpanel" ' + backupPath + ' root@' + IPAddress + ':' + dir + "/" |             ## complete path is a path to the file need to send | ||||||
|  |  | ||||||
|  |             command = 'rsync -avz -e "ssh  -i /root/.ssh/cyberpanel" ' + completedPathToSend + ' root@' + IPAddress + ':/home/backup/transfer-'+folderNumber | ||||||
|             subprocess.call(shlex.split(command), stdout=writeToFile) |             subprocess.call(shlex.split(command), stdout=writeToFile) | ||||||
|  |  | ||||||
|         except BaseException, msg: |         except BaseException, msg: | ||||||
|             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]") |             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]") | ||||||
|  |  | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def backupProcess(ipAddress, dir, backupLogPath): |     def backupProcess(ipAddress, dir, backupLogPath,folderNumber): | ||||||
|         try: |         try: | ||||||
|  |             ## dir is without forward slash | ||||||
|  |  | ||||||
|             writeToFile = open(backupLogPath, "a") |  | ||||||
|  |  | ||||||
|             for virtualHost in os.listdir("/home"): |             for virtualHost in os.listdir("/home"): | ||||||
|                 remoteBackup.createBackup(virtualHost, ipAddress, writeToFile, dir) |  | ||||||
|  |                 try: | ||||||
|  |  | ||||||
|  |                     if virtualHost == "vmail" or virtualHost == "backup": | ||||||
|  |                         pass | ||||||
|  |  | ||||||
|  |                     writeToFile = open(backupLogPath, "a") | ||||||
|  |                     writeToFile.writelines("[" + time.strftime( | ||||||
|  |                         "%I-%M-%S-%a-%b-%Y") + "]" + " Currently generating local backups for: " + virtualHost + "\n") | ||||||
|  |                     writeToFile.close() | ||||||
|  |  | ||||||
|  |  | ||||||
|  |                     finalData = json.dumps({'websiteToBeBacked': virtualHost}) | ||||||
|  |                     r = requests.post("http://localhost:5003/backup/submitBackupCreation", data=finalData) | ||||||
|  |  | ||||||
|  |                     data = json.loads(r.text) | ||||||
|  |  | ||||||
|  |                     fileName = data['tempStorage']+".tar.gz" | ||||||
|  |  | ||||||
|  |                     completePathToBackupFile = fileName | ||||||
|  |  | ||||||
|  |  | ||||||
|  |                     while (1): | ||||||
|  |                         r = requests.post("http://localhost:5003/backup/backupStatus", data= finalData) | ||||||
|  |                         time.sleep(2) | ||||||
|  |                         data = json.loads(r.text) | ||||||
|  |  | ||||||
|  |                         writeToFile = open(backupLogPath, "a") | ||||||
|  |  | ||||||
|  |                         writeToFile.writelines("[" + time.strftime( | ||||||
|  |                             "%I-%M-%S-%a-%b-%Y") + "]" + " Waiting for backup to complete.. " + "\n") | ||||||
|  |  | ||||||
|  |                         writeToFile.close() | ||||||
|  |  | ||||||
|  |  | ||||||
|  |                         if data['status'] == 0: | ||||||
|  |  | ||||||
|  |                             writeToFile = open(backupLogPath, "a") | ||||||
|  |  | ||||||
|  |                             writeToFile.writelines("[" + time.strftime( | ||||||
|  |                                 "%I-%M-%S-%a-%b-%Y") + "]" + " Local Backup Completed for: " +virtualHost + "\n") | ||||||
|  |  | ||||||
|  |  | ||||||
|  |                             ## move the generated backup file to specified destination | ||||||
|  |  | ||||||
|  |                             if os.path.exists(completePathToBackupFile): | ||||||
|  |                                 move(completePathToBackupFile,dir) | ||||||
|  |  | ||||||
|  |                             completedPathToSend = dir +"/" + completePathToBackupFile.split("/")[-1] | ||||||
|  |  | ||||||
|  |                             writeToFile.writelines("[" + time.strftime( | ||||||
|  |                                 "%I-%M-%S-%a-%b-%Y") + "]" + " Sending " + completedPathToSend +" to "+ipAddress +".\n") | ||||||
|  |  | ||||||
|  |  | ||||||
|  |                             remoteBackup.sendBackup(completedPathToSend,ipAddress,str(folderNumber),writeToFile) | ||||||
|  |  | ||||||
|  |                             writeToFile.writelines("[" + time.strftime( | ||||||
|  |                                 "%I-%M-%S-%a-%b-%Y") + "]" + " #############################################" + "\n") | ||||||
|  |  | ||||||
|  |                             writeToFile.close() | ||||||
|  |                             break | ||||||
|  |                 except: | ||||||
|  |                     pass | ||||||
|  |  | ||||||
|  |             writeToFile = open(backupLogPath, "a") | ||||||
|             writeToFile.writelines("[" + time.strftime( |             writeToFile.writelines("[" + time.strftime( | ||||||
|                 "%I-%M-%S-%a-%b-%Y") + "]" + " Remote Backup Complete" + "\n") |                 "%I-%M-%S-%a-%b-%Y") + "]" + " Backups are successfully generated and received on: " + ipAddress + "\n") | ||||||
|             writeToFile.writelines("completed[success]\n") |             writeToFile.close() | ||||||
|  |  | ||||||
|  |             ## removing local directory where backups were generated | ||||||
|  |             time.sleep(5) | ||||||
|  |             rmtree(dir) | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         except BaseException, msg: |         except BaseException, msg: | ||||||
|             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [backupProcess]") |             logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [backupProcess]") | ||||||
| @@ -350,6 +515,8 @@ class remoteBackup: | |||||||
|             writeToFile.writelines("\n") |             writeToFile.writelines("\n") | ||||||
|             writeToFile.writelines("\n") |             writeToFile.writelines("\n") | ||||||
|  |  | ||||||
|  |             writeToFile.close() | ||||||
|  |  | ||||||
|             ## fix yes/no |             ## fix yes/no | ||||||
|  |  | ||||||
|             backupUtil.backupUtilities.verifyHostKey(ipAddress) |             backupUtil.backupUtilities.verifyHostKey(ipAddress) | ||||||
| @@ -368,7 +535,12 @@ class remoteBackup: | |||||||
|                 return [0, "Host is down"] |                 return [0, "Host is down"] | ||||||
|  |  | ||||||
|  |  | ||||||
|             thread.start_new_thread(remoteBackup.backupProcess, (ipAddress, destination, backupLogPath)) |             p = Process(target=remoteBackup.backupProcess, args=(ipAddress, destination, backupLogPath,dir,)) | ||||||
|  |             p.start() | ||||||
|  |  | ||||||
|  |             pid = open(destination + '/pid', "w") | ||||||
|  |             pid.write(str(p.pid)) | ||||||
|  |             pid.close() | ||||||
|  |  | ||||||
|             return [1, None] |             return [1, None] | ||||||
|  |  | ||||||
|   | |||||||
| @@ -55,6 +55,7 @@ class sslUtilities: | |||||||
|                 data = open("/usr/local/lsws/conf/httpd_config.conf").readlines() |                 data = open("/usr/local/lsws/conf/httpd_config.conf").readlines() | ||||||
|                 writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf", 'w') |                 writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf", 'w') | ||||||
|                 sslCheck = 0 |                 sslCheck = 0 | ||||||
|  |  | ||||||
|                 for items in data: |                 for items in data: | ||||||
|                     if (items.find("listener SSL")>-1): |                     if (items.find("listener SSL")>-1): | ||||||
|                         sslCheck = 1 |                         sslCheck = 1 | ||||||
|   | |||||||
| @@ -1268,6 +1268,14 @@ def CreateWebsiteFromBackup(request): | |||||||
|             data = json.loads(request.body) |             data = json.loads(request.body) | ||||||
|             backupFile = data['backupFile'].strip(".tar.gz") |             backupFile = data['backupFile'].strip(".tar.gz") | ||||||
|  |  | ||||||
|  |             originalFile = "/home/backup/" + data['backupFile'] | ||||||
|  |  | ||||||
|  |             if not os.path.exists(originalFile): | ||||||
|  |                 dir = data['dir'] | ||||||
|  |                 path = "/home/backup/transfer-"+str(dir)+"/"+backupFile | ||||||
|  |             else: | ||||||
|  |                 path = "/home/backup/" + backupFile | ||||||
|  |  | ||||||
|             admin = Administrator.objects.get(pk=1) |             admin = Administrator.objects.get(pk=1) | ||||||
|             websiteOwner = admin.userName |             websiteOwner = admin.userName | ||||||
|  |  | ||||||
| @@ -1276,7 +1284,6 @@ def CreateWebsiteFromBackup(request): | |||||||
|  |  | ||||||
|             ## open meta file to read data |             ## open meta file to read data | ||||||
|  |  | ||||||
|             path = "/home/backup/" + backupFile |  | ||||||
|  |  | ||||||
|             data = open(path + "/meta", 'r').readlines() |             data = open(path + "/meta", 'r').readlines() | ||||||
|             domain = data[0].strip('\n') |             domain = data[0].strip('\n') | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user