diff --git a/IncBackups/static/IncBackups/IncBackups.js b/IncBackups/static/IncBackups/IncBackups.js index ea2603ebd..be6ab76bf 100644 --- a/IncBackups/static/IncBackups/IncBackups.js +++ b/IncBackups/static/IncBackups/IncBackups.js @@ -1299,6 +1299,7 @@ app.controller('restorev2backupoage', function ($scope, $http, $timeout, $compil } + function getCreationStatus() { url = "/IncrementalBackups/CreateV2BackupStatus"; @@ -1377,6 +1378,7 @@ app.controller('restorev2backupoage', function ($scope, $http, $timeout, $compil } + $scope.RestorePathV2 = function (SnapshotId, Path) { SnapshotId = document.getElementById('Snapshot_id').innerText @@ -1859,3 +1861,376 @@ function listpaths(pathid, button) { } } +app.controller('ScheduleV2Backup', function ($scope, $http, $timeout, $compile) { + + + $scope.backupLoading = true; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + + var repoG, frequencyG, websiteDataG, websiteDatabasesG, websiteEmailsG; + + $scope.deleteBackupInitialv2 = function (repo, frequency, websiteData, websiteDatabases, websiteEmails) { + repoG = repo; + frequencyG = frequency; + websiteDataG = websiteData; + websiteDatabasesG = websiteDatabases; + websiteEmailsG = websiteEmails; + } + + $scope.DeleteScheduleV2 = function () { + $scope.backupLoading = false; + // document.getElementById('CreateV2BackupButton').style.display = "block"; + var url = "/IncrementalBackups/DeleteScheduleV2"; + + var data = { + Selectedwebsite: $scope.selwebsite, + repo: repoG, + frequency: frequencyG, + websiteData: websiteDataG, + websiteDatabases: websiteDatabasesG, + websiteEmails: websiteEmailsG + }; + //alert( $scope.selwebsite); + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.backupLoading = true; + if (response.data.status === 1) { + $scope.selectwebsite(); + new PNotify({ + title: 'Success!', + text: 'Successfully deleted.', + type: 'success' + }); + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + + } + + function cantLoadInitialDatas(response) { + $scope.backupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + } + + $scope.selectwebsite = function () { + document.getElementById('reposelectbox').innerHTML = ""; + $scope.backupLoading = false; + // document.getElementById('CreateV2BackupButton').style.display = "block"; + var url = "/IncrementalBackups/selectwebsiteCreatev2"; + + var data = { + Selectedwebsite: $scope.selwebsite, + Selectedrepo: $('#reposelectbox').val(), + }; + //alert( $scope.selwebsite); + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.backupLoading = true; + if (response.data.status === 1) { + + const selectBox = document.getElementById('reposelectbox'); + + + const options = response.data.data; + const option = document.createElement('option'); + $scope.records = response.data.currentSchedules; + + + option.value = 1; + option.text = 'Choose Repo'; + + selectBox.appendChild(option); + + if (options.length >= 1) { + for (let i = 0; i < options.length; i++) { + + const option = document.createElement('option'); + + + option.value = options[i]; + option.text = options[i]; + + selectBox.appendChild(option); + } + + } else { + new PNotify({ + title: 'Error!', + text: 'file empty', + type: 'error' + }); + } + + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + + } + + function cantLoadInitialDatas(response) { + $scope.backupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + } + + $scope.CreateScheduleV2 = function () { + $scope.backupLoading = false; + // document.getElementById('CreateV2BackupButton').style.display = "block"; + var url = "/IncrementalBackups/CreateScheduleV2"; + + var data = { + Selectedwebsite: $scope.selwebsite, + repo: $('#reposelectbox').val(), + frequency: $scope.frequency, + websiteData: $scope.websiteData, + websiteDatabases: $scope.websiteDatabases, + websiteEmails: $scope.websiteEmails + }; + //alert( $scope.selwebsite); + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.backupLoading = true; + if (response.data.status === 1) { + $scope.selectwebsite(); + new PNotify({ + title: 'Success!', + text: 'Successfully created.', + type: 'success' + }); + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + + } + + function cantLoadInitialDatas(response) { + $scope.backupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + } + + var Domain; + + $scope.CreateV2BackupButton = function () { + $scope.backupLoading = false; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + + var url = "/IncrementalBackups/CreateV2BackupButton"; + var websiteData = $scope.websiteData; + var websiteEmails = $scope.websiteEmails; + var websiteDatabases = $scope.websiteDatabases; + var chk = 0; + if (websiteData === true || websiteDatabases === true || websiteEmails === true) { + chk = 1; + } + var data = {}; + + + data = { + Selectedwebsite: $scope.selwebsite, + Selectedrepo: $('#reposelectbox').val(), + websiteDatabases: websiteDatabases, + websiteEmails: websiteEmails, + websiteData: websiteData, + + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + //alert('Done..........') + if (chk === 1) { + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + } else { + $scope.backupLoading = true; + new PNotify({ + title: 'Choose Backup Content!', + text: 'Please Choose Backup content Data, Database, Email', + type: 'error' + }); + } + + + function ListInitialDatas(response) { + $scope.backupLoading = true; + if (response.data.status === 1) { + + Domain = $scope.selwebsite; + getCreationStatus(); + + } else { + $scope.backupLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = false; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + $scope.errorMessage = response.data.error_message; + } + + } + + function cantLoadInitialDatas(response) { + $scope.backupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + } + + function getCreationStatus() { + + url = "/IncrementalBackups/CreateV2BackupStatus"; + + var data = { + domain: Domain + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.abort === 1) { + + if (response.data.installStatus === 1) { + + $scope.webSiteCreationLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = false; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + $("#installProgress").css("width", "100%"); + $scope.installPercentage = "100"; + $scope.currentStatus = response.data.currentStatus; + $timeout.cancel(); + + } else { + $scope.webSiteCreationLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = false; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + $scope.errorMessage = response.data.error_message; + + $("#installProgress").css("width", "0%"); + $scope.installPercentage = "0"; + $scope.goBackDisable = false; + + } + + } else { + $scope.webSiteCreationLoading = false; + $("#installProgress").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + $timeout(getCreationStatus, 1000); + } + + } + + function cantLoadInitialDatas(response) { + + $scope.webSiteCreationLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + } + + +}); + diff --git a/IncBackups/templates/IncBackups/ScheduleV2Backup.html b/IncBackups/templates/IncBackups/ScheduleV2Backup.html new file mode 100644 index 000000000..6fb96ab81 --- /dev/null +++ b/IncBackups/templates/IncBackups/ScheduleV2Backup.html @@ -0,0 +1,203 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "Schedule v2 Backup" %}{% endblock %} +{% block content %} + + {% load static %} + + {% get_current_language as LANGUAGE_CODE %} + + + +
+
+

{% trans "Schedule V2 Backup" %} - {% trans "Backup Docs" %}

+

{% trans "This page can be used to schedule your backups." %}

+
+ +
+
+

+ {% trans "Schedule v2 Backup" %} +

+
+ +
+ + +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+
+ + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
{% trans "Repo" %}{% trans "Frequency" %}{% trans "Backup Websites?" %}{% trans "Backup Databases?" %}{% trans "Backup Emails?" %}{% trans "Last Run" %}{% trans "Delete" %}
+
+
+
+ + + + + +
+ +
+ +
+ + +
+ + +{% endblock %} \ No newline at end of file diff --git a/IncBackups/urls.py b/IncBackups/urls.py index 3354254d4..0e7984db2 100644 --- a/IncBackups/urls.py +++ b/IncBackups/urls.py @@ -36,4 +36,8 @@ urlpatterns = [ url(r'^CreateV2BackupStatus$', views.CreateV2BackupStatus, name='CreateV2BackupStatus'), url(r'^ConfigureSftpV2Backup$', views.ConfigureSftpV2Backup, name='ConfigureSftpV2Backup'), + url(r'^schedulev2Backups$', views.schedulev2Backups, name='schedulev2Backups'), + url(r'^DeleteScheduleV2$', views.DeleteScheduleV2, name='DeleteScheduleV2'), + url(r'^CreateScheduleV2$', views.CreateScheduleV2, name='CreateScheduleV2'), + ] \ No newline at end of file diff --git a/IncBackups/views.py b/IncBackups/views.py index e490bd05e..a0c91a11b 100644 --- a/IncBackups/views.py +++ b/IncBackups/views.py @@ -982,6 +982,8 @@ def selectwebsiteCreatev2(request): command = 'cat %s'%(path) CurrentContent = pu.outputExecutioner(command) + status, currentSchedules = CPBackupsV2.FetchCurrentSchedules(str(Selectedwebsite)) + if CurrentContent.find('No such file or directory') > -1: LocalRclonePath = f'/home/{obj.domain}/.config/rclone' @@ -1001,7 +1003,7 @@ def selectwebsiteCreatev2(request): if result.find('type') > -1: pattern = r'\[(.*?)\]' matches = re.findall(pattern, result) - final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": matches}) + final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": matches, 'currentSchedules': currentSchedules}) return HttpResponse(final_json) else: final_json = json.dumps({'status': 0, 'fetchStatus': 0, 'error_message': 'Could not Find repo'}) @@ -1013,10 +1015,10 @@ def selectwebsiteCreatev2(request): if result.find('type') > -1: pattern = r'\[(.*?)\]' matches = re.findall(pattern, result) - final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": matches}) + final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": matches, 'currentSchedules': currentSchedules}) return HttpResponse(final_json) else: - final_json = json.dumps({'status': 0, 'fetchStatus': 0, 'error_message': 'Could not Find repo'}) + final_json = json.dumps({'status': 0, 'fetchStatus': 0, 'error_message': 'Could not Find repo', 'currentSchedules': currentSchedules}) return HttpResponse(final_json) @@ -1065,6 +1067,89 @@ def selectreporestorev2(request): return HttpResponse(final_json) + except BaseException as msg: + final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + +def schedulev2Backups(request): + try: + userID = request.session['userID'] + bm = BackupManager() + return bm.schedulev2Backups(request, userID) + except KeyError: + return redirect(loadLoginPage) + +def DeleteScheduleV2(request): + try: + userID = request.session['userID'] + data = json.loads(request.body) + Selectedwebsite = data['Selectedwebsite'] + repo = data['repo'] + frequency = data['frequency'] + websiteData = data['websiteData'] + websiteDatabases = data['websiteDatabases'] + websiteEmails = data['websiteEmails'] + + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + + if ACLManager.checkOwnership(str(Selectedwebsite), admin, currentACL) == 1: + pass + else: + return ACLManager.loadError() + + + status, message = CPBackupsV2.DeleteSchedule(Selectedwebsite, repo, frequency, websiteData, websiteDatabases, websiteEmails) + + final_dic = {'status': 1, 'error_message': message} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + # final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": None}) + # return HttpResponse(final_json) + + + except BaseException as msg: + final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + +def CreateScheduleV2(request): + try: + userID = request.session['userID'] + data = json.loads(request.body) + Selectedwebsite = data['Selectedwebsite'] + repo = data['repo'] + frequency = data['frequency'] + websiteData = data['websiteData'] + websiteDatabases = data['websiteDatabases'] + websiteEmails = data['websiteEmails'] + + # + # extra_args['BackupData'] = data['websiteData'] if 'websiteData' in data else False + # extra_args['BackupEmails'] = data['websiteEmails'] if 'websiteEmails' in data else False + # extra_args['BackupDatabase'] = data['websiteDatabases'] if 'websiteDatabases' in data else False + + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + + if ACLManager.checkOwnership(str(Selectedwebsite), admin, currentACL) == 1: + pass + else: + return ACLManager.loadError() + + + status, message = CPBackupsV2.CreateScheduleV2(Selectedwebsite, repo, frequency, websiteData, websiteDatabases, websiteEmails) + + final_dic = {'status': 1, 'error_message': message} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + # final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": None}) + # return HttpResponse(final_json) + + except BaseException as msg: final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) diff --git a/backup/backupManager.py b/backup/backupManager.py index 8e0ca7c08..d92de52ef 100755 --- a/backup/backupManager.py +++ b/backup/backupManager.py @@ -57,12 +57,19 @@ class BackupManager: websitesName = ACLManager.findAllSites(currentACL, userID) proc = httpProc(request, 'IncBackups/RestoreV2Backup.html', {'websiteList': websitesName}, 'createBackup') return proc.render() + def CreateV2backupSite(self, request=None, userID=None, data=None): currentACL = ACLManager.loadedACL(userID) websitesName = ACLManager.findAllSites(currentACL, userID) proc = httpProc(request, 'IncBackups/CreateV2Backup.html', {'websiteList': websitesName}, 'createBackup') return proc.render() + def schedulev2Backups(self, request=None, userID=None, data=None): + currentACL = ACLManager.loadedACL(userID) + websitesName = ACLManager.findAllSites(currentACL, userID) + proc = httpProc(request, 'IncBackups/ScheduleV2Backup.html', {'websiteList': websitesName}, 'createBackup') + return proc.render() + def gDrive(self, request=None, userID=None, data=None): currentACL = ACLManager.loadedACL(userID) admin = Administrator.objects.get(pk=userID) diff --git a/backup/templates/backup/googleDrive.html b/backup/templates/backup/googleDrive.html index ce3f4a0b0..0edbb0f49 100755 --- a/backup/templates/backup/googleDrive.html +++ b/backup/templates/backup/googleDrive.html @@ -31,7 +31,6 @@ data-target="#setupGdrive">{% trans "Setup new Account" %}