diff --git a/plogical/IncScheduler.py b/plogical/IncScheduler.py
index ba410c125..67d3721af 100644
--- a/plogical/IncScheduler.py
+++ b/plogical/IncScheduler.py
@@ -10,16 +10,20 @@ from IncBackups.models import BackupJob
from random import randint
import argparse
import json
-from websiteFunctions.models import GitLogs, Websites
+from websiteFunctions.models import GitLogs, Websites, GDrive, GDriveJobLogs
from websiteFunctions.website import WebsiteManager
import time
-
+import google.oauth2.credentials
+import googleapiclient.discovery
+from googleapiclient.discovery import build
+from googleapiclient.http import MediaFileUpload
try:
from plogical.virtualHostUtilities import virtualHostUtilities
from plogical.mailUtilities import mailUtilities
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
except:
pass
+from plogical.backupSchedule import backupSchedule
class IncScheduler():
logPath = '/home/cyberpanel/incbackuplogs'
@@ -192,6 +196,59 @@ class IncScheduler():
except BaseException as msg:
logging.writeToFile('[IncScheduler:193:checkDiskUsage] %s.' % str(msg))
+ @staticmethod
+ def runGoogleDriveBackups(type):
+
+ backupRunTime = time.strftime("%m.%d.%Y_%H-%M-%S")
+ backupLogPath = "/usr/local/lscp/logs/local_backup_log." + backupRunTime
+
+ for items in GDrive.objects.all():
+ try:
+ if items.runTime == type:
+ gDriveData = json.loads(items.auth)
+ try:
+ 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)
+ except BaseException as msg:
+ GDriveJobLogs(owner=items, status=backupSchedule.ERROR, message='Connection to this account failed. Delete and re-setup this account. Error: %s' % (str(msg))).save()
+ continue
+
+ GDriveJobLogs(owner=items, status=backupSchedule.INFO, message='Starting backup job..').save()
+
+ for website in items.gdrivesites_set.all():
+ try:
+ GDriveJobLogs(owner=items, status=backupSchedule.INFO, message='Local backup creation started for %s..' % (website.domain)).save()
+
+ retValues = backupSchedule.createLocalBackup(website.domain, backupLogPath)
+
+ if retValues[0] == 0:
+ GDriveJobLogs(owner=items, status=backupSchedule.ERROR,
+ message='[ERROR] Backup failed for %s, error: %s moving on..' % (website.domain, retValues[1])).save()
+ continue
+
+ completeFileToSend = retValues[1] + ".tar.gz"
+ fileName = completeFileToSend.split('/')[-1]
+
+ file_metadata = {'name': '%s' % (fileName)}
+ media = MediaFileUpload(completeFileToSend, mimetype='application/gzip', resumable=True)
+ drive.files().create(body=file_metadata, media_body=media, fields='id').execute()
+
+ GDriveJobLogs(owner=items, status=backupSchedule.INFO,
+ message='Backup for %s successfully sent to Googe Drive.' % (website.domain)).save()
+
+ except BaseException as msg:
+ GDriveJobLogs(owner=items, status=backupSchedule.ERROR,
+ message='[Site] Site backup failed, Error message: %s.' % (str(msg))).save()
+
+
+ GDriveJobLogs(owner=items, status=backupSchedule.INFO,
+ message='Job Completed').save()
+ except BaseException as msg:
+ GDriveJobLogs(owner=items, status=backupSchedule.ERROR,
+ message='[Completely] Job failed, Error message: %s.' % (str(msg))).save()
+
def main():
@@ -200,6 +257,7 @@ def main():
args = parser.parse_args()
IncScheduler.startBackup(args.function)
+ IncScheduler.runGoogleDriveBackups(args.function)
IncScheduler.git(args.function)
IncScheduler.checkDiskUsage()
diff --git a/static/CLManager/CLManager.js b/static/CLManager/CLManager.js
index ae17f696c..d2c52ef22 100644
--- a/static/CLManager/CLManager.js
+++ b/static/CLManager/CLManager.js
@@ -489,7 +489,6 @@ app.controller('listCloudLinuxPackages', function ($scope, $http) {
});
-
app.controller('websiteContainerLimitCL', function ($scope, $http, $timeout, $window) {
diff --git a/static/backup/backup.js b/static/backup/backup.js
index e233a8636..2533712bd 100644
--- a/static/backup/backup.js
+++ b/static/backup/backup.js
@@ -1534,6 +1534,7 @@ app.controller('remoteBackupControl', function ($scope, $http, $timeout) {
///** Backup site ends **///
//*** Remote Backup site ****//
+
app.controller('backupLogsScheduled', function ($scope, $http, $timeout) {
$scope.cyberpanelLoading = true;
@@ -1595,3 +1596,318 @@ app.controller('backupLogsScheduled', function ($scope, $http, $timeout) {
});
///** Backup site ends **///
+
+app.controller('googleDrive', function ($scope, $http) {
+
+ $scope.cyberPanelLoading = true;
+ $scope.driveHidden = true;
+
+ $scope.setupAccount = function(){
+ window.open("https://platform.cyberpanel.net/gDrive?name=" + $scope.accountName + '&server=' + window.location.href + 'Setup');
+ };
+
+ $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/websiteFunctions/models.py b/websiteFunctions/models.py
index 3c0b99f90..db9e6a516 100755
--- a/websiteFunctions/models.py
+++ b/websiteFunctions/models.py
@@ -70,7 +70,7 @@ class GDrive(models.Model):
class GDriveSites(models.Model):
owner = models.ForeignKey(GDrive, on_delete=models.CASCADE)
- domain = models.CharField(max_length=200, unique=True)
+ domain = models.CharField(max_length=200)
class GDriveJobLogs(models.Model):
owner = models.ForeignKey(GDrive, on_delete=models.CASCADE)