diff --git a/IncBackups/models.py b/IncBackups/models.py index 9e87e6aec..04a8f50c3 100644 --- a/IncBackups/models.py +++ b/IncBackups/models.py @@ -1,5 +1,6 @@ from django.db import models from websiteFunctions.models import Websites +from loginSystem.models import Administrator from datetime import datetime @@ -27,3 +28,19 @@ class BackupJob(models.Model): class JobSites(models.Model): job = models.ForeignKey(BackupJob, on_delete=models.CASCADE) website = models.CharField(max_length=300) + + +class OneClickBackups(models.Model): + owner = models.ForeignKey(Administrator, on_delete=models.PROTECT) + planName = models.CharField(max_length=100) + months = models.CharField(max_length=100) + price = models.CharField(max_length=100) + customer = models.CharField(max_length=300) + subscription = models.CharField(max_length=300, unique=True) + sftpUser = models.CharField(max_length=100) + config = models.TextField(default='{}') + date = models.DateTimeField(default=datetime.now, blank=True) + state = models.IntegerField(default=0) + + + diff --git a/backup/backupManager.py b/backup/backupManager.py index 13a85be36..38f82d796 100755 --- a/backup/backupManager.py +++ b/backup/backupManager.py @@ -2,8 +2,12 @@ import os import os.path import sys -import django +from io import StringIO +import django +import paramiko + +from plogical.applicationInstaller import ApplicationInstaller from plogical.httpProc import httpProc sys.path.append('/usr/local/CyberCP') @@ -1912,4 +1916,405 @@ 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) + + def OneClickBackups(self, request=None, userID=None, data=None): + user = Administrator.objects.get(pk=userID) + + data = {} + + import requests + try: + if request.GET.get('status', 'none') == 'success': + plan_name = request.GET.get('planName') + months = request.GET.get('months') + monthly_price = request.GET.get('monthlyPrice') + yearly_price = request.GET.get('yearlyPrice') + customer = request.GET.get('customer') + subscription = request.GET.get('subscription') + + from IncBackups.models import OneClickBackups + + if months == '1': + price = monthly_price + else: + price = yearly_price + + try: + + backup_plan = OneClickBackups( + owner=user, + planName=plan_name, + months=months, + price=price, + customer=customer, + subscription=subscription, + sftpUser=f'{user.userName}{str(randint(1000, 9999))}', + ) + backup_plan.save() + + #### + + import requests + import json + + + # Define the URL of the endpoint + url = 'http://platform.cyberpersons.com/Billing/CreateSFTPAccount' # Replace with your actual endpoint URL + + # Define the payload to send in the POST request + payload = { + 'sub': subscription, + 'key': ProcessUtilities.outputExecutioner(f'cat /root/.ssh/cyberpanel.pub'), # Replace with the actual SSH public key + 'sftpUser': backup_plan.sftpUser, + 'serverIP': ACLManager.fetchIP(), # Replace with the actual server IP, + 'planName': plan_name + } + + # Convert the payload to JSON format + headers = {'Content-Type': 'application/json'} + dataRet = json.dumps(payload) + + # Make the POST request + response = requests.post(url, headers=headers, data=dataRet) + + # Handle the response + if response.status_code == 200: + response_data = response.json() + if response_data.get('status') == 1: + + ocbkup = OneClickBackups.objects.get(owner=user,subscription=subscription) + ocbkup.state = 1 + ocbkup.save() + + finalDic = {} + + finalDic['IPAddress'] = response_data.get('ipAddress') + finalDic['password'] = 'NOT-NEEDED' + finalDic['backupSSHPort'] = '22' + finalDic['userName'] = backup_plan.sftpUser + finalDic['type'] = 'SFTP' + finalDic['path'] = 'cpbackups' + finalDic['name'] = backup_plan.sftpUser + + wm = BackupManager() + response_inner = wm.submitDestinationCreation(userID, finalDic) + + response_data_inner = json.loads(response_inner.content.decode('utf-8')) + + # Extract the value of 'status' + if response_data_inner.get('status') == 0: + data['status'] = 0 + data[ + 'message'] = f"[2109] Failed to create sftp account {response_data_inner.get('error_message')}" + print("Failed to create SFTP account:", response_data_inner.get('error_message')) + else: + data['status'] = 1 + + else: + data['status'] = 0 + data['message'] = f"[1985] Failed to create sftp account {response_data.get('error_message')}" + print("Failed to create SFTP account:", response_data.get('error_message')) + else: + print("Failed to connect to the server. Status code:", response.status_code) + print("Response:", response.text) + data['status'] = 0 + data['message'] = f"[1991] Failed to create sftp account {response.text}" + + #### + + except BaseException as msg: + data['status'] = 4 + data['message'] = str(msg) + + elif request.GET.get('status', 'none') == 'cancelled': + data['status'] = 0 + else: + data['status'] = 2 + except BaseException as msg: + data['status'] = 0 + data['message'] = f"[2038] Unkown error occured in purchase process. Error message: {str(msg)}" + + + url = 'https://platform.cyberpersons.com/Billing/FetchBackupPlans' + + try: + response = requests.get(url) + response.raise_for_status() # Check if the request was successful + data['plans'] = response.json() # Convert the response to a Python dictionary + except requests.exceptions.HTTPError as http_err: + print(f'HTTP error occurred: {http_err}') + except Exception as err: + print(f'Other error occurred: {err}') + + data['bPlans'] = user.oneclickbackups_set.all() + + proc = httpProc(request, 'backup/oneClickBackups.html', data, 'addDeleteDestinations') + return proc.render() + + def ManageOCBackups(self, request=None, userID=None, data=None): + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + from IncBackups.models import OneClickBackups + ocb = OneClickBackups.objects.get(pk = request.GET.get('id'), owner=admin) + destinations = [NormalBackupDests.objects.get(name=ocb.sftpUser)] + dests = [] + for dest in destinations: + dests.append(dest.name) + + websitesName = ACLManager.findAllSites(currentACL, userID) + + proc = httpProc(request, 'backup/OneClickBackupSchedule.html', {'destination': NormalBackupDests.objects.get(name=ocb.sftpUser).name, 'websites': websitesName}, + 'scheduleBackups') + return proc.render() + + def RestoreOCBackups(self, request=None, userID=None, data=None): + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + from IncBackups.models import OneClickBackups + ocb = OneClickBackups.objects.get(pk = request.GET.get('id'), owner=admin) + + # Load the private key + + nbd = NormalBackupDests.objects.get(name=ocb.sftpUser) + ip = json.loads(nbd.config)['ip'] + + # Connect to the remote server using the private key + ssh = paramiko.SSHClient() + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + # Read the private key content + private_key_path = '/root/.ssh/cyberpanel' + key_content = ProcessUtilities.outputExecutioner(f'cat {private_key_path}').rstrip('\n') + + # Load the private key from the content + key_file = StringIO(key_content) + key = paramiko.RSAKey.from_private_key(key_file) + # Connect to the server using the private key + ssh.connect(ip, username=ocb.sftpUser, pkey=key) + # Command to list directories under the specified path + command = f"ls -d cpbackups/*/" + + # Execute the command + stdin, stdout, stderr = ssh.exec_command(command) + + # Read the results + directories = stdout.read().decode().splitlines() + + finalDirs = [] + + # Print directories + for directory in directories: + finalDirs.append(directory.split('/')[1]) + + proc = httpProc(request, 'backup/restoreOCBackups.html', {'directories': finalDirs}, + 'scheduleBackups') + return proc.render() + + def fetchOCSites(self, request=None, userID=None, data=None): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + data = json.loads(request.body) + id = data['idValue'] + folder = data['folder'] + + admin = Administrator.objects.get(pk=userID) + from IncBackups.models import OneClickBackups + ocb = OneClickBackups.objects.get(pk = id, owner=admin) + + # Load the private key + + nbd = NormalBackupDests.objects.get(name=ocb.sftpUser) + ip = json.loads(nbd.config)['ip'] + + # Connect to the remote server using the private key + ssh = paramiko.SSHClient() + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + # Read the private key content + private_key_path = '/root/.ssh/cyberpanel' + key_content = ProcessUtilities.outputExecutioner(f'cat {private_key_path}').rstrip('\n') + + # Load the private key from the content + key_file = StringIO(key_content) + key = paramiko.RSAKey.from_private_key(key_file) + # Connect to the server using the private key + ssh.connect(ip, username=ocb.sftpUser, pkey=key) + # Command to list directories under the specified path + command = f"ls -d cpbackups/{folder}/*" + + # Execute the command + stdin, stdout, stderr = ssh.exec_command(command) + + # Read the results + directories = stdout.read().decode().splitlines() + + finalDirs = [] + + # Print directories + for directory in directories: + finalDirs.append(directory.split('/')[2]) + + data_ret = {'status': 1, 'finalDirs': finalDirs} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + except BaseException as msg: + data_ret = {'status': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + def StartOCRestore(self, request=None, userID=None, data=None): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + data = json.loads(request.body) + id = data['idValue'] + folder = data['folder'] + backupfile = data['backupfile'] + + + extraArgs = {} + extraArgs['id'] = id + extraArgs['folder'] = folder + extraArgs['backupfile'] = backupfile + extraArgs['userID'] = userID + extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) + + statusFile = open(extraArgs['tempStatusPath'], 'w') + statusFile.writelines("Restore started..") + statusFile.close() + + background = ApplicationInstaller('StartOCRestore', extraArgs) + background.start() + + data_ret = {'status': 1, 'installStatus': 1, 'error_message': 'None', + 'tempStatusPath': extraArgs['tempStatusPath']} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + except BaseException as msg: + data_ret = {'status': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + def DeployAccount(self, request=None, userID=None, data=None): + user = Administrator.objects.get(pk=userID) + + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + import json + + data = json.loads(request.body) + id = data['id'] + + from IncBackups.models import OneClickBackups + ocb = OneClickBackups.objects.get(pk=id, owner=user) + + data = {} + + #### + + import requests + import json + + # Define the URL of the endpoint + url = 'http://platform.cyberpersons.com/Billing/CreateSFTPAccount' # Replace with your actual endpoint URL + + # Define the payload to send in the POST request + payload = { + 'sub': ocb.subscription, + 'key': ProcessUtilities.outputExecutioner(f'cat /root/.ssh/cyberpanel.pub'), + # Replace with the actual SSH public key + 'sftpUser': ocb.sftpUser, + 'serverIP': ACLManager.fetchIP(), # Replace with the actual server IP + 'planName': ocb.planName + } + + # Convert the payload to JSON format + headers = {'Content-Type': 'application/json'} + dataRet = json.dumps(payload) + + # Make the POST request + response = requests.post(url, headers=headers, data=dataRet) + + # Handle the response + # Handle the response + if response.status_code == 200: + response_data = response.json() + if response_data.get('status') == 1: + + ocb.state = 1 + ocb.save() + + print("SFTP account created successfully.") + + finalDic = {} + + finalDic['IPAddress'] = response_data.get('ipAddress') + finalDic['password'] = 'NOT-NEEDED' + finalDic['backupSSHPort'] = '22' + finalDic['userName'] = ocb.sftpUser + finalDic['type'] = 'SFTP' + finalDic['path'] = 'cpbackups' + finalDic['name'] = ocb.sftpUser + + wm = BackupManager() + response_inner = wm.submitDestinationCreation(userID, finalDic) + + response_data_inner = json.loads(response_inner.content.decode('utf-8')) + + # Extract the value of 'status' + if response_data_inner.get('status') == 0: + data_ret = {'status': 1, 'error_message': response_data_inner.get('error_message')} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + data_ret = {'status': 1,} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + else: + + if response_data.get('error_message') == "Already deployed.": + ocb.state = 1 + ocb.save() + + print("SFTP account created successfully.") + + finalDic = {} + + finalDic['IPAddress'] = response_data.get('ipAddress') + finalDic['password'] = 'NOT-NEEDED' + finalDic['backupSSHPort'] = '22' + finalDic['userName'] = ocb.sftpUser + finalDic['type'] = 'SFTP' + finalDic['path'] = 'cpbackups' + finalDic['name'] = ocb.sftpUser + + wm = BackupManager() + response_inner = wm.submitDestinationCreation(userID, finalDic) + + response_data_inner = json.loads(response_inner.content.decode('utf-8')) + + # Extract the value of 'status' + if response_data_inner.get('status') == 0: + data_ret = {'status': 1, 'error_message': response_data_inner.get('error_message')} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + data_ret = {'status': 1, } + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + data_ret = {'status': 0, 'error_message': response_data.get('error_message')} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + data['message'] = f"[1991] Failed to create sftp account {response.text}" + data_ret = {'status': 0, 'error_message': response.text} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + diff --git a/backup/static/backup/backup.js b/backup/static/backup/backup.js index 17e62f6ad..a0d8ebb03 100755 --- a/backup/static/backup/backup.js +++ b/backup/static/backup/backup.js @@ -97,8 +97,7 @@ app.controller('backupWebsiteControl', function ($scope, $http, $timeout) { $scope.status = response.data.status; populateCurrentRecords(); return; - } - else { + } else { $scope.destination = true; $scope.backupButton = true; $scope.runningBackup = false; @@ -109,8 +108,7 @@ app.controller('backupWebsiteControl', function ($scope, $http, $timeout) { $timeout(getBackupStatus, 2000); } - } - else { + } else { $timeout.cancel(); $scope.backupLoadingBottom = true; $scope.backupLoading = true; @@ -230,8 +228,7 @@ app.controller('backupWebsiteControl', function ($scope, $http, $timeout) { populateCurrentRecords(); - } - else { + } else { } @@ -308,8 +305,7 @@ app.controller('restoreWebsiteControl', function ($scope, $http, $timeout) { $scope.restoreFinished = true; $timeout.cancel(); return; - } - else { + } else { $scope.running = response.data.running; $scope.fileName = $scope.backupFile; $scope.restoreLoading = false; @@ -364,18 +360,17 @@ app.controller('restoreWebsiteControl', function ($scope, $http, $timeout) { getRestoreStatus(); restoreBackupButton.disabled = false; - } - else { + } else { $scope.backupError = false; $scope.errorMessage = response.data.error_message; - restoreBackupButton.disabled = false; + restoreBackupButton.disabled = false; } } function cantLoadInitialDatas(response) { $scope.couldNotConnect = false; - restoreBackupButton.disabled = false; + restoreBackupButton.disabled = false; } }; @@ -404,14 +399,12 @@ app.controller('restoreWebsiteControl', function ($scope, $http, $timeout) { if (response.data.createWebSiteStatus == 1) { getRestoreStatus(); - } - else if (response.data.existsStatus == 1) { + } else if (response.data.existsStatus == 1) { $scope.backupError = false; $scope.errorMessage = response.data.error_message; $scope.restoreButton = true; $scope.runningRestore = true; - } - else { + } else { $scope.websiteDomain = domainName; $scope.backupError = false; $scope.errorMessage = response.data.error_message; @@ -484,8 +477,7 @@ app.controller('remoteBackupControl', function ($scope, $http, $timeout) { websitesToBeBacked.push(website); } - } - else { + } else { var tempArray = []; @@ -504,8 +496,7 @@ app.controller('remoteBackupControl', function ($scope, $http, $timeout) { websitesToBeBacked = websitesToBeBackedTemp; $scope.webSiteStatus = true; - } - else { + } else { websitesToBeBacked = []; $scope.webSiteStatus = false; } @@ -568,8 +559,7 @@ app.controller('remoteBackupControl', function ($scope, $http, $timeout) { $scope.backupCancelled = true; - } - else { + } else { $scope.error_message = response.data.error_message; $scope.backupLoading = true; @@ -667,8 +657,7 @@ app.controller('remoteBackupControl', function ($scope, $http, $timeout) { getBackupStatus(); - } - else { + } else { $scope.error_message = response.data.error_message; $scope.backupLoading = true; @@ -730,8 +719,7 @@ app.controller('remoteBackupControl', function ($scope, $http, $timeout) { $scope.backupStatus = false; $scope.requestData = response.data.status; $timeout(getBackupStatus, 2000); - } - else { + } else { $scope.requestData = response.data.status; $timeout.cancel(); @@ -739,8 +727,7 @@ app.controller('remoteBackupControl', function ($scope, $http, $timeout) { remoteBackupRestore(); } - } - else { + } else { $scope.error_message = response.data.error_message; $scope.backupLoading = true; @@ -832,15 +819,13 @@ app.controller('remoteBackupControl', function ($scope, $http, $timeout) { $scope.backupStatus = false; $scope.restoreData = response.data.status; $timeout(localRestoreStatus, 2000); - } - else { + } else { $scope.restoreData = response.data.status; $timeout.cancel(); $scope.backupLoading = true; $scope.startTransferbtn = false; } - } - else { + } else { $scope.error_message = response.data.error_message; $scope.backupLoading = true; @@ -895,8 +880,7 @@ app.controller('remoteBackupControl', function ($scope, $http, $timeout) { $scope.backupStatus = false; $scope.requestData = response.data.status; $timeout(getBackupStatus, 2000); - } - else { + } else { $timeout.cancel(); } } @@ -980,8 +964,7 @@ app.controller('remoteBackupControl', function ($scope, $http, $timeout) { $scope.fetchAccountsBtn = false; - } - else { + } else { $scope.error_message = response.data.error_message; $scope.backupLoading = true; @@ -1067,6 +1050,7 @@ app.controller('backupLogsScheduled', function ($scope, $http, $timeout) { }); } } + function cantLoadInitialData(response) { $scope.cyberpanelLoading = true; new PNotify({ @@ -1085,15 +1069,12 @@ 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(){ + $scope.setupAccount = function () { window.open("https://platform.cyberpersons.com/gDrive?name=" + $scope.accountName + '&server=' + window.location.href + 'Setup'); }; @@ -1252,7 +1233,7 @@ app.controller('googleDrive', function ($scope, $http) { $scope.changeRetention = function () { $scope.cyberPanelLoading = false; - var config = { + var config = { headers: { 'X-CSRFToken': getCookie('csrftoken') } @@ -1268,24 +1249,25 @@ app.controller('googleDrive', function ($scope, $http) { $http.post(dataurl, data, config).then(fileretention, cantLoadInitialData); - function fileretention(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 fileretention(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) { + } + + function cantLoadInitialData(response) { $scope.cyberPanelLoading = true; new PNotify({ title: 'Operation Failed!', @@ -2062,3 +2044,654 @@ app.controller('scheduleBackup', function ($scope, $http, $window) { }; }); + +app.controller('backupPlanNowOneClick', function ($scope, $http, $window) { + $scope.cyberpanelLoading = true; + $scope.sftpHide = true; + $scope.localHide = true; + + $scope.BuyNowBackupP = function (planName, monthlyPrice, yearlyPrice, months) { + + const baseURL = 'https://platform.cyberpersons.com/Billing/CreateOrderforBackupPlans'; + // Get the current URL + var currentURL = window.location.href; + +// Find the position of the question mark + const queryStringIndex = currentURL.indexOf('?'); + +// Check if there is a query string + currentURL = queryStringIndex !== -1 ? currentURL.substring(0, queryStringIndex) : currentURL; + + + // Encode parameters to make them URL-safe + const params = new URLSearchParams({ + planName: planName, + monthlyPrice: monthlyPrice, + yearlyPrice: yearlyPrice, + returnURL: currentURL, // Add the current URL as a query parameter + months: months + }); + + + // Build the complete URL with query string + const fullURL = `${baseURL}?${params.toString()}`; + + // Redirect to the constructed URL + + window.location.href = fullURL; + + } + + + $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' + }); + } + + }; + + $scope.DeployAccount = function (id) { + $scope.cyberpanelLoading = false; + + url = "/backup/DeployAccount"; + + var data = { + id:id + + }; + + 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) { + new PNotify({ + title: 'Success', + text: 'Successfully deployed.', + type: 'success' + }); + $window.location.reload(); + + + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + + } + + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; + restoreBackupButton.disabled = false; + } + + }; + + +}); + + +app.controller('OneClickrestoreWebsiteControl', 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; + $scope.installationProgress = 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; + } + + + }; + + $scope.FetchOCSites = function () { + $scope.restoreLoading = false; + + // Current URL + const currentURL = window.location.href; + +// Create a URL object + const urlN = new URL(currentURL); + +// Get the value of the 'id' parameter + const idValue = urlN.searchParams.get('id'); + + + url = "/backup/fetchOCSites"; + + var data = { + idValue: idValue, + folder: $scope.ocFolder + + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.restoreLoading = true; + if (response.data.status === 1) { + + $scope.backups = response.data.finalDirs; + + } else { + + } + + } + + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = false; + restoreBackupButton.disabled = false; + } + + }; + + $scope.StartOCRestore = function () { + + $scope.restoreLoading = false; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $scope.restoreLoading = false; + + + $scope.currentStatus = "Starting creation.."; + + + // Current URL + const currentURL = window.location.href; + +// Create a URL object + const urlN = new URL(currentURL); + +// Get the value of the 'id' parameter + const idValue = urlN.searchParams.get('id'); + + + //alert(domainNameCreate); + var data = { + + idValue: idValue, + folder: $scope.ocFolder, + backupfile: $scope.ocFile + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var url = "/backup/StartOCRestore"; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.restoreLoading = true; + if (response.data.status === 1) { + statusFile = response.data.tempStatusPath; + getCreationStatus(); + + } else { + $scope.goBackDisable = false; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + + } + + function cantLoadInitialDatas(response) { + + alert("Error..." + response) + + } + + }; + $scope.goBack = function () { + $scope.webSiteCreationLoading = true; + $scope.installationDetailsForm = false; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $("#installProgress").css("width", "0%"); + }; + + function getCreationStatus() { + + url = "/websites/installWordpressStatus"; + + var data = { + statusFile: statusFile + }; + + 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.restoreLoading = 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.restoreLoading = 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.restoreLoading = false; + $("#installProgress").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + $timeout(getCreationStatus, 1000); + } + + } + + function cantLoadInitialDatas(response) { + + $scope.restoreLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + } + + +}); diff --git a/backup/templates/backup/OneClickBackupSchedule.html b/backup/templates/backup/OneClickBackupSchedule.html new file mode 100755 index 000000000..65e5cad33 --- /dev/null +++ b/backup/templates/backup/OneClickBackupSchedule.html @@ -0,0 +1,309 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "Schedule Backup - CyberPanel" %}{% endblock %} +{% block content %} + + {% load static %} + + + {% get_current_language as LANGUAGE_CODE %} + + +
{% trans "On this page you can schedule Backups to localhost or remote server (If you have added one)" %}
+
+
+ {% trans "This page can be used to Backup your websites" %}
-
- {% trans "This page can be used to Backup your websites" %}
+ Configure automatic backups to our secure servers in 60 seconds. Set-up now.
+{% trans "On this page you can set up your Backup destinations. (SFTP)" %}
+ src="{% static 'images/loading.gif' %}">
Configure automatic backups to our secure servers in 60 seconds. Set-up now.
+
+
+
{% trans "On this page you purchase and manage one-click backups." %}
+
+ You have successfully purchased a backup plan.
+Your purchase was not successful.
{{ message }} +{% trans "This page can be used to restore your websites, Backup should be generated from CyberPanel Backup generation tool, it will detect all Backups under /home/backup." %}
+
+ Looks like your websites are not secured with automatic backups. Configure now.
+