diff --git a/backup/backupManager.py b/backup/backupManager.py index f063e071e..78e50d573 100755 --- a/backup/backupManager.py +++ b/backup/backupManager.py @@ -31,6 +31,7 @@ from googleapiclient.discovery import build from websiteFunctions.models import NormalBackupDests, NormalBackupJobs, NormalBackupSites from plogical.IncScheduler import IncScheduler + class BackupManager: localBackupPath = '/home/cyberpanel/localBackupPath' @@ -56,6 +57,16 @@ class BackupManager: proc = httpProc(request, 'backup/backup.html', {'websiteList': websitesName}, 'createBackup') return proc.render() + def backupSiteV2(self, request=None, userID=None, data=None): + currentACL = ACLManager.loadedACL(userID) + websitesName = ACLManager.findAllSites(currentACL, userID) + + command = 'chmod 755 /home/backup' + ProcessUtilities.executioner(command) + + proc = httpProc(request, 'backup/backupV2.html', {'websiteList': websitesName}, 'createBackup') + return proc.render() + def RestoreV2backupSite(self, request=None, userID=None, data=None): if ACLManager.CheckForPremFeature('all'): BackupStat = 1 @@ -63,7 +74,8 @@ class BackupManager: BackupStat = 0 currentACL = ACLManager.loadedACL(userID) websitesName = ACLManager.findAllSites(currentACL, userID) - proc = httpProc(request, 'IncBackups/RestoreV2Backup.html', {'websiteList': websitesName, 'BackupStat': BackupStat}, 'createBackup') + proc = httpProc(request, 'IncBackups/RestoreV2Backup.html', + {'websiteList': websitesName, 'BackupStat': BackupStat}, 'createBackup') return proc.render() def CreateV2backupSite(self, request=None, userID=None, data=None): @@ -81,7 +93,8 @@ class BackupManager: currentACL = ACLManager.loadedACL(userID) websitesName = ACLManager.findAllSites(currentACL, userID) - proc = httpProc(request, 'IncBackups/ScheduleV2Backup.html', {'websiteList': websitesName, "BackupStat": BackupStat}, 'createBackup') + proc = httpProc(request, 'IncBackups/ScheduleV2Backup.html', + {'websiteList': websitesName, "BackupStat": BackupStat}, 'createBackup') return proc.render() def gDrive(self, request=None, userID=None, data=None): @@ -340,7 +353,6 @@ class BackupManager: json_data = json.dumps(data_ret) return HttpResponse(json_data) - def changeFileRetention(self, request=None, userID=None, data=None): try: @@ -362,15 +374,13 @@ class BackupManager: else: return ACLManager.loadErrorJson('status', 0) - - conf = gD.auth # logging.CyberCPLogFileWriter.writeToFile("...... conf...%s " % conf) config = json.loads(conf) # logging.CyberCPLogFileWriter.writeToFile("...... config...%s " % config) config['FileRetentiontime'] = Retentiontime - gD.auth=json.dumps(config) + gD.auth = json.dumps(config) gD.save() data_ret = {'status': 1} @@ -435,6 +445,25 @@ class BackupManager: proc = httpProc(request, 'backup/restore.html', {'backups': all_files}, 'restoreBackup') return proc.render() + def restoreSiteV2(self, request=None, userID=None, data=None): + path = os.path.join("/home", "backup") + if not os.path.exists(path): + proc = httpProc(request, 'backup/restoreV2.html', None, 'restoreBackup') + return proc.render() + else: + all_files = [] + ext = ".tar.gz" + + command = 'sudo chown -R cyberpanel:cyberpanel ' + path + ACLManager.executeCall(command) + + files = os.listdir(path) + for filename in files: + if filename.endswith(ext): + all_files.append(filename) + proc = httpProc(request, 'backup/restoreV2.html', {'backups': all_files}, 'restoreBackup') + return proc.render() + def getCurrentBackups(self, userID=None, data=None): try: currentACL = ACLManager.loadedACL(userID) @@ -1495,7 +1524,6 @@ class BackupManager: recordsToShow = int(data['recordsToShow']) page = int(str(data['page']).strip('\n')) - if ACLManager.currentContextPermission(currentACL, 'scheduleBackups') == 0: return ACLManager.loadErrorJson('scheduleStatus', 0) @@ -1726,7 +1754,6 @@ class BackupManager: json_data = json.dumps(data_ret) return HttpResponse(json_data) - def deleteAccountNormal(self, request=None, userID=None, data=None): try: @@ -1838,7 +1865,7 @@ class BackupManager: json_data = json.dumps(data_ret) return HttpResponse(json_data) - #currentStatus:"cat: /home/cyberpanel/9219: No such file or directory" + # currentStatus:"cat: /home/cyberpanel/9219: No such file or directory" statusData = ProcessUtilities.outputExecutioner("cat " + statusFile).splitlines() @@ -1871,4 +1898,4 @@ class BackupManager: except BaseException as msg: data_ret = {'abort': 0, 'installStatus': 0, 'installationProgress': "0", 'error_message': str(msg)} json_data = json.dumps(data_ret) - return HttpResponse(json_data) \ No newline at end of file + return HttpResponse(json_data) diff --git a/backup/static/backup/backupV2.js b/backup/static/backup/backupV2.js new file mode 100644 index 000000000..e1885b6a6 --- /dev/null +++ b/backup/static/backup/backupV2.js @@ -0,0 +1,415 @@ +newapp.controller('backupWebsiteControlV2', function ($scope, $http, $timeout) { + + $(document).ready(function () { + $(".destinationHide").hide(); + $('#create-backup-select').select2(); + }); + + $('#create-backup-select').on('select2:select', function (e) { + var data = e.params.data; + $scope.websiteToBeBacked = data.text; + $(".destinationHide").show(); + getBackupStatus(); + populateCurrentRecords(); + $scope.destination = false; + $scope.runningBackup = true; + }); + + $scope.destination = true; + $scope.backupButton = true; + $scope.backupLoading = true; + $scope.runningBackup = true; + $scope.cancelButton = true; + + populateCurrentRecords(); + + $scope.cancelBackup = function () { + + var backupCancellationDomain = $scope.websiteToBeBacked; + + url = "/backup/cancelBackupCreation"; + + var data = { + backupCancellationDomain: backupCancellationDomain, fileName: $scope.fileName, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + }; + + $scope.fetchDetails = function () { + getBackupStatus(); + populateCurrentRecords(); + $scope.destination = false; + $scope.runningBackup = true; + + }; + + function getBackupStatus() { + + $scope.backupLoadingBottom = false; + + var websiteToBeBacked = $scope.websiteToBeBacked; + + url = "/backup/backupStatus"; + + var data = { + websiteToBeBacked: websiteToBeBacked, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.backupStatus === 1) { + + if (response.data.abort === 1) { + $timeout.cancel(); + $scope.backupLoadingBottom = true; + $scope.destination = false; + $scope.runningBackup = false; + $scope.cancelButton = true; + $scope.backupButton = false; + $scope.backupLoading = true; + $scope.fileName = response.data.fileName; + $scope.status = response.data.status; + populateCurrentRecords(); + return; + } else { + $scope.destination = true; + $scope.backupButton = true; + $scope.runningBackup = false; + $scope.cancelButton = false; + + $scope.fileName = response.data.fileName; + $scope.status = response.data.status; + $timeout(getBackupStatus, 2000); + + } + } else { + $timeout.cancel(); + $scope.backupLoadingBottom = true; + $scope.backupLoading = true; + $scope.cancelButton = true; + $scope.backupButton = false; + } + + } + + function cantLoadInitialDatas(response) { + } + + }; + + $scope.destinationSelection = function () { + $scope.backupButton = false; + }; + + function populateCurrentRecords() { + + var websiteToBeBacked = $scope.websiteToBeBacked; + + url = "/backup/getCurrentBackups"; + + var data = { + websiteToBeBacked: websiteToBeBacked, + }; + + 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.createBackup = function () { + + var createBackupButton = document.getElementById("createBackup"); + createBackupButton.disabled = true; + var websiteToBeBacked = $scope.websiteToBeBacked; + $scope.backupLoading = false; + + + url = "/backup/submitBackupCreation"; + + var data = { + websiteToBeBacked: websiteToBeBacked, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + // console.log("-------------------") + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.metaStatus === 1) { + getBackupStatus(); + createBackupButton.disabled = false; + } + + } + + function cantLoadInitialDatas(response) { + createBackupButton.disabled = false; + } + + }; + + $scope.deleteBackup = function (id) { + + url = "/backup/deleteBackup"; + + var data = { + backupID: id, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.deleteStatus == 1) { + + populateCurrentRecords(); + + + } else { + + } + + } + + function cantLoadInitialDatas(response) { + + + } + + + }; + + +}); +$("#websiteDeleteFailure").hide(); +$("#websiteDeleteSuccess").hide(); + +newapp.controller('restoreWebsiteControlV2', function ($scope, $http, $timeout) { + + $scope.restoreLoading = true; + $scope.runningRestore = true; + $scope.restoreButton = true; + $scope.restoreFinished = false; + $scope.couldNotConnect = true; + $scope.backupError = true; + $scope.siteExists = true; + + // check to start time of status function + + var check = 1; + + + $scope.fetchDetails = function () { + $scope.restoreLoading = false; + getRestoreStatus(); + }; + + + function getRestoreStatus() { + + var backupFile = $scope.backupFile; + + url = "/backup/restoreStatus"; + + var data = { + backupFile: backupFile, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.restoreStatus === 1) { + + if (response.data.abort === 1) { + $scope.running = response.data.running; + $scope.fileName = $scope.backupFile; + $scope.restoreLoading = true; + $scope.status = response.data.status; + $scope.runningRestore = false; + $scope.restoreButton = false; + $scope.restoreFinished = true; + $timeout.cancel(); + return; + } else { + $scope.running = response.data.running; + $scope.fileName = $scope.backupFile; + $scope.restoreLoading = false; + $scope.status = response.data.status; + $scope.runningRestore = false; + $scope.restoreButton = true; + $timeout(getRestoreStatus, 2000); + } + } + + } + + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; + + + } + + }; + + + $scope.restoreBackup = function () { + var restoreBackupButton = document.getElementById("restoreBackup"); + restoreBackupButton.disabled = true; + var backupFile = $scope.backupFile; + $scope.running = "Lets start.." + + url = "/backup/submitRestore"; + + var data = { + backupFile: backupFile, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.restoreLoading = true; + if (response.data.restoreStatus == 1) { + $scope.runningRestore = false; + $scope.running = "Running"; + $scope.fileName = $scope.backupFile; + $scope.status = "Just Started.."; + + getRestoreStatus(); + restoreBackupButton.disabled = false; + } else { + $scope.backupError = false; + $scope.errorMessage = response.data.error_message; + restoreBackupButton.disabled = false; + } + + } + + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; + restoreBackupButton.disabled = false; + } + + }; + + + function createWebsite() { + + var backupFile = $scope.backupFile; + + url = "/websites/CreateWebsiteFromBackup"; + + var data = { + backupFile: backupFile, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.createWebSiteStatus == 1) { + getRestoreStatus(); + } else if (response.data.existsStatus == 1) { + $scope.backupError = false; + $scope.errorMessage = response.data.error_message; + $scope.restoreButton = true; + $scope.runningRestore = true; + } else { + $scope.websiteDomain = domainName; + $scope.backupError = false; + $scope.errorMessage = response.data.error_message; + } + + + } + + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; + } + + + }; + + +}); \ No newline at end of file diff --git a/backup/templates/backup/backup.html b/backup/templates/backup/backup.html index e90e97ab0..be7f878ed 100755 --- a/backup/templates/backup/backup.html +++ b/backup/templates/backup/backup.html @@ -1,155 +1,131 @@ - {% extends "baseTemplate/index.html" %} {% load i18n %} {% block title %}{% trans "Backup Website" %}{% endblock %} {% block content %} -{% load static %} + {% load static %} -{% get_current_language as LANGUAGE_CODE %} - + {% get_current_language as LANGUAGE_CODE %} + -
{% trans "This page can be used to Backup your websites" %}
-{% trans "This page can be used to Backup your websites" %}
+
-