From fb12c2679e253337d63c43187c685a4d67fe8939 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sat, 13 Jun 2020 21:56:37 +0500 Subject: [PATCH] complete google drive backups; --- backup/backupManager.py | 19 +- backup/static/backup/backup.js | 13 +- backup/templates/backup/googleDrive.html | 14 +- plogical/IncScheduler.py | 62 ++++- static/CLManager/CLManager.js | 1 - static/backup/backup.js | 316 +++++++++++++++++++++++ websiteFunctions/models.py | 2 +- 7 files changed, 396 insertions(+), 31 deletions(-) diff --git a/backup/backupManager.py b/backup/backupManager.py index 6e28e42aa..3bc1545af 100755 --- a/backup/backupManager.py +++ b/backup/backupManager.py @@ -10,8 +10,7 @@ django.setup() import json from plogical.acl import ACLManager import plogical.CyberCPLogFileWriter as logging -from websiteFunctions.models import Websites, Backups, dest, backupSchedules, BackupJob, BackupJobLogs, GDrive, \ - GDriveSites, GDriveJobLogs +from websiteFunctions.models import Websites, Backups, dest, backupSchedules, BackupJob, BackupJobLogs, GDrive, GDriveSites, GDriveJobLogs from plogical.virtualHostUtilities import virtualHostUtilities import subprocess import shlex @@ -93,18 +92,10 @@ class BackupManager: gDriveData['client_secret'] = request.GET.get('cl') gDriveData['scopes'] = request.GET.get('s') - credentials = google.oauth2.credentials.Credentials(gDriveData['token'], gDriveData['refresh_token'], - gDriveData['token_uri'], gDriveData['client_id'], - gDriveData['client_secret'], gDriveData['scopes']) - - drive = build('drive', 'v3', credentials=credentials) - gD = GDrive(owner=admin, name=request.GET.get('n'), auth=json.dumps(gDriveData)) gD.save() - final_json = json.dumps({'status': 1, 'message': 'Successfully saved.', - 'data': str(drive.files().list(pageSize=10, fields="files(id, name)").execute())}) - return HttpResponse(final_json) + return self.gDrive(request, userID) except BaseException as msg: final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) @@ -318,8 +309,10 @@ class BackupManager: website = data['website'] gD = GDrive.objects.get(name=selectedAccount) - gDSite = GDriveSites.objects.get(owner=gD, domain=website) - gDSite.delete() + sites = GDriveSites.objects.filter(owner=gD, domain=website) + + for items in sites: + items.delete() data_ret = {'status': 1} json_data = json.dumps(data_ret) diff --git a/backup/static/backup/backup.js b/backup/static/backup/backup.js index 3ad2693c3..2533712bd 100755 --- a/backup/static/backup/backup.js +++ b/backup/static/backup/backup.js @@ -1611,7 +1611,7 @@ app.controller('googleDrive', function ($scope, $http) { $scope.fetchWebsites = function () { - $scope.cyberpanelLoading = false; + $scope.cyberPanelLoading = false; var config = { headers: { @@ -1631,7 +1631,7 @@ app.controller('googleDrive', function ($scope, $http) { $http.post(dataurl, data, config).then(ListInitialDatas, cantLoadInitialDatas); function ListInitialDatas(response) { - $scope.cyberpanelLoading = true; + $scope.cyberPanelLoading = true; if (response.data.status === 1) { $scope.driveHidden = false; new PNotify({ @@ -1652,7 +1652,7 @@ app.controller('googleDrive', function ($scope, $http) { } function cantLoadInitialDatas(response) { - $scope.cyberpanelLoading = true; + $scope.cyberPanelLoading = true; new PNotify({ title: 'Operation Failed!', text: 'Could not connect to server, please refresh this page.', @@ -1859,7 +1859,7 @@ app.controller('googleDrive', function ($scope, $http) { $scope.fetchLogs = function () { - $scope.cyberpanelLoading = false; + $scope.cyberPanelLoading = false; var config = { headers: { @@ -1879,7 +1879,7 @@ app.controller('googleDrive', function ($scope, $http) { $http.post(dataurl, data, config).then(ListInitialDatas, cantLoadInitialDatas); function ListInitialDatas(response) { - $scope.cyberpanelLoading = true; + $scope.cyberPanelLoading = true; if (response.data.status === 1) { $scope.driveHidden = false; new PNotify({ @@ -1899,14 +1899,13 @@ app.controller('googleDrive', function ($scope, $http) { } function cantLoadInitialDatas(response) { - $scope.cyberpanelLoading = true; + $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/googleDrive.html b/backup/templates/backup/googleDrive.html index 339faf9b4..86f3048c8 100755 --- a/backup/templates/backup/googleDrive.html +++ b/backup/templates/backup/googleDrive.html @@ -114,10 +114,10 @@
-
+
+ class="btn btn-gray">{% trans "View Logs" %}