From e274e8b829ed6cc6c6eb41b1cd4132570cfb31dd Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sun, 20 Sep 2020 23:00:54 +0500 Subject: [PATCH] optmize naming convention --- backup/backupManager.py | 65 +- backup/static/backup/backup.js | 596 +++++----- .../templates/backup/backupDestinations.html | 11 +- backup/templates/backup/backupSchedule.html | 225 ++-- static/backup/backup.js | 1032 ++++++++--------- 5 files changed, 1002 insertions(+), 927 deletions(-) diff --git a/backup/backupManager.py b/backup/backupManager.py index ac8a5e090..95b05e574 100755 --- a/backup/backupManager.py +++ b/backup/backupManager.py @@ -757,7 +757,7 @@ class BackupManager: return HttpResponse(final_json) else: config = {'type': data['type'], 'path': data['path']} - nd = NormalBackupDests(name='local', config=json.dumps(config)) + nd = NormalBackupDests(name=data['name'], config=json.dumps(config)) nd.save() final_dic = {'status' : 1, 'destStatus': 1, 'error_message': "None"} @@ -786,25 +786,26 @@ class BackupManager: config = json.loads(items.config) - if config['type'] == data['type'] and data['type'] == 'SFTP': - dic = { - 'name': items.name, - 'ip': config['ip'], - 'username': config['username'], - 'path': config['path'], - 'port': config['port'], - } - else: - dic = { - 'name': items.name, - 'path': config['path'], - } + if config['type'] == data['type']: + if config['type'] == 'SFTP': + dic = { + 'name': items.name, + 'ip': config['ip'], + 'username': config['username'], + 'path': config['path'], + 'port': config['port'], + } + else: + dic = { + 'name': items.name, + 'path': config['path'], + } - if checker == 0: - json_data = json_data + json.dumps(dic) - checker = 1 - else: - json_data = json_data + ',' + json.dumps(dic) + if checker == 0: + json_data = json_data + json.dumps(dic) + checker = 1 + else: + json_data = json_data + ',' + json.dumps(dic) json_data = json_data + ']' final_json = json.dumps({'status': 1, 'error_message': "None", "data": json_data}) @@ -854,15 +855,7 @@ class BackupManager: nameOrPath = data['nameOrPath'] type = data['type'] - if type == 'SFTP': - NormalBackupDests.objects.get(name=nameOrPath).delete() - else: - dests = NormalBackupDests.objects.filter(name='local') - for items in dests: - config = json.loads(items.config) - if config['path'] == nameOrPath: - items.delete() - break + NormalBackupDests.objects.get(name=nameOrPath).delete() final_dic = {'status': 1, 'delStatus': 1, 'error_message': "None"} final_json = json.dumps(final_dic) @@ -880,20 +873,14 @@ class BackupManager: if ACLManager.currentContextPermission(currentACL, 'scheDuleBackups') == 0: return ACLManager.loadError() - if dest.objects.all().count() <= 1: - try: - homeDest = dest(destLoc="Home") - homeDest.save() - except: - pass - backups = dest.objects.all() + destinations = NormalBackupDests.objects.all() - destinations = [] + dests = [] - for items in backups: - destinations.append(items.destLoc) + for dest in destinations: + dests.append(dest.name) - return render(request, 'backup/backupSchedule.html', {'destinations': destinations}) + return render(request, 'backup/backupSchedule.html', {'destinations': dests}) except BaseException as msg: return HttpResponse(str(msg)) diff --git a/backup/static/backup/backup.js b/backup/static/backup/backup.js index 67e7cc3ef..9d2d49516 100755 --- a/backup/static/backup/backup.js +++ b/backup/static/backup/backup.js @@ -415,288 +415,6 @@ app.controller('restoreWebsiteControl', function ($scope, $http, $timeout) { //*** Restore site ends here ***/// -///** Schedule Backup ***// - -app.controller('scheduleBackup', function ($scope, $http, $timeout) { - - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = true; - $scope.scheduleBtn = true; - $scope.localPath = true; - - populateCurrentRecords(); - - $scope.scheduleFreqView = function () { - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = false; - $scope.scheduleBtn = true; - - if($scope.backupDest === 'Home'){ - $scope.localPath = false; - }else{ - $scope.localPath = true; - } - - }; - - $scope.scheduleBtnView = function () { - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = false; - $scope.scheduleBtn = false; - - }; - - $scope.addSchedule = function () { - - $scope.scheduleBackupLoading = false; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = false; - $scope.scheduleBtn = false; - - - url = "/backup/submitBackupSchedule"; - - - var data = { - backupDest: $scope.backupDest, - backupFreq: $scope.backupFreq, - localPath: $scope.localPathValue - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.scheduleStatus == 1) { - - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = false; - $scope.couldNotConnect = true; - $scope.scheduleFreq = true; - $scope.scheduleBtn = true; - - - populateCurrentRecords(); - - } - else { - - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = false; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = false; - $scope.scheduleBtn = false; - - $scope.errorMessage = response.data.error_message; - } - } - - function cantLoadInitialDatas(response) { - - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = false; - $scope.scheduleFreq = false; - $scope.scheduleBtn = false; - - } - - }; - - $scope.checkConn = function (ip) { - - $scope.destinationLoading = false; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - - url = "/backup/getConnectionStatus"; - - - var data = { - IPAddress: ip, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.connStatus == 1) { - - $scope.destinationLoading = true; - $scope.connectionFailed = true; - $scope.connectionSuccess = false; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - - $scope.IPAddress = ip; - - } - else { - $scope.destinationLoading = true; - $scope.connectionFailed = false; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - - $scope.errorMessage = response.data.error_message; - $scope.IPAddress = ip; - } - } - - function cantLoadInitialDatas(response) { - $scope.destinationLoading = true; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = false; - } - - }; - - $scope.delSchedule = function (destLoc, frequency) { - - $scope.scheduleBackupLoading = false; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = true; - $scope.scheduleBtn = true; - - - url = "/backup/scheduleDelete"; - - - var data = { - destLoc: destLoc, - frequency: frequency, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.delStatus == 1) { - - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = true; - $scope.scheduleBtn = true; - - - populateCurrentRecords(); - - - } - else { - - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = true; - $scope.scheduleBtn = true; - $scope.errorMessage = response.data.error_message; - } - } - - function cantLoadInitialDatas(response) { - - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = false; - $scope.scheduleFreq = true; - $scope.scheduleBtn = true; - } - - }; - - - function populateCurrentRecords() { - - url = "/backup/getCurrentBackupSchedules"; - - var data = {}; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.fetchStatus == 1) { - - $scope.records = JSON.parse(response.data.data); - - } - } - - function cantLoadInitialDatas(response) { - $scope.couldNotConnect = false; - } - - }; - -}); - -//*** Schedule Backup ***/// - //*** Remote Backup site ****// app.controller('remoteBackupControl', function ($scope, $http, $timeout) { @@ -1755,6 +1473,7 @@ app.controller('backupDestinations', function ($scope, $http) { var data = { type: type, path: $scope.localPath, + name: $scope.name }; } @@ -1851,3 +1570,316 @@ app.controller('backupDestinations', function ($scope, $http) { }); + +// + +app.controller('scheduleBackup', function ($scope, $http) { + + $scope.cyberPanelLoading = true; + $scope.driveHidden = true; + + $scope.currentPage = 1; + $scope.recordsToShow = 10; + + $scope.fetchWebsites = function () { + + $scope.cyberPanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + selectedAccount: $scope.selectedAccount, + page: $scope.currentPage, + recordsToShow: $scope.recordsToShow + }; + + + dataurl = "/backup/fetchgDriveSites"; + + $http.post(dataurl, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + $scope.cyberPanelLoading = true; + if (response.data.status === 1) { + $scope.driveHidden = false; + new PNotify({ + title: 'Success', + text: 'Successfully fetched.', + type: 'success' + }); + $scope.websites = JSON.parse(response.data.websites); + $scope.pagination = response.data.pagination; + $scope.currently = response.data.currently; + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + + + } + + }; + + $scope.addSite = function () { + $scope.cyberPanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var data = { + selectedWebsite: $scope.selectedWebsite, + selectedAccount: $scope.selectedAccount + }; + + dataurl = "/backup/addSitegDrive"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + + function ListInitialData(response) { + $scope.cyberPanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Site successfully added.', + type: 'success' + }); + $scope.fetchWebsites(); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialData(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + + }; + + $scope.deleteAccount = function () { + $scope.cyberPanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var data = { + selectedAccount: $scope.selectedAccount + }; + + dataurl = "/backup/deleteAccountgDrive"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + + function ListInitialData(response) { + $scope.cyberPanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Account successfully deleted.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialData(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + + }; + + $scope.changeFrequency = function () { + $scope.cyberPanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var data = { + selectedAccount: $scope.selectedAccount, + backupFrequency: $scope.backupFrequency + }; + + dataurl = "/backup/changeAccountFrequencygDrive"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + + function ListInitialData(response) { + $scope.cyberPanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Changes successfully applied', + type: 'success' + }); + $scope.fetchWebsites(); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialData(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + + }; + + $scope.deleteSite = function (website) { + $scope.cyberPanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var data = { + selectedAccount: $scope.selectedAccount, + website: website + }; + + dataurl = "/backup/deleteSitegDrive"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + + function ListInitialData(response) { + $scope.cyberPanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Website Deleted.', + type: 'success' + }); + $scope.fetchWebsites(); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialData(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + + }; + + $scope.currentPageLogs = 1; + $scope.recordsToShowLogs = 10; + + $scope.fetchLogs = function () { + + $scope.cyberPanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + selectedAccount: $scope.selectedAccount, + page: $scope.currentPageLogs, + recordsToShow: $scope.recordsToShowLogs + }; + + + dataurl = "/backup/fetchDriveLogs"; + + $http.post(dataurl, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + $scope.cyberPanelLoading = true; + if (response.data.status === 1) { + $scope.driveHidden = false; + new PNotify({ + title: 'Success', + text: 'Successfully fetched.', + type: 'success' + }); + $scope.logs = JSON.parse(response.data.logs); + $scope.paginationLogs = response.data.pagination; + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + + } + + }; + +}); diff --git a/backup/templates/backup/backupDestinations.html b/backup/templates/backup/backupDestinations.html index 8107e5c2f..4a7f24912 100755 --- a/backup/templates/backup/backupDestinations.html +++ b/backup/templates/backup/backupDestinations.html @@ -138,6 +138,13 @@ +
+ +
+ +
+
+
@@ -168,14 +175,16 @@ + + - diff --git a/backup/templates/backup/backupSchedule.html b/backup/templates/backup/backupSchedule.html index 6fb11b5b5..e8b1fbf74 100755 --- a/backup/templates/backup/backupSchedule.html +++ b/backup/templates/backup/backupSchedule.html @@ -1,130 +1,205 @@ {% extends "baseTemplate/index.html" %} {% load i18n %} -{% block title %}{% trans "Schedule Back up - CyberPanel" %} {% endblock %} +{% block title %}{% trans "Schedule Back up - CyberPanel" %}{% endblock %} {% block content %} {% load static %} + {% get_current_language as LANGUAGE_CODE %}
-

{% trans "Schedule Back up" %} - {% trans "Schedule Back up" %} - {% trans "Remote Backups" %}

-

{% trans "On this page you can schedule Back ups to localhost or remote server (If you have added one)." %}

+ title="">{% trans "Remote Backups" %} + +

{% trans "On this page you can schedule Back ups to localhost or remote server (If you have added one)" %}

-
+

- {% trans "Schedule Back up" %} - {% trans "Backup Logs" %} + {% trans "Schedule Back up" %}

-
- {% for items in destinations %} {% endfor %}
+
-
- +
+
- +
+ Currently: {$ currently $}
-
- +
+
- +
+
+
+
+
+ +
{% trans "Name" %} {% trans "Path" %} {% trans "Delete" %}
+
+ + + + + + + + + + + + +
TypeMessage
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+ + + +
+
+
+
+ +
+
- + + + + + + + + + + + + + +
SitesAction
+ +
- - - -
- - -
- -
-

{% trans "Cannot add schedule. Error message:" %} {$ errorMessage $}

-
- -
-

{% trans "Schedule Added" %}

-
- -
-

{% trans "Could not connect to server. Please refresh this page." %}

+
+
+
+
+
+
+
+ +
+
+
-
- -
- - - - - - - - - - - - - - - - - - - -
{% trans "ID" %}{% trans "Destination" %}{% trans "Frequency" %}{% trans "Delete" %}
-
-
- - - - @@ -136,4 +211,4 @@
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/static/backup/backup.js b/static/backup/backup.js index 2533712bd..9d2d49516 100644 --- a/static/backup/backup.js +++ b/static/backup/backup.js @@ -415,536 +415,6 @@ app.controller('restoreWebsiteControl', function ($scope, $http, $timeout) { //*** Restore site ends here ***/// -///** Backup Destination ***// - -app.controller('backupDestinations', function ($scope, $http, $timeout) { - - $scope.destinationLoading = true; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - - populateCurrentRecords(); - - $scope.addDestination = function () { - - $scope.destinationLoading = false; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - - url = "/backup/submitDestinationCreation"; - - - var data = { - IPAddress: $scope.IPAddress, - password: $scope.password, - user: $scope.user, - backupSSHPort: $scope.backupSSHPort, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.destStatus == 1) { - - $scope.destinationLoading = true; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = false; - $scope.couldNotConnect = true; - - populateCurrentRecords(); - - } - else { - $scope.destinationLoading = true; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = false; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - - $scope.errorMessage = response.data.error_message; - } - } - - function cantLoadInitialDatas(response) { - $scope.destinationLoading = true; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = false; - } - - }; - - $scope.checkConn = function (ip) { - - $scope.destinationLoading = false; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - - url = "/backup/getConnectionStatus"; - - - var data = { - IPAddress: ip, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.connStatus == 1) { - - $scope.destinationLoading = true; - $scope.connectionFailed = true; - $scope.connectionSuccess = false; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - - $scope.IPAddress = ip; - - } - else { - $scope.destinationLoading = true; - $scope.connectionFailed = false; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - - $scope.errorMessage = response.data.error_message; - $scope.IPAddress = ip; - } - } - - function cantLoadInitialDatas(response) { - $scope.destinationLoading = true; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = false; - } - - }; - - $scope.delDest = function (ip) { - - $scope.destinationLoading = false; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - - url = "/backup/deleteDestination"; - - - var data = { - IPAddress: ip, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.delStatus == 1) { - - $scope.destinationLoading = true; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - populateCurrentRecords(); - - $scope.IPAddress = ip; - - } - else { - $scope.destinationLoading = true; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - - $scope.errorMessage = response.data.error_message; - $scope.IPAddress = ip; - } - } - - function cantLoadInitialDatas(response) { - $scope.destinationLoading = true; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = false; - } - - }; - - - function populateCurrentRecords() { - - url = "/backup/getCurrentBackupDestinations"; - - var data = {}; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.fetchStatus == 1) { - - $scope.records = JSON.parse(response.data.data); - - } - } - - function cantLoadInitialDatas(response) { - $scope.couldNotConnect = false; - } - - }; - -}); - -//*** Backup destination ***/// - -///** Schedule Backup ***// - -app.controller('scheduleBackup', function ($scope, $http, $timeout) { - - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = true; - $scope.scheduleBtn = true; - $scope.localPath = true; - - populateCurrentRecords(); - - $scope.scheduleFreqView = function () { - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = false; - $scope.scheduleBtn = true; - - if($scope.backupDest === 'Home'){ - $scope.localPath = false; - }else{ - $scope.localPath = true; - } - - }; - - $scope.scheduleBtnView = function () { - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = false; - $scope.scheduleBtn = false; - - }; - - $scope.addSchedule = function () { - - $scope.scheduleBackupLoading = false; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = false; - $scope.scheduleBtn = false; - - - url = "/backup/submitBackupSchedule"; - - - var data = { - backupDest: $scope.backupDest, - backupFreq: $scope.backupFreq, - localPath: $scope.localPathValue - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.scheduleStatus == 1) { - - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = false; - $scope.couldNotConnect = true; - $scope.scheduleFreq = true; - $scope.scheduleBtn = true; - - - populateCurrentRecords(); - - } - else { - - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = false; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = false; - $scope.scheduleBtn = false; - - $scope.errorMessage = response.data.error_message; - } - } - - function cantLoadInitialDatas(response) { - - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = false; - $scope.scheduleFreq = false; - $scope.scheduleBtn = false; - - } - - }; - - $scope.checkConn = function (ip) { - - $scope.destinationLoading = false; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - - url = "/backup/getConnectionStatus"; - - - var data = { - IPAddress: ip, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.connStatus == 1) { - - $scope.destinationLoading = true; - $scope.connectionFailed = true; - $scope.connectionSuccess = false; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - - $scope.IPAddress = ip; - - } - else { - $scope.destinationLoading = true; - $scope.connectionFailed = false; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = true; - - $scope.errorMessage = response.data.error_message; - $scope.IPAddress = ip; - } - } - - function cantLoadInitialDatas(response) { - $scope.destinationLoading = true; - $scope.connectionFailed = true; - $scope.connectionSuccess = true; - $scope.canNotAddDestination = true; - $scope.destinationAdded = true; - $scope.couldNotConnect = false; - } - - }; - - $scope.delSchedule = function (destLoc, frequency) { - - $scope.scheduleBackupLoading = false; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = true; - $scope.scheduleBtn = true; - - - url = "/backup/scheduleDelete"; - - - var data = { - destLoc: destLoc, - frequency: frequency, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.delStatus == 1) { - - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = true; - $scope.scheduleBtn = true; - - - populateCurrentRecords(); - - - } - else { - - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = true; - $scope.scheduleFreq = true; - $scope.scheduleBtn = true; - $scope.errorMessage = response.data.error_message; - } - } - - function cantLoadInitialDatas(response) { - - $scope.scheduleBackupLoading = true; - $scope.canNotAddSchedule = true; - $scope.scheduleAdded = true; - $scope.couldNotConnect = false; - $scope.scheduleFreq = true; - $scope.scheduleBtn = true; - } - - }; - - - function populateCurrentRecords() { - - url = "/backup/getCurrentBackupSchedules"; - - var data = {}; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.fetchStatus == 1) { - - $scope.records = JSON.parse(response.data.data); - - } - } - - function cantLoadInitialDatas(response) { - $scope.couldNotConnect = false; - } - - }; - -}); - -//*** Schedule Backup ***/// - //*** Remote Backup site ****// app.controller('remoteBackupControl', function ($scope, $http, $timeout) { @@ -1911,3 +1381,505 @@ app.controller('googleDrive', function ($scope, $http) { }; }); + +/// + +app.controller('backupDestinations', function ($scope, $http) { + $scope.cyberpanelLoading = true; + $scope.sftpHide = true; + $scope.localHide = true; + + $scope.fetchDetails = function () { + + if ($scope.destinationType === 'SFTP') { + $scope.sftpHide = false; + $scope.localHide = true; + $scope.populateCurrentRecords(); + } else { + $scope.sftpHide = true; + $scope.localHide = false; + $scope.populateCurrentRecords(); + } + }; + + $scope.populateCurrentRecords = function () { + + $scope.cyberpanelLoading = false; + + url = "/backup/getCurrentBackupDestinations"; + + var type = 'SFTP'; + if ($scope.destinationType === 'SFTP') { + type = 'SFTP'; + } else { + type = 'local'; + } + + var data = { + type: type + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + $scope.records = JSON.parse(response.data.data); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + + } + + function cantLoadInitialDatas(response) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + }; + + $scope.addDestination = function (type) { + $scope.cyberpanelLoading = false; + + url = "/backup/submitDestinationCreation"; + + if (type === 'SFTP') { + var data = { + type: type, + name: $scope.name, + IPAddress: $scope.IPAddress, + userName: $scope.userName, + password: $scope.password, + backupSSHPort: $scope.backupSSHPort, + path: $scope.path + }; + } else { + var data = { + type: type, + path: $scope.localPath, + name: $scope.name + }; + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + $scope.populateCurrentRecords(); + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Destination successfully added.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + + } + + function cantLoadInitialDatas(response) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + }; + + $scope.removeDestination = function (type, nameOrPath) { + $scope.cyberpanelLoading = false; + + + url = "/backup/deleteDestination"; + + var data = { + type: type, + nameOrPath: nameOrPath, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + $scope.populateCurrentRecords(); + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Destination successfully removed.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + + } + + function cantLoadInitialDatas(response) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + }; + + +}); + +// + +app.controller('scheduleBackup', function ($scope, $http) { + + $scope.cyberPanelLoading = true; + $scope.driveHidden = true; + + $scope.currentPage = 1; + $scope.recordsToShow = 10; + + $scope.fetchWebsites = function () { + + $scope.cyberPanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + selectedAccount: $scope.selectedAccount, + page: $scope.currentPage, + recordsToShow: $scope.recordsToShow + }; + + + dataurl = "/backup/fetchgDriveSites"; + + $http.post(dataurl, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + $scope.cyberPanelLoading = true; + if (response.data.status === 1) { + $scope.driveHidden = false; + new PNotify({ + title: 'Success', + text: 'Successfully fetched.', + type: 'success' + }); + $scope.websites = JSON.parse(response.data.websites); + $scope.pagination = response.data.pagination; + $scope.currently = response.data.currently; + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + + + } + + }; + + $scope.addSite = function () { + $scope.cyberPanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var data = { + selectedWebsite: $scope.selectedWebsite, + selectedAccount: $scope.selectedAccount + }; + + dataurl = "/backup/addSitegDrive"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + + function ListInitialData(response) { + $scope.cyberPanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Site successfully added.', + type: 'success' + }); + $scope.fetchWebsites(); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialData(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + + }; + + $scope.deleteAccount = function () { + $scope.cyberPanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var data = { + selectedAccount: $scope.selectedAccount + }; + + dataurl = "/backup/deleteAccountgDrive"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + + function ListInitialData(response) { + $scope.cyberPanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Account successfully deleted.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialData(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + + }; + + $scope.changeFrequency = function () { + $scope.cyberPanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var data = { + selectedAccount: $scope.selectedAccount, + backupFrequency: $scope.backupFrequency + }; + + dataurl = "/backup/changeAccountFrequencygDrive"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + + function ListInitialData(response) { + $scope.cyberPanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Changes successfully applied', + type: 'success' + }); + $scope.fetchWebsites(); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialData(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + + }; + + $scope.deleteSite = function (website) { + $scope.cyberPanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var data = { + selectedAccount: $scope.selectedAccount, + website: website + }; + + dataurl = "/backup/deleteSitegDrive"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + + function ListInitialData(response) { + $scope.cyberPanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Website Deleted.', + type: 'success' + }); + $scope.fetchWebsites(); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialData(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + + }; + + $scope.currentPageLogs = 1; + $scope.recordsToShowLogs = 10; + + $scope.fetchLogs = function () { + + $scope.cyberPanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + selectedAccount: $scope.selectedAccount, + page: $scope.currentPageLogs, + recordsToShow: $scope.recordsToShowLogs + }; + + + dataurl = "/backup/fetchDriveLogs"; + + $http.post(dataurl, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + $scope.cyberPanelLoading = true; + if (response.data.status === 1) { + $scope.driveHidden = false; + new PNotify({ + title: 'Success', + text: 'Successfully fetched.', + type: 'success' + }); + $scope.logs = JSON.parse(response.data.logs); + $scope.paginationLogs = response.data.pagination; + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + + } + + }; + +});