diff --git a/api/views.py b/api/views.py index e4cfb0393..1cabe9cc1 100644 --- a/api/views.py +++ b/api/views.py @@ -364,18 +364,22 @@ def fetchSSHkey(request): if hashPassword.check_password(admin.password, password): - keyPath = os.path.join("/root",".ssh") - pubKey = keyPath + "/cyberpanel.pub" - + pubKey = os.path.join("/root",".ssh",'cyberpanel.pub') execPath = "sudo cat " + pubKey - data = subprocess.check_output(shlex.split(execPath)) - data_ret = {'pubKeyStatus': 1, 'error_message': "None", "pubKey":data} + data_ret = { + 'pubKeyStatus': 1, + 'error_message': "None", + 'pubKey':data + } json_data = json.dumps(data_ret) return HttpResponse(json_data) else: - data_ret = {'pubKeyStatus': 0, 'error_message': "Invalid Credentials"} + data_ret = { + 'pubKeyStatus': 0, + 'error_message': "Could not authorize access to API." + } json_data = json.dumps(data_ret) return HttpResponse(json_data) @@ -546,7 +550,6 @@ def cancelRemoteTransfer(request): json_data = json.dumps(data) return HttpResponse(json_data) - def cyberPanelVersion(request): try: if request.method == 'POST': @@ -563,22 +566,28 @@ def cyberPanelVersion(request): Version = version.objects.get(pk=1) - data_ret = {"getVersion": 1, - 'error_message': "Could not authorize access to API", + data_ret = { + "getVersion": 1, + 'error_message': "none", 'currentVersion':Version.currentVersion, - 'build':Version.build} + 'build':Version.build + } json_data = json.dumps(data_ret) return HttpResponse(json_data) else: - data_ret = {"getVersion": 0, - 'error_message': "Could not authorize access to API"} + data_ret = { + "getVersion": 0, + 'error_message': "Could not authorize access to API." + } json_data = json.dumps(data_ret) return HttpResponse(json_data) except BaseException, msg: - data_ret = {"getVersion": 0, - 'error_message': "Could not authorize access to API"} + data_ret = { + "getVersion": 0, + 'error_message': str(msg) + } json_data = json.dumps(data_ret) return HttpResponse(json_data) diff --git a/backup/static/backup/backup.js b/backup/static/backup/backup.js index 9242635ab..eb78b0fb3 100644 --- a/backup/static/backup/backup.js +++ b/backup/static/backup/backup.js @@ -1074,7 +1074,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { function ListInitialDatas(response) { - if (response.data.status == 1) { + if (response.data.status === 1) { $scope.records = JSON.parse(response.data.data); var parsed = JSON.parse(response.data.data); @@ -1268,7 +1268,10 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { else{ $scope.requestData = response.data.status; $timeout.cancel(); - $scope.backupLoading = true; + + // Start the restore of remote backups that are transferred to local server + + remoteBackupRestore(); } } @@ -1318,7 +1321,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { function ListInitialDatas(response) { - if (response.data.remoteRestoreStatus == 1) { + if (response.data.remoteRestoreStatus === 1) { localRestoreStatus(); } } @@ -1330,6 +1333,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { $scope.errorMessage = true; $scope.accountsFetched = true; $scope.notificationsBox = false; + $scope.backupLoading = true; } /////////////// @@ -1357,9 +1361,9 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) { function ListInitialDatas(response) { - if (response.data.remoteTransferStatus == 1) { + if (response.data.remoteTransferStatus === 1) { - if(response.data.complete == 0){ + if(response.data.complete === 0){ $scope.backupStatus = false; $scope.restoreData = response.data.status; $timeout(localRestoreStatus, 2000); diff --git a/backup/views.py b/backup/views.py index 47efc802e..85e30391d 100644 --- a/backup/views.py +++ b/backup/views.py @@ -1189,7 +1189,6 @@ def scheduleDelete(request): final_json = json.dumps({'delStatus': 0, 'error_message': str(msg)}) return HttpResponse(final_json) - def remoteBackups(request): try: userID = request.session['userID'] @@ -1211,10 +1210,10 @@ def submitRemoteBackups(request): ipAddress = data['ipAddress'] password = data['password'] - ## ask for remote version + ## Ask for Remote version of CyberPanel try: - finalData = json.dumps({'username': "admin","password": password}) + finalData = json.dumps({'username': "admin", "password": password}) url = "https://" + ipAddress + ":8090/api/cyberPanelVersion" @@ -1222,7 +1221,6 @@ def submitRemoteBackups(request): data = json.loads(r.text) - if data['getVersion'] == 1: Version = version.objects.get(pk=1) @@ -1230,28 +1228,31 @@ def submitRemoteBackups(request): if data['currentVersion'] == Version.currentVersion and data['build'] == Version.build: pass else: - data_ret = {'status': 0, 'error_message': "Your version does not match with version of remote server.", - "dir": "Null" } + data_ret = {'status': 0, + 'error_message': "Your version does not match with version of remote server.", + "dir": "Null"} data_ret = json.dumps(data_ret) return HttpResponse(data_ret) - else: - data_ret = {'status': 0, 'error_message': "Not able to fetch version of remote server. Error Message: "+data['error_message'], "dir": "Null"} + data_ret = {'status': 0, + 'error_message': "Not able to fetch version of remote server. Error Message: " + data[ + 'error_message'], "dir": "Null"} data_ret = json.dumps(data_ret) return HttpResponse(data_ret) - except BaseException,msg: + + + except BaseException, msg: data_ret = {'status': 0, - 'error_message': "Not able to fetch version of remote server. Error Message: " + str(msg), "dir": "Null"} + 'error_message': "Not able to fetch version of remote server. Error Message: " + str(msg), + "dir": "Null"} data_ret = json.dumps(data_ret) return HttpResponse(data_ret) - ## setup ssh key - + ## Fetch public key of remote server! finalData = json.dumps({'username': "admin", "password": password}) - url = "https://" + ipAddress + ":8090/api/fetchSSHkey" r = requests.post(url, data=finalData, verify=False) data = json.loads(r.text) @@ -1259,25 +1260,23 @@ def submitRemoteBackups(request): if data['pubKeyStatus'] == 1: pubKey = data["pubKey"].strip("\n") else: - final_json = json.dumps({'status': 0, 'error_message': "I am sorry, I could not fetch key from remote server. Error Message: "+data['error_message']}) + final_json = json.dumps({'status': 0, + 'error_message': "I am sorry, I could not fetch key from remote server. Error Message: " +data['error_message'] + }) return HttpResponse(final_json) - ## write key - ## + ## Writing key to a temporary location, to be read later by backup process. pathToKey = "/home/cyberpanel/" + str(randint(1000, 9999)) vhost = open(pathToKey, "w") - vhost.write(pubKey) - vhost.close() ## - execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/remoteTransferUtilities.py" execPath = execPath + " writeAuthKey --pathToKey " + pathToKey output = subprocess.check_output(shlex.split(execPath)) @@ -1285,13 +1284,13 @@ def submitRemoteBackups(request): if output.find("1,None") > -1: pass else: - final_json = json.dumps({'status': 0, 'type': 'exception', 'error_message': output}) + final_json = json.dumps({'status': 0, 'error_message': output}) return HttpResponse(final_json) ## try: - finalData = json.dumps({'username': "admin","password": password}) + finalData = json.dumps({'username': "admin", "password": password}) url = "https://" + ipAddress + ":8090/api/fetchAccountsFromRemoteServer" @@ -1299,28 +1298,30 @@ def submitRemoteBackups(request): data = json.loads(r.text) - if data['fetchStatus'] == 1: json_data = data['data'] data_ret = {'status': 1, 'error_message': "None", - "dir": "Null",'data':json_data} + "dir": "Null", 'data': json_data} data_ret = json.dumps(data_ret) return HttpResponse(data_ret) else: - data_ret = {'status': 0, 'error_message': "Not able to fetch accounts from remote server. Error Message: "+data['error_message'], "dir": "Null"} + data_ret = {'status': 0, + 'error_message': "Not able to fetch accounts from remote server. Error Message: " + + data['error_message'], "dir": "Null"} data_ret = json.dumps(data_ret) return HttpResponse(data_ret) - except BaseException,msg: + except BaseException, msg: data_ret = {'status': 0, - 'error_message': "Not able to fetch accounts from remote server. Error Message: " + str(msg), "dir": "Null"} + 'error_message': "Not able to fetch accounts from remote server. Error Message: " + str( + msg), "dir": "Null"} data_ret = json.dumps(data_ret) return HttpResponse(data_ret) else: return HttpResponse("This URL only accepts POST requests") except BaseException, msg: - final_json = json.dumps({'status': 0, 'type':'exception', 'error_message': str(msg)}) - return HttpResponse(final_json) + final_json = json.dumps({'status': 0, 'type': 'exception', 'error_message': str(msg)}) + return HttpResponse(final_json) def starRemoteTransfer(request): try: diff --git a/plogical/backupUtilities.py b/plogical/backupUtilities.py index d7f380188..c2522ae9c 100644 --- a/plogical/backupUtilities.py +++ b/plogical/backupUtilities.py @@ -64,7 +64,10 @@ class backupUtilities: status.write("Backing up email accounts!\n") status.close() - make_archive(os.path.join(tempStoragePath,domainName),'gztar',os.path.join("/home","vmail",domainName)) + try: + make_archive(os.path.join(tempStoragePath,domainName),'gztar',os.path.join("/home","vmail",domainName)) + except: + pass ## Backing up databases databases = backupMetaData.findall('Databases/database') @@ -303,12 +306,16 @@ class backupUtilities: status.write("Extracting email accounts!") status.close() - pathToCompressedEmails = os.path.join(completPath, masterDomain + ".tar.gz") - emailHome = os.path.join("/home","vmail",masterDomain) + try: - tar = tarfile.open(pathToCompressedEmails) - tar.extractall(emailHome) - tar.close() + pathToCompressedEmails = os.path.join(completPath, masterDomain + ".tar.gz") + emailHome = os.path.join("/home","vmail",masterDomain) + + tar = tarfile.open(pathToCompressedEmails) + tar.extractall(emailHome) + tar.close() + except: + pass ## emails extracted diff --git a/plogical/test.py b/plogical/test.py index ebddfac3b..757755ae4 100644 --- a/plogical/test.py +++ b/plogical/test.py @@ -6,7 +6,10 @@ try: mydoc = ElementTree.parse('domain.xml') - print mydoc.find('masterDomain').text + len = 0 + + if len == 0: + raise BaseException("Error occurred!") domains = mydoc.findall('ChildDomains/domain') @@ -32,4 +35,4 @@ try: print os.path.join("/home", "cyberpanel", str(randint(1000, 9999)) + ".xml/", "test") except BaseException,msg: - print "hello" + print str(msg)