From 3028dc5f604c67aceffed3e68fb1a20a53e3c00d Mon Sep 17 00:00:00 2001 From: usmannasir <01-134132-158@student.bahria.edu.pk> Date: Sun, 5 Nov 2017 21:07:12 +0500 Subject: [PATCH] Changes to backup engine and security improvments. --- backup/static/backup/backup.js | 1 + .../templates/backup/backupDestinations.html | 9 +- backup/views.py | 57 ++++--- .../baseTemplate/custom-js/system-status.js | 3 + .../templates/baseTemplate/index.html | 6 +- baseTemplate/views.py | 9 +- firewall/views.py | 16 +- install/install.py | 48 +++++- plogical/backupSchedule.py | 32 ++-- plogical/backupUtilities.py | 155 ++++++------------ plogical/mysqlUtilities.py | 106 ++++++------ static/backup/backup.js | 1 + .../themes/frontend/color-schemes/default.css | 81 ++++++++- .../baseTemplate/custom-js/system-status.js | 3 + 14 files changed, 308 insertions(+), 219 deletions(-) diff --git a/backup/static/backup/backup.js b/backup/static/backup/backup.js index cf81eb4bd..f0b47e5c5 100644 --- a/backup/static/backup/backup.js +++ b/backup/static/backup/backup.js @@ -527,6 +527,7 @@ app.controller('backupDestinations', function($scope,$http,$timeout) { var data = { IPAddress : $scope.IPAddress, password : $scope.password, + backupSSHPort:$scope.backupSSHPort, }; var config = { diff --git a/backup/templates/backup/backupDestinations.html b/backup/templates/backup/backupDestinations.html index dfe398c79..4f219637c 100644 --- a/backup/templates/backup/backupDestinations.html +++ b/backup/templates/backup/backupDestinations.html @@ -37,7 +37,14 @@
- + +
+
+ +
+ +
+
diff --git a/backup/views.py b/backup/views.py index b7605ca85..f8eb792e4 100644 --- a/backup/views.py +++ b/backup/views.py @@ -513,6 +513,13 @@ def submitDestinationCreation(request): ipAddress = data['IPAddress'] password = data['password'] + port = "22" + + try: + port = data['backupSSHPort'] + except: + pass + if dest.objects.all().count() == 2: final_dic = {'destStatus': 0, 'error_message': "Currently only one remote destination is allowed."} final_json = json.dumps(final_dic) @@ -527,44 +534,36 @@ def submitDestinationCreation(request): except: - keyPath = "/home/cyberpanel/.ssh" - if not os.path.exists(keyPath): - os.makedirs(keyPath) - command = "ssh-keygen -f "+keyPath+"/cyberpanel -t rsa -N ''" - cmd = shlex.split(command) - res = subprocess.call(cmd) + setupKeys = backupUtil.backupUtilities.setupSSHKeys(ipAddress,password,port) - pubKey = keyPath+"/cyberpanel.pub" - - f = open(pubKey) - data = f.read() - - finalData = json.dumps({'username': "admin", "password": password,"putSSHKey":data}) - - url = "https://" + ipAddress + ":8090/api/putSSHkey" - - r = requests.post(url, data=finalData, verify=False) - - data = json.loads(r.text) - - if data['putSSHKey'] == 1: - - newDest = dest(destLoc=ipAddress) - newDest.save() - - writeToFile = open(destinations, "w") - writeToFile.writelines(ipAddress + "\n") - writeToFile.close() + if setupKeys[0] == 1: - backupUtil.backupUtilities.initiateBackupDirCreation(ipAddress) + + backupUtil.backupUtilities.initiateBackupDirCreation(ipAddress,port) + + try: + writeToFile = open(destinations, "w") + writeToFile.writelines(ipAddress + "\n") + writeToFile.writelines(data['backupSSHPort'] + "\n") + writeToFile.close() + newDest = dest(destLoc=ipAddress) + newDest.save() + except: + writeToFile = open(destinations, "w") + writeToFile.writelines(ipAddress + "\n") + writeToFile.writelines("22"+"\n") + writeToFile.close() + newDest = dest(destLoc=ipAddress) + newDest.save() + final_dic = {'destStatus': 1, 'error_message': "None"} final_json = json.dumps(final_dic) return HttpResponse(final_json) else: - final_dic = {'destStatus': 0, 'error_message': data['error_message']} + final_dic = {'destStatus': 0, 'error_message': setupKeys[1]} final_json = json.dumps(final_dic) return HttpResponse(final_json) diff --git a/baseTemplate/static/baseTemplate/custom-js/system-status.js b/baseTemplate/static/baseTemplate/custom-js/system-status.js index b68fdf590..119160194 100644 --- a/baseTemplate/static/baseTemplate/custom-js/system-status.js +++ b/baseTemplate/static/baseTemplate/custom-js/system-status.js @@ -99,6 +99,9 @@ app.controller('adminController', function($scope,$http,$timeout) { $scope.currentAdmin = response.data.user_name; $scope.admin_type = response.data.admin_type; + + $("#serverIPAddress").text(response.data.serverIPAddress); + if (response.data.admin_type != "Administrator") { diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index 360e8402f..2cbd85a4e 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -410,11 +410,15 @@