diff --git a/CLScript/CLMain.py b/CLScript/CLMain.py index 7fe666ab5..8755edcaa 100644 --- a/CLScript/CLMain.py +++ b/CLScript/CLMain.py @@ -4,8 +4,8 @@ class CLMain(): def __init__(self): self.path = '/usr/local/CyberCP/version.txt' #versionInfo = json.loads(open(self.path, 'r').read()) - self.version = '2.3' - self.build = '9' + self.version = '2.4' + self.build = '0' ipFile = "/etc/cyberpanel/machineIP" f = open(ipFile) diff --git a/backup/backupManager.py b/backup/backupManager.py index 37b52ec83..8dffe8a1a 100755 --- a/backup/backupManager.py +++ b/backup/backupManager.py @@ -34,6 +34,7 @@ import googleapiclient.discovery from googleapiclient.discovery import build from websiteFunctions.models import NormalBackupDests, NormalBackupJobs, NormalBackupSites from plogical.IncScheduler import IncScheduler +from django.http import JsonResponse class BackupManager: localBackupPath = '/home/cyberpanel/localBackupPath' @@ -2338,4 +2339,76 @@ class BackupManager: json_data = json.dumps(data_ret) return HttpResponse(json_data) + def ReconfigureSubscription(self, request=None, userID=None, data=None): + try: + if not data: + return JsonResponse({'status': 0, 'error_message': 'No data provided'}) + + subscription_id = data['subscription_id'] + customer_id = data['customer_id'] + plan_name = data['plan_name'] + amount = data['amount'] + interval = data['interval'] + + # Call platform API to update SFTP key + import requests + import json + + url = 'http://platform.cyberpersons.com/Billing/ReconfigureSubscription' + + payload = { + 'subscription_id': subscription_id, + 'key': ProcessUtilities.outputExecutioner(f'cat /root/.ssh/cyberpanel.pub'), + 'serverIP': ACLManager.fetchIP(), + 'email': data['email'], + 'code': data['code'] + } + + headers = {'Content-Type': 'application/json'} + response = requests.post(url, headers=headers, data=json.dumps(payload)) + + if response.status_code == 200: + response_data = response.json() + if response_data.get('status') == 1: + # Create OneClickBackups record + from IncBackups.models import OneClickBackups + backup_plan = OneClickBackups( + owner=Administrator.objects.get(pk=userID), + planName=plan_name, + months='1' if interval == 'month' else '12', + price=amount, + customer=customer_id, + subscription=subscription_id, + sftpUser=response_data.get('sftpUser'), + state=1 # Set as active since SFTP is already configured + ) + backup_plan.save() + + # Create SFTP destination in CyberPanel + finalDic = { + 'IPAddress': response_data.get('ipAddress'), + 'password': 'NOT-NEEDED', + 'backupSSHPort': '22', + 'userName': response_data.get('sftpUser'), + 'type': 'SFTP', + 'path': 'cpbackups', + 'name': response_data.get('sftpUser') + } + + wm = BackupManager() + response_inner = wm.submitDestinationCreation(userID, finalDic) + response_data_inner = json.loads(response_inner.content.decode('utf-8')) + + if response_data_inner.get('status') == 0: + return JsonResponse({'status': 0, 'error_message': response_data_inner.get('error_message')}) + + return JsonResponse({'status': 1}) + else: + return JsonResponse({'status': 0, 'error_message': response_data.get('error_message')}) + else: + return JsonResponse({'status': 0, 'error_message': f'Platform API error: {response.text}'}) + + except Exception as e: + return JsonResponse({'status': 0, 'error_message': str(e)}) + diff --git a/backup/static/backup/backup.js b/backup/static/backup/backup.js index 1500147a8..1760c54fc 100755 --- a/backup/static/backup/backup.js +++ b/backup/static/backup/backup.js @@ -2,6 +2,309 @@ * Created by usman on 9/17/17. */ +// Using existing CyberCP module +app.controller('backupPlanNowOneClick', function($scope, $http) { + $scope.cyberpanelLoading = true; + $scope.showVerification = false; + $scope.verificationCodeSent = false; + + $scope.showEmailVerification = function() { + console.log('showEmailVerification called'); + $scope.showVerification = true; + }; + + $scope.cancelVerification = function() { + $scope.showVerification = false; + $scope.verificationCodeSent = false; + $scope.verificationEmail = ''; + $scope.verificationCode = ''; + }; + + $scope.sendVerificationCode = function() { + $scope.cyberpanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post('https://platform.cyberpersons.com/Billing/SendBackupVerificationCode', { + email: $scope.verificationEmail + }, config).then(function(response) { + $scope.cyberpanelLoading = true; + if (response.data.status == 1) { + $scope.verificationCodeSent = true; + new PNotify({ + title: 'Success', + text: 'Verification code sent to your email.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Error', + text: response.data.error_message, + type: 'error' + }); + } + }, function(error) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Error', + text: 'Could not send verification code. Please try again.', + type: 'error' + }); + }); + }; + + $scope.verifyCode = function() { + $scope.cyberpanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post('https://platform.cyberpersons.com/Billing/VerifyBackupCode', { + email: $scope.verificationEmail, + code: $scope.verificationCode + }, config).then(function(response) { + if (response.data.status == 1) { + // After successful verification, fetch Stripe subscriptions + $http.post('https://platform.cyberpersons.com/Billing/FetchStripeSubscriptionsByEmail', { + email: $scope.verificationEmail, + code: $scope.verificationCode + }, config).then(function(subResponse) { + $scope.cyberpanelLoading = true; + if (subResponse.data.status == 1) { + $scope.showVerification = false; + $scope.subscriptions = subResponse.data.subscriptions; + $scope.showSubscriptionsTable = true; + + if ($scope.subscriptions.length == 0) { + new PNotify({ + title: 'Info', + text: 'No active subscriptions found for this email.', + type: 'info' + }); + } + } else { + new PNotify({ + title: 'Error', + text: subResponse.data.error_message, + type: 'error' + }); + } + }, function(error) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Error', + text: 'Could not fetch subscriptions. Please try again.', + type: 'error' + }); + }); + } else { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Error', + text: response.data.error_message, + type: 'error' + }); + } + }, function(error) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Error', + text: 'Could not verify code. Please try again.', + type: 'error' + }); + }); + }; + + $scope.fetchBackupPlans = function() { + $scope.cyberpanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post('https://platform.cyberpersons.com/Billing/FetchBackupPlans', { + email: $scope.verificationEmail + }, config).then(function(response) { + $scope.cyberpanelLoading = true; + if (response.data.status == 1) { + $scope.plans = response.data.plans; + new PNotify({ + title: 'Success', + text: 'Backup plans fetched successfully.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Error', + text: response.data.error_message, + type: 'error' + }); + } + }, function(error) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Error', + text: 'Could not fetch backup plans. Please try again.', + type: 'error' + }); + }); + }; + + $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.PaypalBuyNowBackup = function (planName, monthlyPrice, yearlyPrice, months) { + const baseURL = 'https://platform.cyberpersons.com/Billing/PaypalCreateOrderforBackupPlans'; + // 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.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.cyberpanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + }; + + $scope.ReconfigureSubscription = function(subscription) { + $scope.cyberpanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + subscription_id: subscription.subscription_id, + customer_id: subscription.customer, + plan_name: subscription.plan_name, + amount: subscription.amount, + interval: subscription.interval, + email: $scope.verificationEmail, + code: $scope.verificationCode + }; + + $http.post('/backup/ReconfigureSubscription', data, config).then(function(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Subscription configured successfully for this server.', + type: 'success' + }); + // Refresh the page to show new backup plan in the list + window.location.reload(); + } else { + new PNotify({ + title: 'Error', + text: response.data.error_message, + type: 'error' + }); + } + }, function(error) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Error', + text: 'Could not configure subscription. Please try again.', + type: 'error' + }); + }); + }; +}); + //*** Backup site ****// app.controller('backupWebsiteControl', function ($scope, $http, $timeout) { @@ -2045,307 +2348,6 @@ 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; - } - - }; - - //// paypal - - $scope.PaypalBuyNowBackup = function (planName, monthlyPrice, yearlyPrice, months) { - - const baseURL = 'https://platform.cyberpersons.com/Billing/PaypalCreateOrderforBackupPlans'; - // 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; - - } - - -}); - - app.controller('OneClickrestoreWebsiteControl', function ($scope, $http, $timeout) { $scope.restoreLoading = true; diff --git a/backup/templates/backup/oneClickBackups.html b/backup/templates/backup/oneClickBackups.html index 902572294..6b9b23b57 100755 --- a/backup/templates/backup/oneClickBackups.html +++ b/backup/templates/backup/oneClickBackups.html @@ -5,177 +5,601 @@ {% load static %} - {% get_current_language as LANGUAGE_CODE %} + +
{% trans "On this page you purchase and manage one-click backups." %}
+ + +On this page you purchase and manage one-click backups.
-
- You have successfully purchased a backup plan.
+ +Your purchase was not successful.
{{ message }} -| Subscription ID | +Status | +Amount | +Billing Interval | +Next Billing Date | +Actions | +
|---|---|---|---|---|---|
{$ sub.subscription_id $} |
+ + + {$ sub.status $} + + | +${$ sub.amount $} | +{$ sub.interval $} | +{$ sub.current_period_end | date:'medium' $} | ++ + | +
You have successfully purchased a backup plan.
+Your purchase was not successful. {{ message }}
+{{ message }}
+