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 "One-click Backups" %} - {% trans "One-Click Backup Docs" %} -

-

{% trans "On this page you purchase and manage one-click backups." %}

+ + + + +

On this page you purchase and manage one-click backups.

-
-
-

- {% trans "Set up Backup Destinations." %} -

-
+
+ + - {% if status == 1 %} -
-

You have successfully purchased a backup plan.

+ +
+
+ {% trans "Verify Your Email" %} +
+
+
+
+
+ + +
+ +
+ + +
+ +
+ + + +
- {% elif status == 0 %} +
+
+
-
-

Your purchase was not successful.

{{ message }} -
- {% elif status == 4 %} + +
+
+ Your Active Subscriptions +
+
+ + + + + + + + + + + + + + + + + + + + + +
Subscription IDStatusAmountBilling IntervalNext Billing DateActions
{$ sub.subscription_id $} + + {$ sub.status $} + + ${$ sub.amount $}{$ sub.interval $}{$ sub.current_period_end | date:'medium' $} + +
+
+
-
- {{ message }} -
- {% endif %} + + {% if status == 1 %} +
+

You have successfully purchased a backup plan.

+
+ {% elif status == 0 %} +
+

Your purchase was not successful. {{ message }}

+
+ {% elif status == 4 %} +
+

{{ message }}

+
+ {% endif %} -
- -

With CyberPanel's one-click backups, you can easily back - up your website to our secure - servers in just 60 seconds. It's simple, fast, and reliable.

- - - - -
- -
- - - - - - - - - - - - - - {% for plan in bPlans %} - - - - + +
+
Your Backup Plans
+
+
{% trans "Account" %}{% trans "Plan Name" %}{% trans "Subscription" %}{% trans "Billing Cycle" %}{% trans "Purchase Date" %}{% trans "Actions" %}
{{ plan.sftpUser }}{{ plan.planName }}{{ plan.subscription }}
+ + + + + + + + + + + + {% for plan in bPlans %} + + + + + + ${{ plan.price }}/month {% else %} - + ${{ plan.price }}/year {% endif %} - - - - - {% endfor %} - -
{% trans "Account" %}{% trans "Plan Name" %}{% trans "Subscription" %}{% trans "Billing Cycle" %}{% trans "Purchase Date" %}{% trans "Actions" %}
{{ plan.sftpUser }}{{ plan.planName }}{{ plan.subscription }} + {% if plan.months == '1' %} - ${{ plan.price }}/month${{ plan.price }}/year{{ plan.date }} - {% if plan.state == 1 %} - - - - - - - {% else %} - - {% endif %} - -
-
- -
- - - - - - -

- {% trans "Subscribe to one-click backup plans." %} -

- -
-
- - - - - - - - - - - {% for plan in plans %} - - - - - + + - - - {% endfor %} - -
{% trans "Plan Name" %}{% trans "Monthly Price" %}{% trans "Yearly Price" %}{% trans "Actions" %}
{{ plan.name }}${{ plan.monthlyPrice }}${{ plan.yearlyPrice }} - {% if plan.name != '100GB' %} - - {% endif %} + + {{ plan.date }} +
+ {% if plan.state == 1 %} + + {% trans "Schedule Backups" %} + + + {% trans "Restore Backups" %} + + {% else %} - {% if plan.name != '100GB' %} - - {% endif %} - -
+ ng-click="DeployAccount('{{ plan.id }}')" + class="cp-btn cp-btn-primary"> + {% trans "Deploy Account" %} + + {% endif %} +
+ + + {% endfor %} + + +
+
+ + +

Available Backup Plans

+
+
+ +
+
100GB
+
+
+
${{ plans.0.monthlyPrice }}
+
/month
- +
+
${{ plans.0.yearlyPrice }}
+
/year
+
+ + + Yearly via Card +
- - - - - - - - - - +
+ + +
+
500GB
+
+
+
${{ plans.1.monthlyPrice }}
+
/month
+
+
+
${{ plans.1.yearlyPrice }}
+
/year
+
+ + +
+
+ + +
+
1TB
+
+
+
${{ plans.2.monthlyPrice }}
+
/month
+
+
+
${{ plans.2.yearlyPrice }}
+
/year
+
+ + +
+
+ + +
+
2TB
+
+
+
${{ plans.3.monthlyPrice }}
+
/month
+
+
+
${{ plans.3.yearlyPrice }}
+
/year
+
+ + +
+
+ + +
+
3TB
+
+
+
${{ plans.4.monthlyPrice }}
+
/month
+
+
+
${{ plans.4.yearlyPrice }}
+
/year
+
+ + +
+
- -
- {% endblock %} \ No newline at end of file diff --git a/backup/urls.py b/backup/urls.py index 310a7c95d..22b0a2953 100755 --- a/backup/urls.py +++ b/backup/urls.py @@ -10,6 +10,7 @@ urlpatterns = [ re_path(r'^fetchOCSites$', views.fetchOCSites, name='fetchOCSites'), re_path(r'^StartOCRestore$', views.StartOCRestore, name='StartOCRestore'), re_path(r'^DeployAccount$', views.DeployAccount, name='DeployAccount'), + re_path(r'^ReconfigureSubscription$', views.ReconfigureSubscription, name='ReconfigureSubscription'), re_path(r'^backupSite$', views.backupSite, name='backupSite'), re_path(r'^restoreSite$', views.restoreSite, name='restoreSite'), diff --git a/backup/views.py b/backup/views.py index 7689ef1ac..c3f843fc9 100755 --- a/backup/views.py +++ b/backup/views.py @@ -5,6 +5,7 @@ import json from django.shortcuts import redirect +from django.http import HttpResponse from backup.backupManager import BackupManager from backup.pluginManager import pluginManager @@ -12,6 +13,8 @@ from loginSystem.views import loadLoginPage import os from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging from django.views.decorators.csrf import csrf_exempt +from django.contrib.auth.models import User +from loginSystem.models import Administrator def loadBackupHome(request): try: @@ -538,4 +541,15 @@ def DeployAccount(request): bm = BackupManager() return bm.DeployAccount(request, userID) except KeyError: - return redirect(loadLoginPage) \ No newline at end of file + return redirect(loadLoginPage) + +def ReconfigureSubscription(request): + try: + userID = request.session['userID'] + bm = BackupManager() + data = json.loads(request.body) + return bm.ReconfigureSubscription(request, userID, data) + except BaseException as msg: + data_ret = {'status': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) \ No newline at end of file diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index 8a37e7eaf..07b9e5b00 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -77,7 +77,7 @@ - {% with version="2.3.8.1.1" %} + {% with version="2.4.0" %} @@ -87,7 +87,7 @@ + href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> @@ -248,7 +248,7 @@ title="{% trans 'Server IP Address' %}"> - {{ ipAddress }} + {{ ipAddress }} @@ -376,7 +376,6 @@
{% trans "Docker Apps" %} - {% trans "Beta" %}
{% block footer_scripts %} {% endblock %} + diff --git a/baseTemplate/views.py b/baseTemplate/views.py index 14b80d9d5..57ffada4c 100755 --- a/baseTemplate/views.py +++ b/baseTemplate/views.py @@ -20,8 +20,8 @@ from plogical.httpProc import httpProc # Create your views here. -VERSION = '2.3' -BUILD = 9 +VERSION = '2.4' +BUILD = 0 @ensure_csrf_cookie diff --git a/cyberpanel_upgrade.sh b/cyberpanel_upgrade.sh index 90db1e673..add013a9d 100644 --- a/cyberpanel_upgrade.sh +++ b/cyberpanel_upgrade.sh @@ -765,7 +765,7 @@ else Check_Return fi -wget https://cyberpanel.sh/www.litespeedtech.com/packages/lsapi/wsgi-lsapi-2.1.tgz +wget https://www.litespeedtech.com/packages/lsapi/wsgi-lsapi-2.1.tgz tar xf wsgi-lsapi-2.1.tgz cd wsgi-lsapi-2.1 || exit /usr/local/CyberPanel/bin/python ./configure.py diff --git a/dockerManager/container.py b/dockerManager/container.py index 69b8fef01..5cd95f266 100755 --- a/dockerManager/container.py +++ b/dockerManager/container.py @@ -3,6 +3,7 @@ import os.path import sys import django +from datetime import datetime from plogical.DockerSites import Docker_Sites @@ -1116,27 +1117,68 @@ class ContainerManager(multi.Thread): if admin.acl.adminStatus != 1: return ACLManager.loadError() - name = data['name'] containerID = data['id'] - passdata = {} - passdata["JobID"] = None - passdata['name'] = name - passdata['containerID'] = containerID - da = Docker_Sites(None, passdata) - retdata = da.ContainerInfo() + # Create a Docker client + client = docker.from_env() + container = client.containers.get(containerID) + # Get detailed container info + container_info = container.attrs - data_ret = {'status': 1, 'error_message': 'None', 'data':retdata} + # Calculate uptime + started_at = container_info.get('State', {}).get('StartedAt', '') + if started_at: + started_time = datetime.strptime(started_at.split('.')[0], '%Y-%m-%dT%H:%M:%S') + uptime = datetime.now() - started_time + uptime_str = str(uptime).split('.')[0] # Format as HH:MM:SS + else: + uptime_str = "N/A" + + # Get container details + details = { + 'id': container.short_id, + 'name': container.name, + 'status': container.status, + 'created': container_info.get('Created', ''), + 'started_at': started_at, + 'uptime': uptime_str, + 'image': container_info.get('Config', {}).get('Image', ''), + 'ports': container_info.get('NetworkSettings', {}).get('Ports', {}), + 'volumes': container_info.get('Mounts', []), + 'environment': self._mask_sensitive_env(container_info.get('Config', {}).get('Env', [])), + 'memory_usage': container.stats(stream=False)['memory_stats'].get('usage', 0), + 'cpu_usage': container.stats(stream=False)['cpu_stats']['cpu_usage'].get('total_usage', 0) + } + + data_ret = {'status': 1, 'error_message': 'None', 'data': [1, details]} json_data = json.dumps(data_ret) return HttpResponse(json_data) except BaseException as msg: - data_ret = {'removeImageStatus': 0, 'error_message': str(msg)} + data_ret = {'status': 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) return HttpResponse(json_data) + def _mask_sensitive_env(self, env_vars): + """Helper method to mask sensitive data in environment variables""" + masked_vars = [] + sensitive_keywords = ['password', 'secret', 'key', 'token', 'auth'] + + for var in env_vars: + if '=' in var: + name, value = var.split('=', 1) + # Check if this is a sensitive variable + if any(keyword in name.lower() for keyword in sensitive_keywords): + masked_vars.append(f"{name}=********") + else: + masked_vars.append(var) + else: + masked_vars.append(var) + + return masked_vars + def getContainerApplog(self, userID=None, data=None): try: admin = Administrator.objects.get(pk=userID) diff --git a/dockerManager/urls.py b/dockerManager/urls.py index 47ffc0d01..12ecdc16a 100755 --- a/dockerManager/urls.py +++ b/dockerManager/urls.py @@ -1,7 +1,7 @@ from django.urls import path, re_path from . import views -from websiteFunctions.views import Dockersitehome +from websiteFunctions.views import Dockersitehome, startContainer, stopContainer, restartContainer urlpatterns = [ re_path(r'^$', views.loadDockerHome, name='dockerHome'), @@ -27,7 +27,7 @@ urlpatterns = [ re_path(r'^recreateContainer$', views.recreateContainer, name='recreateContainer'), re_path(r'^installDocker$', views.installDocker, name='installDocker'), re_path(r'^images$', views.images, name='containerImage'), - re_path(r'^view/(?P.+)$', views.viewContainer, name='viewContainer'), + re_path(r'^view/(?P.+)$', views.viewContainer, name='viewContainer'), path('manage//app', Dockersitehome, name='Dockersitehome'), path('getDockersiteList', views.getDockersiteList, name='getDockersiteList'), @@ -36,4 +36,9 @@ urlpatterns = [ path('recreateappcontainer', views.recreateappcontainer, name='recreateappcontainer'), path('RestartContainerAPP', views.RestartContainerAPP, name='RestartContainerAPP'), path('StopContainerAPP', views.StopContainerAPP, name='StopContainerAPP'), + + # Docker Container Actions + path('startContainer', startContainer, name='startContainer'), + path('stopContainer', stopContainer, name='stopContainer'), + path('restartContainer', restartContainer, name='restartContainer'), ] diff --git a/install/install.py b/install/install.py index c01206e09..dec901953 100755 --- a/install/install.py +++ b/install/install.py @@ -14,8 +14,8 @@ from os.path import * from stat import * import stat -VERSION = '2.3' -BUILD = 9 +VERSION = '2.4' +BUILD = 0 char_set = {'small': 'abcdefghijklmnopqrstuvwxyz', 'nums': '0123456789', 'big': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'} diff --git a/loginSystem/views.py b/loginSystem/views.py index 256f9aab5..9a35c76f5 100644 --- a/loginSystem/views.py +++ b/loginSystem/views.py @@ -16,8 +16,8 @@ from django.http import HttpResponse from django.utils import translation # Create your views here. -VERSION = '2.3' -BUILD = 9 +VERSION = '2.4' +BUILD = 0 def verifyLogin(request): diff --git a/plogical/DockerSites.py b/plogical/DockerSites.py index 62a0d2f12..181d53855 100644 --- a/plogical/DockerSites.py +++ b/plogical/DockerSites.py @@ -4,6 +4,9 @@ import os import sys import time from random import randint +import socket +import shutil +import docker sys.path.append('/usr/local/CyberCP') @@ -24,11 +27,25 @@ from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging import argparse import threading as multi +class DockerDeploymentError(Exception): + def __init__(self, message, error_code=None, recovery_possible=True): + self.message = message + self.error_code = error_code + self.recovery_possible = recovery_possible + super().__init__(self.message) class Docker_Sites(multi.Thread): Wordpress = 1 Joomla = 2 + # Error codes + ERROR_DOCKER_NOT_INSTALLED = 'DOCKER_NOT_INSTALLED' + ERROR_PORT_IN_USE = 'PORT_IN_USE' + ERROR_CONTAINER_FAILED = 'CONTAINER_FAILED' + ERROR_NETWORK_FAILED = 'NETWORK_FAILED' + ERROR_VOLUME_FAILED = 'VOLUME_FAILED' + ERROR_DB_FAILED = 'DB_FAILED' + def __init__(self, function_run, data): multi.Thread.__init__(self) self.function_run = function_run @@ -165,15 +182,54 @@ class Docker_Sites(multi.Thread): return 0, ReturnCode else: - command = 'apt install docker-compose -y' - - ReturnCode = ProcessUtilities.executioner(command) - - if ReturnCode: - return 1, None - else: + # Add Docker's official GPG key + command = 'curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg' + ReturnCode = ProcessUtilities.executioner(command, 'root', True) + if not ReturnCode: return 0, ReturnCode + # Add Docker repository + command = 'echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null' + ReturnCode = ProcessUtilities.executioner(command, 'root', True) + if not ReturnCode: + return 0, ReturnCode + + # Update package index + command = 'apt-get update' + ReturnCode = ProcessUtilities.executioner(command) + if not ReturnCode: + return 0, ReturnCode + + # Install Docker packages + command = 'apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin' + ReturnCode = ProcessUtilities.executioner(command) + if not ReturnCode: + return 0, ReturnCode + + # Enable and start Docker service + command = 'systemctl enable docker' + ReturnCode = ProcessUtilities.executioner(command) + if not ReturnCode: + return 0, ReturnCode + + command = 'systemctl start docker' + ReturnCode = ProcessUtilities.executioner(command) + if not ReturnCode: + return 0, ReturnCode + + # Install Docker Compose + command = 'curl -L "https://github.com/docker/compose/releases/download/v2.23.2/docker-compose-linux-$(uname -m)" -o /usr/local/bin/docker-compose' + ReturnCode = ProcessUtilities.executioner(command, 'root', True) + if not ReturnCode: + return 0, ReturnCode + + command = 'chmod +x /usr/local/bin/docker-compose' + ReturnCode = ProcessUtilities.executioner(command, 'root', True) + if not ReturnCode: + return 0, ReturnCode + + return 1, None + @staticmethod def SetupProxy(port): import xml.etree.ElementTree as ET @@ -614,8 +670,6 @@ services: ### forcefully delete containers - import docker - # Create a Docker client client = docker.from_env() @@ -651,43 +705,73 @@ services: ## This function need site name which was passed while creating the app def ListContainers(self): try: - - import docker - # Create a Docker client client = docker.from_env() - FilerValue = self.DockerAppName + # Debug logging + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f'DockerAppName: {self.DockerAppName}') - # Define the label to filter containers - label_filter = {'name': FilerValue} + # List all containers without filtering first + all_containers = client.containers.list(all=True) + + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f'Total containers found: {len(all_containers)}') + for container in all_containers: + logging.writeToFile(f'Container name: {container.name}') + # Now filter containers - handle both CentOS and Ubuntu naming + containers = [] + + # Get both possible name formats + if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + search_name = self.DockerAppName # Already in hyphen format for CentOS + else: + # For Ubuntu, convert underscore to hyphen as containers use hyphens + search_name = self.DockerAppName.replace('_', '-') + + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f'Searching for containers with name containing: {search_name}') - # List containers matching the label filter - containers = client.containers.list(filters=label_filter) + for container in all_containers: + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f'Checking container: {container.name} against filter: {search_name}') + if search_name.lower() in container.name.lower(): + containers.append(container) + + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f'Filtered containers count: {len(containers)}') json_data = "[" checker = 0 for container in containers: + try: + dic = { + 'id': container.short_id, + 'name': container.name, + 'status': container.status, + 'state': container.attrs.get('State', {}), + 'health': container.attrs.get('State', {}).get('Health', {}).get('Status', 'unknown'), + 'volumes': container.attrs['HostConfig']['Binds'] if 'HostConfig' in container.attrs else [], + 'logs_50': container.logs(tail=50).decode('utf-8'), + 'ports': container.attrs['HostConfig']['PortBindings'] if 'HostConfig' in container.attrs else {} + } - dic = { - 'id': container.short_id, - 'name': container.name, - 'status': container.status, - 'volumes': container.attrs['HostConfig']['Binds'] if 'HostConfig' in container.attrs else [], - 'logs_50': container.logs(tail=50).decode('utf-8'), - 'ports': container.attrs['HostConfig']['PortBindings'] if 'HostConfig' in container.attrs else {} - } - - if checker == 0: - json_data = json_data + json.dumps(dic) - checker = 1 - else: - json_data = json_data + ',' + json.dumps(dic) + if checker == 0: + json_data = json_data + json.dumps(dic) + checker = 1 + else: + json_data = json_data + ',' + json.dumps(dic) + except Exception as e: + logging.writeToFile(f"Error processing container {container.name}: {str(e)}") + continue json_data = json_data + ']' + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f'Final JSON data: {json_data}') + return 1, json_data except BaseException as msg: @@ -697,7 +781,6 @@ services: ### pass container id and number of lines to fetch from logs def ContainerLogs(self): try: - import docker # Create a Docker client client = docker.from_env() @@ -716,7 +799,6 @@ services: def ContainerInfo(self): try: - import docker # Create a Docker client client = docker.from_env() @@ -748,7 +830,6 @@ services: def RestartContainer(self): try: - import docker # Create a Docker client client = docker.from_env() @@ -764,7 +845,6 @@ services: def StopContainer(self): try: - import docker # Create a Docker client client = docker.from_env() @@ -780,172 +860,550 @@ services: ##### N8N Container - def DeployN8NContainer(self): + def check_container_health(self, container_name, max_retries=3, delay=80): + """ + Check if a container is running, accepting healthy, unhealthy, and starting states + Total wait time will be 4 minutes (3 retries * 80 seconds) + """ try: + # Format container name to match Docker's naming convention + formatted_name = f"{self.data['ServiceName']}-{container_name}-1" + logging.writeToFile(f'Checking container health for: {formatted_name}') + + for attempt in range(max_retries): + client = docker.from_env() + container = client.containers.get(formatted_name) + + if container.status == 'running': + health = container.attrs.get('State', {}).get('Health', {}).get('Status') + + # Accept healthy, unhealthy, and starting states as long as container is running + if health in ['healthy', 'unhealthy', 'starting'] or health is None: + logging.writeToFile(f'Container {formatted_name} is running with status: {health}') + return True + else: + health_logs = container.attrs.get('State', {}).get('Health', {}).get('Log', []) + if health_logs: + last_log = health_logs[-1] + logging.writeToFile(f'Container health check failed: {last_log.get("Output", "")}') + + logging.writeToFile(f'Container {formatted_name} status: {container.status}, health: {health}, attempt {attempt + 1}/{max_retries}') + time.sleep(delay) + + return False + + except docker.errors.NotFound: + logging.writeToFile(f'Container {formatted_name} not found') + return False + except Exception as e: + logging.writeToFile(f'Error checking container health: {str(e)}') + return False - logging.statusWriter(self.JobID, 'Checking if Docker is installed..,0') + def verify_system_resources(self): + try: + # Check available disk space using root access + command = "df -B 1G /home/docker --output=avail | tail -1" + result, output = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise DockerDeploymentError("Failed to check disk space") + available_gb = int(output.strip()) - command = 'docker --help' - result = ProcessUtilities.outputExecutioner(command) + if available_gb < 5: # Require minimum 5GB free space + raise DockerDeploymentError( + f"Insufficient disk space. Need at least 5GB but only {available_gb}GB available.", + self.ERROR_VOLUME_FAILED + ) - if os.path.exists(ProcessUtilities.debugPath): - logging.writeToFile(f'return code of docker install {result}') + # Check if Docker is running and accessible + command = "systemctl is-active docker" + result, docker_status = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise DockerDeploymentError("Failed to check Docker status") + if docker_status.strip() != "active": + raise DockerDeploymentError("Docker service is not running") - if result.find("not found") > -1: - if os.path.exists(ProcessUtilities.debugPath): - logging.writeToFile(f'About to run docker install function...') + # Check Docker system info for resource limits + command = "docker info --format '{{.MemTotal}}'" + result, total_memory = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise DockerDeploymentError("Failed to get Docker memory info") + + # Convert total_memory from bytes to MB + total_memory_mb = int(total_memory.strip()) / (1024 * 1024) + + # Calculate required memory from site and MySQL requirements + required_memory = int(self.data['MemoryMySQL']) + int(self.data['MemorySite']) + + if total_memory_mb < required_memory: + raise DockerDeploymentError( + f"Insufficient memory. Need {required_memory}MB but only {int(total_memory_mb)}MB available", + 'INSUFFICIENT_MEMORY' + ) - execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/dockerManager/dockerInstall.py" + # Verify Docker group and permissions + command = "getent group docker" + result, docker_group = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0 or not docker_group: + raise DockerDeploymentError("Docker group does not exist") + + return True + + except DockerDeploymentError as e: + raise e + except Exception as e: + raise DockerDeploymentError(f"Resource verification failed: {str(e)}") + + def setup_docker_environment(self): + try: + # Create docker directory with root + command = f"mkdir -p /home/docker/{self.data['finalURL']}" + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # Set proper permissions + command = f"chown -R {self.data['externalApp']}:docker /home/docker/{self.data['finalURL']}" + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # Create docker network if doesn't exist + command = "docker network ls | grep cyberpanel" + network_exists = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if not network_exists: + command = "docker network create cyberpanel" + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + return True + + except Exception as e: + raise DockerDeploymentError(f"Environment setup failed: {str(e)}") + + def deploy_containers(self): + try: + # Write docker-compose file + command = f"cat > {self.data['ComposePath']} << 'EOF'\n{self.data['ComposeContent']}\nEOF" + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # Set proper permissions on compose file + command = f"chmod 600 {self.data['ComposePath']} && chown root:root {self.data['ComposePath']}" + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # Deploy with docker-compose + command = f"cd {os.path.dirname(self.data['ComposePath'])} && docker-compose up -d" + result = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if "error" in result.lower(): + raise DockerDeploymentError(f"Container deployment failed: {result}") + + return True + + except Exception as e: + raise DockerDeploymentError(f"Deployment failed: {str(e)}") + + def cleanup_failed_deployment(self): + try: + # Stop and remove containers + command = f"cd {os.path.dirname(self.data['ComposePath'])} && docker-compose down -v" + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # Remove docker directory + command = f"rm -rf /home/docker/{self.data['finalURL']}" + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # Remove compose file + command = f"rm -f {self.data['ComposePath']}" + ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + return True + + except Exception as e: + logging.writeToFile(f"Cleanup failed: {str(e)}") + return False + + def monitor_deployment(self): + try: + # Format container names + n8n_container_name = f"{self.data['ServiceName']}-{self.data['ServiceName']}-1" + db_container_name = f"{self.data['ServiceName']}-{self.data['ServiceName']}-db-1" + + logging.writeToFile(f'Monitoring containers: {n8n_container_name} and {db_container_name}') + + # Check container health + command = f"docker ps -a --filter name={self.data['ServiceName']} --format '{{{{.Status}}}}'" + result, status = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # Only raise error if container is exited + if "exited" in status: + # Get container logs + command = f"docker logs {n8n_container_name}" + result, logs = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + raise DockerDeploymentError(f"Container exited. Logs: {logs}") + + # Wait for database to be ready + max_retries = 30 + retry_count = 0 + db_ready = False + + while retry_count < max_retries: + # Check if database container is ready + command = f"docker exec {db_container_name} pg_isready -U postgres" + result, output = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if "accepting connections" in output: + db_ready = True + break + + # Check container status + command = f"docker inspect --format='{{{{.State.Status}}}}' {db_container_name}" + result, db_status = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # Only raise error if database container is in a failed state + if db_status == 'exited': + raise DockerDeploymentError(f"Database container is in {db_status} state") + + retry_count += 1 + time.sleep(2) + logging.writeToFile(f'Waiting for database to be ready, attempt {retry_count}/{max_retries}') + + if not db_ready: + raise DockerDeploymentError("Database failed to become ready within timeout period") + + # Check n8n container status + command = f"docker inspect --format='{{{{.State.Status}}}}' {n8n_container_name}" + result, n8n_status = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + # Only raise error if n8n container is in a failed state + if n8n_status == 'exited': + raise DockerDeploymentError(f"n8n container is in {n8n_status} state") + + logging.writeToFile(f'Deployment monitoring completed successfully. n8n status: {n8n_status}, database ready: {db_ready}') + return True + + except Exception as e: + logging.writeToFile(f'Error during monitoring: {str(e)}') + raise DockerDeploymentError(f"Monitoring failed: {str(e)}") + + def handle_deployment_failure(self, error, cleanup=True): + """ + Handle deployment failures and attempt recovery + """ + try: + logging.writeToFile(f'Deployment failed: {str(error)}') + + if cleanup: + self.cleanup_failed_deployment() + + if isinstance(error, DockerDeploymentError): + if error.error_code == self.ERROR_DOCKER_NOT_INSTALLED: + # Attempt to install Docker + execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/dockerManager/dockerInstall.py" + ProcessUtilities.executioner(execPath) + return True + + elif error.error_code == self.ERROR_PORT_IN_USE: + # Find next available port + new_port = int(self.data['port']) + 1 + while new_port < 65535: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + result = sock.connect_ex(('127.0.0.1', new_port)) + sock.close() + if result != 0: + self.data['port'] = str(new_port) + return True + new_port += 1 + + elif error.error_code == self.ERROR_DB_FAILED: + # Attempt database recovery + return self.recover_database() + + return False + + except Exception as e: + logging.writeToFile(f'Error during failure handling: {str(e)}') + return False + + def recover_database(self): + """ + Attempt to recover the database container + """ + try: + client = docker.from_env() + db_container_name = f"{self.data['ServiceName']}-db" + + try: + db_container = client.containers.get(db_container_name) + + if db_container.status == 'running': + exec_result = db_container.exec_run( + 'pg_isready -U postgres' + ) + + if exec_result.exit_code != 0: + db_container.restart() + time.sleep(10) + + if self.check_container_health(db_container_name): + return True + + except docker.errors.NotFound: + pass + + return False + + except Exception as e: + logging.writeToFile(f'Database recovery failed: {str(e)}') + return False + + def log_deployment_metrics(self, metrics): + """ + Log deployment metrics for analysis + """ + if metrics: + try: + log_file = f"/var/log/cyberpanel/docker/{self.data['ServiceName']}_metrics.json" + os.makedirs(os.path.dirname(log_file), exist_ok=True) + + with open(log_file, 'w') as f: + json.dump(metrics, f, indent=2) + + except Exception as e: + logging.writeToFile(f'Error logging metrics: {str(e)}') + + def DeployN8NContainer(self): + """ + Main deployment method with error handling + """ + max_retries = 3 + current_try = 0 + + while current_try < max_retries: + try: + logging.statusWriter(self.JobID, 'Starting deployment verification...,0') + + # Check Docker installation + command = 'docker --help' + result = ProcessUtilities.outputExecutioner(command) + if result.find("not found") > -1: + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f'About to run docker install function...') + + # Call InstallDocker to install Docker + install_result, error = self.InstallDocker() + if not install_result: + logging.statusWriter(self.JobID, f'Failed to install Docker: {error} [404]') + return 0 + + logging.statusWriter(self.JobID, 'Docker installation verified...,20') + + # Verify system resources + self.verify_system_resources() + logging.statusWriter(self.JobID, 'System resources verified...,10') + + # Create directories + command = f"mkdir -p /home/docker/{self.data['finalURL']}" + result, message = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise DockerDeploymentError(f"Failed to create directories: {message}") + logging.statusWriter(self.JobID, 'Directories created...,30') + + # Generate and write docker-compose file + self.data['ServiceName'] = self.data["SiteName"].replace(' ', '-') + compose_config = self.generate_compose_config() + + TempCompose = f'/home/cyberpanel/{self.data["finalURL"]}-docker-compose.yml' + with open(TempCompose, 'w') as f: + f.write(compose_config) + + command = f"mv {TempCompose} {self.data['ComposePath']}" + result, message = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise DockerDeploymentError(f"Failed to move compose file: {message}") + + command = f"chmod 600 {self.data['ComposePath']} && chown root:root {self.data['ComposePath']}" + ProcessUtilities.executioner(command, 'root', True) + logging.statusWriter(self.JobID, 'Docker compose file created...,40') + + # Deploy containers + if ProcessUtilities.decideDistro() == ProcessUtilities.cent8 or ProcessUtilities.decideDistro() == ProcessUtilities.centos: + dockerCommand = 'docker compose' + else: + dockerCommand = 'docker-compose' + + command = f"{dockerCommand} -f {self.data['ComposePath']} -p '{self.data['SiteName']}' up -d" + result, message = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: + raise DockerDeploymentError(f"Failed to deploy containers: {message}") + logging.statusWriter(self.JobID, 'Containers deployed...,60') + + # Wait for containers to be healthy + time.sleep(25) + if not self.check_container_health(f"{self.data['ServiceName']}-db") or \ + not self.check_container_health(self.data['ServiceName']): + raise DockerDeploymentError("Containers failed to reach healthy state", self.ERROR_CONTAINER_FAILED) + logging.statusWriter(self.JobID, 'Containers healthy...,70') + + # Setup proxy + execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/DockerSites.py" + execPath = execPath + f" SetupProxy --port {self.data['port']}" ProcessUtilities.executioner(execPath) + logging.statusWriter(self.JobID, 'Proxy configured...,80') - logging.statusWriter(self.JobID, 'Docker is ready to use..,10') + # Setup ht access + execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/DockerSites.py" + execPath = execPath + f" SetupHTAccess --port {self.data['port']} --htaccess {self.data['htaccessPath']}" + ProcessUtilities.executioner(execPath, self.data['externalApp']) + logging.statusWriter(self.JobID, 'HTAccess configured...,90') - self.data['ServiceName'] = self.data["SiteName"].replace(' ', '-') + # Restart web server + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeedSocket() - WPSite = f''' -version: '3.8' + # Monitor deployment + metrics = self.monitor_deployment() + self.log_deployment_metrics(metrics) + + logging.statusWriter(self.JobID, 'Deployment completed successfully. [200]') + return True + + except DockerDeploymentError as e: + logging.writeToFile(f'Deployment error: {str(e)}') + + if self.handle_deployment_failure(e): + current_try += 1 + continue + else: + logging.statusWriter(self.JobID, f'Deployment failed: {str(e)} [404]') + return False + + except Exception as e: + logging.writeToFile(f'Unexpected error: {str(e)}') + self.handle_deployment_failure(e) + logging.statusWriter(self.JobID, f'Deployment failed: {str(e)} [404]') + return False + + logging.statusWriter(self.JobID, f'Deployment failed after {max_retries} attempts [404]') + return False + + def generate_compose_config(self): + """ + Generate the docker-compose configuration with improved security and reliability + """ + postgres_config = { + 'image': 'postgres:16-alpine', + 'user': 'root', + 'healthcheck': { + 'test': ["CMD-SHELL", "pg_isready -U postgres"], + 'interval': '10s', + 'timeout': '5s', + 'retries': 5, + 'start_period': '30s' + }, + 'environment': { + 'POSTGRES_USER': 'postgres', + 'POSTGRES_PASSWORD': self.data['MySQLPassword'], + 'POSTGRES_DB': self.data['MySQLDBName'] + } + } + + n8n_config = { + 'image': 'docker.n8n.io/n8nio/n8n', + 'user': 'root', + 'healthcheck': { + 'test': ["CMD", "wget", "--spider", "http://localhost:5678"], + 'interval': '20s', + 'timeout': '10s', + 'retries': 3 + }, + 'environment': { + 'DB_TYPE': 'postgresdb', + 'DB_POSTGRESDB_HOST': f"{self.data['ServiceName']}-db", + 'DB_POSTGRESDB_PORT': '5432', + 'DB_POSTGRESDB_DATABASE': self.data['MySQLDBName'], + 'DB_POSTGRESDB_USER': 'postgres', + 'DB_POSTGRESDB_PASSWORD': self.data['MySQLPassword'], + 'N8N_HOST': self.data['finalURL'], + 'NODE_ENV': 'production', + 'WEBHOOK_URL': f"https://{self.data['finalURL']}", + 'N8N_PUSH_BACKEND': 'sse', + 'GENERIC_TIMEZONE': 'UTC', + 'N8N_ENCRYPTION_KEY': 'auto', + 'N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS': 'true', + 'DB_POSTGRESDB_SCHEMA': 'public' + } + } + + return f'''version: '3.8' volumes: db_storage: + driver: local n8n_storage: + driver: local services: '{self.data['ServiceName']}-db': - image: docker.io/bitnami/postgresql:16 - user: root + image: {postgres_config['image']} + user: {postgres_config['user']} restart: always + healthcheck: + test: {postgres_config['healthcheck']['test']} + interval: {postgres_config['healthcheck']['interval']} + timeout: {postgres_config['healthcheck']['timeout']} + retries: {postgres_config['healthcheck']['retries']} + start_period: {postgres_config['healthcheck']['start_period']} environment: -# - POSTGRES_USER:root - - POSTGRESQL_USERNAME={self.data['MySQLDBNUser']} - - POSTGRESQL_DATABASE={self.data['MySQLDBName']} - - POSTGRESQL_POSTGRES_PASSWORD={self.data['MySQLPassword']} - - POSTGRESQL_PASSWORD={self.data['MySQLPassword']} + - POSTGRES_USER={postgres_config['environment']['POSTGRES_USER']} + - POSTGRES_PASSWORD={postgres_config['environment']['POSTGRES_PASSWORD']} + - POSTGRES_DB={postgres_config['environment']['POSTGRES_DB']} volumes: -# - "/home/docker/{self.data['finalURL']}/db:/var/lib/postgresql/data" - - "/home/docker/{self.data['finalURL']}/db:/bitnami/postgresql" + - "/home/docker/{self.data['finalURL']}/db:/var/lib/postgresql/data" + networks: + - n8n-network + deploy: + resources: + limits: + cpus: '{self.data["CPUsMySQL"]}' + memory: {self.data["MemoryMySQL"]}M '{self.data['ServiceName']}': - image: docker.n8n.io/n8nio/n8n - user: root + image: {n8n_config['image']} + user: {n8n_config['user']} restart: always + healthcheck: + test: {n8n_config['healthcheck']['test']} + interval: {n8n_config['healthcheck']['interval']} + timeout: {n8n_config['healthcheck']['timeout']} + retries: {n8n_config['healthcheck']['retries']} environment: - - DB_TYPE=postgresdb - - DB_POSTGRESDB_HOST={self.data['ServiceName']}-db - - DB_POSTGRESDB_PORT=5432 - - DB_POSTGRESDB_DATABASE={self.data['MySQLDBName']} - - DB_POSTGRESDB_USER={self.data['MySQLDBNUser']} - - DB_POSTGRESDB_PASSWORD={self.data['MySQLPassword']} - - N8N_HOST={self.data['finalURL']} - - NODE_ENV=production - - WEBHOOK_URL=https://{self.data['finalURL']} - - N8N_PUSH_BACKEND=sse # Use Server-Sent Events instead of WebSockets + - DB_TYPE={n8n_config['environment']['DB_TYPE']} + - DB_POSTGRESDB_HOST={n8n_config['environment']['DB_POSTGRESDB_HOST']} + - DB_POSTGRESDB_PORT={n8n_config['environment']['DB_POSTGRESDB_PORT']} + - DB_POSTGRESDB_DATABASE={n8n_config['environment']['DB_POSTGRESDB_DATABASE']} + - DB_POSTGRESDB_USER={n8n_config['environment']['DB_POSTGRESDB_USER']} + - DB_POSTGRESDB_PASSWORD={n8n_config['environment']['DB_POSTGRESDB_PASSWORD']} + - DB_POSTGRESDB_SCHEMA={n8n_config['environment']['DB_POSTGRESDB_SCHEMA']} + - N8N_HOST={n8n_config['environment']['N8N_HOST']} + - NODE_ENV={n8n_config['environment']['NODE_ENV']} + - WEBHOOK_URL={n8n_config['environment']['WEBHOOK_URL']} + - N8N_PUSH_BACKEND={n8n_config['environment']['N8N_PUSH_BACKEND']} + - GENERIC_TIMEZONE={n8n_config['environment']['GENERIC_TIMEZONE']} + - N8N_ENCRYPTION_KEY={n8n_config['environment']['N8N_ENCRYPTION_KEY']} + - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS={n8n_config['environment']['N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS']} ports: - "{self.data['port']}:5678" - links: + depends_on: - {self.data['ServiceName']}-db volumes: - "/home/docker/{self.data['finalURL']}/data:/home/node/.n8n" - depends_on: - - '{self.data['ServiceName']}-db' -''' - - ### WriteConfig to compose-file - - command = f"mkdir -p /home/docker/{self.data['finalURL']}" - result, message = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - logging.statusWriter(self.JobID, f'Error {str(message)} . [404]') - return 0 - - TempCompose = f'/home/cyberpanel/{self.data["finalURL"]}-docker-compose.yml' - - WriteToFile = open(TempCompose, 'w') - WriteToFile.write(WPSite) - WriteToFile.close() - - command = f"mv {TempCompose} {self.data['ComposePath']}" - result, message = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - if result == 0: - logging.statusWriter(self.JobID, f'Error {str(message)} . [404]') - return 0 - - command = f"chmod 600 {self.data['ComposePath']} && chown root:root {self.data['ComposePath']}" - ProcessUtilities.executioner(command, 'root', True) - - #### - - if ProcessUtilities.decideDistro() == ProcessUtilities.cent8 or ProcessUtilities.decideDistro() == ProcessUtilities.centos: - dockerCommand = 'docker compose' - else: - dockerCommand = 'docker-compose' - - command = f"{dockerCommand} -f {self.data['ComposePath']} -p '{self.data['SiteName']}' up -d" - result, message = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - - - if result == 0: - logging.statusWriter(self.JobID, f'Error {str(message)} . [404]') - return 0 - - logging.statusWriter(self.JobID, 'Bringing containers online..,50') - - time.sleep(25) - - - ### checking if everything ran properly - - passdata = {} - passdata["JobID"] = None - passdata['name'] = self.data['ServiceName'] - da = Docker_Sites(None, passdata) - retdata, containers = da.ListContainers() - - containers = json.loads(containers) - - if os.path.exists(ProcessUtilities.debugPath): - logging.writeToFile(str(containers)) - - ### it means less then two containers which means something went wrong - if len(containers) < 2: - logging.writeToFile(f'Unkonwn error, containers not running. [DeployN8NContainer] . [404]') - logging.statusWriter(self.JobID, f'Unkonwn error, containers not running. [DeployN8NContainer] . [404]') - return 0 - - ### Set up Proxy - - execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/DockerSites.py" - execPath = execPath + f" SetupProxy --port {self.data['port']}" - ProcessUtilities.executioner(execPath) - - ### Set up ht access - - execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/DockerSites.py" - execPath = execPath + f" SetupHTAccess --port {self.data['port']} --htaccess {self.data['htaccessPath']}" - ProcessUtilities.executioner(execPath, self.data['externalApp']) - - # if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: - # group = 'nobody' - # else: - # group = 'nogroup' - # - # command = f"chown -R nobody:{group} /home/docker/{self.data['finalURL']}/data" - # ProcessUtilities.executioner(command) - - ### just restart ls for htaccess - - from plogical.installUtilities import installUtilities - installUtilities.reStartLiteSpeedSocket() - - logging.statusWriter(self.JobID, 'Completed. [200]') - - except BaseException as msg: - logging.writeToFile(f'{str(msg)}. [DeployN8NContainer]') - logging.statusWriter(self.JobID, f'Error {str(msg)} . [404]') - print(str(msg)) - pass + networks: + - n8n-network + deploy: + resources: + limits: + cpus: '{self.data["CPUsSite"]}' + memory: {self.data["MemorySite"]}M +networks: + n8n-network: + driver: bridge + name: {self.data['ServiceName']}_network''' def Main(): try: diff --git a/plogical/adminPass.py b/plogical/adminPass.py index cb1dc308d..c6c226664 100755 --- a/plogical/adminPass.py +++ b/plogical/adminPass.py @@ -12,8 +12,8 @@ from plogical.acl import ACLManager from packages.models import Package from baseTemplate.models import version -VERSION = '2.3' -BUILD = 9 +VERSION = '2.4' +BUILD = 0 if not os.geteuid() == 0: sys.exit("\nOnly root can run this script\n") diff --git a/plogical/backupUtilities.py b/plogical/backupUtilities.py index 3e1552883..6561ba956 100755 --- a/plogical/backupUtilities.py +++ b/plogical/backupUtilities.py @@ -53,8 +53,8 @@ try: except: pass -VERSION = '2.3' -BUILD = 9 +VERSION = '2.4' +BUILD = 0 ## I am not the monster that you think I am.. @@ -739,7 +739,7 @@ class backupUtilities: dbName = database.find('dbName').text - if (VERSION == '2.1' or VERSION == '2.3') and int(BUILD) >= 1: + if ((VERSION == '2.1' or VERSION == '2.3') and int(BUILD) >= 1) or (VERSION == '2.4' and int(BUILD) >= 0): logging.CyberCPLogFileWriter.writeToFile('Backup version 2.1.1+ detected..') databaseUsers = database.findall('databaseUsers') @@ -1073,7 +1073,7 @@ class backupUtilities: dbName = database.find('dbName').text - if (VERSION == '2.1' or VERSION == '2.3') and int(BUILD) >= 1: + if ((VERSION == '2.1' or VERSION == '2.3') and int(BUILD) >= 1) or (VERSION == '2.4' and int(BUILD) >= 0): logging.CyberCPLogFileWriter.writeToFile('Backup version 2.1.1+ detected..') diff --git a/plogical/upgrade.py b/plogical/upgrade.py index 7dd2dfb70..e7ea704e2 100755 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -17,8 +17,8 @@ from CyberCP import settings import random import string -VERSION = '2.3' -BUILD = 9 +VERSION = '2.4' +BUILD = 0 CENTOS7 = 0 CENTOS8 = 1 diff --git a/plogical/vhost.py b/plogical/vhost.py index 10d110115..a3f5df68e 100755 --- a/plogical/vhost.py +++ b/plogical/vhost.py @@ -25,7 +25,7 @@ from managePHP.phpManager import PHPManager from plogical.vhostConfs import vhostConfs from ApachController.ApacheVhosts import ApacheVhost try: - from websiteFunctions.models import Websites, ChildDomains, aliasDomains + from websiteFunctions.models import Websites, ChildDomains, aliasDomains, DockerSites from databases.models import Databases except: pass @@ -404,6 +404,23 @@ class vhost: if ACLManager.FindIfChild() == 0: + ### Delete Docker Sites first before website deletion + + if os.path.exists('/home/docker/%s' % (virtualHostName)): + try: + dockerSite = DockerSites.objects.get(admin__domain=virtualHostName) + passdata = { + "domain": virtualHostName, + "name": dockerSite.SiteName + } + from plogical.DockerSites import Docker_Sites + da = Docker_Sites(None, passdata) + da.DeleteDockerApp() + dockerSite.delete() + except: + # If anything fails in Docker cleanup, at least remove the directory + shutil.rmtree('/home/docker/%s' % (virtualHostName)) + for items in databases: mysqlUtilities.deleteDatabase(items.dbName, items.dbUser) diff --git a/serverStatus/views.py b/serverStatus/views.py index 12c797283..6a655159e 100755 --- a/serverStatus/views.py +++ b/serverStatus/views.py @@ -25,8 +25,8 @@ EXPIRE = 3 ### Version -VERSION = '2.3' -BUILD = 9 +VERSION = '2.4' +BUILD = 0 def serverStatusHome(request): diff --git a/static/websiteFunctions/websiteFunctions.js b/static/websiteFunctions/websiteFunctions.js index ddb265b42..810267b6f 100644 --- a/static/websiteFunctions/websiteFunctions.js +++ b/static/websiteFunctions/websiteFunctions.js @@ -237,7 +237,7 @@ app.controller('createWebsite', function ($scope, $http, $timeout, $window) { $("#listFail").hide(); -app.controller('listWebsites', function ($scope, $http) { +app.controller('listWebsites', function ($scope, $http, $window) { $scope.currentPage = 1; @@ -384,6 +384,244 @@ app.controller('listWebsites', function ($scope, $http) { }; + $scope.getFullUrl = function(url) { + console.log('getFullUrl called with:', url); + if (!url) { + // If no URL is provided, try to use the domain + if (this.wp && this.wp.domain) { + url = this.wp.domain; + } else { + return ''; + } + } + if (url.startsWith('http://') || url.startsWith('https://')) { + return url; + } + return 'https://' + url; + }; + + $scope.showWPSites = function(domain) { + var site = $scope.WebSitesList.find(function(site) { + return site.domain === domain; + }); + if (site) { + site.showWPSites = !site.showWPSites; + if (site.showWPSites && (!site.wp_sites || !site.wp_sites.length)) { + // Fetch WordPress sites if not already loaded + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var data = { domain: domain }; + site.loadingWPSites = true; + $http.post('/websites/getWordPressSites', data, config).then( + function(response) { + site.loadingWPSites = false; + if (response.data.status === 1) { + site.wp_sites = response.data.sites; + site.wp_sites.forEach(function(wp) { + // Ensure each WP site has a URL + if (!wp.url) { + wp.url = wp.domain || domain; + } + fetchWPSiteData(wp); + }); + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message || 'Could not fetch WordPress sites', + type: 'error' + }); + } + }, + function(response) { + site.loadingWPSites = false; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server', + type: 'error' + }); + } + ); + } + } + }; + + function fetchWPSiteData(wp) { + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var data = { WPid: wp.id }; + + // Fetch site data + $http.post('/websites/FetchWPdata', data, config).then( + function(response) { + if (response.data.status === 1) { + var data = response.data.ret_data; + wp.version = data.version; + wp.phpVersion = data.phpVersion || 'PHP 7.4'; + wp.searchIndex = data.searchIndex === 1; + wp.debugging = data.debugging === 1; + wp.passwordProtection = data.passwordprotection === 1; + wp.maintenanceMode = data.maintenanceMode === 1; + fetchPluginData(wp); + fetchThemeData(wp); + } + } + ); + } + + function fetchPluginData(wp) { + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var data = { WPid: wp.id }; + $http.post('/websites/GetCurrentPlugins', data, config).then( + function(response) { + if (response.data.status === 1) { + var plugins = JSON.parse(response.data.plugins); + wp.activePlugins = plugins.filter(function(p) { return p.status === 'active'; }).length; + wp.totalPlugins = plugins.length; + } + } + ); + } + + function fetchThemeData(wp) { + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var data = { WPid: wp.id }; + $http.post('/websites/GetCurrentThemes', data, config).then( + function(response) { + if (response.data.status === 1) { + var themes = JSON.parse(response.data.themes); + wp.theme = themes.find(function(t) { return t.status === 'active'; }).name; + wp.totalThemes = themes.length; + } + } + ); + } + + $scope.updateSetting = function(wp, setting) { + var settingMap = { + 'search-indexing': 'searchIndex', + 'debugging': 'debugging', + 'password-protection': 'passwordProtection', + 'maintenance-mode': 'maintenanceMode' + }; + + var data = { + siteId: wp.id, + setting: setting, + value: wp[settingMap[setting]] ? 1 : 0 + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post('/websites/UpdateWPSettings', data, config).then( + function(response) { + if (!response.data.status) { + wp[settingMap[setting]] = !wp[settingMap[setting]]; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message || 'Unknown error', + type: 'error' + }); + } else { + new PNotify({ + title: 'Success!', + text: 'Setting updated successfully.', + type: 'success' + }); + } + }, + function(response) { + wp[settingMap[setting]] = !wp[settingMap[setting]]; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please try again.', + type: 'error' + }); + } + ); + }; + + $scope.wpLogin = function(wpId) { + window.open('/websites/AutoLogin?id=' + wpId, '_blank'); + }; + + $scope.manageWP = function(wpId) { + window.location.href = '/websites/WPHome?ID=' + wpId; + }; + + $scope.deleteWPSite = function(wp) { + if (confirm('Are you sure you want to delete this WordPress site? This action cannot be undone.')) { + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var data = { + wpid: wp.id, + domain: wp.domain + }; + + $http.post('/websites/deleteWordPressSite', data, config).then( + function(response) { + if (response.data.status === 1) { + // Remove the WP site from the list + var site = $scope.WebSitesList.find(function(site) { + return site.domain === wp.domain; + }); + if (site && site.wp_sites) { + site.wp_sites = site.wp_sites.filter(function(wpSite) { + return wpSite.id !== wp.id; + }); + } + new PNotify({ + title: 'Success!', + text: 'WordPress site deleted successfully.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message || 'Could not delete WordPress site', + type: 'error' + }); + } + }, + function(response) { + new PNotify({ + title: 'Error!', + text: 'Could not connect to server', + type: 'error' + }); + } + ); + } + }; + + $scope.visitSite = function(wp) { + var url = wp.url || wp.domain; + if (!url) return ''; + if (url.startsWith('http://') || url.startsWith('https://')) { + return url; + } + return 'https://' + url; + }; }); @@ -3460,7 +3698,6 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind $window.location.reload(); }, 3000); - } else { $scope.aliasTable = false; diff --git a/websiteFunctions/dockerviews.py b/websiteFunctions/dockerviews.py new file mode 100644 index 000000000..2d4c6136c --- /dev/null +++ b/websiteFunctions/dockerviews.py @@ -0,0 +1,170 @@ +import json +import docker +from django.http import HttpResponse +from .models import DockerSites +from loginSystem.models import Administrator +from plogical.acl import ACLManager +from django.shortcuts import redirect +from loginSystem.views import loadLoginPage +from django.views.decorators.csrf import csrf_exempt +from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging + +def require_login(view_func): + def wrapper(request, *args, **kwargs): + try: + userID = request.session['userID'] + return view_func(request, *args, **kwargs) + except KeyError: + return redirect(loadLoginPage) + return wrapper + +class DockerManager: + def __init__(self): + self.client = docker.from_env() + + def get_container(self, container_id): + try: + return self.client.containers.get(container_id) + except docker.errors.NotFound: + return None + except Exception as e: + logging.writeToFile(f"Error getting container {container_id}: {str(e)}") + return None + +@csrf_exempt +@require_login +def startContainer(request): + try: + if request.method == 'POST': + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + + data = json.loads(request.body) + container_id = data.get('container_id') + site_name = data.get('name') + + # Verify Docker site ownership + try: + docker_site = DockerSites.objects.get(SiteName=site_name) + if currentACL['admin'] != 1 and docker_site.admin != admin and docker_site.admin.owner != admin.pk: + return HttpResponse(json.dumps({ + 'status': 0, + 'error_message': 'Not authorized to access this container' + })) + except DockerSites.DoesNotExist: + return HttpResponse(json.dumps({ + 'status': 0, + 'error_message': 'Docker site not found' + })) + + docker_manager = DockerManager() + container = docker_manager.get_container(container_id) + + if not container: + return HttpResponse(json.dumps({ + 'status': 0, + 'error_message': 'Container not found' + })) + + container.start() + return HttpResponse(json.dumps({'status': 1})) + + return HttpResponse('Not allowed') + except Exception as e: + return HttpResponse(json.dumps({ + 'status': 0, + 'error_message': str(e) + })) + +@csrf_exempt +@require_login +def stopContainer(request): + try: + if request.method == 'POST': + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + + data = json.loads(request.body) + container_id = data.get('container_id') + site_name = data.get('name') + + # Verify Docker site ownership + try: + docker_site = DockerSites.objects.get(SiteName=site_name) + if currentACL['admin'] != 1 and docker_site.admin != admin and docker_site.admin.owner != admin.pk: + return HttpResponse(json.dumps({ + 'status': 0, + 'error_message': 'Not authorized to access this container' + })) + except DockerSites.DoesNotExist: + return HttpResponse(json.dumps({ + 'status': 0, + 'error_message': 'Docker site not found' + })) + + docker_manager = DockerManager() + container = docker_manager.get_container(container_id) + + if not container: + return HttpResponse(json.dumps({ + 'status': 0, + 'error_message': 'Container not found' + })) + + container.stop() + return HttpResponse(json.dumps({'status': 1})) + + return HttpResponse('Not allowed') + except Exception as e: + return HttpResponse(json.dumps({ + 'status': 0, + 'error_message': str(e) + })) + +@csrf_exempt +@require_login +def restartContainer(request): + try: + if request.method == 'POST': + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + + data = json.loads(request.body) + container_id = data.get('container_id') + site_name = data.get('name') + + # Verify Docker site ownership + try: + docker_site = DockerSites.objects.get(SiteName=site_name) + if currentACL['admin'] != 1 and docker_site.admin != admin and docker_site.admin.owner != admin.pk: + return HttpResponse(json.dumps({ + 'status': 0, + 'error_message': 'Not authorized to access this container' + })) + except DockerSites.DoesNotExist: + return HttpResponse(json.dumps({ + 'status': 0, + 'error_message': 'Docker site not found' + })) + + docker_manager = DockerManager() + container = docker_manager.get_container(container_id) + + if not container: + return HttpResponse(json.dumps({ + 'status': 0, + 'error_message': 'Container not found' + })) + + container.restart() + return HttpResponse(json.dumps({'status': 1})) + + return HttpResponse('Not allowed') + except Exception as e: + return HttpResponse(json.dumps({ + 'status': 0, + 'error_message': str(e) + })) \ No newline at end of file diff --git a/websiteFunctions/static/websiteFunctions/DockerContainers.js b/websiteFunctions/static/websiteFunctions/DockerContainers.js new file mode 100644 index 000000000..247db9e7f --- /dev/null +++ b/websiteFunctions/static/websiteFunctions/DockerContainers.js @@ -0,0 +1,395 @@ +app.controller('ListDockersitecontainer', function ($scope, $http) { + $scope.cyberPanelLoading = true; + $scope.conatinerview = true; + $('#cyberpanelLoading').hide(); + + // Format bytes to human readable + function formatBytes(bytes, decimals = 2) { + if (bytes === 0) return '0 Bytes'; + const k = 1024; + const dm = decimals < 0 ? 0 : decimals; + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; + } + + $scope.getcontainer = function () { + $('#cyberpanelLoading').show(); + url = "/docker/getDockersiteList"; + + var data = {'name': $('#sitename').html()}; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); + + function ListInitialData(response) { + $('#cyberpanelLoading').hide(); + if (response.data.status === 1) { + $scope.cyberPanelLoading = true; + var finalData = JSON.parse(response.data.data[1]); + $scope.ContainerList = finalData; + $("#listFail").hide(); + } else { + $("#listFail").fadeIn(); + $scope.errorMessage = response.data.error_message; + } + } + + function cantLoadInitialData(response) { + $scope.cyberPanelLoading = true; + $('#cyberpanelLoading').hide(); + new PNotify({ + title: 'Operation Failed!', + text: 'Connection disrupted, refresh the page.', + type: 'error' + }); + } + }; + + $scope.Lunchcontainer = function (containerid) { + $scope.cyberpanelLoading = false; + $('#cyberpanelLoading').show(); + var url = "/docker/getContainerAppinfo"; + + var data = { + 'name': $('#sitename').html(), + 'id': containerid + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); + + function ListInitialData(response) { + $scope.cyberpanelLoading = true; + $('#cyberpanelLoading').hide(); + + if (response.data.status === 1) { + var containerInfo = response.data.data[1]; + console.log("Full container info:", containerInfo); + + // Find the container in the list and update its information + for (var i = 0; i < $scope.ContainerList.length; i++) { + if ($scope.ContainerList[i].id === containerid) { + // Basic Information + $scope.ContainerList[i].status = containerInfo.status; + $scope.ContainerList[i].created = new Date(containerInfo.created); + $scope.ContainerList[i].uptime = containerInfo.uptime; + $scope.ContainerList[i].image = containerInfo.image; + + // Environment Variables - ensure it's properly set + if (containerInfo.environment) { + console.log("Setting environment:", containerInfo.environment); + $scope.ContainerList[i].environment = containerInfo.environment; + console.log("Container after env update:", $scope.ContainerList[i]); + } else { + console.log("No environment in container info"); + } + + // Resource Usage + var memoryBytes = containerInfo.memory_usage; + $scope.ContainerList[i].memoryUsage = formatBytes(memoryBytes); + $scope.ContainerList[i].memoryUsagePercent = (memoryBytes / (1024 * 1024 * 1024)) * 100; + $scope.ContainerList[i].cpuUsagePercent = (containerInfo.cpu_usage / 10000000000) * 100; + + // Network & Ports + $scope.ContainerList[i].ports = containerInfo.ports; + + // Volumes + $scope.ContainerList[i].volumes = containerInfo.volumes; + break; + } + } + + // Get container logs + $scope.getcontainerlog(containerid); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialData(response) { + $scope.cyberpanelLoading = true; + $('#cyberpanelLoading').hide(); + new PNotify({ + title: 'Operation Failed!', + text: 'Connection disrupted, refresh the page.', + type: 'error' + }); + } + }; + + $scope.getcontainerlog = function (containerid) { + $scope.cyberpanelLoading = false; + var url = "/docker/getContainerApplog"; + + var data = { + 'name': $('#sitename').html(), + 'id': containerid + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); + + function ListInitialData(response) { + $scope.cyberpanelLoading = true; + $scope.conatinerview = false; + $('#cyberpanelLoading').hide(); + + if (response.data.status === 1) { + // Find the container in the list and update its logs + for (var i = 0; i < $scope.ContainerList.length; i++) { + if ($scope.ContainerList[i].id === containerid) { + $scope.ContainerList[i].logs = response.data.data[1]; + break; + } + } + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialData(response) { + $scope.cyberpanelLoading = true; + $('#cyberpanelLoading').hide(); + $scope.conatinerview = false; + new PNotify({ + title: 'Operation Failed!', + text: 'Connection disrupted, refresh the page.', + type: 'error' + }); + } + }; + + // Auto-refresh container info every 30 seconds + var refreshInterval; + $scope.$watch('conatinerview', function(newValue, oldValue) { + if (newValue === false) { // When container view is shown + refreshInterval = setInterval(function() { + if ($scope.cid) { + $scope.Lunchcontainer($scope.cid); + } + }, 30000); // 30 seconds + } else { // When container view is hidden + if (refreshInterval) { + clearInterval(refreshInterval); + } + } + }); + + // Clean up on controller destruction + $scope.$on('$destroy', function() { + if (refreshInterval) { + clearInterval(refreshInterval); + } + }); + + // Initialize + $scope.getcontainer(); + + // Keep your existing functions + $scope.recreateappcontainer = function() { /* ... */ }; + $scope.refreshStatus = function() { /* ... */ }; + $scope.restarthStatus = function() { /* ... */ }; + $scope.StopContainerAPP = function() { /* ... */ }; + $scope.cAction = function(action) { + $scope.cyberpanelLoading = false; + $('#cyberpanelLoading').show(); + + var url = "/docker/"; + switch(action) { + case 'start': + url += "startContainer"; + break; + case 'stop': + url += "stopContainer"; + break; + case 'restart': + url += "restartContainer"; + break; + default: + console.error("Unknown action:", action); + return; + } + + var data = { + 'name': $('#sitename').html(), + 'container_id': $scope.selectedContainer.id + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then( + function(response) { + $scope.cyberpanelLoading = true; + $('#cyberpanelLoading').hide(); + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Container ' + action + ' successful.', + type: 'success' + }); + + // Update container status after action + $scope.selectedContainer.status = action === 'stop' ? 'stopped' : 'running'; + + // Refresh container info + $scope.Lunchcontainer($scope.selectedContainer.id); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message || 'An unknown error occurred.', + type: 'error' + }); + } + }, + function(error) { + $scope.cyberpanelLoading = true; + $('#cyberpanelLoading').hide(); + + new PNotify({ + title: 'Operation Failed!', + text: 'Connection disrupted or server error occurred.', + type: 'error' + }); + + console.error("Error during container action:", error); + } + ); + }; + + // Update the container selection when actions are triggered + $scope.setSelectedContainer = function(container) { + $scope.selectedContainer = container; + }; + + // Update the button click handlers to set selected container + $scope.handleAction = function(action, container) { + $scope.setSelectedContainer(container); + $scope.cAction(action); + }; + + $scope.openSettings = function(container) { + $scope.selectedContainer = container; + $('#settings').modal('show'); + }; + + $scope.saveSettings = function() { + $scope.cyberpanelLoading = false; + $('#cyberpanelLoading').show(); + + var url = "/docker/updateContainerSettings"; + var data = { + 'name': $('#sitename').html(), + 'id': $scope.selectedContainer.id, + 'memoryLimit': $scope.selectedContainer.memoryLimit, + 'startOnReboot': $scope.selectedContainer.startOnReboot + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); + + function ListInitialData(response) { + $scope.cyberpanelLoading = true; + $('#cyberpanelLoading').hide(); + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Container settings updated successfully.', + type: 'success' + }); + $('#settings').modal('hide'); + // Refresh container info after update + $scope.Lunchcontainer($scope.selectedContainer.id); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialData(response) { + $scope.cyberpanelLoading = true; + $('#cyberpanelLoading').hide(); + new PNotify({ + title: 'Operation Failed!', + text: 'Connection disrupted, refresh the page.', + type: 'error' + }); + } + }; + + // Add location service to the controller for the n8n URL + $scope.location = window.location; + + // Function to extract n8n version from environment variables + $scope.getN8nVersion = function(container) { + console.log('getN8nVersion called with container:', container); + + if (!container || !container.environment) { + console.log('No container or environment data'); + return 'unknown'; + } + + console.log('Container environment:', container.environment); + + var version = null; + + // Try to find NODE_VERSION first + version = container.environment.find(function(env) { + return env && env.startsWith('NODE_VERSION='); + }); + + if (version) { + console.log('Found NODE_VERSION:', version); + return version.split('=')[1]; + } + + // Try to find N8N_VERSION + version = container.environment.find(function(env) { + return env && env.startsWith('N8N_VERSION='); + }); + + if (version) { + console.log('Found N8N_VERSION:', version); + return version.split('=')[1]; + } + + console.log('No version found in environment'); + return 'unknown'; + }; +}); \ No newline at end of file diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index e6fad7f0f..143947cb5 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -549,9 +549,8 @@ function create_staging_checkbox_function() { create_staging_checkbox_function(); app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $window) { - var CheckBoxpasssword = 0; - + $scope.wordpresshomeloading = true; $scope.stagingDetailsForm = false; $scope.installationProgress = true; @@ -559,27 +558,161 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo $scope.success = true; $scope.couldNotConnect = true; $scope.goBackDisable = true; + $scope.searchIndex = 0; + $(document).ready(function () { var checkstatus = document.getElementById("wordpresshome"); if (checkstatus !== null) { $scope.LoadWPdata(); - } }); - $scope.LoadWPdata = function () { - $scope.wordpresshomeloading = false; $('#wordpresshomeloading').show(); var url = "/websites/FetchWPdata"; + var data = { + WPid: $('#WPid').html(), + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(function(response) { + $scope.wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + $('#WPVersion').text(response.data.ret_data.version); + if (response.data.ret_data.lscache === 1) { + $('#lscache').prop('checked', true); + } + if (response.data.ret_data.debugging === 1) { + $('#debugging').prop('checked', true); + } + + // Set search index state + $scope.searchIndex = response.data.ret_data.searchIndex; + + if (response.data.ret_data.maintenanceMode === 1) { + $('#maintenanceMode').prop('checked', true); + } + if (response.data.ret_data.wpcron === 1) { + $('#wpcron').prop('checked', true); + } + if (response.data.ret_data.passwordprotection == 1) { + var dc = ''; + var mp = $compile(dc)($scope); + angular.element(document.getElementById('prsswdprodata')).append(mp); + CheckBoxpasssword = 1; + } else { + var dc = ''; + $('#prsswdprodata').append(dc); + CheckBoxpasssword = 0; + } + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + }, function(error) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + console.error('Failed to load WP data:', error); + }); + }; + + $scope.UpdateWPSettings = function (setting) { + $scope.wordpresshomeloading = false; + $('#wordpresshomeloading').show(); + + var url = "/websites/UpdateWPSettings"; + var data; + + if (setting === "PasswordProtection") { + data = { + WPid: $('#WPid').html(), + setting: setting, + PPUsername: CheckBoxpasssword == 0 ? $scope.PPUsername : '', + PPPassword: CheckBoxpasssword == 0 ? $scope.PPPassword : '' + }; + } else { + var settingValue; + if (setting === 'searchIndex') { + $scope.searchIndex = $scope.searchIndex === 1 ? 0 : 1; + settingValue = $scope.searchIndex; + } else { + settingValue = $('#' + setting).is(":checked") ? 1 : 0; + } + data = { + WPid: $('#WPid').html(), + setting: setting, + settingValue: settingValue + }; + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(function(response) { + $scope.wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Updated!', + type: 'success' + }); + if (setting === "PasswordProtection") { + location.reload(); + } + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + // Revert the change on error + if (setting === 'searchIndex') { + $scope.searchIndex = $scope.searchIndex === 1 ? 0 : 1; + } + if (setting === "PasswordProtection") { + location.reload(); + } + } + }, function(error) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + // Revert the change on error + if (setting === 'searchIndex') { + $scope.searchIndex = $scope.searchIndex === 1 ? 0 : 1; + } + console.error('Failed to update setting:', error); + }); + }; + + $scope.GetCurrentPlugins = function () { + $('#wordpresshomeloading').show(); + + $scope.wordpresshomeloading = false; + + var url = "/websites/GetCurrentPlugins"; + var data = { WPid: $('#WPid').html(), } - console.log(data); var config = { headers: { 'X-CSRFToken': getCookie('csrftoken') @@ -595,49 +728,12 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo $('#wordpresshomeloading').hide(); if (response.data.status === 1) { - $('#WPVersion').text(response.data.ret_data.version); - if (response.data.ret_data.lscache === 1) { - $('#lscache').prop('checked', true); - } - if (response.data.ret_data.debugging === 1) { - $('#debugging').prop('checked', true); - } - if (response.data.ret_data.searchIndex === 1) { - $('#searchIndex').prop('checked', true); - } - if (response.data.ret_data.maintenanceMode === 1) { - $('#maintenanceMode').prop('checked', true); - } - if (response.data.ret_data.wpcron === 1) { - $('#wpcron').prop('checked', true); - } - if (response.data.ret_data.passwordprotection == 1) { - - var dc = '\n' + - ' ' - var mp = $compile(dc)($scope); - angular.element(document.getElementById('prsswdprodata')).append(mp); - CheckBoxpasssword = 1; - } else if (response.data.ret_data.passwordprotection == 0) { - var dc = '\n' + - ' ' - $('#prsswdprodata').append(dc); - CheckBoxpasssword = 0; - } + $('#PluginBody').html(''); + var plugins = JSON.parse(response.data.plugins); + plugins.forEach(AddPlugins); } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); + alert("Error:" + response.data.error_message) } @@ -659,46 +755,17 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo }; - $scope.UpdateWPSettings = function (setting) { - - $scope.wordpresshomeloading = false; + $scope.GetCurrentThemes = function () { $('#wordpresshomeloading').show(); + $scope.wordpresshomeloading = false; - var url = "/websites/UpdateWPSettings"; + var url = "/websites/GetCurrentThemes"; - if (setting === "PasswordProtection") { - if (CheckBoxpasssword == 0) { - var data = { - WPid: $('#WPid').html(), - setting: setting, - PPUsername: $scope.PPUsername, - PPPassword: $scope.PPPassword, - } - - } else { - var data = { - WPid: $('#WPid').html(), - setting: setting, - PPUsername: '', - PPPassword: '', - } - - } - - } else { - var settingValue = 0; - if ($('#' + setting).is(":checked")) { - settingValue = 1; - } - var data = { - WPid: $('#WPid').html(), - setting: setting, - settingValue: settingValue - } + var data = { + WPid: $('#WPid').html(), } - var config = { headers: { 'X-CSRFToken': getCookie('csrftoken') @@ -710,27 +777,75 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo function ListInitialDatas(response) { - $scope.wordpresshomeloading = true; + wordpresshomeloading = true; $('#wordpresshomeloading').hide(); + if (response.data.status === 1) { + + $('#ThemeBody').html(''); + var themes = JSON.parse(response.data.themes); + themes.forEach(AddThemes); + + } else { + alert("Error:" + response.data.error_message) + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.webSiteCreationLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + }; + + $scope.UpdatePlugins = function (plugin) { + $('#wordpresshomeloading').show(); + var data = { + plugin: plugin, + pluginarray: PluginsList, + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/UpdatePlugins"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + if (response.data.status === 1) { new PNotify({ title: 'Success!', - text: 'Successfully Updated!.', + text: 'Updating Plugins in Background!.', type: 'success' }); - if (setting === "PasswordProtection") { - location.reload(); - } } else { new PNotify({ title: 'Operation Failed!', text: response.data.error_message, type: 'error' }); - if (setting === "PasswordProtection") { - location.reload(); - } } @@ -746,6 +861,2763 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo }; + $scope.DeletePlugins = function (plugin) { + $('#wordpresshomeloading').show(); + var data = { + plugin: plugin, + pluginarray: PluginsList, + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/DeletePlugins"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Deleting Plugin in Background!', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + + } + + $scope.ChangeStatus = function (plugin) { + $('#wordpresshomeloading').show(); + var data = { + plugin: plugin, + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/ChangeStatus"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Changed Plugin state Successfully !.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + + } + + function AddPlugins(value, index, array) { + var FinalMarkup = '' + FinalMarkup = FinalMarkup + ''; + for (let x in value) { + if (x === 'status') { + if (value[x] === 'inactive') { + FinalMarkup = FinalMarkup + '
'; + } else { + FinalMarkup = FinalMarkup + '
'; + } + } else if (x === 'update') { + if (value[x] === 'none') { + FinalMarkup = FinalMarkup + 'Upto Date'; + } else { + FinalMarkup = FinalMarkup + ''; + } + } else { + FinalMarkup = FinalMarkup + '' + value[x] + ""; + } + } + FinalMarkup = FinalMarkup + '' + FinalMarkup = FinalMarkup + '' + var temp = $compile(FinalMarkup)($scope) + AppendToTable('#PluginBody', temp) + } + + $scope.UpdateThemes = function (theme) { + $('#wordpresshomeloading').show(); + var data = { + Theme: theme, + Themearray: ThemesList, + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/UpdateThemes"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Updating Theme in background !.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + + + }; + + $scope.DeleteThemes = function (theme) { + $('#wordpresshomeloading').show(); + var data = { + Theme: theme, + Themearray: ThemesList, + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/DeleteThemes"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Deleting Theme in Background!.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + }; + + $scope.ChangeStatusThemes = function (theme) { + $('#wordpresshomeloading').show(); + var data = { + theme: theme, + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/StatusThemes"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Change Theme state in Bsckground!.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + + }; + + function AddThemes(value, index, array) { + var FinalMarkup = '' + FinalMarkup = FinalMarkup + ''; + for (let x in value) { + if (x === 'status') { + if (value[x] === 'inactive') { + FinalMarkup = FinalMarkup + '
'; + } else { + FinalMarkup = FinalMarkup + '
'; + } + } else if (x === 'update') { + if (value[x] === 'none') { + FinalMarkup = FinalMarkup + 'Upto Date'; + } else { + FinalMarkup = FinalMarkup + ''; + } + } else { + FinalMarkup = FinalMarkup + '' + value[x] + ""; + } + } + FinalMarkup = FinalMarkup + '' + FinalMarkup = FinalMarkup + '' + var temp = $compile(FinalMarkup)($scope) + AppendToTable('#ThemeBody', temp) + } + + $scope.CreateStagingNow = function () { + $('#wordpresshomeloading').show(); + + $scope.wordpresshomeloading = false; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + + + $scope.currentStatus = "Starting creation Staging.."; + + //here enter domain name + if (create_staging_domain_check == 0) { + var Part2_domainNameCreate = document.getElementById('Part2_domainNameCreate').value; + var domainNameCreate = document.getElementById('TestDomainNameCreate').value + Part2_domainNameCreate; + } + if (create_staging_domain_check == 1) { + + var domainNameCreate = $scope.own_domainNameCreate; + } + var data = { + StagingName: $('#stagingName').val(), + StagingDomain: domainNameCreate, + WPid: $('#WPid').html(), + } + var url = "/websites/CreateStagingNow"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + if (response.data.status === 1) { + statusFile = response.data.tempStatusPath; + getCreationStatus(); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + }; + + function getCreationStatus() { + $('#wordpresshomeloading').show(); + + 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) { + //$('#wordpresshomeloading').hide(); + + if (response.data.abort === 1) { + if (response.data.installStatus === 1) { + + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = false; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + + $("#installProgress").css("width", "100%"); + $("#installProgressbackup").css("width", "100%"); + $scope.installPercentage = "100"; + $scope.currentStatus = response.data.currentStatus; + $timeout.cancel(); + + + } else { + + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = 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%"); + $("#installProgressbackup").css("width", "0%"); + $scope.installPercentage = "0"; + $scope.goBackDisable = false; + + + } + + } else { + + $("#installProgress").css("width", response.data.installationProgress + "%"); + $("#installProgressbackup").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + $timeout(getCreationStatus, 1000); + + } + + } + + function cantLoadInitialDatas(response) { + //$('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + } + + $scope.goBack = function () { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = false; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $("#installProgress").css("width", "0%"); + }; + + $scope.fetchstaging = function () { + + $('#wordpresshomeloading').show(); + $scope.wordpresshomeloading = false; + + var url = "/websites/fetchstaging"; + + var data = { + WPid: $('#WPid').html(), + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + + // $('#ThemeBody').html(''); + // var themes = JSON.parse(response.data.themes); + // themes.forEach(AddThemes); + + $('#StagingBody').html(''); + var staging = JSON.parse(response.data.wpsites); + staging.forEach(AddStagings); + + } else { + alert("Error data.error_message:" + response.data.error_message) + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + alert("Error" + response) + + } + + }; + + $scope.fetchDatabase = function () { + + $('#wordpresshomeloading').show(); + $scope.wordpresshomeloading = false; + + var url = "/websites/fetchDatabase"; + + var data = { + WPid: $('#WPid').html(), + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + $('#DB_Name').html(response.data.DataBaseName); + $('#DB_User').html(response.data.DataBaseUser); + $('#tableprefix').html(response.data.tableprefix); + } else { + alert("Error data.error_message:" + response.data.error_message) + + } + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + alert("Error" + response) + + } + + }; + + $scope.SaveUpdateConfig = function () { + $('#wordpresshomeloading').show(); + var data = { + AutomaticUpdates: $('#AutomaticUpdates').find(":selected").text(), + Plugins: $('#Plugins').find(":selected").text(), + Themes: $('#Themes').find(":selected").text(), + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/SaveUpdateConfig"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Update Configurations Sucessfully!.', + type: 'success' + }); + $("#autoUpdateConfig").modal('hide'); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + new PNotify({ + title: 'Operation Failed!', + text: response, + type: 'error' + }); + + } + }; + + function AddStagings(value, index, array) { + var FinalMarkup = '' + for (let x in value) { + if (x === 'name') { + FinalMarkup = FinalMarkup + '' + value[x] + ''; + } else if (x !== 'url' && x !== 'deleteURL' && x !== 'id') { + FinalMarkup = FinalMarkup + '' + value[x] + ""; + } + } + FinalMarkup = FinalMarkup + '' + + ' ' + FinalMarkup = FinalMarkup + '' + AppendToTable('#StagingBody', FinalMarkup); + } + + $scope.FinalDeployToProduction = function () { + + $('#wordpresshomeloading').show(); + + $scope.wordpresshomeloading = false; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + + var data = { + WPid: $('#WPid').html(), + StagingID: DeploytoProductionID + } + + var url = "/websites/DeploytoProduction"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + + $('#wordpresshomeloading').hide(); + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Deploy To Production start!.', + type: 'success' + }); + statusFile = response.data.tempStatusPath; + getCreationStatus(); + + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + new PNotify({ + title: 'Operation Failed!', + text: response, + type: 'error' + }); + + } + + }; + + + $scope.CreateBackup = function () { + $('#wordpresshomeloading').show(); + + $scope.wordpresshomeloading = false; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $scope.currentStatus = "Starting creation Backups.."; + var data = { + WPid: $('#WPid').html(), + Backuptype: $('#backuptype').val() + } + var url = "/websites/WPCreateBackup"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $('createbackupbutton').hide(); + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Creating Backups!.', + type: 'success' + }); + statusFile = response.data.tempStatusPath; + getCreationStatus(); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + alert(response) + + } + + }; + + + $scope.installwpcore = function () { + + $('#wordpresshomeloading').show(); + $('#wordpresshomeloadingsec').show(); + var data = { + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/installwpcore"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $('#wordpresshomeloadingsec').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Results fetched..', + type: 'success' + }); + $('#SecurityResult').html(response.data.result); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $('#wordpresshomeloadingsec').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + + }; + + $scope.dataintegrity = function () { + + $('#wordpresshomeloading').show(); + $('#wordpresshomeloadingsec').show(); + var data = { + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/dataintegrity"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $('#wordpresshomeloadingsec').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Results fetched', + type: 'success' + }); + $('#SecurityResult').html(response.data.result); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $('#wordpresshomeloadingsec').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + }; + +}); + + +var PluginsList = []; + + +function AddPluginToArray(cBox, name) { + if (cBox.checked) { + PluginsList.push(name); + // alert(PluginsList); + } else { + const index = PluginsList.indexOf(name); + if (index > -1) { + PluginsList.splice(index, 1); + } + // alert(PluginsList); + } +} + +var ThemesList = []; + +function AddThemeToArray(cBox, name) { + if (cBox.checked) { + ThemesList.push(name); + // alert(ThemesList); + } else { + const index = ThemesList.indexOf(name); + if (index > -1) { + ThemesList.splice(index, 1); + } + // alert(ThemesList); + } +} + + +function AppendToTable(table, markup) { + $(table).append(markup); +} + + +//..................Restore Backup Home + + +app.controller('RestoreWPBackup', function ($scope, $http, $timeout, $window) { + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = false; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + + + $scope.checkmethode = function () { + var val = $('#RestoreMethode').children("option:selected").val(); + if (val == 1) { + $('#Newsitediv').show(); + $('#exinstingsitediv').hide(); + } else if (val == 0) { + $('#exinstingsitediv').show(); + $('#Newsitediv').hide(); + } else { + + } + }; + + + $scope.RestoreWPbackupNow = function () { + $('#wordpresshomeloading').show(); + $scope.wordpresshomeloading = false; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $scope.currentStatus = "Start Restoring WordPress.."; + + var Domain = $('#wprestoresubdirdomain').val() + var path = $('#wprestoresubdirpath').val(); + var home = "1"; + + if (typeof path != 'undefined' || path != '') { + home = "0"; + } + if (typeof path == 'undefined') { + path = ""; + } + + + var backuptype = $('#backuptype').html(); + var data; + if (backuptype == "DataBase Backup") { + data = { + backupid: $('#backupid').html(), + DesSite: $('#DesSite').children("option:selected").val(), + Domain: '', + path: path, + home: home, + } + } else { + data = { + backupid: $('#backupid').html(), + DesSite: $('#DesSite').children("option:selected").val(), + Domain: Domain, + path: path, + home: home, + } + + } + + var url = "/websites/RestoreWPbackupNow"; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + // console.log(data) + + var d = $('#DesSite').children("option:selected").val(); + var c = $("input[name=Newdomain]").val(); + // if (d == -1 || c == "") { + // alert("Please Select Method of Backup Restore"); + // } else { + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + // } + + + function ListInitialDatas(response) { + wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Restoring process starts!.', + type: 'success' + }); + statusFile = response.data.tempStatusPath; + getCreationStatus(); + + } else { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = 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; + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + } + + function getCreationStatus() { + $('#wordpresshomeloading').show(); + + 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) { + //$('#wordpresshomeloading').hide(); + + if (response.data.abort === 1) { + + if (response.data.installStatus === 1) { + + + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = false; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + + $("#installProgress").css("width", "100%"); + $("#installProgressbackup").css("width", "100%"); + $scope.installPercentage = "100"; + $scope.currentStatus = response.data.currentStatus; + $timeout.cancel(); + + + } else { + + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = 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%"); + $("#installProgressbackup").css("width", "0%"); + $scope.installPercentage = "0"; + $scope.goBackDisable = false; + + + } + + } else { + + $("#installProgress").css("width", response.data.installationProgress + "%"); + $("#installProgressbackup").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + $timeout(getCreationStatus, 1000); + + } + + } + + function cantLoadInitialDatas(response) { + //$('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + } + + $scope.goBack = function () { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = false; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $("#installProgress").css("width", "0%"); + }; +}); + + +//.......................................Remote Backup + +//........... delete DeleteBackupConfigNow + +function DeleteBackupConfigNow(url) { + window.location.href = url; +} + +function DeleteRemoteBackupsiteNow(url) { + window.location.href = url; +} + +function DeleteBackupfileConfigNow(url) { + window.location.href = url; +} + + +app.controller('RemoteBackupConfig', function ($scope, $http, $timeout, $window) { + $scope.RemoteBackupLoading = true; + $scope.SFTPBackUpdiv = true; + + $scope.EndpointURLdiv = true; + $scope.Selectprovider = true; + $scope.S3keyNamediv = true; + $scope.Accesskeydiv = true; + $scope.SecretKeydiv = true; + $scope.SelectRemoteBackuptype = function () { + var val = $scope.RemoteBackuptype; + if (val == "SFTP") { + $scope.SFTPBackUpdiv = false; + $scope.EndpointURLdiv = true; + $scope.Selectprovider = true; + $scope.S3keyNamediv = true; + $scope.Accesskeydiv = true; + $scope.SecretKeydiv = true; + } else if (val == "S3") { + $scope.EndpointURLdiv = true; + $scope.Selectprovider = false; + $scope.S3keyNamediv = false; + $scope.Accesskeydiv = false; + $scope.SecretKeydiv = false; + $scope.SFTPBackUpdiv = true; + } else { + $scope.RemoteBackupLoading = true; + $scope.SFTPBackUpdiv = true; + + $scope.EndpointURLdiv = true; + $scope.Selectprovider = true; + $scope.S3keyNamediv = true; + $scope.Accesskeydiv = true; + $scope.SecretKeydiv = true; + } + } + + $scope.SelectProvidertype = function () { + $scope.EndpointURLdiv = true; + var provider = $scope.Providervalue + if (provider == 'Backblaze') { + $scope.EndpointURLdiv = false; + } else { + $scope.EndpointURLdiv = true; + } + } + + $scope.SaveBackupConfig = function () { + $scope.RemoteBackupLoading = false; + var Hname = $scope.Hostname; + var Uname = $scope.Username; + var Passwd = $scope.Password; + var path = $scope.path; + var type = $scope.RemoteBackuptype; + var Providervalue = $scope.Providervalue; + var data; + if (type == "SFTP") { + + data = { + Hname: Hname, + Uname: Uname, + Passwd: Passwd, + path: path, + type: type + } + } else if (type == "S3") { + if (Providervalue == "Backblaze") { + data = { + S3keyname: $scope.S3keyName, + Provider: Providervalue, + AccessKey: $scope.Accesskey, + SecertKey: $scope.SecretKey, + EndUrl: $scope.EndpointURL, + type: type + } + } else { + data = { + S3keyname: $scope.S3keyName, + Provider: Providervalue, + AccessKey: $scope.Accesskey, + SecertKey: $scope.SecretKey, + type: type + } + + } + + } + var url = "/websites/SaveBackupConfig"; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.RemoteBackupLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Saved!.', + type: 'success' + }); + location.reload(); + + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.RemoteBackupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + + + } + +}); + +var UpdatescheduleID; +app.controller('BackupSchedule', function ($scope, $http, $timeout, $window) { + $scope.BackupScheduleLoading = true; + $scope.SaveBackupSchedule = function () { + $scope.RemoteBackupLoading = false; + var FileRetention = $scope.Fretention; + var Backfrequency = $scope.Bfrequency; + + + var data = { + FileRetention: FileRetention, + Backfrequency: Backfrequency, + ScheduleName: $scope.ScheduleName, + RemoteConfigID: $('#RemoteConfigID').html(), + BackupType: $scope.BackupType + } + var url = "/websites/SaveBackupSchedule"; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.RemoteBackupLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Saved!.', + type: 'success' + }); + location.reload(); + + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.RemoteBackupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + + + }; + + + $scope.getupdateid = function (ID) { + UpdatescheduleID = ID; + } + + $scope.UpdateRemoteschedules = function () { + $scope.RemoteBackupLoading = false; + var Frequency = $scope.RemoteFrequency; + var fretention = $scope.RemoteFileretention; + + var data = { + ScheduleID: UpdatescheduleID, + Frequency: Frequency, + FileRetention: fretention + } + var url = "/websites/UpdateRemoteschedules"; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.RemoteBackupLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Updated!.', + type: 'success' + }); + location.reload(); + + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.RemoteBackupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + }; + + $scope.AddWPsiteforRemoteBackup = function () { + $scope.RemoteBackupLoading = false; + + + var data = { + WpsiteID: $('#Wpsite').val(), + RemoteScheduleID: $('#RemoteScheduleID').html() + } + var url = "/websites/AddWPsiteforRemoteBackup"; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.RemoteBackupLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Saved!.', + type: 'success' + }); + location.reload(); + + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.RemoteBackupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + + + }; +}); +/* Java script code to create account */ + +var website_create_domain_check = 0; + +function website_create_checkbox_function() { + + var checkBox = document.getElementById("myCheck"); + // Get the output text + + + // If the checkbox is checked, display the output text + if (checkBox.checked == true) { + website_create_domain_check = 0; + document.getElementById('Website_Create_Test_Domain').style.display = "block"; + document.getElementById('Website_Create_Own_Domain').style.display = "none"; + + } else { + document.getElementById('Website_Create_Test_Domain').style.display = "none"; + document.getElementById('Website_Create_Own_Domain').style.display = "block"; + website_create_domain_check = 1; + } + + // alert(domain_check); +} + + +/* Java script code to create account ends here */ + +/* Java script code to list accounts */ + +$("#listFail").hide(); + + +app.controller('listWebsites', function ($scope, $http, $window) { + $scope.web = {}; + $scope.WebSitesList = []; + $scope.loading = true; // Add loading state + + $scope.currentPage = 1; + $scope.recordsToShow = 10; + + // Initial fetch of websites + $scope.getFurtherWebsitesFromDB = function () { + $scope.loading = true; // Set loading to true when starting fetch + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + page: $scope.currentPage, + recordsToShow: $scope.recordsToShow + }; + + var dataurl = "/websites/fetchWebsitesList"; + + $http.post(dataurl, data, config).then(function(response) { + if (response.data.listWebSiteStatus === 1) { + $scope.WebSitesList = JSON.parse(response.data.data); + $scope.pagination = response.data.pagination; + $("#listFail").hide(); + } else { + $("#listFail").fadeIn(); + $scope.errorMessage = response.data.error_message; + } + $scope.loading = false; // Set loading to false when done + }).catch(function(error) { + $("#listFail").fadeIn(); + $scope.errorMessage = error.message || 'An error occurred while fetching websites'; + $scope.loading = false; // Set loading to false on error + }); + }; + + // Call it immediately + $scope.getFurtherWebsitesFromDB(); + + $scope.showWPSites = function(domain) { + console.log('showWPSites called for domain:', domain); + + // Make sure domain is defined + if (!domain) { + console.error('Domain is undefined'); + return; + } + + // Find the website in the list + var site = $scope.WebSitesList.find(function(website) { + return website.domain === domain; + }); + + if (!site) { + console.error('Website not found:', domain); + return; + } + + // Set loading state + site.loadingWPSites = true; + + // Toggle visibility + site.showWPSites = !site.showWPSites; + + // If we're hiding, just return + if (!site.showWPSites) { + site.loadingWPSites = false; + return; + } + + var config = { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = $.param({ + domain: domain + }); + + $http.post('/websites/fetchWPDetails', data, config) + .then(function(response) { + console.log('Response received:', response); + if (response.data.status === 1 && response.data.fetchStatus === 1) { + site.wp_sites = response.data.sites || []; + // Initialize loading states for each WP site + site.wp_sites.forEach(function(wp) { + wp.loading = false; + wp.loadingPlugins = false; + wp.loadingTheme = false; + }); + $("#listFail").hide(); + } else { + $("#listFail").fadeIn(); + site.showWPSites = false; + $scope.errorMessage = response.data.error_message || 'Failed to fetch WordPress sites'; + console.error('Error in response:', response.data.error_message); + new PNotify({ + title: 'Error!', + text: response.data.error_message || 'Failed to fetch WordPress sites', + type: 'error' + }); + } + }) + .catch(function(error) { + console.error('Request failed:', error); + site.showWPSites = false; + $("#listFail").fadeIn(); + $scope.errorMessage = error.message || 'An error occurred while fetching WordPress sites'; + new PNotify({ + title: 'Error!', + text: error.message || 'Could not connect to server', + type: 'error' + }); + }) + .finally(function() { + site.loadingWPSites = false; + }); + }; + + $scope.visitSite = function(wp) { + var url = wp.url || wp.domain; + if (!url) return; + if (!url.startsWith('http://') && !url.startsWith('https://')) { + url = 'https://' + url; + } + window.open(url, '_blank'); + }; + + $scope.wpLogin = function(wpId) { + window.open('/websites/AutoLogin?id=' + wpId, '_blank'); + }; + + $scope.manageWP = function(wpId) { + window.location.href = '/websites/WPHome?ID=' + wpId; + }; + + $scope.getFullUrl = function(url) { + console.log('getFullUrl called with:', url); + if (!url) { + // If no URL is provided, try to use the domain + if (this.wp && this.wp.domain) { + url = this.wp.domain; + } else { + return ''; + } + } + if (url.startsWith('http://') || url.startsWith('https://')) { + return url; + } + return 'https://' + url; + }; + + + $scope.updateSetting = function(wp, setting) { + var settingMap = { + 'search-indexing': 'searchIndex', + 'debugging': 'debugging', + 'password-protection': 'passwordProtection', + 'maintenance-mode': 'maintenanceMode' + }; + + // Toggle the state before sending request + wp[settingMap[setting]] = wp[settingMap[setting]] === 1 ? 0 : 1; + + var data = { + siteId: wp.id, + setting: setting, + value: wp[settingMap[setting]] + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post('/websites/UpdateWPSettings', data, config).then(function(response) { + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Setting updated successfully.', + type: 'success' + }); + if (setting === 'password-protection' && wp[settingMap[setting]] === 1) { + // Show password protection modal if enabling + wp.PPUsername = ""; + wp.PPPassword = ""; + $scope.currentWP = wp; + $('#passwordProtectionModal').modal('show'); + } + } else { + // Revert the change if update failed + wp[settingMap[setting]] = wp[settingMap[setting]] === 1 ? 0 : 1; + new PNotify({ + title: 'Error', + text: response.data.error_message || 'Failed to update setting.', + type: 'error' + }); + } + }).catch(function(error) { + // Revert the change on error + wp[settingMap[setting]] = wp[settingMap[setting]] === 1 ? 0 : 1; + new PNotify({ + title: 'Error', + text: 'Connection failed while updating setting.', + type: 'error' + }); + }); + }; + + $scope.UpdateWPSettings = function(wp) { + $('#wordpresshomeloading').show(); + + var url = "/websites/UpdateWPSettings"; + var data = {}; + + if (wp.setting === "PasswordProtection") { + data = { + wpID: wp.id, + setting: wp.setting, + PPUsername: wp.PPUsername, + PPPassword: wp.PPPassword + }; + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken'), + 'Content-Type': 'application/x-www-form-urlencoded' + }, + transformRequest: function(obj) { + var str = []; + for(var p in obj) + str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); + return str.join("&"); + } + }; + + $http.post(url, data, config).then(function(response) { + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Updated!', + type: 'success' + }); + if (wp.setting === "PasswordProtection") { + location.reload(); + } + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + if (wp.setting === "PasswordProtection") { + location.reload(); + } + } + }, function(error) { + $('#wordpresshomeloading').hide(); + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + }); + }; + + $scope.togglePasswordProtection = function(wp) { + console.log('togglePasswordProtection called for:', wp); + console.log('Current password protection state:', wp.passwordProtection); + + if (wp.passwordProtection) { + // Show modal for credentials + console.log('Showing modal for credentials'); + wp.PPUsername = ""; + wp.PPPassword = ""; + $scope.currentWP = wp; + console.log('Current WP set to:', $scope.currentWP); + $('#passwordProtectionModal').modal('show'); + } else { + // Disable password protection + console.log('Disabling password protection'); + var data = { + siteId: wp.id, + setting: 'password-protection', + value: 0 + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + console.log('Sending request with data:', data); + $http.post('/websites/UpdateWPSettings', data, config).then(function(response) { + console.log('Received response:', response); + if (!response.data.status) { + wp.passwordProtection = !wp.passwordProtection; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message || 'Failed to disable password protection', + type: 'error' + }); + } else { + new PNotify({ + title: 'Success!', + text: 'Password protection disabled successfully.', + type: 'success' + }); + } + }).catch(function(error) { + console.error('Request failed:', error); + wp.passwordProtection = !wp.passwordProtection; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server.', + type: 'error' + }); + }); + } + }; + + $scope.submitPasswordProtection = function() { + console.log('submitPasswordProtection called'); + console.log('Current WP:', $scope.currentWP); + + if (!$scope.currentWP) { + console.error('No WordPress site selected'); + new PNotify({ + title: 'Error!', + text: 'No WordPress site selected.', + type: 'error' + }); + return; + } + + if (!$scope.currentWP.PPUsername || !$scope.currentWP.PPPassword) { + console.error('Missing username or password'); + new PNotify({ + title: 'Error!', + text: 'Please provide both username and password', + type: 'error' + }); + return; + } + + var data = { + siteId: $scope.currentWP.id, + setting: 'password-protection', + value: 1, + username: $scope.currentWP.PPUsername, + password: $scope.currentWP.PPPassword + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + console.log('Sending request with data:', data); + $('#passwordProtectionModal').modal('hide'); + + $http.post('/websites/UpdateWPSettings', data, config).then(function(response) { + console.log('Received response:', response); + if (response.data.status) { + new PNotify({ + title: 'Success!', + text: 'Password protection enabled successfully!', + type: 'success' + }); + } else { + $scope.currentWP.passwordProtection = false; + new PNotify({ + title: 'Error!', + text: response.data.error_message || 'Failed to enable password protection', + type: 'error' + }); + } + }).catch(function(error) { + console.error('Request failed:', error); + $scope.currentWP.passwordProtection = false; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server', + type: 'error' + }); + }); + }; + + $scope.cyberPanelLoading = true; + + $scope.issueSSL = function (virtualHost) { + $scope.cyberPanelLoading = false; + + var url = "/manageSSL/issueSSL"; + + + var data = { + virtualHost: virtualHost + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberPanelLoading = true; + if (response.data.SSL === 1) { + new PNotify({ + title: 'Success!', + text: 'SSL successfully issued.', + 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.cyberPanelLoading = true; + + $scope.searchWebsites = function () { + $scope.loading = true; // Set loading to true when starting search + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + patternAdded: $scope.patternAdded + }; + + dataurl = "/websites/searchWebsites"; + + $http.post(dataurl, data, config).then(function(response) { + if (response.data.listWebSiteStatus === 1) { + var finalData = JSON.parse(response.data.data); + $scope.WebSitesList = finalData; + $("#listFail").hide(); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + $scope.loading = false; // Set loading to false when done + }).catch(function(error) { + new PNotify({ + title: 'Operation Failed!', + text: 'Connect disrupted, refresh the page.', + type: 'error' + }); + $scope.loading = false; // Set loading to false on error + }); + }; + + $scope.ScanWordpressSite = function () { + + $('#cyberPanelLoading').show(); + + + var url = "/websites/ScanWordpressSite"; + + var data = {} + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $('#cyberPanelLoading').hide(); + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Saved!.', + type: 'success' + }); + location.reload(); + + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#cyberPanelLoading').hide(); + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + + + }; + +}); + +/** + * Created by usman on 7/26/17. + */ +function getCookie(name) { + var cookieValue = null; + var t = document.cookie; + if (document.cookie && document.cookie !== '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = jQuery.trim(cookies[i]); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) === (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; +} + + +var arry = [] + +function selectpluginJs(val) { + $('#mysearch').hide() + arry.push(val) + + // console.log(arry) + document.getElementById('selJS').innerHTML = ""; + + for (var i = 0; i < arry.length; i++) { + $('#selJS').show() + var mlm = ' ' + arry[i] + '    ' + $('#selJS').append(mlm) + } + + +} + + +var DeletePluginURL; + +function DeletePluginBuucket(url) { + DeletePluginURL = url; +} + +function FinalDeletePluginBuucket() { + window.location.href = DeletePluginURL; +} + +var SPVal; + +app.controller('WPAddNewPlugin', function ($scope, $http, $timeout, $window, $compile) { + $scope.webSiteCreationLoading = true; + + $scope.SearchPluginName = function (val) { + $scope.webSiteCreationLoading = false; + SPVal = val; + url = "/websites/SearchOnkeyupPlugin"; + + var searchcontent = $scope.searchcontent; + + + var data = { + pluginname: searchcontent + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.webSiteCreationLoading = true; + + if (response.data.status === 1) { + if (SPVal == 'add') { + $('#mysearch').show() + document.getElementById('mysearch').innerHTML = ""; + var res = response.data.plugns.plugins + // console.log(res); + for (i = 0; i <= res.length; i++) { + // + var tml = '
'; + $('#mysearch').append(tml); + } + } else if (SPVal == 'eidt') { + $('#mysearch').show() + document.getElementById('mysearch').innerHTML = ""; + var res = response.data.plugns.plugins + // console.log(res); + for (i = 0; i <= res.length; i++) { + // + var tml = '
'; + var temp = $compile(tml)($scope) + angular.element(document.getElementById('mysearch')).append(temp); + } + + } + + + } else { + + // $scope.errorMessage = response.data.error_message; + alert("Status not = 1: Error..." + response.data.error_message) + } + + + } + + function cantLoadInitialDatas(response) { + + alert("Error..." + response) + + } + } + + $scope.AddNewplugin = function () { + + url = "/websites/AddNewpluginAjax"; + + var bucketname = $scope.PluginbucketName + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + var data = { + config: arry, + Name: bucketname + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Bucket created.', + type: 'success' + }); + location.reload(); + } else { + + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + + + } + + function cantLoadInitialDatas(response) { + + alert("Error..." + response) + + } + } + + $scope.deletesPlgin = function (val) { + + url = "/websites/deletesPlgin"; + + + var data = { + pluginname: val, + pluginbBucketID: $('#pluginbID').html() + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.status === 1) { + location.reload(); + + } else { + + // $scope.errorMessage = response.data.error_message; + alert("Status not = 1: Error..." + response.data.error_message) + } + + + } + + function cantLoadInitialDatas(response) { + + alert("Error..." + response) + + } + + } + + $scope.Addplugin = function (slug) { + $('#mysearch').hide() + + url = "/websites/Addplugineidt"; + + + var data = { + pluginname: slug, + pluginbBucketID: $('#pluginbID').html() + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.status === 1) { + location.reload(); + + } else { + + // $scope.errorMessage = response.data.error_message; + alert("Status not = 1: Error..." + response.data.error_message) + } + + + } + + function cantLoadInitialDatas(response) { + + alert("Error..." + response) + + } + + + } + +}); + +var domain_check = 0; + +function checkbox_function() { + + var checkBox = document.getElementById("myCheck"); + // Get the output text + + + // If the checkbox is checked, display the output text + if (checkBox.checked == true) { + domain_check = 0; + document.getElementById('Test_Domain').style.display = "block"; + document.getElementById('Own_Domain').style.display = "none"; + + } else { + document.getElementById('Test_Domain').style.display = "none"; + document.getElementById('Own_Domain').style.display = "block"; + domain_check = 1; + } + + // alert(domain_check); +} + +app.controller('createWordpress', function ($scope, $http, $timeout, $compile, $window) { + $scope.webSiteCreationLoading = true; + $scope.installationDetailsForm = false; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + + + var statusFile; + + $scope.createWordPresssite = function () { + + $scope.webSiteCreationLoading = false; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + + + $scope.currentStatus = "Starting creation.."; + + var apacheBackend = 0; + + if ($scope.apacheBackend === true) { + apacheBackend = 1; + } else { + apacheBackend = 0 + } + + var package = $scope.packageForWebsite; + var websiteOwner = $scope.websiteOwner; + var WPtitle = $scope.WPtitle; + + // if (domain_check == 0) { + // var Part2_domainNameCreate = document.getElementById('Part2_domainNameCreate').value; + // var domainNameCreate = document.getElementById('TestDomainNameCreate').value + Part2_domainNameCreate; + // } + // if (domain_check == 1) { + // + // var domainNameCreate = $scope.own_domainNameCreate; + // } + + var domainNameCreate = $scope.domainNameCreate; + + + var WPUsername = $scope.WPUsername; + var adminEmail = $scope.adminEmail; + var WPPassword = $scope.WPPassword; + var WPVersions = $scope.WPVersions; + var pluginbucket = $scope.pluginbucket; + var autoupdates = $scope.autoupdates; + var pluginupdates = $scope.pluginupdates; + var themeupdates = $scope.themeupdates; + + if (domain_check == 0) { + + var path = ""; + + } + if (domain_check = 1) { + + var path = $scope.installPath; + + } + + + var home = "1"; + + if (typeof path != 'undefined') { + home = "0"; + } + + //alert(domainNameCreate); + var data = { + + title: WPtitle, + domain: domainNameCreate, + WPVersion: WPVersions, + pluginbucket: pluginbucket, + adminUser: WPUsername, + Email: adminEmail, + PasswordByPass: WPPassword, + AutomaticUpdates: autoupdates, + Plugins: pluginupdates, + Themes: themeupdates, + websiteOwner: websiteOwner, + package: package, + home: home, + path: path, + apacheBackend: apacheBackend + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var url = "/websites/submitWorpressCreation"; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.webSiteCreationLoading = 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.webSiteCreationLoading = 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.webSiteCreationLoading = 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.webSiteCreationLoading = false; + $("#installProgress").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + $timeout(getCreationStatus, 1000); + } + + } + + function cantLoadInitialDatas(response) { + + $scope.webSiteCreationLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + } + + +}); + + +//........... delete wp list +var FurlDeleteWP; + +function DeleteWPNow(url) { + FurlDeleteWP = url; +} + +function FinalDeleteWPNow() { + window.location.href = FurlDeleteWP; +} + +var DeploytoProductionID; + +function DeployToProductionInitial(vall) { + DeploytoProductionID = vall; +} + +var create_staging_domain_check = 0; + +function create_staging_checkbox_function() { + + try { + + var checkBox = document.getElementById("Create_Staging_Check"); + // Get the output text + + + // If the checkbox is checked, display the output text + if (checkBox.checked == true) { + create_staging_domain_check = 0; + document.getElementById('Website_Create_Test_Domain').style.display = "block"; + document.getElementById('Website_Create_Own_Domain').style.display = "none"; + + } else { + document.getElementById('Website_Create_Test_Domain').style.display = "none"; + document.getElementById('Website_Create_Own_Domain').style.display = "block"; + create_staging_domain_check = 1; + } + } catch (e) { + + } + + // alert(domain_check); +} + +create_staging_checkbox_function(); + +app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $window) { + var CheckBoxpasssword = 0; + + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = false; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $scope.searchIndex = 0; + + $(document).ready(function () { + var checkstatus = document.getElementById("wordpresshome"); + if (checkstatus !== null) { + $scope.LoadWPdata(); + } + }); + + $scope.LoadWPdata = function () { + $scope.wordpresshomeloading = false; + $('#wordpresshomeloading').show(); + + var url = "/websites/FetchWPdata"; + + var data = { + WPid: $('#WPid').html(), + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(function(response) { + $scope.wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + $('#WPVersion').text(response.data.ret_data.version); + if (response.data.ret_data.lscache === 1) { + $('#lscache').prop('checked', true); + } + if (response.data.ret_data.debugging === 1) { + $('#debugging').prop('checked', true); + } + + // Set search index state + $scope.searchIndex = response.data.ret_data.searchIndex; + + if (response.data.ret_data.maintenanceMode === 1) { + $('#maintenanceMode').prop('checked', true); + } + if (response.data.ret_data.wpcron === 1) { + $('#wpcron').prop('checked', true); + } + if (response.data.ret_data.passwordprotection == 1) { + var dc = ''; + var mp = $compile(dc)($scope); + angular.element(document.getElementById('prsswdprodata')).append(mp); + CheckBoxpasssword = 1; + } else { + var dc = ''; + $('#prsswdprodata').append(dc); + CheckBoxpasssword = 0; + } + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + }, function(error) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + console.error('Failed to load WP data:', error); + }); + }; + + $scope.UpdateWPSettings = function (setting) { + $scope.wordpresshomeloading = false; + $('#wordpresshomeloading').show(); + + var url = "/websites/UpdateWPSettings"; + var data; + + if (setting === "PasswordProtection") { + data = { + WPid: $('#WPid').html(), + setting: setting, + PPUsername: CheckBoxpasssword == 0 ? $scope.PPUsername : '', + PPPassword: CheckBoxpasssword == 0 ? $scope.PPPassword : '' + }; + } else { + var settingValue; + if (setting === 'searchIndex') { + $scope.searchIndex = $scope.searchIndex === 1 ? 0 : 1; + settingValue = $scope.searchIndex; + } else { + settingValue = $('#' + setting).is(":checked") ? 1 : 0; + } + data = { + WPid: $('#WPid').html(), + setting: setting, + settingValue: settingValue + }; + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(function(response) { + $scope.wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Updated!', + type: 'success' + }); + if (setting === "PasswordProtection") { + location.reload(); + } + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + // Revert the change on error + if (setting === 'searchIndex') { + $scope.searchIndex = $scope.searchIndex === 1 ? 0 : 1; + } + if (setting === "PasswordProtection") { + location.reload(); + } + } + }, function(error) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + // Revert the change on error + if (setting === 'searchIndex') { + $scope.searchIndex = $scope.searchIndex === 1 ? 0 : 1; + } + console.error('Failed to update setting:', error); + }); + }; + $scope.GetCurrentPlugins = function () { $('#wordpresshomeloading').show(); @@ -2464,13 +5336,10 @@ app.controller('createWebsite', function ($scope, $http, $timeout, $window) { // var domainName = document.getElementById('TestDomainNameCreate').value + Part2_domainNameCreate; // } // if (website_create_domain_check == 1) { - // // var domainName = $scope.domainNameCreate; // } var domainName = $scope.domainNameCreate; - // var domainName = $scope.domainNameCreate; - var adminEmail = $scope.adminEmail; var phpSelection = $scope.phpSelection; var websiteOwner = $scope.websiteOwner; @@ -2634,16 +5503,16 @@ $("#listFail").hide(); app.controller('listWebsites', function ($scope, $http, $window) { - console.log('Initializing listWebsites controller'); $scope.web = {}; $scope.WebSitesList = []; - + $scope.loading = true; // Add loading state + $scope.currentPage = 1; $scope.recordsToShow = 10; // Initial fetch of websites $scope.getFurtherWebsitesFromDB = function () { - console.log('Fetching websites from DB'); + $scope.loading = true; // Set loading to true when starting fetch var config = { headers: { 'X-CSRFToken': getCookie('csrftoken') @@ -2656,29 +5525,21 @@ app.controller('listWebsites', function ($scope, $http, $window) { }; var dataurl = "/websites/fetchWebsitesList"; - console.log('Making request to:', dataurl); $http.post(dataurl, data, config).then(function(response) { - console.log('Received response:', response); if (response.data.listWebSiteStatus === 1) { - try { - $scope.WebSitesList = JSON.parse(response.data.data); - console.log('Parsed WebSitesList:', $scope.WebSitesList); - $scope.pagination = response.data.pagination; - $("#listFail").hide(); - } catch (e) { - console.error('Error parsing response data:', e); - $("#listFail").fadeIn(); - $scope.errorMessage = 'Error parsing server response'; - } + $scope.WebSitesList = JSON.parse(response.data.data); + $scope.pagination = response.data.pagination; + $("#listFail").hide(); } else { $("#listFail").fadeIn(); $scope.errorMessage = response.data.error_message; } + $scope.loading = false; // Set loading to false when done }).catch(function(error) { - console.error('Error fetching websites:', error); $("#listFail").fadeIn(); $scope.errorMessage = error.message || 'An error occurred while fetching websites'; + $scope.loading = false; // Set loading to false on error }); }; @@ -2686,87 +5547,93 @@ app.controller('listWebsites', function ($scope, $http, $window) { $scope.getFurtherWebsitesFromDB(); $scope.showWPSites = function(domain) { + console.log('showWPSites called for domain:', domain); + + // Make sure domain is defined + if (!domain) { + console.error('Domain is undefined'); + return; + } + + // Find the website in the list + var site = $scope.WebSitesList.find(function(website) { + return website.domain === domain; + }); + + if (!site) { + console.error('Website not found:', domain); + return; + } + + // Set loading state + site.loadingWPSites = true; + + // Toggle visibility + site.showWPSites = !site.showWPSites; + + // If we're hiding, just return + if (!site.showWPSites) { + site.loadingWPSites = false; + return; + } + var config = { headers: { + 'Content-Type': 'application/x-www-form-urlencoded', 'X-CSRFToken': getCookie('csrftoken') } }; - var data = { + var data = $.param({ domain: domain - }; + }); - var url = '/websites/GetWPSitesByDomain'; - - $http.post(url, data, config).then(function(response) { - if (response.data.status === 1) { - // Find the website in the list and update its WordPress sites - for (var i = 0; i < $scope.WebSitesList.length; i++) { - if ($scope.WebSitesList[i].domain === domain) { - $scope.WebSitesList[i].wp_sites = response.data.data; - $scope.WebSitesList[i].showWPSites = !$scope.WebSitesList[i].showWPSites; - break; - } + $http.post('/websites/fetchWPDetails', data, config) + .then(function(response) { + console.log('Response received:', response); + if (response.data.status === 1 && response.data.fetchStatus === 1) { + site.wp_sites = response.data.sites || []; + // Initialize loading states for each WP site + site.wp_sites.forEach(function(wp) { + wp.loading = false; + wp.loadingPlugins = false; + wp.loadingTheme = false; + }); + $("#listFail").hide(); + } else { + $("#listFail").fadeIn(); + site.showWPSites = false; + $scope.errorMessage = response.data.error_message || 'Failed to fetch WordPress sites'; + console.error('Error in response:', response.data.error_message); + new PNotify({ + title: 'Error!', + text: response.data.error_message || 'Failed to fetch WordPress sites', + type: 'error' + }); } - } else { - console.error('Error fetching WordPress sites:', response.data.error_message); + }) + .catch(function(error) { + console.error('Request failed:', error); + site.showWPSites = false; + $("#listFail").fadeIn(); + $scope.errorMessage = error.message || 'An error occurred while fetching WordPress sites'; new PNotify({ title: 'Error!', - text: response.data.error_message, + text: error.message || 'Could not connect to server', type: 'error' }); - } - }, function(error) { - console.error('Error fetching WordPress sites:', error); - new PNotify({ - title: 'Error!', - text: 'Failed to fetch WordPress sites. Please try again.', - type: 'error' + }) + .finally(function() { + site.loadingWPSites = false; }); - }); }; - $scope.updateSetting = function(wpId, setting, value) { - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - var data = { - siteId: wpId, - setting: setting, - value: value - }; - - var url = '/websites/UpdateWPSettings'; - - $http.post(url, data, config).then(function(response) { - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Setting updated successfully.', - type: 'success' - }); - } else { - console.error('Error updating setting:', response.data.error_message); - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type: 'error' - }); - } - }, function(error) { - console.error('Error updating setting:', error); - new PNotify({ - title: 'Error!', - text: 'Failed to update setting. Please try again.', - type: 'error' - }); - }); - }; - - $scope.visitSite = function(url) { + $scope.visitSite = function(wp) { + var url = wp.url || wp.domain; + if (!url) return; + if (!url.startsWith('http://') && !url.startsWith('https://')) { + url = 'https://' + url; + } window.open(url, '_blank'); }; @@ -2778,6 +5645,460 @@ app.controller('listWebsites', function ($scope, $http, $window) { window.location.href = '/websites/listWPsites?wpID=' + wpId; }; + $scope.getFullUrl = function(url) { + console.log('getFullUrl called with:', url); + if (!url) { + // If no URL is provided, try to use the domain + if (this.wp && this.wp.domain) { + url = this.wp.domain; + } else { + return ''; + } + } + if (url.startsWith('http://') || url.startsWith('https://')) { + return url; + } + return 'https://' + url; + }; + + + + $scope.updateSetting = function(wp, setting) { + var settingMap = { + 'search-indexing': 'searchIndex', + 'debugging': 'debugging', + 'password-protection': 'passwordProtection', + 'maintenance-mode': 'maintenanceMode' + }; + + // Toggle the state before sending request + wp[settingMap[setting]] = wp[settingMap[setting]] === 1 ? 0 : 1; + + var data = { + siteId: wp.id, + setting: setting, + value: wp[settingMap[setting]] + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post('/websites/UpdateWPSettings', data, config).then(function(response) { + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Setting updated successfully.', + type: 'success' + }); + if (setting === 'password-protection' && wp[settingMap[setting]] === 1) { + // Show password protection modal if enabling + wp.PPUsername = ""; + wp.PPPassword = ""; + $scope.currentWP = wp; + $('#passwordProtectionModal').modal('show'); + } + } else { + // Revert the change if update failed + wp[settingMap[setting]] = wp[settingMap[setting]] === 1 ? 0 : 1; + new PNotify({ + title: 'Error', + text: response.data.error_message || 'Failed to update setting.', + type: 'error' + }); + } + }).catch(function(error) { + // Revert the change on error + wp[settingMap[setting]] = wp[settingMap[setting]] === 1 ? 0 : 1; + new PNotify({ + title: 'Error', + text: 'Connection failed while updating setting.', + type: 'error' + }); + }); + }; + + $scope.UpdateWPSettings = function(wp) { + $('#wordpresshomeloading').show(); + + var url = "/websites/UpdateWPSettings"; + var data = {}; + + if (wp.setting === "PasswordProtection") { + data = { + wpID: wp.id, + setting: wp.setting, + PPUsername: wp.PPUsername, + PPPassword: wp.PPPassword + }; + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken'), + 'Content-Type': 'application/x-www-form-urlencoded' + }, + transformRequest: function(obj) { + var str = []; + for(var p in obj) + str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); + return str.join("&"); + } + }; + + $http.post(url, data, config).then(function(response) { + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Updated!', + type: 'success' + }); + if (wp.setting === "PasswordProtection") { + location.reload(); + } + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + if (wp.setting === "PasswordProtection") { + location.reload(); + } + } + }, function(error) { + $('#wordpresshomeloading').hide(); + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + }); + }; + + $scope.togglePasswordProtection = function(wp) { + console.log('togglePasswordProtection called for:', wp); + console.log('Current password protection state:', wp.passwordProtection); + + if (wp.passwordProtection) { + // Show modal for credentials + console.log('Showing modal for credentials'); + wp.PPUsername = ""; + wp.PPPassword = ""; + $scope.currentWP = wp; + console.log('Current WP set to:', $scope.currentWP); + $('#passwordProtectionModal').modal('show'); + } else { + // Disable password protection + console.log('Disabling password protection'); + var data = { + siteId: wp.id, + setting: 'password-protection', + value: 0 + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + console.log('Sending request with data:', data); + $http.post('/websites/UpdateWPSettings', data, config).then(function(response) { + console.log('Received response:', response); + if (!response.data.status) { + wp.passwordProtection = !wp.passwordProtection; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message || 'Failed to disable password protection', + type: 'error' + }); + } else { + new PNotify({ + title: 'Success!', + text: 'Password protection disabled successfully.', + type: 'success' + }); + } + }).catch(function(error) { + console.error('Request failed:', error); + wp.passwordProtection = !wp.passwordProtection; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server.', + type: 'error' + }); + }); + } + }; + + $scope.submitPasswordProtection = function() { + console.log('submitPasswordProtection called'); + console.log('Current WP:', $scope.currentWP); + + if (!$scope.currentWP) { + console.error('No WordPress site selected'); + new PNotify({ + title: 'Error!', + text: 'No WordPress site selected.', + type: 'error' + }); + return; + } + + if (!$scope.currentWP.PPUsername || !$scope.currentWP.PPPassword) { + console.error('Missing username or password'); + new PNotify({ + title: 'Error!', + text: 'Please provide both username and password', + type: 'error' + }); + return; + } + + var data = { + siteId: $scope.currentWP.id, + setting: 'password-protection', + value: 1, + username: $scope.currentWP.PPUsername, + password: $scope.currentWP.PPPassword + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + console.log('Sending request with data:', data); + $('#passwordProtectionModal').modal('hide'); + + $http.post('/websites/UpdateWPSettings', data, config).then(function(response) { + console.log('Received response:', response); + if (response.data.status) { + new PNotify({ + title: 'Success!', + text: 'Password protection enabled successfully!', + type: 'success' + }); + } else { + $scope.currentWP.passwordProtection = false; + new PNotify({ + title: 'Error!', + text: response.data.error_message || 'Failed to enable password protection', + type: 'error' + }); + } + }).catch(function(error) { + console.error('Request failed:', error); + $scope.currentWP.passwordProtection = false; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server', + type: 'error' + }); + }); + }; + + $scope.cyberPanelLoading = true; + + $scope.issueSSL = function (virtualHost) { + $scope.cyberPanelLoading = false; + + var url = "/manageSSL/issueSSL"; + + + var data = { + virtualHost: virtualHost + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberPanelLoading = true; + if (response.data.SSL === 1) { + new PNotify({ + title: 'Success!', + text: 'SSL successfully issued.', + 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.cyberPanelLoading = true; + + $scope.searchWebsites = function () { + $scope.loading = true; // Set loading to true when starting search + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + patternAdded: $scope.patternAdded + }; + + dataurl = "/websites/searchWebsites"; + + $http.post(dataurl, data, config).then(function(response) { + if (response.data.listWebSiteStatus === 1) { + var finalData = JSON.parse(response.data.data); + $scope.WebSitesList = finalData; + $("#listFail").hide(); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + $scope.loading = false; // Set loading to false when done + }).catch(function(error) { + new PNotify({ + title: 'Operation Failed!', + text: 'Connect disrupted, refresh the page.', + type: 'error' + }); + $scope.loading = false; // Set loading to false on error + }); + }; + + $scope.ScanWordpressSite = function () { + + $('#cyberPanelLoading').show(); + + + var url = "/websites/ScanWordpressSite"; + + var data = {} + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $('#cyberPanelLoading').hide(); + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Saved!.', + type: 'success' + }); + location.reload(); + + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#cyberPanelLoading').hide(); + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + + + }; + +}); + +app.controller('listChildDomainsMain', function ($scope, $http, $timeout) { + + $scope.currentPage = 1; + $scope.recordsToShow = 10; + + $scope.getFurtherWebsitesFromDB = function () { + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + page: $scope.currentPage, + recordsToShow: $scope.recordsToShow + }; + + + dataurl = "/websites/fetchChildDomainsMain"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + + function ListInitialData(response) { + if (response.data.listWebSiteStatus === 1) { + + $scope.WebSitesList = JSON.parse(response.data.data); + $scope.pagination = response.data.pagination; + $scope.clients = JSON.parse(response.data.data); + $("#listFail").hide(); + } else { + $("#listFail").fadeIn(); + $scope.errorMessage = response.data.error_message; + + } + } + + function cantLoadInitialData(response) { + } + + + }; + $scope.getFurtherWebsitesFromDB(); + $scope.cyberPanelLoading = true; $scope.issueSSL = function (virtualHost) { @@ -2845,7 +6166,7 @@ app.controller('listWebsites', function ($scope, $http, $window) { patternAdded: $scope.patternAdded }; - dataurl = "/websites/searchWebsites"; + dataurl = "/websites/searchChilds"; $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); @@ -2879,6 +6200,3085 @@ app.controller('listWebsites', function ($scope, $http, $window) { }; + $scope.initConvert = function (virtualHost) { + $scope.domainName = virtualHost; + }; + + var statusFile; + + $scope.installationProgress = true; + + $scope.convert = function () { + + $scope.cyberPanelLoading = false; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.goBackDisable = true; + + $scope.currentStatus = "Starting creation.."; + + var ssl, dkimCheck, openBasedir; + + if ($scope.sslCheck === true) { + ssl = 1; + } else { + ssl = 0 + } + + if ($scope.dkimCheck === true) { + dkimCheck = 1; + } else { + dkimCheck = 0 + } + + if ($scope.openBasedir === true) { + openBasedir = 1; + } else { + openBasedir = 0 + } + + url = "/websites/convertDomainToSite"; + + + var data = { + package: $scope.packageForWebsite, + domainName: $scope.domainName, + adminEmail: $scope.adminEmail, + phpSelection: $scope.phpSelection, + websiteOwner: $scope.websiteOwner, + ssl: ssl, + dkimCheck: dkimCheck, + openBasedir: openBasedir + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.createWebSiteStatus === 1) { + statusFile = response.data.tempStatusPath; + getCreationStatus(); + } else { + + $scope.cyberPanelLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.goBackDisable = false; + + $scope.currentStatus = response.data.error_message; + } + + + } + + function cantLoadInitialDatas(response) { + + $scope.cyberPanelLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.goBackDisable = false; + + } + + + }; + $scope.goBack = function () { + $scope.cyberPanelLoading = true; + $scope.installationDetailsForm = false; + $scope.installationProgress = 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.cyberPanelLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.goBackDisable = false; + + $("#installProgress").css("width", "100%"); + $scope.installPercentage = "100"; + $scope.currentStatus = response.data.currentStatus; + $timeout.cancel(); + + } else { + + $scope.cyberPanelLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.goBackDisable = false; + + $scope.currentStatus = response.data.error_message; + + $("#installProgress").css("width", "0%"); + $scope.installPercentage = "0"; + $scope.goBackDisable = false; + + } + + } else { + $("#installProgress").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + $timeout(getCreationStatus, 1000); + } + + } + + function cantLoadInitialDatas(response) { + + $scope.cyberPanelLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.goBackDisable = false; + + } + + + } + + var DeleteDomain; + $scope.deleteDomainInit = function (childDomainForDeletion) { + DeleteDomain = childDomainForDeletion; + }; + + $scope.deleteChildDomain = function () { + $scope.cyberPanelLoading = false; + url = "/websites/submitDomainDeletion"; + + var data = { + websiteName: DeleteDomain, + DeleteDocRoot: $scope.DeleteDocRoot + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + $scope.cyberPanelLoading = true; + if (response.data.websiteDeleteStatus === 1) { + new PNotify({ + title: 'Success!', + text: 'Child Domain successfully deleted.', + type: 'success' + }); + $scope.getFurtherWebsitesFromDB(); + } 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' + }); + + } + + }; + +}); + +/* Java script code to list accounts ends here */ + + +/* Java script code to delete Website */ + + +$("#websiteDeleteFailure").hide(); +$("#websiteDeleteSuccess").hide(); + +$("#deleteWebsiteButton").hide(); +$("#deleteLoading").hide(); + +app.controller('deleteWebsiteControl', function ($scope, $http) { + + + $scope.deleteWebsite = function () { + + $("#deleteWebsiteButton").fadeIn(); + + + }; + + $scope.deleteWebsiteFinal = function () { + + $("#deleteLoading").show(); + + var websiteName = $scope.websiteToBeDeleted; + + + url = "/websites/submitWebsiteDeletion"; + + var data = { + websiteName: websiteName + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.websiteDeleteStatus === 0) { + $scope.errorMessage = response.data.error_message; + $("#websiteDeleteFailure").fadeIn(); + $("#websiteDeleteSuccess").hide(); + $("#deleteWebsiteButton").hide(); + + + $("#deleteLoading").hide(); + + } else { + $("#websiteDeleteFailure").hide(); + $("#websiteDeleteSuccess").fadeIn(); + $("#deleteWebsiteButton").hide(); + $scope.deletedWebsite = websiteName; + $("#deleteLoading").hide(); + + } + + + } + + function cantLoadInitialDatas(response) { + } + + + }; + +}); + + +/** + * Created by usman on 7/26/17. + */ +function getCookie(name) { + var cookieValue = null; + var t = document.cookie; + if (document.cookie && document.cookie !== '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = jQuery.trim(cookies[i]); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) === (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; +} + + +var arry = [] + +function selectpluginJs(val) { + $('#mysearch').hide() + arry.push(val) + + // console.log(arry) + document.getElementById('selJS').innerHTML = ""; + + for (var i = 0; i < arry.length; i++) { + $('#selJS').show() + var mlm = ' ' + arry[i] + '    ' + $('#selJS').append(mlm) + } + + +} + + +var DeletePluginURL; + +function DeletePluginBuucket(url) { + DeletePluginURL = url; +} + +function FinalDeletePluginBuucket() { + window.location.href = DeletePluginURL; +} + +var SPVal; + +app.controller('WPAddNewPlugin', function ($scope, $http, $timeout, $window, $compile) { + $scope.webSiteCreationLoading = true; + + $scope.SearchPluginName = function (val) { + $scope.webSiteCreationLoading = false; + SPVal = val; + url = "/websites/SearchOnkeyupPlugin"; + + var searchcontent = $scope.searchcontent; + + + var data = { + pluginname: searchcontent + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.webSiteCreationLoading = true; + + if (response.data.status === 1) { + if (SPVal == 'add') { + $('#mysearch').show() + document.getElementById('mysearch').innerHTML = ""; + var res = response.data.plugns.plugins + // console.log(res); + for (i = 0; i <= res.length; i++) { + // + var tml = '
'; + $('#mysearch').append(tml); + } + } else if (SPVal == 'eidt') { + $('#mysearch').show() + document.getElementById('mysearch').innerHTML = ""; + var res = response.data.plugns.plugins + // console.log(res); + for (i = 0; i <= res.length; i++) { + // + var tml = '
'; + var temp = $compile(tml)($scope) + angular.element(document.getElementById('mysearch')).append(temp); + } + + } + + + } else { + + // $scope.errorMessage = response.data.error_message; + alert("Status not = 1: Error..." + response.data.error_message) + } + + + } + + function cantLoadInitialDatas(response) { + + alert("Error..." + response) + + } + } + + $scope.AddNewplugin = function () { + + url = "/websites/AddNewpluginAjax"; + + var bucketname = $scope.PluginbucketName + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + var data = { + config: arry, + Name: bucketname + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Bucket created.', + type: 'success' + }); + location.reload(); + } else { + + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + + + } + + function cantLoadInitialDatas(response) { + + alert("Error..." + response) + + } + } + + $scope.deletesPlgin = function (val) { + + url = "/websites/deletesPlgin"; + + + var data = { + pluginname: val, + pluginbBucketID: $('#pluginbID').html() + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.status === 1) { + location.reload(); + + } else { + + // $scope.errorMessage = response.data.error_message; + alert("Status not = 1: Error..." + response.data.error_message) + } + + + } + + function cantLoadInitialDatas(response) { + + alert("Error..." + response) + + } + + } + + $scope.Addplugin = function (slug) { + $('#mysearch').hide() + + url = "/websites/Addplugineidt"; + + + var data = { + pluginname: slug, + pluginbBucketID: $('#pluginbID').html() + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.status === 1) { + location.reload(); + + } else { + + // $scope.errorMessage = response.data.error_message; + alert("Status not = 1: Error..." + response.data.error_message) + } + + + } + + function cantLoadInitialDatas(response) { + + alert("Error..." + response) + + } + + + } + +}); + +var domain_check = 0; + +function checkbox_function() { + + var checkBox = document.getElementById("myCheck"); + // Get the output text + + + // If the checkbox is checked, display the output text + if (checkBox.checked == true) { + domain_check = 0; + document.getElementById('Test_Domain').style.display = "block"; + document.getElementById('Own_Domain').style.display = "none"; + + } else { + document.getElementById('Test_Domain').style.display = "none"; + document.getElementById('Own_Domain').style.display = "block"; + domain_check = 1; + } + + // alert(domain_check); +} + +app.controller('createWordpress', function ($scope, $http, $timeout, $compile, $window) { + $scope.webSiteCreationLoading = true; + $scope.installationDetailsForm = false; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + + + var statusFile; + + $scope.createWordPresssite = function () { + + $scope.webSiteCreationLoading = false; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + + + $scope.currentStatus = "Starting creation.."; + + var apacheBackend = 0; + + if ($scope.apacheBackend === true) { + apacheBackend = 1; + } else { + apacheBackend = 0 + } + + var package = $scope.packageForWebsite; + var websiteOwner = $scope.websiteOwner; + var WPtitle = $scope.WPtitle; + + // if (domain_check == 0) { + // var Part2_domainNameCreate = document.getElementById('Part2_domainNameCreate').value; + // var domainNameCreate = document.getElementById('TestDomainNameCreate').value + Part2_domainNameCreate; + // } + // if (domain_check == 1) { + // + // var domainNameCreate = $scope.own_domainNameCreate; + // } + + var domainNameCreate = $scope.domainNameCreate; + + + var WPUsername = $scope.WPUsername; + var adminEmail = $scope.adminEmail; + var WPPassword = $scope.WPPassword; + var WPVersions = $scope.WPVersions; + var pluginbucket = $scope.pluginbucket; + var autoupdates = $scope.autoupdates; + var pluginupdates = $scope.pluginupdates; + var themeupdates = $scope.themeupdates; + + if (domain_check == 0) { + + var path = ""; + + } + if (domain_check = 1) { + + var path = $scope.installPath; + + } + + + var home = "1"; + + if (typeof path != 'undefined') { + home = "0"; + } + + //alert(domainNameCreate); + var data = { + + title: WPtitle, + domain: domainNameCreate, + WPVersion: WPVersions, + pluginbucket: pluginbucket, + adminUser: WPUsername, + Email: adminEmail, + PasswordByPass: WPPassword, + AutomaticUpdates: autoupdates, + Plugins: pluginupdates, + Themes: themeupdates, + websiteOwner: websiteOwner, + package: package, + home: home, + path: path, + apacheBackend: apacheBackend + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + var url = "/websites/submitWorpressCreation"; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.webSiteCreationLoading = 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.webSiteCreationLoading = 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.webSiteCreationLoading = 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.webSiteCreationLoading = false; + $("#installProgress").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + $timeout(getCreationStatus, 1000); + } + + } + + function cantLoadInitialDatas(response) { + + $scope.webSiteCreationLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + } + + +}); + + +//........... delete wp list +var FurlDeleteWP; + +function DeleteWPNow(url) { + FurlDeleteWP = url; +} + +function FinalDeleteWPNow() { + window.location.href = FurlDeleteWP; +} + +var DeploytoProductionID; + +function DeployToProductionInitial(vall) { + DeploytoProductionID = vall; +} + +var create_staging_domain_check = 0; + +function create_staging_checkbox_function() { + + try { + + var checkBox = document.getElementById("Create_Staging_Check"); + // Get the output text + + + // If the checkbox is checked, display the output text + if (checkBox.checked == true) { + create_staging_domain_check = 0; + document.getElementById('Website_Create_Test_Domain').style.display = "block"; + document.getElementById('Website_Create_Own_Domain').style.display = "none"; + + } else { + document.getElementById('Website_Create_Test_Domain').style.display = "none"; + document.getElementById('Website_Create_Own_Domain').style.display = "block"; + create_staging_domain_check = 1; + } + } catch (e) { + + } + + // alert(domain_check); +} + +create_staging_checkbox_function(); + +app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $window) { + var CheckBoxpasssword = 0; + + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = false; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $scope.searchIndex = 0; + + $(document).ready(function () { + var checkstatus = document.getElementById("wordpresshome"); + if (checkstatus !== null) { + $scope.LoadWPdata(); + } + }); + + $scope.LoadWPdata = function () { + $scope.wordpresshomeloading = false; + $('#wordpresshomeloading').show(); + + var url = "/websites/FetchWPdata"; + + var data = { + WPid: $('#WPid').html(), + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(function(response) { + $scope.wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + $('#WPVersion').text(response.data.ret_data.version); + if (response.data.ret_data.lscache === 1) { + $('#lscache').prop('checked', true); + } + if (response.data.ret_data.debugging === 1) { + $('#debugging').prop('checked', true); + } + + // Set search index state + $scope.searchIndex = response.data.ret_data.searchIndex; + + if (response.data.ret_data.maintenanceMode === 1) { + $('#maintenanceMode').prop('checked', true); + } + if (response.data.ret_data.wpcron === 1) { + $('#wpcron').prop('checked', true); + } + if (response.data.ret_data.passwordprotection == 1) { + var dc = ''; + var mp = $compile(dc)($scope); + angular.element(document.getElementById('prsswdprodata')).append(mp); + CheckBoxpasssword = 1; + } else { + var dc = ''; + $('#prsswdprodata').append(dc); + CheckBoxpasssword = 0; + } + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + }, function(error) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + console.error('Failed to load WP data:', error); + }); + }; + + $scope.UpdateWPSettings = function (setting) { + $scope.wordpresshomeloading = false; + $('#wordpresshomeloading').show(); + + var url = "/websites/UpdateWPSettings"; + var data; + + if (setting === "PasswordProtection") { + data = { + WPid: $('#WPid').html(), + setting: setting, + PPUsername: CheckBoxpasssword == 0 ? $scope.PPUsername : '', + PPPassword: CheckBoxpasssword == 0 ? $scope.PPPassword : '' + }; + } else { + var settingValue; + if (setting === 'searchIndex') { + $scope.searchIndex = $scope.searchIndex === 1 ? 0 : 1; + settingValue = $scope.searchIndex; + } else { + settingValue = $('#' + setting).is(":checked") ? 1 : 0; + } + data = { + WPid: $('#WPid').html(), + setting: setting, + settingValue: settingValue + }; + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(function(response) { + $scope.wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Updated!', + type: 'success' + }); + if (setting === "PasswordProtection") { + location.reload(); + } + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + // Revert the change on error + if (setting === 'searchIndex') { + $scope.searchIndex = $scope.searchIndex === 1 ? 0 : 1; + } + if (setting === "PasswordProtection") { + location.reload(); + } + } + }, function(error) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + // Revert the change on error + if (setting === 'searchIndex') { + $scope.searchIndex = $scope.searchIndex === 1 ? 0 : 1; + } + console.error('Failed to update setting:', error); + }); + }; + + $scope.GetCurrentPlugins = function () { + $('#wordpresshomeloading').show(); + + $scope.wordpresshomeloading = false; + + var url = "/websites/GetCurrentPlugins"; + + var data = { + WPid: $('#WPid').html(), + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + $('#PluginBody').html(''); + var plugins = JSON.parse(response.data.plugins); + plugins.forEach(AddPlugins); + + } else { + alert("Error:" + response.data.error_message) + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + + $scope.webSiteCreationLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + }; + + $scope.GetCurrentThemes = function () { + $('#wordpresshomeloading').show(); + + $scope.wordpresshomeloading = false; + + var url = "/websites/GetCurrentThemes"; + + var data = { + WPid: $('#WPid').html(), + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + + $('#ThemeBody').html(''); + var themes = JSON.parse(response.data.themes); + themes.forEach(AddThemes); + + } else { + alert("Error:" + response.data.error_message) + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.webSiteCreationLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + }; + + $scope.UpdatePlugins = function (plugin) { + $('#wordpresshomeloading').show(); + var data = { + plugin: plugin, + pluginarray: PluginsList, + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/UpdatePlugins"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Updating Plugins in Background!.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + + + }; + + $scope.DeletePlugins = function (plugin) { + $('#wordpresshomeloading').show(); + var data = { + plugin: plugin, + pluginarray: PluginsList, + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/DeletePlugins"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Deleting Plugin in Background!', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + + } + + $scope.ChangeStatus = function (plugin) { + $('#wordpresshomeloading').show(); + var data = { + plugin: plugin, + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/ChangeStatus"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Changed Plugin state Successfully !.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + + } + + function AddPlugins(value, index, array) { + var FinalMarkup = '' + FinalMarkup = FinalMarkup + ''; + for (let x in value) { + if (x === 'status') { + if (value[x] === 'inactive') { + FinalMarkup = FinalMarkup + '
'; + } else { + FinalMarkup = FinalMarkup + '
'; + } + } else if (x === 'update') { + if (value[x] === 'none') { + FinalMarkup = FinalMarkup + 'Upto Date'; + } else { + FinalMarkup = FinalMarkup + ''; + } + } else { + FinalMarkup = FinalMarkup + '' + value[x] + ""; + } + } + FinalMarkup = FinalMarkup + '' + FinalMarkup = FinalMarkup + '' + var temp = $compile(FinalMarkup)($scope) + AppendToTable('#PluginBody', temp) + } + + $scope.UpdateThemes = function (theme) { + $('#wordpresshomeloading').show(); + var data = { + Theme: theme, + Themearray: ThemesList, + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/UpdateThemes"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Updating Theme in background !.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + + + }; + + $scope.DeleteThemes = function (theme) { + $('#wordpresshomeloading').show(); + var data = { + Theme: theme, + Themearray: ThemesList, + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/DeleteThemes"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Deleting Theme in Background!.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + }; + + $scope.ChangeStatusThemes = function (theme) { + $('#wordpresshomeloading').show(); + var data = { + theme: theme, + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/StatusThemes"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Change Theme state in Bsckground!.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + + }; + + function AddThemes(value, index, array) { + var FinalMarkup = '' + FinalMarkup = FinalMarkup + ''; + for (let x in value) { + if (x === 'status') { + if (value[x] === 'inactive') { + FinalMarkup = FinalMarkup + '
'; + } else { + FinalMarkup = FinalMarkup + '
'; + } + } else if (x === 'update') { + if (value[x] === 'none') { + FinalMarkup = FinalMarkup + 'Upto Date'; + } else { + FinalMarkup = FinalMarkup + ''; + } + } else { + FinalMarkup = FinalMarkup + '' + value[x] + ""; + } + } + FinalMarkup = FinalMarkup + '' + FinalMarkup = FinalMarkup + '' + var temp = $compile(FinalMarkup)($scope) + AppendToTable('#ThemeBody', temp) + } + + $scope.CreateStagingNow = function () { + $('#wordpresshomeloading').show(); + + $scope.wordpresshomeloading = false; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + + + $scope.currentStatus = "Starting creation Staging.."; + + //here enter domain name + if (create_staging_domain_check == 0) { + var Part2_domainNameCreate = document.getElementById('Part2_domainNameCreate').value; + var domainNameCreate = document.getElementById('TestDomainNameCreate').value + Part2_domainNameCreate; + } + if (create_staging_domain_check == 1) { + + var domainNameCreate = $scope.own_domainNameCreate; + } + var data = { + StagingName: $('#stagingName').val(), + StagingDomain: domainNameCreate, + WPid: $('#WPid').html(), + } + var url = "/websites/CreateStagingNow"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + if (response.data.status === 1) { + statusFile = response.data.tempStatusPath; + getCreationStatus(); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + }; + + function getCreationStatus() { + $('#wordpresshomeloading').show(); + + 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) { + //$('#wordpresshomeloading').hide(); + + if (response.data.abort === 1) { + if (response.data.installStatus === 1) { + + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = false; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + + $("#installProgress").css("width", "100%"); + $("#installProgressbackup").css("width", "100%"); + $scope.installPercentage = "100"; + $scope.currentStatus = response.data.currentStatus; + $timeout.cancel(); + + + } else { + + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = 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%"); + $("#installProgressbackup").css("width", "0%"); + $scope.installPercentage = "0"; + $scope.goBackDisable = false; + + + } + + } else { + + $("#installProgress").css("width", response.data.installationProgress + "%"); + $("#installProgressbackup").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + $timeout(getCreationStatus, 1000); + + } + + } + + function cantLoadInitialDatas(response) { + //$('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + } + + $scope.goBack = function () { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = false; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $("#installProgress").css("width", "0%"); + }; + + $scope.fetchstaging = function () { + + $('#wordpresshomeloading').show(); + $scope.wordpresshomeloading = false; + + var url = "/websites/fetchstaging"; + + var data = { + WPid: $('#WPid').html(), + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + + // $('#ThemeBody').html(''); + // var themes = JSON.parse(response.data.themes); + // themes.forEach(AddThemes); + + $('#StagingBody').html(''); + var staging = JSON.parse(response.data.wpsites); + staging.forEach(AddStagings); + + } else { + alert("Error data.error_message:" + response.data.error_message) + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + alert("Error" + response) + + } + + }; + + $scope.fetchDatabase = function () { + + $('#wordpresshomeloading').show(); + $scope.wordpresshomeloading = false; + + var url = "/websites/fetchDatabase"; + + var data = { + WPid: $('#WPid').html(), + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + $('#DB_Name').html(response.data.DataBaseName); + $('#DB_User').html(response.data.DataBaseUser); + $('#tableprefix').html(response.data.tableprefix); + } else { + alert("Error data.error_message:" + response.data.error_message) + + } + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + alert("Error" + response) + + } + + }; + + $scope.SaveUpdateConfig = function () { + $('#wordpresshomeloading').show(); + var data = { + AutomaticUpdates: $('#AutomaticUpdates').find(":selected").text(), + Plugins: $('#Plugins').find(":selected").text(), + Themes: $('#Themes').find(":selected").text(), + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/SaveUpdateConfig"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Update Configurations Sucessfully!.', + type: 'success' + }); + $("#autoUpdateConfig").modal('hide'); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + new PNotify({ + title: 'Operation Failed!', + text: response, + type: 'error' + }); + + } + }; + + function AddStagings(value, index, array) { + var FinalMarkup = '' + for (let x in value) { + if (x === 'name') { + FinalMarkup = FinalMarkup + '' + value[x] + ''; + } else if (x !== 'url' && x !== 'deleteURL' && x !== 'id') { + FinalMarkup = FinalMarkup + '' + value[x] + ""; + } + } + FinalMarkup = FinalMarkup + '' + + ' ' + FinalMarkup = FinalMarkup + '' + AppendToTable('#StagingBody', FinalMarkup); + } + + $scope.FinalDeployToProduction = function () { + + $('#wordpresshomeloading').show(); + + $scope.wordpresshomeloading = false; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + + var data = { + WPid: $('#WPid').html(), + StagingID: DeploytoProductionID + } + + var url = "/websites/DeploytoProduction"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + + $('#wordpresshomeloading').hide(); + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Deploy To Production start!.', + type: 'success' + }); + statusFile = response.data.tempStatusPath; + getCreationStatus(); + + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + new PNotify({ + title: 'Operation Failed!', + text: response, + type: 'error' + }); + + } + + }; + + + $scope.CreateBackup = function () { + $('#wordpresshomeloading').show(); + + $scope.wordpresshomeloading = false; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $scope.currentStatus = "Starting creation Backups.."; + var data = { + WPid: $('#WPid').html(), + Backuptype: $('#backuptype').val() + } + var url = "/websites/WPCreateBackup"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $('createbackupbutton').hide(); + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Creating Backups!.', + type: 'success' + }); + statusFile = response.data.tempStatusPath; + getCreationStatus(); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + alert(response) + + } + + }; + + + $scope.installwpcore = function () { + + $('#wordpresshomeloading').show(); + $('#wordpresshomeloadingsec').show(); + var data = { + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/installwpcore"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $('#wordpresshomeloadingsec').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Results fetched..', + type: 'success' + }); + $('#SecurityResult').html(response.data.result); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $('#wordpresshomeloadingsec').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + + }; + + $scope.dataintegrity = function () { + + $('#wordpresshomeloading').show(); + $('#wordpresshomeloadingsec').show(); + var data = { + WPid: $('#WPid').html(), + } + + $scope.wordpresshomeloading = false; + + var url = "/websites/dataintegrity"; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $('#wordpresshomeloadingsec').hide(); + $scope.wordpresshomeloading = true; + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Results fetched', + type: 'success' + }); + $('#SecurityResult').html(response.data.result); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $('#wordpresshomeloadingsec').hide(); + $scope.wordpresshomeloading = true; + alert(response) + + } + }; + + $scope.updateSetting = function(site, setting) { + var settingMap = { + 'search-indexing': 'searchIndex', + 'debugging': 'debugging', + 'password-protection': 'passwordProtection', + 'maintenance-mode': 'maintenanceMode' + }; + + // Toggle the state before sending request + site[settingMap[setting]] = site[settingMap[setting]] === 1 ? 0 : 1; + + var data = { + siteId: site.id, + setting: setting, + value: site[settingMap[setting]] + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post('/websites/UpdateWPSettings', data, config).then(function(response) { + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Setting updated successfully.', + type: 'success' + }); + if (setting === 'password-protection' && site[settingMap[setting]] === 1) { + // Show password protection modal if enabling + site.PPUsername = ""; + site.PPPassword = ""; + $scope.currentWP = site; + $('#passwordProtectionModal').modal('show'); + } + } else { + // Revert the change if update failed + site[settingMap[setting]] = site[settingMap[setting]] === 1 ? 0 : 1; + new PNotify({ + title: 'Error', + text: response.data.error_message || 'Failed to update setting.', + type: 'error' + }); + } + }).catch(function(error) { + // Revert the change on error + site[settingMap[setting]] = site[settingMap[setting]] === 1 ? 0 : 1; + new PNotify({ + title: 'Error', + text: 'Connection failed while updating setting.', + type: 'error' + }); + }); + }; + + $scope.submitPasswordProtection = function() { + console.log('submitPasswordProtection called'); + console.log('Current WP:', $scope.currentWP); + + if (!$scope.currentWP) { + console.error('No WordPress site selected'); + new PNotify({ + title: 'Error!', + text: 'No WordPress site selected.', + type: 'error' + }); + return; + } + + if (!$scope.currentWP.PPUsername || !$scope.currentWP.PPPassword) { + console.error('Missing username or password'); + new PNotify({ + title: 'Error!', + text: 'Please provide both username and password', + type: 'error' + }); + return; + } + + var data = { + siteId: $scope.currentWP.id, + setting: 'password-protection', + value: 1, + username: $scope.currentWP.PPUsername, + password: $scope.currentWP.PPPassword + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + console.log('Sending request with data:', data); + $('#passwordProtectionModal').modal('hide'); + + $http.post('/websites/UpdateWPSettings', data, config).then(function(response) { + console.log('Received response:', response); + if (response.data.status) { + new PNotify({ + title: 'Success!', + text: 'Password protection enabled successfully!', + type: 'success' + }); + } else { + $scope.currentWP.passwordProtection = false; + new PNotify({ + title: 'Error!', + text: response.data.error_message || 'Failed to enable password protection', + type: 'error' + }); + } + }).catch(function(error) { + console.error('Request failed:', error); + $scope.currentWP.passwordProtection = false; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server', + type: 'error' + }); + }); + }; + +}); + + +var PluginsList = []; + + +function AddPluginToArray(cBox, name) { + if (cBox.checked) { + PluginsList.push(name); + // alert(PluginsList); + } else { + const index = PluginsList.indexOf(name); + if (index > -1) { + PluginsList.splice(index, 1); + } + // alert(PluginsList); + } +} + +var ThemesList = []; + +function AddThemeToArray(cBox, name) { + if (cBox.checked) { + ThemesList.push(name); + // alert(ThemesList); + } else { + const index = ThemesList.indexOf(name); + if (index > -1) { + ThemesList.splice(index, 1); + } + // alert(ThemesList); + } +} + + +function AppendToTable(table, markup) { + $(table).append(markup); +} + + +//..................Restore Backup Home + + +app.controller('RestoreWPBackup', function ($scope, $http, $timeout, $window) { + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = false; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + + + $scope.checkmethode = function () { + var val = $('#RestoreMethode').children("option:selected").val(); + if (val == 1) { + $('#Newsitediv').show(); + $('#exinstingsitediv').hide(); + } else if (val == 0) { + $('#exinstingsitediv').show(); + $('#Newsitediv').hide(); + } else { + + } + }; + + + $scope.RestoreWPbackupNow = function () { + $('#wordpresshomeloading').show(); + $scope.wordpresshomeloading = false; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $scope.currentStatus = "Start Restoring WordPress.."; + + var Domain = $('#wprestoresubdirdomain').val() + var path = $('#wprestoresubdirpath').val(); + var home = "1"; + + if (typeof path != 'undefined' || path != '') { + home = "0"; + } + if (typeof path == 'undefined') { + path = ""; + } + + + var backuptype = $('#backuptype').html(); + var data; + if (backuptype == "DataBase Backup") { + data = { + backupid: $('#backupid').html(), + DesSite: $('#DesSite').children("option:selected").val(), + Domain: '', + path: path, + home: home, + } + } else { + data = { + backupid: $('#backupid').html(), + DesSite: $('#DesSite').children("option:selected").val(), + Domain: Domain, + path: path, + home: home, + } + + } + + var url = "/websites/RestoreWPbackupNow"; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + // console.log(data) + + var d = $('#DesSite').children("option:selected").val(); + var c = $("input[name=Newdomain]").val(); + // if (d == -1 || c == "") { + // alert("Please Select Method of Backup Restore"); + // } else { + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + // } + + + function ListInitialDatas(response) { + wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Restoring process starts!.', + type: 'success' + }); + statusFile = response.data.tempStatusPath; + getCreationStatus(); + + } else { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = 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; + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + } + + function getCreationStatus() { + $('#wordpresshomeloading').show(); + + 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) { + //$('#wordpresshomeloading').hide(); + + if (response.data.abort === 1) { + + if (response.data.installStatus === 1) { + + + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = false; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + + $("#installProgress").css("width", "100%"); + $("#installProgressbackup").css("width", "100%"); + $scope.installPercentage = "100"; + $scope.currentStatus = response.data.currentStatus; + $timeout.cancel(); + + + } else { + + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = 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%"); + $("#installProgressbackup").css("width", "0%"); + $scope.installPercentage = "0"; + $scope.goBackDisable = false; + + + } + + } else { + + $("#installProgress").css("width", response.data.installationProgress + "%"); + $("#installProgressbackup").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + $timeout(getCreationStatus, 1000); + + } + + } + + function cantLoadInitialDatas(response) { + //$('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + } + + $scope.goBack = function () { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = false; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $("#installProgress").css("width", "0%"); + }; +}); + + +//.......................................Remote Backup + +//........... delete DeleteBackupConfigNow + +function DeleteBackupConfigNow(url) { + window.location.href = url; +} + +function DeleteRemoteBackupsiteNow(url) { + window.location.href = url; +} + +function DeleteBackupfileConfigNow(url) { + window.location.href = url; +} + + +app.controller('RemoteBackupConfig', function ($scope, $http, $timeout, $window) { + $scope.RemoteBackupLoading = true; + $scope.SFTPBackUpdiv = true; + + $scope.EndpointURLdiv = true; + $scope.Selectprovider = true; + $scope.S3keyNamediv = true; + $scope.Accesskeydiv = true; + $scope.SecretKeydiv = true; + $scope.SelectRemoteBackuptype = function () { + var val = $scope.RemoteBackuptype; + if (val == "SFTP") { + $scope.SFTPBackUpdiv = false; + $scope.EndpointURLdiv = true; + $scope.Selectprovider = true; + $scope.S3keyNamediv = true; + $scope.Accesskeydiv = true; + $scope.SecretKeydiv = true; + } else if (val == "S3") { + $scope.EndpointURLdiv = true; + $scope.Selectprovider = false; + $scope.S3keyNamediv = false; + $scope.Accesskeydiv = false; + $scope.SecretKeydiv = false; + $scope.SFTPBackUpdiv = true; + } else { + $scope.RemoteBackupLoading = true; + $scope.SFTPBackUpdiv = true; + + $scope.EndpointURLdiv = true; + $scope.Selectprovider = true; + $scope.S3keyNamediv = true; + $scope.Accesskeydiv = true; + $scope.SecretKeydiv = true; + } + } + + $scope.SelectProvidertype = function () { + $scope.EndpointURLdiv = true; + var provider = $scope.Providervalue + if (provider == 'Backblaze') { + $scope.EndpointURLdiv = false; + } else { + $scope.EndpointURLdiv = true; + } + } + + $scope.SaveBackupConfig = function () { + $scope.RemoteBackupLoading = false; + var Hname = $scope.Hostname; + var Uname = $scope.Username; + var Passwd = $scope.Password; + var path = $scope.path; + var type = $scope.RemoteBackuptype; + var Providervalue = $scope.Providervalue; + var data; + if (type == "SFTP") { + + data = { + Hname: Hname, + Uname: Uname, + Passwd: Passwd, + path: path, + type: type + } + } else if (type == "S3") { + if (Providervalue == "Backblaze") { + data = { + S3keyname: $scope.S3keyName, + Provider: Providervalue, + AccessKey: $scope.Accesskey, + SecertKey: $scope.SecretKey, + EndUrl: $scope.EndpointURL, + type: type + } + } else { + data = { + S3keyname: $scope.S3keyName, + Provider: Providervalue, + AccessKey: $scope.Accesskey, + SecertKey: $scope.SecretKey, + type: type + } + + } + + } + var url = "/websites/SaveBackupConfig"; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.RemoteBackupLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Saved!.', + type: 'success' + }); + location.reload(); + + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.RemoteBackupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + + + } + +}); + +var UpdatescheduleID; +app.controller('BackupSchedule', function ($scope, $http, $timeout, $window) { + $scope.BackupScheduleLoading = true; + $scope.SaveBackupSchedule = function () { + $scope.RemoteBackupLoading = false; + var FileRetention = $scope.Fretention; + var Backfrequency = $scope.Bfrequency; + + + var data = { + FileRetention: FileRetention, + Backfrequency: Backfrequency, + ScheduleName: $scope.ScheduleName, + RemoteConfigID: $('#RemoteConfigID').html(), + BackupType: $scope.BackupType + } + var url = "/websites/SaveBackupSchedule"; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.RemoteBackupLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Saved!.', + type: 'success' + }); + location.reload(); + + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.RemoteBackupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + + + }; + + + $scope.getupdateid = function (ID) { + UpdatescheduleID = ID; + } + + $scope.UpdateRemoteschedules = function () { + $scope.RemoteBackupLoading = false; + var Frequency = $scope.RemoteFrequency; + var fretention = $scope.RemoteFileretention; + + var data = { + ScheduleID: UpdatescheduleID, + Frequency: Frequency, + FileRetention: fretention + } + var url = "/websites/UpdateRemoteschedules"; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.RemoteBackupLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Updated!.', + type: 'success' + }); + location.reload(); + + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.RemoteBackupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + }; + + $scope.AddWPsiteforRemoteBackup = function () { + $scope.RemoteBackupLoading = false; + + + var data = { + WpsiteID: $('#Wpsite').val(), + RemoteScheduleID: $('#RemoteScheduleID').html() + } + var url = "/websites/AddWPsiteforRemoteBackup"; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.RemoteBackupLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Successfully Saved!.', + type: 'success' + }); + location.reload(); + + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.RemoteBackupLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + + + }; +}); +/* Java script code to create account */ + +var website_create_domain_check = 0; + +function website_create_checkbox_function() { + + var checkBox = document.getElementById("myCheck"); + // Get the output text + + + // If the checkbox is checked, display the output text + if (checkBox.checked == true) { + website_create_domain_check = 0; + document.getElementById('Website_Create_Test_Domain').style.display = "block"; + document.getElementById('Website_Create_Own_Domain').style.display = "none"; + + } else { + document.getElementById('Website_Create_Test_Domain').style.display = "none"; + document.getElementById('Website_Create_Own_Domain').style.display = "block"; + website_create_domain_check = 1; + } + + // alert(domain_check); +} + + +/* Java script code to create account ends here */ + +/* Java script code to list accounts */ + +$("#listFail").hide(); + + +app.controller('listWebsites', function ($scope, $http, $window) { + $scope.web = {}; + $scope.WebSitesList = []; + $scope.loading = true; // Add loading state + + $scope.currentPage = 1; + $scope.recordsToShow = 10; + + // Initial fetch of websites + $scope.getFurtherWebsitesFromDB = function () { + $scope.loading = true; // Set loading to true when starting fetch + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + page: $scope.currentPage, + recordsToShow: $scope.recordsToShow + }; + + var dataurl = "/websites/fetchWebsitesList"; + + $http.post(dataurl, data, config).then(function(response) { + if (response.data.listWebSiteStatus === 1) { + $scope.WebSitesList = JSON.parse(response.data.data); + $scope.pagination = response.data.pagination; + $("#listFail").hide(); + } else { + $("#listFail").fadeIn(); + $scope.errorMessage = response.data.error_message; + } + $scope.loading = false; // Set loading to false when done + }).catch(function(error) { + $("#listFail").fadeIn(); + $scope.errorMessage = error.message || 'An error occurred while fetching websites'; + $scope.loading = false; // Set loading to false on error + }); + }; + + // Call it immediately + $scope.getFurtherWebsitesFromDB(); + + $scope.showWPSites = function(domain) { + console.log('showWPSites called for domain:', domain); + + // Make sure domain is defined + if (!domain) { + console.error('Domain is undefined'); + return; + } + + // Find the website in the list + var site = $scope.WebSitesList.find(function(website) { + return website.domain === domain; + }); + + if (!site) { + console.error('Website not found:', domain); + return; + } + + // Set loading state + site.loadingWPSites = true; + + // Toggle visibility + site.showWPSites = !site.showWPSites; + + // If we're hiding, just return + if (!site.showWPSites) { + site.loadingWPSites = false; + return; + } + + var config = { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = $.param({ + domain: domain + }); + + $http.post('/websites/fetchWPDetails', data, config) + .then(function(response) { + console.log('Response received:', response); + if (response.data.status === 1 && response.data.fetchStatus === 1) { + site.wp_sites = response.data.sites || []; + // Initialize loading states for each WP site + site.wp_sites.forEach(function(wp) { + wp.loading = false; + wp.loadingPlugins = false; + wp.loadingTheme = false; + }); + $("#listFail").hide(); + } else { + $("#listFail").fadeIn(); + site.showWPSites = false; + $scope.errorMessage = response.data.error_message || 'Failed to fetch WordPress sites'; + console.error('Error in response:', response.data.error_message); + new PNotify({ + title: 'Error!', + text: response.data.error_message || 'Failed to fetch WordPress sites', + type: 'error' + }); + } + }) + .catch(function(error) { + console.error('Request failed:', error); + site.showWPSites = false; + $("#listFail").fadeIn(); + $scope.errorMessage = error.message || 'An error occurred while fetching WordPress sites'; + new PNotify({ + title: 'Error!', + text: error.message || 'Could not connect to server', + type: 'error' + }); + }) + .finally(function() { + site.loadingWPSites = false; + }); + }; + + $scope.visitSite = function(wp) { + var url = wp.url || wp.domain; + if (!url) return; + if (!url.startsWith('http://') && !url.startsWith('https://')) { + url = 'https://' + url; + } + window.open(url, '_blank'); + }; + + $scope.wpLogin = function(wpId) { + window.open('/websites/wpLogin?wpID=' + wpId, '_blank'); + }; + + $scope.manageWP = function(wpId) { + window.location.href = '/websites/WPHome?ID=' + wpId; + }; + + $scope.updateSetting = function(wp, setting) { + var settingMap = { + 'search-indexing': 'searchIndex', + 'debugging': 'debugging', + 'password-protection': 'passwordProtection', + 'maintenance-mode': 'maintenanceMode' + }; + + // Toggle the state before sending request + wp[settingMap[setting]] = wp[settingMap[setting]] === 1 ? 0 : 1; + + var data = { + siteId: wp.id, + setting: setting, + value: wp[settingMap[setting]] + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post('/websites/UpdateWPSettings', data, config).then(function(response) { + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Setting updated successfully.', + type: 'success' + }); + if (setting === 'password-protection' && wp[settingMap[setting]] === 1) { + // Show password protection modal if enabling + wp.PPUsername = ""; + wp.PPPassword = ""; + $scope.currentWP = wp; + $('#passwordProtectionModal').modal('show'); + } + } else { + // Revert the change if update failed + wp[settingMap[setting]] = wp[settingMap[setting]] === 1 ? 0 : 1; + new PNotify({ + title: 'Error', + text: response.data.error_message || 'Failed to update setting.', + type: 'error' + }); + } + }).catch(function(error) { + // Revert the change on error + wp[settingMap[setting]] = wp[settingMap[setting]] === 1 ? 0 : 1; + new PNotify({ + title: 'Error', + text: 'Connection failed while updating setting.', + type: 'error' + }); + }); + }; + + $scope.cyberPanelLoading = true; + + $scope.issueSSL = function (virtualHost) { + $scope.cyberPanelLoading = false; + + var url = "/manageSSL/issueSSL"; + + + var data = { + virtualHost: virtualHost + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberPanelLoading = true; + if (response.data.SSL === 1) { + new PNotify({ + title: 'Success!', + text: 'SSL successfully issued.', + 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.cyberPanelLoading = true; + + $scope.searchWebsites = function () { + $scope.loading = true; // Set loading to true when starting search + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + patternAdded: $scope.patternAdded + }; + + dataurl = "/websites/searchWebsites"; + + $http.post(dataurl, data, config).then(function(response) { + if (response.data.listWebSiteStatus === 1) { + var finalData = JSON.parse(response.data.data); + $scope.WebSitesList = finalData; + $("#listFail").hide(); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + $scope.loading = false; // Set loading to false when done + }).catch(function(error) { + new PNotify({ + title: 'Operation Failed!', + text: 'Connect disrupted, refresh the page.', + type: 'error' + }); + $scope.loading = false; // Set loading to false on error + }); + }; + $scope.ScanWordpressSite = function () { $('#cyberPanelLoading').show(); @@ -2936,6 +9336,136 @@ app.controller('listWebsites', function ($scope, $http, $window) { }; + $scope.deleteWPSite = function(wp) { + if (confirm('Are you sure you want to delete this WordPress site? This action cannot be undone.')) { + window.location.href = '/websites/ListWPSites?DeleteID=' + wp.id; + } + }; + + $scope.togglePasswordProtection = function(wp) { + console.log('togglePasswordProtection called for:', wp); + console.log('Current password protection state:', wp.passwordProtection); + + if (wp.passwordProtection) { + // Show modal for credentials + console.log('Showing modal for credentials'); + wp.PPUsername = ""; + wp.PPPassword = ""; + $scope.currentWP = wp; + console.log('Current WP set to:', $scope.currentWP); + $('#passwordProtectionModal').modal('show'); + } else { + // Disable password protection + console.log('Disabling password protection'); + var data = { + siteId: wp.id, + setting: 'password-protection', + value: 0 + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + console.log('Sending request with data:', data); + $http.post('/websites/UpdateWPSettings', data, config).then(function(response) { + console.log('Received response:', response); + if (!response.data.status) { + wp.passwordProtection = !wp.passwordProtection; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message || 'Failed to disable password protection', + type: 'error' + }); + } else { + new PNotify({ + title: 'Success!', + text: 'Password protection disabled successfully.', + type: 'success' + }); + } + }).catch(function(error) { + console.error('Request failed:', error); + wp.passwordProtection = !wp.passwordProtection; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server.', + type: 'error' + }); + }); + } + }; + + $scope.submitPasswordProtection = function() { + console.log('submitPasswordProtection called'); + console.log('Current WP:', $scope.currentWP); + + if (!$scope.currentWP) { + console.error('No WordPress site selected'); + new PNotify({ + title: 'Error!', + text: 'No WordPress site selected.', + type: 'error' + }); + return; + } + + if (!$scope.currentWP.PPUsername || !$scope.currentWP.PPPassword) { + console.error('Missing username or password'); + new PNotify({ + title: 'Error!', + text: 'Please provide both username and password', + type: 'error' + }); + return; + } + + var data = { + siteId: $scope.currentWP.id, + setting: 'password-protection', + value: 1, + username: $scope.currentWP.PPUsername, + password: $scope.currentWP.PPPassword + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + console.log('Sending request with data:', data); + $('#passwordProtectionModal').modal('hide'); + + $http.post('/websites/UpdateWPSettings', data, config).then(function(response) { + console.log('Received response:', response); + if (response.data.status) { + new PNotify({ + title: 'Success!', + text: 'Password protection enabled successfully!', + type: 'success' + }); + } else { + $scope.currentWP.passwordProtection = false; + new PNotify({ + title: 'Error!', + text: response.data.error_message || 'Failed to enable password protection', + type: 'error' + }); + } + }).catch(function(error) { + console.error('Request failed:', error); + $scope.currentWP.passwordProtection = false; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server', + type: 'error' + }); + }); + }; + }); app.controller('listChildDomainsMain', function ($scope, $http, $timeout) { @@ -5307,5520 +11837,7 @@ app.controller('websitePages', function ($scope, $http, $timeout, $window) { $scope.operationFailed = false; $scope.operationSuccessfull = true; $scope.couldNotConnect = true; - $scope.openBaseDirBox = false; - - $scope.errorMessage = response.data.error_message; - - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.baseDirLoading = true; - $scope.operationFailed = true; - $scope.operationSuccessfull = true; - $scope.couldNotConnect = false; - $scope.openBaseDirBox = false; - - - } - - } - - - // REWRITE Template - - const httpToHTTPS = `### Rewrite Rules Added by CyberPanel Rewrite Rule Generator - -RewriteEngine On -RewriteCond %{HTTPS} !=on -RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] - -### End CyberPanel Generated Rules. - -`; - - const WWWToNonWWW = `### Rewrite Rules Added by CyberPanel Rewrite Rule Generator - -RewriteEngine On -RewriteCond %{HTTP_HOST} ^www\.(.*)$ -RewriteRule ^(.*)$ http://%1/$1 [L,R=301] - -### End CyberPanel Generated Rules. - -`; - - const nonWWWToWWW = `### Rewrite Rules Added by CyberPanel Rewrite Rule Generator - -RewriteEngine On -RewriteCond %{HTTP_HOST} !^www\. [NC] -RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] - -### End CyberPanel Generated Rules. - -`; - - const WordpressProtect = `### Rewrite Rules Added by CyberPanel Rewrite Rule Generator - -RewriteEngine On -RewriteRule ^/(xmlrpc|wp-trackback)\.php - [F,L,NC] - -### End CyberPanel Generated Rules. - -`; - - $scope.applyRewriteTemplate = function () { - - if ($scope.rewriteTemplate === "Force HTTP -> HTTPS") { - $scope.rewriteRules = httpToHTTPS + $scope.rewriteRules; - } else if ($scope.rewriteTemplate === "Force NON-WWW -> WWW") { - $scope.rewriteRules = nonWWWToWWW + $scope.rewriteRules; - } else if ($scope.rewriteTemplate === "Force WWW -> NON-WWW") { - $scope.rewriteRules = WWWToNonWWW + $scope.rewriteRules; - } else if ($scope.rewriteTemplate === "Disable Wordpress XMLRPC & Trackback") { - $scope.rewriteRules = WordpressProtect + $scope.rewriteRules; - } - }; - - -}); - -/* Java script code to create account ends here */ - -/* Java script code to suspend/un-suspend Website */ - -app.controller('suspendWebsiteControl', function ($scope, $http) { - - $scope.suspendLoading = true; - $scope.stateView = true; - - $scope.websiteSuspendFailure = true; - $scope.websiteUnsuspendFailure = true; - $scope.websiteSuccess = true; - $scope.couldNotConnect = true; - - $scope.showSuspendUnsuspend = function () { - - $scope.stateView = false; - - - }; - - $scope.save = function () { - - $scope.suspendLoading = false; - - var websiteName = $scope.websiteToBeSuspended - var state = $scope.state; - - - url = "/websites/submitWebsiteStatus"; - - var data = { - websiteName: websiteName, - state: state, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.websiteStatus === 1) { - if (state == "Suspend") { - - $scope.suspendLoading = true; - $scope.stateView = false; - - $scope.websiteSuspendFailure = true; - $scope.websiteUnsuspendFailure = true; - $scope.websiteSuccess = false; - $scope.couldNotConnect = true; - - $scope.websiteStatus = websiteName; - $scope.finalStatus = "Suspended"; - - } else { - $scope.suspendLoading = true; - $scope.stateView = false; - - $scope.websiteSuspendFailure = true; - $scope.websiteUnsuspendFailure = true; - $scope.websiteSuccess = false; - $scope.couldNotConnect = true; - - $scope.websiteStatus = websiteName; - $scope.finalStatus = "Un-suspended"; - - } - - } else { - - if (state == "Suspend") { - - $scope.suspendLoading = true; - $scope.stateView = false; - - $scope.websiteSuspendFailure = false; - $scope.websiteUnsuspendFailure = true; - $scope.websiteSuccess = true; - $scope.couldNotConnect = true; - - - } else { - $scope.suspendLoading = true; - $scope.stateView = false; - - $scope.websiteSuspendFailure = true; - $scope.websiteUnsuspendFailure = false; - $scope.websiteSuccess = true; - $scope.couldNotConnect = true; - - - } - - - $scope.errorMessage = response.data.error_message; - - } - - - } - - function cantLoadInitialDatas(response) { - $scope.couldNotConnect = false; - $scope.suspendLoading = true; - $scope.stateView = true; - - $scope.websiteSuspendFailure = true; - $scope.websiteUnsuspendFailure = true; - $scope.websiteSuccess = true; - - } - - - }; - -}); - -/** - * Created by usman on 7/26/17. - */ -function getCookie(name) { - var cookieValue = null; - var t = document.cookie; - if (document.cookie && document.cookie !== '') { - var cookies = document.cookie.split(';'); - for (var i = 0; i < cookies.length; i++) { - var cookie = jQuery.trim(cookies[i]); - // Does this cookie string begin with the name we want? - if (cookie.substring(0, name.length + 1) === (name + '=')) { - cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); - break; - } - } - } - return cookieValue; -} - - -var arry = [] - -function selectpluginJs(val) { - $('#mysearch').hide() - arry.push(val) - - // console.log(arry) - document.getElementById('selJS').innerHTML = ""; - - for (var i = 0; i < arry.length; i++) { - $('#selJS').show() - var mlm = ' ' + arry[i] + '    ' - $('#selJS').append(mlm) - } - - -} - - -var DeletePluginURL; - -function DeletePluginBuucket(url) { - DeletePluginURL = url; -} - -function FinalDeletePluginBuucket() { - window.location.href = DeletePluginURL; -} - -var SPVal; - -app.controller('WPAddNewPlugin', function ($scope, $http, $timeout, $window, $compile) { - $scope.webSiteCreationLoading = true; - - $scope.SearchPluginName = function (val) { - $scope.webSiteCreationLoading = false; - SPVal = val; - url = "/websites/SearchOnkeyupPlugin"; - - var searchcontent = $scope.searchcontent; - - - var data = { - pluginname: searchcontent - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $scope.webSiteCreationLoading = true; - - if (response.data.status === 1) { - if (SPVal == 'add') { - $('#mysearch').show() - document.getElementById('mysearch').innerHTML = ""; - var res = response.data.plugns.plugins - // console.log(res); - for (i = 0; i <= res.length; i++) { - // - var tml = '
'; - $('#mysearch').append(tml); - } - } else if (SPVal == 'eidt') { - $('#mysearch').show() - document.getElementById('mysearch').innerHTML = ""; - var res = response.data.plugns.plugins - // console.log(res); - for (i = 0; i <= res.length; i++) { - // - var tml = '
'; - var temp = $compile(tml)($scope) - angular.element(document.getElementById('mysearch')).append(temp); - } - - } - - - } else { - - // $scope.errorMessage = response.data.error_message; - alert("Status not = 1: Error..." + response.data.error_message) - } - - - } - - function cantLoadInitialDatas(response) { - - alert("Error..." + response) - - } - } - - $scope.AddNewplugin = function () { - - url = "/websites/AddNewpluginAjax"; - - var bucketname = $scope.PluginbucketName - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - var data = { - config: arry, - Name: bucketname - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - function ListInitialDatas(response) { - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Bucket created.', - type: 'success' - }); - location.reload(); - } else { - - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type: 'error' - }); - } - - - } - - function cantLoadInitialDatas(response) { - - alert("Error..." + response) - - } - } - - $scope.deletesPlgin = function (val) { - - url = "/websites/deletesPlgin"; - - - var data = { - pluginname: val, - pluginbBucketID: $('#pluginbID').html() - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.status === 1) { - location.reload(); - - } else { - - // $scope.errorMessage = response.data.error_message; - alert("Status not = 1: Error..." + response.data.error_message) - } - - - } - - function cantLoadInitialDatas(response) { - - alert("Error..." + response) - - } - - } - - $scope.Addplugin = function (slug) { - $('#mysearch').hide() - - url = "/websites/Addplugineidt"; - - - var data = { - pluginname: slug, - pluginbBucketID: $('#pluginbID').html() - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.status === 1) { - location.reload(); - - } else { - - // $scope.errorMessage = response.data.error_message; - alert("Status not = 1: Error..." + response.data.error_message) - } - - - } - - function cantLoadInitialDatas(response) { - - alert("Error..." + response) - - } - - - } - -}); - -var domain_check = 0; - -function checkbox_function() { - - var checkBox = document.getElementById("myCheck"); - // Get the output text - - - // If the checkbox is checked, display the output text - if (checkBox.checked == true) { - domain_check = 0; - document.getElementById('Test_Domain').style.display = "block"; - document.getElementById('Own_Domain').style.display = "none"; - - } else { - document.getElementById('Test_Domain').style.display = "none"; - document.getElementById('Own_Domain').style.display = "block"; - domain_check = 1; - } - - // alert(domain_check); -} - -app.controller('createWordpress', function ($scope, $http, $timeout, $compile, $window) { - $scope.webSiteCreationLoading = true; - $scope.installationDetailsForm = false; - $scope.installationProgress = true; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - - - var statusFile; - - $scope.createWordPresssite = function () { - - $scope.webSiteCreationLoading = false; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - - - $scope.currentStatus = "Starting creation.."; - - var apacheBackend = 0; - - if ($scope.apacheBackend === true) { - apacheBackend = 1; - } else { - apacheBackend = 0 - } - - var package = $scope.packageForWebsite; - var websiteOwner = $scope.websiteOwner; - var WPtitle = $scope.WPtitle; - - // if (domain_check == 0) { - // var Part2_domainNameCreate = document.getElementById('Part2_domainNameCreate').value; - // var domainNameCreate = document.getElementById('TestDomainNameCreate').value + Part2_domainNameCreate; - // } - // if (domain_check == 1) { - // - // var domainNameCreate = $scope.own_domainNameCreate; - // } - - var domainNameCreate = $scope.domainNameCreate; - - - var WPUsername = $scope.WPUsername; - var adminEmail = $scope.adminEmail; - var WPPassword = $scope.WPPassword; - var WPVersions = $scope.WPVersions; - var pluginbucket = $scope.pluginbucket; - var autoupdates = $scope.autoupdates; - var pluginupdates = $scope.pluginupdates; - var themeupdates = $scope.themeupdates; - - if (domain_check == 0) { - - var path = ""; - - } - if (domain_check = 1) { - - var path = $scope.installPath; - - } - - - var home = "1"; - - if (typeof path != 'undefined') { - home = "0"; - } - - //alert(domainNameCreate); - var data = { - - title: WPtitle, - domain: domainNameCreate, - WPVersion: WPVersions, - pluginbucket: pluginbucket, - adminUser: WPUsername, - Email: adminEmail, - PasswordByPass: WPPassword, - AutomaticUpdates: autoupdates, - Plugins: pluginupdates, - Themes: themeupdates, - websiteOwner: websiteOwner, - package: package, - home: home, - path: path, - apacheBackend: apacheBackend - } - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - var url = "/websites/submitWorpressCreation"; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $scope.webSiteCreationLoading = 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.webSiteCreationLoading = 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.webSiteCreationLoading = 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.webSiteCreationLoading = false; - $("#installProgress").css("width", response.data.installationProgress + "%"); - $scope.installPercentage = response.data.installationProgress; - $scope.currentStatus = response.data.currentStatus; - $timeout(getCreationStatus, 1000); - } - - } - - function cantLoadInitialDatas(response) { - - $scope.webSiteCreationLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = false; - $scope.goBackDisable = false; - - } - - - } - - -}); - - -//........... delete wp list -var FurlDeleteWP; - -function DeleteWPNow(url) { - FurlDeleteWP = url; -} - -function FinalDeleteWPNow() { - window.location.href = FurlDeleteWP; -} - -var DeploytoProductionID; - -function DeployToProductionInitial(vall) { - DeploytoProductionID = vall; -} - -var create_staging_domain_check = 0; - -function create_staging_checkbox_function() { - - try { - - var checkBox = document.getElementById("Create_Staging_Check"); - // Get the output text - - - // If the checkbox is checked, display the output text - if (checkBox.checked == true) { - create_staging_domain_check = 0; - document.getElementById('Website_Create_Test_Domain').style.display = "block"; - document.getElementById('Website_Create_Own_Domain').style.display = "none"; - - } else { - document.getElementById('Website_Create_Test_Domain').style.display = "none"; - document.getElementById('Website_Create_Own_Domain').style.display = "block"; - create_staging_domain_check = 1; - } - } catch (e) { - - } - - // alert(domain_check); -} - -create_staging_checkbox_function(); - -app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $window) { - - var CheckBoxpasssword = 0; - - $scope.wordpresshomeloading = true; - $scope.stagingDetailsForm = false; - $scope.installationProgress = true; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - $(document).ready(function () { - var checkstatus = document.getElementById("wordpresshome"); - if (checkstatus !== null) { - $scope.LoadWPdata(); - - } - }); - - - $scope.LoadWPdata = function () { - - $scope.wordpresshomeloading = false; - $('#wordpresshomeloading').show(); - - var url = "/websites/FetchWPdata"; - - var data = { - WPid: $('#WPid').html(), - } - - console.log(data); - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - wordpresshomeloading = true; - $('#wordpresshomeloading').hide(); - - if (response.data.status === 1) { - $('#WPVersion').text(response.data.ret_data.version); - if (response.data.ret_data.lscache === 1) { - $('#lscache').prop('checked', true); - } - if (response.data.ret_data.debugging === 1) { - $('#debugging').prop('checked', true); - } - if (response.data.ret_data.searchIndex === 1) { - $('#searchIndex').prop('checked', true); - } - if (response.data.ret_data.maintenanceMode === 1) { - $('#maintenanceMode').prop('checked', true); - } - if (response.data.ret_data.wpcron === 1) { - $('#wpcron').prop('checked', true); - } - if (response.data.ret_data.passwordprotection == 1) { - - var dc = '\n' + - ' ' - var mp = $compile(dc)($scope); - angular.element(document.getElementById('prsswdprodata')).append(mp); - CheckBoxpasssword = 1; - } else if (response.data.ret_data.passwordprotection == 0) { - var dc = '\n' + - ' ' - $('#prsswdprodata').append(dc); - CheckBoxpasssword = 0; - } - - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - - $scope.webSiteCreationLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = false; - $scope.goBackDisable = false; - - } - - - }; - - $scope.UpdateWPSettings = function (setting) { - - $scope.wordpresshomeloading = false; - $('#wordpresshomeloading').show(); - - - var url = "/websites/UpdateWPSettings"; - - if (setting === "PasswordProtection") { - if (CheckBoxpasssword == 0) { - var data = { - WPid: $('#WPid').html(), - setting: setting, - PPUsername: $scope.PPUsername, - PPPassword: $scope.PPPassword, - } - - } else { - var data = { - WPid: $('#WPid').html(), - setting: setting, - PPUsername: '', - PPPassword: '', - } - - } - - } else { - var settingValue = 0; - if ($('#' + setting).is(":checked")) { - settingValue = 1; - } - var data = { - WPid: $('#WPid').html(), - setting: setting, - settingValue: settingValue - } - } - - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $scope.wordpresshomeloading = true; - $('#wordpresshomeloading').hide(); - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Successfully Updated!.', - type: 'success' - }); - if (setting === "PasswordProtection") { - location.reload(); - } - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - if (setting === "PasswordProtection") { - location.reload(); - } - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - alert(response) - - } - - - }; - - $scope.GetCurrentPlugins = function () { - $('#wordpresshomeloading').show(); - - $scope.wordpresshomeloading = false; - - var url = "/websites/GetCurrentPlugins"; - - var data = { - WPid: $('#WPid').html(), - } - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - wordpresshomeloading = true; - $('#wordpresshomeloading').hide(); - - if (response.data.status === 1) { - $('#PluginBody').html(''); - var plugins = JSON.parse(response.data.plugins); - plugins.forEach(AddPlugins); - - } else { - alert("Error:" + response.data.error_message) - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - - $scope.webSiteCreationLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = false; - $scope.goBackDisable = false; - - } - - - }; - - $scope.GetCurrentThemes = function () { - $('#wordpresshomeloading').show(); - - $scope.wordpresshomeloading = false; - - var url = "/websites/GetCurrentThemes"; - - var data = { - WPid: $('#WPid').html(), - } - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - wordpresshomeloading = true; - $('#wordpresshomeloading').hide(); - - if (response.data.status === 1) { - - $('#ThemeBody').html(''); - var themes = JSON.parse(response.data.themes); - themes.forEach(AddThemes); - - } else { - alert("Error:" + response.data.error_message) - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.webSiteCreationLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = false; - $scope.goBackDisable = false; - - } - - - }; - - $scope.UpdatePlugins = function (plugin) { - $('#wordpresshomeloading').show(); - var data = { - plugin: plugin, - pluginarray: PluginsList, - WPid: $('#WPid').html(), - } - - $scope.wordpresshomeloading = false; - - var url = "/websites/UpdatePlugins"; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Updating Plugins in Background!.', - type: 'success' - }); - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - alert(response) - - } - - - }; - - $scope.DeletePlugins = function (plugin) { - $('#wordpresshomeloading').show(); - var data = { - plugin: plugin, - pluginarray: PluginsList, - WPid: $('#WPid').html(), - } - - $scope.wordpresshomeloading = false; - - var url = "/websites/DeletePlugins"; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Deleting Plugin in Background!', - type: 'success' - }); - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - alert(response) - - } - - } - - $scope.ChangeStatus = function (plugin) { - $('#wordpresshomeloading').show(); - var data = { - plugin: plugin, - WPid: $('#WPid').html(), - } - - $scope.wordpresshomeloading = false; - - var url = "/websites/ChangeStatus"; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Changed Plugin state Successfully !.', - type: 'success' - }); - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - alert(response) - - } - - } - - function AddPlugins(value, index, array) { - var FinalMarkup = '' - FinalMarkup = FinalMarkup + ''; - for (let x in value) { - if (x === 'status') { - if (value[x] === 'inactive') { - FinalMarkup = FinalMarkup + '
'; - } else { - FinalMarkup = FinalMarkup + '
'; - } - } else if (x === 'update') { - if (value[x] === 'none') { - FinalMarkup = FinalMarkup + 'Upto Date'; - } else { - FinalMarkup = FinalMarkup + ''; - } - } else { - FinalMarkup = FinalMarkup + '' + value[x] + ""; - } - } - FinalMarkup = FinalMarkup + '' - FinalMarkup = FinalMarkup + '' - var temp = $compile(FinalMarkup)($scope) - AppendToTable('#PluginBody', temp) - } - - $scope.UpdateThemes = function (theme) { - $('#wordpresshomeloading').show(); - var data = { - Theme: theme, - Themearray: ThemesList, - WPid: $('#WPid').html(), - } - - $scope.wordpresshomeloading = false; - - var url = "/websites/UpdateThemes"; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Updating Theme in background !.', - type: 'success' - }); - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - alert(response) - - } - - - }; - - $scope.DeleteThemes = function (theme) { - $('#wordpresshomeloading').show(); - var data = { - Theme: theme, - Themearray: ThemesList, - WPid: $('#WPid').html(), - } - - $scope.wordpresshomeloading = false; - - var url = "/websites/DeleteThemes"; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Deleting Theme in Background!.', - type: 'success' - }); - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - alert(response) - - } - }; - - $scope.ChangeStatusThemes = function (theme) { - $('#wordpresshomeloading').show(); - var data = { - theme: theme, - WPid: $('#WPid').html(), - } - - $scope.wordpresshomeloading = false; - - var url = "/websites/StatusThemes"; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Change Theme state in Bsckground!.', - type: 'success' - }); - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - alert(response) - - } - - }; - - function AddThemes(value, index, array) { - var FinalMarkup = '' - FinalMarkup = FinalMarkup + ''; - for (let x in value) { - if (x === 'status') { - if (value[x] === 'inactive') { - FinalMarkup = FinalMarkup + '
'; - } else { - FinalMarkup = FinalMarkup + '
'; - } - } else if (x === 'update') { - if (value[x] === 'none') { - FinalMarkup = FinalMarkup + 'Upto Date'; - } else { - FinalMarkup = FinalMarkup + ''; - } - } else { - FinalMarkup = FinalMarkup + '' + value[x] + ""; - } - } - FinalMarkup = FinalMarkup + '' - FinalMarkup = FinalMarkup + '' - var temp = $compile(FinalMarkup)($scope) - AppendToTable('#ThemeBody', temp) - } - - $scope.CreateStagingNow = function () { - $('#wordpresshomeloading').show(); - - $scope.wordpresshomeloading = false; - $scope.stagingDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - - - $scope.currentStatus = "Starting creation Staging.."; - - //here enter domain name - if (create_staging_domain_check == 0) { - var Part2_domainNameCreate = document.getElementById('Part2_domainNameCreate').value; - var domainNameCreate = document.getElementById('TestDomainNameCreate').value + Part2_domainNameCreate; - } - if (create_staging_domain_check == 1) { - - var domainNameCreate = $scope.own_domainNameCreate; - } - var data = { - StagingName: $('#stagingName').val(), - StagingDomain: domainNameCreate, - WPid: $('#WPid').html(), - } - var url = "/websites/CreateStagingNow"; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $('#wordpresshomeloading').hide(); - if (response.data.status === 1) { - statusFile = response.data.tempStatusPath; - getCreationStatus(); - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - alert(response) - - } - }; - - function getCreationStatus() { - $('#wordpresshomeloading').show(); - - 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) { - //$('#wordpresshomeloading').hide(); - - if (response.data.abort === 1) { - if (response.data.installStatus === 1) { - - $scope.wordpresshomeloading = true; - $scope.stagingDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = false; - $scope.couldNotConnect = true; - $scope.goBackDisable = false; - - - $("#installProgress").css("width", "100%"); - $("#installProgressbackup").css("width", "100%"); - $scope.installPercentage = "100"; - $scope.currentStatus = response.data.currentStatus; - $timeout.cancel(); - - - } else { - - $scope.wordpresshomeloading = true; - $scope.stagingDetailsForm = 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%"); - $("#installProgressbackup").css("width", "0%"); - $scope.installPercentage = "0"; - $scope.goBackDisable = false; - - - } - - } else { - - $("#installProgress").css("width", response.data.installationProgress + "%"); - $("#installProgressbackup").css("width", response.data.installationProgress + "%"); - $scope.installPercentage = response.data.installationProgress; - $scope.currentStatus = response.data.currentStatus; - $timeout(getCreationStatus, 1000); - - } - - } - - function cantLoadInitialDatas(response) { - //$('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - $scope.stagingDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = false; - $scope.goBackDisable = false; - - } - - - } - - $scope.goBack = function () { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - $scope.stagingDetailsForm = false; - $scope.installationProgress = true; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - $("#installProgress").css("width", "0%"); - }; - - $scope.fetchstaging = function () { - - $('#wordpresshomeloading').show(); - $scope.wordpresshomeloading = false; - - var url = "/websites/fetchstaging"; - - var data = { - WPid: $('#WPid').html(), - } - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - wordpresshomeloading = true; - $('#wordpresshomeloading').hide(); - - if (response.data.status === 1) { - - // $('#ThemeBody').html(''); - // var themes = JSON.parse(response.data.themes); - // themes.forEach(AddThemes); - - $('#StagingBody').html(''); - var staging = JSON.parse(response.data.wpsites); - staging.forEach(AddStagings); - - } else { - alert("Error data.error_message:" + response.data.error_message) - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - alert("Error" + response) - - } - - }; - - $scope.fetchDatabase = function () { - - $('#wordpresshomeloading').show(); - $scope.wordpresshomeloading = false; - - var url = "/websites/fetchDatabase"; - - var data = { - WPid: $('#WPid').html(), - } - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - wordpresshomeloading = true; - $('#wordpresshomeloading').hide(); - - if (response.data.status === 1) { - $('#DB_Name').html(response.data.DataBaseName); - $('#DB_User').html(response.data.DataBaseUser); - $('#tableprefix').html(response.data.tableprefix); - } else { - alert("Error data.error_message:" + response.data.error_message) - - } - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - alert("Error" + response) - - } - - }; - - $scope.SaveUpdateConfig = function () { - $('#wordpresshomeloading').show(); - var data = { - AutomaticUpdates: $('#AutomaticUpdates').find(":selected").text(), - Plugins: $('#Plugins').find(":selected").text(), - Themes: $('#Themes').find(":selected").text(), - WPid: $('#WPid').html(), - } - - $scope.wordpresshomeloading = false; - - var url = "/websites/SaveUpdateConfig"; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Update Configurations Sucessfully!.', - type: 'success' - }); - $("#autoUpdateConfig").modal('hide'); - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - new PNotify({ - title: 'Operation Failed!', - text: response, - type: 'error' - }); - - } - }; - - function AddStagings(value, index, array) { - var FinalMarkup = '' - for (let x in value) { - if (x === 'name') { - FinalMarkup = FinalMarkup + '' + value[x] + ''; - } else if (x !== 'url' && x !== 'deleteURL' && x !== 'id') { - FinalMarkup = FinalMarkup + '' + value[x] + ""; - } - } - FinalMarkup = FinalMarkup + '' + - ' ' - FinalMarkup = FinalMarkup + '' - AppendToTable('#StagingBody', FinalMarkup); - } - - $scope.FinalDeployToProduction = function () { - - $('#wordpresshomeloading').show(); - - $scope.wordpresshomeloading = false; - $scope.stagingDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - - var data = { - WPid: $('#WPid').html(), - StagingID: DeploytoProductionID - } - - var url = "/websites/DeploytoProduction"; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - function ListInitialDatas(response) { - - $('#wordpresshomeloading').hide(); - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Deploy To Production start!.', - type: 'success' - }); - statusFile = response.data.tempStatusPath; - getCreationStatus(); - - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - new PNotify({ - title: 'Operation Failed!', - text: response, - type: 'error' - }); - - } - - }; - - - $scope.CreateBackup = function () { - $('#wordpresshomeloading').show(); - - $scope.wordpresshomeloading = false; - $scope.stagingDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - $scope.currentStatus = "Starting creation Backups.."; - var data = { - WPid: $('#WPid').html(), - Backuptype: $('#backuptype').val() - } - var url = "/websites/WPCreateBackup"; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $('createbackupbutton').hide(); - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Creating Backups!.', - type: 'success' - }); - statusFile = response.data.tempStatusPath; - getCreationStatus(); - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - alert(response) - - } - - }; - - - $scope.installwpcore = function () { - - $('#wordpresshomeloading').show(); - $('#wordpresshomeloadingsec').show(); - var data = { - WPid: $('#WPid').html(), - } - - $scope.wordpresshomeloading = false; - - var url = "/websites/installwpcore"; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $('#wordpresshomeloadingsec').hide(); - $scope.wordpresshomeloading = true; - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Results fetched..', - type: 'success' - }); - $('#SecurityResult').html(response.data.result); - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $('#wordpresshomeloadingsec').hide(); - $scope.wordpresshomeloading = true; - alert(response) - - } - - }; - - $scope.dataintegrity = function () { - - $('#wordpresshomeloading').show(); - $('#wordpresshomeloadingsec').show(); - var data = { - WPid: $('#WPid').html(), - } - - $scope.wordpresshomeloading = false; - - var url = "/websites/dataintegrity"; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $('#wordpresshomeloadingsec').hide(); - $scope.wordpresshomeloading = true; - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Results fetched', - type: 'success' - }); - $('#SecurityResult').html(response.data.result); - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - $('#wordpresshomeloadingsec').hide(); - $scope.wordpresshomeloading = true; - alert(response) - - } - }; - -}); - - -var PluginsList = []; - - -function AddPluginToArray(cBox, name) { - if (cBox.checked) { - PluginsList.push(name); - // alert(PluginsList); - } else { - const index = PluginsList.indexOf(name); - if (index > -1) { - PluginsList.splice(index, 1); - } - // alert(PluginsList); - } -} - -var ThemesList = []; - -function AddThemeToArray(cBox, name) { - if (cBox.checked) { - ThemesList.push(name); - // alert(ThemesList); - } else { - const index = ThemesList.indexOf(name); - if (index > -1) { - ThemesList.splice(index, 1); - } - // alert(ThemesList); - } -} - - -function AppendToTable(table, markup) { - $(table).append(markup); -} - - -//..................Restore Backup Home - - -app.controller('RestoreWPBackup', function ($scope, $http, $timeout, $window) { - $scope.wordpresshomeloading = true; - $scope.stagingDetailsForm = false; - $scope.installationProgress = true; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - - - $scope.checkmethode = function () { - var val = $('#RestoreMethode').children("option:selected").val(); - if (val == 1) { - $('#Newsitediv').show(); - $('#exinstingsitediv').hide(); - } else if (val == 0) { - $('#exinstingsitediv').show(); - $('#Newsitediv').hide(); - } else { - - } - }; - - - $scope.RestoreWPbackupNow = function () { - $('#wordpresshomeloading').show(); - $scope.wordpresshomeloading = false; - $scope.stagingDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - $scope.currentStatus = "Start Restoring WordPress.."; - - var Domain = $('#wprestoresubdirdomain').val() - var path = $('#wprestoresubdirpath').val(); - var home = "1"; - - if (typeof path != 'undefined' || path != '') { - home = "0"; - } - if (typeof path == 'undefined') { - path = ""; - } - - - var backuptype = $('#backuptype').html(); - var data; - if (backuptype == "DataBase Backup") { - data = { - backupid: $('#backupid').html(), - DesSite: $('#DesSite').children("option:selected").val(), - Domain: '', - path: path, - home: home, - } - } else { - data = { - backupid: $('#backupid').html(), - DesSite: $('#DesSite').children("option:selected").val(), - Domain: Domain, - path: path, - home: home, - } - - } - - var url = "/websites/RestoreWPbackupNow"; - - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - // console.log(data) - - var d = $('#DesSite').children("option:selected").val(); - var c = $("input[name=Newdomain]").val(); - // if (d == -1 || c == "") { - // alert("Please Select Method of Backup Restore"); - // } else { - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - // } - - - function ListInitialDatas(response) { - wordpresshomeloading = true; - $('#wordpresshomeloading').hide(); - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Restoring process starts!.', - type: 'success' - }); - statusFile = response.data.tempStatusPath; - getCreationStatus(); - - } else { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = 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; - - } - - } - - function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); - - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - - } - } - - function getCreationStatus() { - $('#wordpresshomeloading').show(); - - 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) { - //$('#wordpresshomeloading').hide(); - - if (response.data.abort === 1) { - - if (response.data.installStatus === 1) { - - - $scope.wordpresshomeloading = true; - $scope.stagingDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = false; - $scope.couldNotConnect = true; - $scope.goBackDisable = false; - - - $("#installProgress").css("width", "100%"); - $("#installProgressbackup").css("width", "100%"); - $scope.installPercentage = "100"; - $scope.currentStatus = response.data.currentStatus; - $timeout.cancel(); - - - } else { - - $scope.wordpresshomeloading = true; - $scope.stagingDetailsForm = 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%"); - $("#installProgressbackup").css("width", "0%"); - $scope.installPercentage = "0"; - $scope.goBackDisable = false; - - - } - - } else { - - $("#installProgress").css("width", response.data.installationProgress + "%"); - $("#installProgressbackup").css("width", response.data.installationProgress + "%"); - $scope.installPercentage = response.data.installationProgress; - $scope.currentStatus = response.data.currentStatus; - $timeout(getCreationStatus, 1000); - - } - - } - - function cantLoadInitialDatas(response) { - //$('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - $scope.stagingDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = false; - $scope.goBackDisable = false; - - } - - - } - - $scope.goBack = function () { - $('#wordpresshomeloading').hide(); - $scope.wordpresshomeloading = true; - $scope.stagingDetailsForm = false; - $scope.installationProgress = true; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - $("#installProgress").css("width", "0%"); - }; -}); - - -//.......................................Remote Backup - -//........... delete DeleteBackupConfigNow - -function DeleteBackupConfigNow(url) { - window.location.href = url; -} - -function DeleteRemoteBackupsiteNow(url) { - window.location.href = url; -} - -function DeleteBackupfileConfigNow(url) { - window.location.href = url; -} - - -app.controller('RemoteBackupConfig', function ($scope, $http, $timeout, $window) { - $scope.RemoteBackupLoading = true; - $scope.SFTPBackUpdiv = true; - - $scope.EndpointURLdiv = true; - $scope.Selectprovider = true; - $scope.S3keyNamediv = true; - $scope.Accesskeydiv = true; - $scope.SecretKeydiv = true; - $scope.SelectRemoteBackuptype = function () { - var val = $scope.RemoteBackuptype; - if (val == "SFTP") { - $scope.SFTPBackUpdiv = false; - $scope.EndpointURLdiv = true; - $scope.Selectprovider = true; - $scope.S3keyNamediv = true; - $scope.Accesskeydiv = true; - $scope.SecretKeydiv = true; - } else if (val == "S3") { - $scope.EndpointURLdiv = true; - $scope.Selectprovider = false; - $scope.S3keyNamediv = false; - $scope.Accesskeydiv = false; - $scope.SecretKeydiv = false; - $scope.SFTPBackUpdiv = true; - } else { - $scope.RemoteBackupLoading = true; - $scope.SFTPBackUpdiv = true; - - $scope.EndpointURLdiv = true; - $scope.Selectprovider = true; - $scope.S3keyNamediv = true; - $scope.Accesskeydiv = true; - $scope.SecretKeydiv = true; - } - } - - $scope.SelectProvidertype = function () { - $scope.EndpointURLdiv = true; - var provider = $scope.Providervalue - if (provider == 'Backblaze') { - $scope.EndpointURLdiv = false; - } else { - $scope.EndpointURLdiv = true; - } - } - - $scope.SaveBackupConfig = function () { - $scope.RemoteBackupLoading = false; - var Hname = $scope.Hostname; - var Uname = $scope.Username; - var Passwd = $scope.Password; - var path = $scope.path; - var type = $scope.RemoteBackuptype; - var Providervalue = $scope.Providervalue; - var data; - if (type == "SFTP") { - - data = { - Hname: Hname, - Uname: Uname, - Passwd: Passwd, - path: path, - type: type - } - } else if (type == "S3") { - if (Providervalue == "Backblaze") { - data = { - S3keyname: $scope.S3keyName, - Provider: Providervalue, - AccessKey: $scope.Accesskey, - SecertKey: $scope.SecretKey, - EndUrl: $scope.EndpointURL, - type: type - } - } else { - data = { - S3keyname: $scope.S3keyName, - Provider: Providervalue, - AccessKey: $scope.Accesskey, - SecertKey: $scope.SecretKey, - type: type - } - - } - - } - var url = "/websites/SaveBackupConfig"; - - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $scope.RemoteBackupLoading = true; - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Successfully Saved!.', - type: 'success' - }); - location.reload(); - - - } else { - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type: 'error' - }); - } - } - - function cantLoadInitialDatas(response) { - $scope.RemoteBackupLoading = true; - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - - } - - - } - -}); - -var UpdatescheduleID; -app.controller('BackupSchedule', function ($scope, $http, $timeout, $window) { - $scope.BackupScheduleLoading = true; - $scope.SaveBackupSchedule = function () { - $scope.RemoteBackupLoading = false; - var FileRetention = $scope.Fretention; - var Backfrequency = $scope.Bfrequency; - - - var data = { - FileRetention: FileRetention, - Backfrequency: Backfrequency, - ScheduleName: $scope.ScheduleName, - RemoteConfigID: $('#RemoteConfigID').html(), - BackupType: $scope.BackupType - } - var url = "/websites/SaveBackupSchedule"; - - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $scope.RemoteBackupLoading = true; - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Successfully Saved!.', - type: 'success' - }); - location.reload(); - - - } else { - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type: 'error' - }); - } - } - - function cantLoadInitialDatas(response) { - $scope.RemoteBackupLoading = true; - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - - } - - - }; - - - $scope.getupdateid = function (ID) { - UpdatescheduleID = ID; - } - - $scope.UpdateRemoteschedules = function () { - $scope.RemoteBackupLoading = false; - var Frequency = $scope.RemoteFrequency; - var fretention = $scope.RemoteFileretention; - - var data = { - ScheduleID: UpdatescheduleID, - Frequency: Frequency, - FileRetention: fretention - } - var url = "/websites/UpdateRemoteschedules"; - - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $scope.RemoteBackupLoading = true; - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Successfully Updated!.', - type: 'success' - }); - location.reload(); - - - } else { - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type: 'error' - }); - } - } - - function cantLoadInitialDatas(response) { - $scope.RemoteBackupLoading = true; - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - - } - }; - - $scope.AddWPsiteforRemoteBackup = function () { - $scope.RemoteBackupLoading = false; - - - var data = { - WpsiteID: $('#Wpsite').val(), - RemoteScheduleID: $('#RemoteScheduleID').html() - } - var url = "/websites/AddWPsiteforRemoteBackup"; - - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $scope.RemoteBackupLoading = true; - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Successfully Saved!.', - type: 'success' - }); - location.reload(); - - - } else { - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type: 'error' - }); - } - } - - function cantLoadInitialDatas(response) { - $scope.RemoteBackupLoading = true; - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - - } - - - }; -}); -/* Java script code to create account */ - -var website_create_domain_check = 0; - -function website_create_checkbox_function() { - - var checkBox = document.getElementById("myCheck"); - // Get the output text - - - // If the checkbox is checked, display the output text - if (checkBox.checked == true) { - website_create_domain_check = 0; - document.getElementById('Website_Create_Test_Domain').style.display = "block"; - document.getElementById('Website_Create_Own_Domain').style.display = "none"; - - } else { - document.getElementById('Website_Create_Test_Domain').style.display = "none"; - document.getElementById('Website_Create_Own_Domain').style.display = "block"; - website_create_domain_check = 1; - } - - // alert(domain_check); -} - -app.controller('createWebsite', function ($scope, $http, $timeout, $window) { - - $scope.webSiteCreationLoading = true; - $scope.installationDetailsForm = false; - $scope.installationProgress = true; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - - var statusFile; - - $scope.createWebsite = function () { - - $scope.webSiteCreationLoading = false; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - - $scope.currentStatus = "Starting creation.."; - - var ssl, dkimCheck, openBasedir, mailDomain, apacheBackend; - - if ($scope.sslCheck === true) { - ssl = 1; - } else { - ssl = 0 - } - - if ($scope.apacheBackend === true) { - apacheBackend = 1; - } else { - apacheBackend = 0 - } - - if ($scope.dkimCheck === true) { - dkimCheck = 1; - } else { - dkimCheck = 0 - } - - if ($scope.openBasedir === true) { - openBasedir = 1; - } else { - openBasedir = 0 - } - - if ($scope.mailDomain === true) { - mailDomain = 1; - } else { - mailDomain = 0 - } - - url = "/websites/submitWebsiteCreation"; - - var package = $scope.packageForWebsite; - - // if (website_create_domain_check == 0) { - // var Part2_domainNameCreate = document.getElementById('Part2_domainNameCreate').value; - // var domainName = document.getElementById('TestDomainNameCreate').value + Part2_domainNameCreate; - // } - // if (website_create_domain_check == 1) { - // - // var domainName = $scope.domainNameCreate; - // } - var domainName = $scope.domainNameCreate; - - // var domainName = $scope.domainNameCreate; - - var adminEmail = $scope.adminEmail; - var phpSelection = $scope.phpSelection; - var websiteOwner = $scope.websiteOwner; - - - var data = { - package: package, - domainName: domainName, - adminEmail: adminEmail, - phpSelection: phpSelection, - ssl: ssl, - websiteOwner: websiteOwner, - dkimCheck: dkimCheck, - openBasedir: openBasedir, - mailDomain: mailDomain, - apacheBackend: apacheBackend - }; - - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.createWebSiteStatus === 1) { - statusFile = response.data.tempStatusPath; - getCreationStatus(); - } else { - - $scope.webSiteCreationLoading = 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; - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.webSiteCreationLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = false; - $scope.goBackDisable = false; - - } - - - }; - $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.webSiteCreationLoading = 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.webSiteCreationLoading = 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 { - $("#installProgress").css("width", response.data.installationProgress + "%"); - $scope.installPercentage = response.data.installationProgress; - $scope.currentStatus = response.data.currentStatus; - $timeout(getCreationStatus, 1000); - } - - } - - function cantLoadInitialDatas(response) { - - $scope.webSiteCreationLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = false; - $scope.goBackDisable = false; - - } - - - } - -}); -/* Java script code to create account ends here */ - -/* Java script code to list accounts */ - -$("#listFail").hide(); - - -app.controller('listWebsites', function ($scope, $http, $window) { - console.log('Initializing listWebsites controller'); - $scope.web = {}; - $scope.WebSitesList = []; - - $scope.currentPage = 1; - $scope.recordsToShow = 10; - - // Initial fetch of websites - $scope.getFurtherWebsitesFromDB = function () { - console.log('Fetching websites from DB'); - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - var data = { - page: $scope.currentPage, - recordsToShow: $scope.recordsToShow - }; - - var dataurl = "/websites/fetchWebsitesList"; - console.log('Making request to:', dataurl); - - $http.post(dataurl, data, config).then(function(response) { - console.log('Received response:', response); - if (response.data.listWebSiteStatus === 1) { - try { - $scope.WebSitesList = JSON.parse(response.data.data); - console.log('Parsed WebSitesList:', $scope.WebSitesList); - $scope.pagination = response.data.pagination; - $("#listFail").hide(); - } catch (e) { - console.error('Error parsing response data:', e); - $("#listFail").fadeIn(); - $scope.errorMessage = 'Error parsing server response'; - } - } else { - $("#listFail").fadeIn(); - $scope.errorMessage = response.data.error_message; - } - }).catch(function(error) { - console.error('Error fetching websites:', error); - $("#listFail").fadeIn(); - $scope.errorMessage = error.message || 'An error occurred while fetching websites'; - }); - }; - - // Call it immediately - $scope.getFurtherWebsitesFromDB(); - - $scope.showWPSites = function(domain) { - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - var data = { - domain: domain - }; - - var url = '/websites/GetWPSitesByDomain'; - - $http.post(url, data, config).then(function(response) { - if (response.data.status === 1) { - // Find the website in the list and update its WordPress sites - for (var i = 0; i < $scope.WebSitesList.length; i++) { - if ($scope.WebSitesList[i].domain === domain) { - $scope.WebSitesList[i].wp_sites = response.data.data; - $scope.WebSitesList[i].showWPSites = !$scope.WebSitesList[i].showWPSites; - break; - } - } - } else { - console.error('Error fetching WordPress sites:', response.data.error_message); - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type: 'error' - }); - } - }, function(error) { - console.error('Error fetching WordPress sites:', error); - new PNotify({ - title: 'Error!', - text: 'Failed to fetch WordPress sites. Please try again.', - type: 'error' - }); - }); - }; - - $scope.updateSetting = function(wpId, setting, value) { - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - var data = { - siteId: wpId, - setting: setting, - value: value - }; - - var url = '/websites/UpdateWPSettings'; - - $http.post(url, data, config).then(function(response) { - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Setting updated successfully.', - type: 'success' - }); - } else { - console.error('Error updating setting:', response.data.error_message); - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type: 'error' - }); - } - }, function(error) { - console.error('Error updating setting:', error); - new PNotify({ - title: 'Error!', - text: 'Failed to update setting. Please try again.', - type: 'error' - }); - }); - }; - - $scope.visitSite = function(url) { - window.open(url, '_blank'); - }; - - $scope.wpLogin = function(wpId) { - window.open('/websites/wpLogin?wpID=' + wpId, '_blank'); - }; - - $scope.manageWP = function(wpId) { - window.location.href = '/websites/listWPsites?wpID=' + wpId; - }; - - $scope.cyberPanelLoading = true; - - $scope.issueSSL = function (virtualHost) { - $scope.cyberPanelLoading = false; - - var url = "/manageSSL/issueSSL"; - - - var data = { - virtualHost: virtualHost - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $scope.cyberPanelLoading = true; - if (response.data.SSL === 1) { - new PNotify({ - title: 'Success!', - text: 'SSL successfully issued.', - 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.cyberPanelLoading = true; - - $scope.searchWebsites = function () { - - $scope.cyberPanelLoading = false; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - var data = { - patternAdded: $scope.patternAdded - }; - - dataurl = "/websites/searchWebsites"; - - $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.cyberPanelLoading = true; - if (response.data.listWebSiteStatus === 1) { - - var finalData = JSON.parse(response.data.data); - $scope.WebSitesList = finalData; - $("#listFail").hide(); - } 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: 'Connect disrupted, refresh the page.', - type: 'error' - }); - } - - - }; - - $scope.ScanWordpressSite = function () { - - $('#cyberPanelLoading').show(); - - - var url = "/websites/ScanWordpressSite"; - - var data = {} - - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $('#cyberPanelLoading').hide(); - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Successfully Saved!.', - type: 'success' - }); - location.reload(); - - } else { - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - - } - - function cantLoadInitialDatas(response) { - $('#cyberPanelLoading').hide(); - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - - } - - - }; - -}); - -app.controller('listChildDomainsMain', function ($scope, $http, $timeout) { - - $scope.currentPage = 1; - $scope.recordsToShow = 10; - - $scope.getFurtherWebsitesFromDB = function () { - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - var data = { - page: $scope.currentPage, - recordsToShow: $scope.recordsToShow - }; - - - dataurl = "/websites/fetchChildDomainsMain"; - - $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - if (response.data.listWebSiteStatus === 1) { - - $scope.WebSitesList = JSON.parse(response.data.data); - $scope.pagination = response.data.pagination; - $scope.clients = JSON.parse(response.data.data); - $("#listFail").hide(); - } else { - $("#listFail").fadeIn(); - $scope.errorMessage = response.data.error_message; - - } - } - - function cantLoadInitialData(response) { - } - - - }; - $scope.getFurtherWebsitesFromDB(); - - $scope.cyberPanelLoading = true; - - $scope.issueSSL = function (virtualHost) { - $scope.cyberPanelLoading = false; - - var url = "/manageSSL/issueSSL"; - - - var data = { - virtualHost: virtualHost - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - $scope.cyberPanelLoading = true; - if (response.data.SSL === 1) { - new PNotify({ - title: 'Success!', - text: 'SSL successfully issued.', - 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.cyberPanelLoading = true; - - $scope.searchWebsites = function () { - - $scope.cyberPanelLoading = false; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - var data = { - patternAdded: $scope.patternAdded - }; - - dataurl = "/websites/searchChilds"; - - $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.cyberPanelLoading = true; - if (response.data.listWebSiteStatus === 1) { - - var finalData = JSON.parse(response.data.data); - $scope.WebSitesList = finalData; - $("#listFail").hide(); - } 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: 'Connect disrupted, refresh the page.', - type: 'error' - }); - } - - - }; - - $scope.initConvert = function (virtualHost) { - $scope.domainName = virtualHost; - }; - - var statusFile; - - $scope.installationProgress = true; - - $scope.convert = function () { - - $scope.cyberPanelLoading = false; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.goBackDisable = true; - - $scope.currentStatus = "Starting creation.."; - - var ssl, dkimCheck, openBasedir; - - if ($scope.sslCheck === true) { - ssl = 1; - } else { - ssl = 0 - } - - if ($scope.dkimCheck === true) { - dkimCheck = 1; - } else { - dkimCheck = 0 - } - - if ($scope.openBasedir === true) { - openBasedir = 1; - } else { - openBasedir = 0 - } - - url = "/websites/convertDomainToSite"; - - - var data = { - package: $scope.packageForWebsite, - domainName: $scope.domainName, - adminEmail: $scope.adminEmail, - phpSelection: $scope.phpSelection, - websiteOwner: $scope.websiteOwner, - ssl: ssl, - dkimCheck: dkimCheck, - openBasedir: openBasedir - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.createWebSiteStatus === 1) { - statusFile = response.data.tempStatusPath; - getCreationStatus(); - } else { - - $scope.cyberPanelLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.goBackDisable = false; - - $scope.currentStatus = response.data.error_message; - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.cyberPanelLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.goBackDisable = false; - - } - - - }; - $scope.goBack = function () { - $scope.cyberPanelLoading = true; - $scope.installationDetailsForm = false; - $scope.installationProgress = 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.cyberPanelLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.goBackDisable = false; - - $("#installProgress").css("width", "100%"); - $scope.installPercentage = "100"; - $scope.currentStatus = response.data.currentStatus; - $timeout.cancel(); - - } else { - - $scope.cyberPanelLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.goBackDisable = false; - - $scope.currentStatus = response.data.error_message; - - $("#installProgress").css("width", "0%"); - $scope.installPercentage = "0"; - $scope.goBackDisable = false; - - } - - } else { - $("#installProgress").css("width", response.data.installationProgress + "%"); - $scope.installPercentage = response.data.installationProgress; - $scope.currentStatus = response.data.currentStatus; - $timeout(getCreationStatus, 1000); - } - - } - - function cantLoadInitialDatas(response) { - - $scope.cyberPanelLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.goBackDisable = false; - - } - - - } - - var DeleteDomain; - $scope.deleteDomainInit = function (childDomainForDeletion) { - DeleteDomain = childDomainForDeletion; - }; - - $scope.deleteChildDomain = function () { - $scope.cyberPanelLoading = false; - url = "/websites/submitDomainDeletion"; - - var data = { - websiteName: DeleteDomain, - DeleteDocRoot: $scope.DeleteDocRoot - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - function ListInitialDatas(response) { - $scope.cyberPanelLoading = true; - if (response.data.websiteDeleteStatus === 1) { - new PNotify({ - title: 'Success!', - text: 'Child Domain successfully deleted.', - type: 'success' - }); - $scope.getFurtherWebsitesFromDB(); - } 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' - }); - - } - - }; - -}); - -/* Java script code to list accounts ends here */ - - -/* Java script code to delete Website */ - - -$("#websiteDeleteFailure").hide(); -$("#websiteDeleteSuccess").hide(); - -$("#deleteWebsiteButton").hide(); -$("#deleteLoading").hide(); - -app.controller('deleteWebsiteControl', function ($scope, $http) { - - - $scope.deleteWebsite = function () { - - $("#deleteWebsiteButton").fadeIn(); - - - }; - - $scope.deleteWebsiteFinal = function () { - - $("#deleteLoading").show(); - - var websiteName = $scope.websiteToBeDeleted; - - - url = "/websites/submitWebsiteDeletion"; - - var data = { - websiteName: websiteName - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.websiteDeleteStatus === 0) { - $scope.errorMessage = response.data.error_message; - $("#websiteDeleteFailure").fadeIn(); - $("#websiteDeleteSuccess").hide(); - $("#deleteWebsiteButton").hide(); - - - $("#deleteLoading").hide(); - - } else { - $("#websiteDeleteFailure").hide(); - $("#websiteDeleteSuccess").fadeIn(); - $("#deleteWebsiteButton").hide(); - $scope.deletedWebsite = websiteName; - $("#deleteLoading").hide(); - - } - - - } - - function cantLoadInitialDatas(response) { - } - - - }; - -}); - - -/* Java script code to delete website ends here */ - - -/* Java script code to modify package ends here */ - -$("#canNotModify").hide(); -$("#webSiteDetailsToBeModified").hide(); -$("#websiteModifyFailure").hide(); -$("#websiteModifySuccess").hide(); -$("#websiteSuccessfullyModified").hide(); -$("#modifyWebsiteLoading").hide(); -$("#modifyWebsiteButton").hide(); - -app.controller('modifyWebsitesController', function ($scope, $http) { - - $scope.fetchWebsites = function () { - - $("#modifyWebsiteLoading").show(); - - - var websiteToBeModified = $scope.websiteToBeModified; - - url = "/websites/getWebsiteDetails"; - - var data = { - websiteToBeModified: websiteToBeModified, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.modifyStatus === 0) { - console.log(response.data); - $scope.errorMessage = response.data.error_message; - $("#websiteModifyFailure").fadeIn(); - $("#websiteModifySuccess").hide(); - $("#modifyWebsiteButton").hide(); - $("#modifyWebsiteLoading").hide(); - $("#canNotModify").hide(); - - - } else { - console.log(response.data); - $("#modifyWebsiteButton").fadeIn(); - - $scope.adminEmail = response.data.adminEmail; - $scope.currentPack = response.data.current_pack; - $scope.webpacks = JSON.parse(response.data.packages); - $scope.adminNames = JSON.parse(response.data.adminNames); - $scope.currentAdmin = response.data.currentAdmin; - - $("#webSiteDetailsToBeModified").fadeIn(); - $("#websiteModifySuccess").fadeIn(); - $("#modifyWebsiteButton").fadeIn(); - $("#modifyWebsiteLoading").hide(); - $("#canNotModify").hide(); - - - } - - - } - - function cantLoadInitialDatas(response) { - $("#websiteModifyFailure").fadeIn(); - } - - }; - - - $scope.modifyWebsiteFunc = function () { - - var domain = $scope.websiteToBeModified; - var packForWeb = $scope.selectedPack; - var email = $scope.adminEmail; - var phpVersion = $scope.phpSelection; - var admin = $scope.selectedAdmin; - - - $("#websiteModifyFailure").hide(); - $("#websiteModifySuccess").hide(); - $("#websiteSuccessfullyModified").hide(); - $("#canNotModify").hide(); - $("#modifyWebsiteLoading").fadeIn(); - - - url = "/websites/saveWebsiteChanges"; - - var data = { - domain: domain, - packForWeb: packForWeb, - email: email, - phpVersion: phpVersion, - admin: admin - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.saveStatus === 0) { - $scope.errMessage = response.data.error_message; - - $("#canNotModify").fadeIn(); - $("#websiteModifyFailure").hide(); - $("#websiteModifySuccess").hide(); - $("#websiteSuccessfullyModified").hide(); - $("#modifyWebsiteLoading").hide(); - - - } else { - $("#modifyWebsiteButton").hide(); - $("#canNotModify").hide(); - $("#websiteModifyFailure").hide(); - $("#websiteModifySuccess").hide(); - - $("#websiteSuccessfullyModified").fadeIn(); - $("#modifyWebsiteLoading").hide(); - - $scope.websiteModified = domain; - - - } - - - } - - function cantLoadInitialDatas(response) { - $scope.errMessage = response.data.error_message; - $("#canNotModify").fadeIn(); - } - - - }; - -}); - -/* Java script code to Modify Pacakge ends here */ - - -/* Java script code to create account */ -var website_child_domain_check = 0; - -function website_child_domain_checkbox_function() { - - var checkBox = document.getElementById("myCheck"); - // Get the output text - - - // If the checkbox is checked, display the output text - if (checkBox.checked == true) { - website_child_domain_check = 0; - document.getElementById('Website_Create_Test_Domain').style.display = "block"; - document.getElementById('Website_Create_Own_Domain').style.display = "none"; - - } else { - document.getElementById('Website_Create_Test_Domain').style.display = "none"; - document.getElementById('Website_Create_Own_Domain').style.display = "block"; - website_child_domain_check = 1; - } - - // alert(domain_check); -} - -app.controller('websitePages', function ($scope, $http, $timeout, $window) { - - $scope.logFileLoading = true; - $scope.logsFeteched = true; - $scope.couldNotFetchLogs = true; - $scope.couldNotConnect = true; - $scope.fetchedData = true; - $scope.hideLogs = true; - $scope.hideErrorLogs = true; - - $scope.hidelogsbtn = function () { - $scope.hideLogs = true; - }; - - $scope.hideErrorLogsbtn = function () { - $scope.hideLogs = true; - }; - - $scope.fileManagerURL = "/filemanager/" + $("#domainNamePage").text(); - $scope.wordPressInstallURL = $("#domainNamePage").text() + "/wordpressInstall"; - $scope.joomlaInstallURL = $("#domainNamePage").text() + "/joomlaInstall"; - $scope.setupGit = $("#domainNamePage").text() + "/setupGit"; - $scope.installPrestaURL = $("#domainNamePage").text() + "/installPrestaShop"; - $scope.installMagentoURL = $("#domainNamePage").text() + "/installMagento"; - $scope.installMauticURL = $("#domainNamePage").text() + "/installMautic"; - $scope.domainAliasURL = "/websites/" + $("#domainNamePage").text() + "/domainAlias"; - $scope.previewUrl = "/preview/" + $("#domainNamePage").text() + "/"; - - var logType = 0; - $scope.pageNumber = 1; - - $scope.fetchLogs = function (type) { - - var pageNumber = $scope.pageNumber; - - - if (type == 3) { - pageNumber = $scope.pageNumber + 1; - $scope.pageNumber = pageNumber; - } else if (type == 4) { - pageNumber = $scope.pageNumber - 1; - $scope.pageNumber = pageNumber; - } else { - logType = type; - } - - - $scope.logFileLoading = false; - $scope.logsFeteched = true; - $scope.couldNotFetchLogs = true; - $scope.couldNotConnect = true; - $scope.fetchedData = false; - $scope.hideErrorLogs = true; - - - url = "/websites/getDataFromLogFile"; - - var domainNamePage = $("#domainNamePage").text(); - - - var data = { - logType: logType, - virtualHost: domainNamePage, - page: pageNumber, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.logstatus == 1) { - - - $scope.logFileLoading = true; - $scope.logsFeteched = false; - $scope.couldNotFetchLogs = true; - $scope.couldNotConnect = true; - $scope.fetchedData = false; - $scope.hideLogs = false; - - - $scope.records = JSON.parse(response.data.data); - - } else { - - $scope.logFileLoading = true; - $scope.logsFeteched = true; - $scope.couldNotFetchLogs = false; - $scope.couldNotConnect = true; - $scope.fetchedData = true; - $scope.hideLogs = false; - - - $scope.errorMessage = response.data.error_message; - console.log(domainNamePage) - - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.logFileLoading = true; - $scope.logsFeteched = true; - $scope.couldNotFetchLogs = true; - $scope.couldNotConnect = false; - $scope.fetchedData = true; - $scope.hideLogs = false; - - } - - - }; - - $scope.errorPageNumber = 1; - - - $scope.fetchErrorLogs = function (type) { - - var errorPageNumber = $scope.errorPageNumber; - - - if (type == 3) { - errorPageNumber = $scope.errorPageNumber + 1; - $scope.errorPageNumber = errorPageNumber; - } else if (type == 4) { - errorPageNumber = $scope.errorPageNumber - 1; - $scope.errorPageNumber = errorPageNumber; - } else { - logType = type; - } - - // notifications - - $scope.logFileLoading = false; - $scope.logsFeteched = true; - $scope.couldNotFetchLogs = true; - $scope.couldNotConnect = true; - $scope.fetchedData = true; - $scope.hideErrorLogs = true; - $scope.hideLogs = false; - - - url = "/websites/fetchErrorLogs"; - - var domainNamePage = $("#domainNamePage").text(); - - - var data = { - virtualHost: domainNamePage, - page: errorPageNumber, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.logstatus === 1) { - - - // notifications - - $scope.logFileLoading = true; - $scope.logsFeteched = false; - $scope.couldNotFetchLogs = true; - $scope.couldNotConnect = true; - $scope.fetchedData = true; - $scope.hideLogs = false; - $scope.hideErrorLogs = false; - - - $scope.errorLogsData = response.data.data; - - } else { - - // notifications - - $scope.logFileLoading = true; - $scope.logsFeteched = true; - $scope.couldNotFetchLogs = false; - $scope.couldNotConnect = true; - $scope.fetchedData = true; - $scope.hideLogs = true; - $scope.hideErrorLogs = true; - - - $scope.errorMessage = response.data.error_message; - - } - - - } - - function cantLoadInitialDatas(response) { - - // notifications - - $scope.logFileLoading = true; - $scope.logsFeteched = true; - $scope.couldNotFetchLogs = true; - $scope.couldNotConnect = false; - $scope.fetchedData = true; - $scope.hideLogs = true; - $scope.hideErrorLogs = true; - - } - - - }; - - ///////// Configurations Part - - $scope.configurationsBox = true; - $scope.configsFetched = true; - $scope.couldNotFetchConfigs = true; - $scope.couldNotConnect = true; - $scope.fetchedConfigsData = true; - $scope.configFileLoading = true; - $scope.configSaved = true; - $scope.couldNotSaveConfigurations = true; - - $scope.hideconfigbtn = function () { - - $scope.configurationsBox = true; - }; - - $scope.fetchConfigurations = function () { - - - $scope.hidsslconfigs = true; - $scope.configurationsBoxRewrite = true; - $scope.changePHPView = true; - - - //Rewrite rules - $scope.configurationsBoxRewrite = true; - $scope.rewriteRulesFetched = true; - $scope.couldNotFetchRewriteRules = true; - $scope.rewriteRulesSaved = true; - $scope.couldNotSaveRewriteRules = true; - $scope.fetchedRewriteRules = true; - $scope.saveRewriteRulesBTN = true; - - /// - - $scope.configFileLoading = false; - - - url = "/websites/getDataFromConfigFile"; - - var virtualHost = $("#domainNamePage").text(); - - - var data = { - virtualHost: virtualHost, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.configstatus === 1) { - - //Rewrite rules - - $scope.configurationsBoxRewrite = true; - $scope.rewriteRulesFetched = true; - $scope.couldNotFetchRewriteRules = true; - $scope.rewriteRulesSaved = true; - $scope.couldNotSaveRewriteRules = true; - $scope.fetchedRewriteRules = true; - $scope.saveRewriteRulesBTN = true; - - /// - - $scope.configurationsBox = false; - $scope.configsFetched = false; - $scope.couldNotFetchConfigs = true; - $scope.couldNotConnect = true; - $scope.fetchedConfigsData = false; - $scope.configFileLoading = true; - $scope.configSaved = true; - $scope.couldNotSaveConfigurations = true; - $scope.saveConfigBtn = false; - - - $scope.configData = response.data.configData; - - } else { - - //Rewrite rules - $scope.configurationsBoxRewrite = true; - $scope.rewriteRulesFetched = true; - $scope.couldNotFetchRewriteRules = true; - $scope.rewriteRulesSaved = true; - $scope.couldNotSaveRewriteRules = true; - $scope.fetchedRewriteRules = true; - $scope.saveRewriteRulesBTN = true; - - /// - $scope.configurationsBox = false; - $scope.configsFetched = true; - $scope.couldNotFetchConfigs = false; - $scope.couldNotConnect = true; - $scope.fetchedConfigsData = true; - $scope.configFileLoading = true; - $scope.configSaved = true; - $scope.couldNotSaveConfigurations = true; - - - $scope.errorMessage = response.data.error_message; - - } - - - } - - function cantLoadInitialDatas(response) { - - //Rewrite rules - $scope.configurationsBoxRewrite = true; - $scope.rewriteRulesFetched = true; - $scope.couldNotFetchRewriteRules = true; - $scope.rewriteRulesSaved = true; - $scope.couldNotSaveRewriteRules = true; - $scope.fetchedRewriteRules = true; - $scope.saveRewriteRulesBTN = true; - /// - - $scope.configurationsBox = false; - $scope.configsFetched = true; - $scope.couldNotFetchConfigs = true; - $scope.couldNotConnect = false; - $scope.fetchedConfigsData = true; - $scope.configFileLoading = true; - $scope.configSaved = true; - $scope.couldNotSaveConfigurations = true; - - - } - - - }; - - $scope.saveCongiruations = function () { - - $scope.configFileLoading = false; - - - url = "/websites/saveConfigsToFile"; - - var virtualHost = $("#domainNamePage").text(); - var configData = $scope.configData; - - - var data = { - virtualHost: virtualHost, - configData: configData, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.configstatus === 1) { - - $scope.configurationsBox = false; - $scope.configsFetched = true; - $scope.couldNotFetchConfigs = true; - $scope.couldNotConnect = true; - $scope.fetchedConfigsData = true; - $scope.configFileLoading = true; - $scope.configSaved = false; - $scope.couldNotSaveConfigurations = true; - $scope.saveConfigBtn = true; - - - } else { - $scope.configurationsBox = false; - $scope.configsFetched = true; - $scope.couldNotFetchConfigs = true; - $scope.couldNotConnect = true; - $scope.fetchedConfigsData = false; - $scope.configFileLoading = true; - $scope.configSaved = true; - $scope.couldNotSaveConfigurations = false; - - - $scope.errorMessage = response.data.error_message; - - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.configurationsBox = false; - $scope.configsFetched = true; - $scope.couldNotFetchConfigs = true; - $scope.couldNotConnect = false; - $scope.fetchedConfigsData = true; - $scope.configFileLoading = true; - $scope.configSaved = true; - $scope.couldNotSaveConfigurations = true; - - - } - - - }; - - - ///////// Rewrite Rules - - $scope.configurationsBoxRewrite = true; - $scope.rewriteRulesFetched = true; - $scope.couldNotFetchRewriteRules = true; - $scope.rewriteRulesSaved = true; - $scope.couldNotSaveRewriteRules = true; - $scope.fetchedRewriteRules = true; - $scope.saveRewriteRulesBTN = true; - - $scope.hideRewriteRulesbtn = function () { - $scope.configurationsBoxRewrite = true; - }; - - $scope.fetchRewriteFules = function () { - - $scope.hidsslconfigs = true; - $scope.configurationsBox = true; - $scope.changePHPView = true; - - - $scope.configurationsBox = true; - $scope.configsFetched = true; - $scope.couldNotFetchConfigs = true; - $scope.couldNotConnect = true; - $scope.fetchedConfigsData = true; - $scope.configFileLoading = true; - $scope.configSaved = true; - $scope.couldNotSaveConfigurations = true; - $scope.saveConfigBtn = true; - - $scope.configFileLoading = false; - - - url = "/websites/getRewriteRules"; - - var virtualHost = $("#domainNamePage").text(); - - - var data = { - virtualHost: virtualHost, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.rewriteStatus == 1) { - - - // from main - - $scope.configurationsBox = true; - $scope.configsFetched = true; - $scope.couldNotFetchConfigs = true; - $scope.fetchedConfigsData = true; - $scope.configSaved = true; - $scope.couldNotSaveConfigurations = true; - $scope.saveConfigBtn = true; - - // main ends - - $scope.configFileLoading = true; - - // - - - $scope.configurationsBoxRewrite = false; - $scope.rewriteRulesFetched = false; - $scope.couldNotFetchRewriteRules = true; - $scope.rewriteRulesSaved = true; - $scope.couldNotSaveRewriteRules = true; - $scope.fetchedRewriteRules = false; - $scope.saveRewriteRulesBTN = false; - $scope.couldNotConnect = true; - - - $scope.rewriteRules = response.data.rewriteRules; - - } else { - // from main - $scope.configurationsBox = true; - $scope.configsFetched = true; - $scope.couldNotFetchConfigs = true; - $scope.fetchedConfigsData = true; - $scope.configFileLoading = true; - $scope.configSaved = true; - $scope.couldNotSaveConfigurations = true; - $scope.saveConfigBtn = true; - // from main - - $scope.configFileLoading = true; - - /// - - $scope.configurationsBoxRewrite = true; - $scope.rewriteRulesFetched = true; - $scope.couldNotFetchRewriteRules = false; - $scope.rewriteRulesSaved = true; - $scope.couldNotSaveRewriteRules = true; - $scope.fetchedRewriteRules = true; - $scope.saveRewriteRulesBTN = true; - $scope.couldNotConnect = true; - - - $scope.errorMessage = response.data.error_message; - - } - - - } - - function cantLoadInitialDatas(response) { - // from main - - $scope.configurationsBox = true; - $scope.configsFetched = true; - $scope.couldNotFetchConfigs = true; - $scope.fetchedConfigsData = true; - $scope.configFileLoading = true; - $scope.configSaved = true; - $scope.couldNotSaveConfigurations = true; - $scope.saveConfigBtn = true; - - // from main - - $scope.configFileLoading = true; - - /// - - $scope.configurationsBoxRewrite = true; - $scope.rewriteRulesFetched = true; - $scope.couldNotFetchRewriteRules = true; - $scope.rewriteRulesSaved = true; - $scope.couldNotSaveRewriteRules = true; - $scope.fetchedRewriteRules = true; - $scope.saveRewriteRulesBTN = true; - - $scope.couldNotConnect = false; - - - } - - - }; - - $scope.saveRewriteRules = function () { - - $scope.configFileLoading = false; - - - url = "/websites/saveRewriteRules"; - - var virtualHost = $("#domainNamePage").text(); - var rewriteRules = $scope.rewriteRules; - - - var data = { - virtualHost: virtualHost, - rewriteRules: rewriteRules, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.rewriteStatus == 1) { - - $scope.configurationsBoxRewrite = false; - $scope.rewriteRulesFetched = true; - $scope.couldNotFetchRewriteRules = true; - $scope.rewriteRulesSaved = false; - $scope.couldNotSaveRewriteRules = true; - $scope.fetchedRewriteRules = true; - $scope.saveRewriteRulesBTN = true; - $scope.configFileLoading = true; - - - } else { - $scope.configurationsBoxRewrite = false; - $scope.rewriteRulesFetched = false; - $scope.couldNotFetchRewriteRules = true; - $scope.rewriteRulesSaved = true; - $scope.couldNotSaveRewriteRules = false; - $scope.fetchedRewriteRules = true; - $scope.saveRewriteRulesBTN = false; - - $scope.configFileLoading = true; - - - $scope.errorMessage = response.data.error_message; - - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.configurationsBoxRewrite = false; - $scope.rewriteRulesFetched = false; - $scope.couldNotFetchRewriteRules = true; - $scope.rewriteRulesSaved = true; - $scope.couldNotSaveRewriteRules = true; - $scope.fetchedRewriteRules = true; - $scope.saveRewriteRulesBTN = false; - - $scope.configFileLoading = true; - - $scope.couldNotConnect = false; - - - } - - - }; - - //////// Application Installation part - - $scope.installationDetailsForm = true; - $scope.installationDetailsFormJoomla = true; - $scope.applicationInstallerLoading = true; - $scope.installationFailed = true; - $scope.installationSuccessfull = true; - $scope.couldNotConnect = true; - - - $scope.installationDetails = function () { - - $scope.installationDetailsForm = !$scope.installationDetailsForm; - $scope.installationDetailsFormJoomla = true; - - }; - - $scope.installationDetailsJoomla = function () { - - $scope.installationDetailsFormJoomla = !$scope.installationDetailsFormJoomla; - $scope.installationDetailsForm = true; - - }; - - $scope.installWordpress = function () { - - - $scope.installationDetailsForm = false; - $scope.applicationInstallerLoading = false; - $scope.installationFailed = true; - $scope.installationSuccessfull = true; - $scope.couldNotConnect = true; - - var domain = $("#domainNamePage").text(); - var path = $scope.installPath; - - url = "/websites/installWordpress"; - - var home = "1"; - - if (typeof path != 'undefined') { - home = "0"; - } - - - var data = { - domain: domain, - home: home, - path: path, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.installStatus === 1) { - if (typeof path != 'undefined') { - $scope.installationURL = "http://" + domain + "/" + path; - } else { - $scope.installationURL = domain; - } - - $scope.installationDetailsForm = false; - $scope.applicationInstallerLoading = true; - $scope.installationFailed = true; - $scope.installationSuccessfull = false; - $scope.couldNotConnect = true; - - } else { - - $scope.installationDetailsForm = false; - $scope.applicationInstallerLoading = true; - $scope.installationFailed = false; - $scope.installationSuccessfull = true; - $scope.couldNotConnect = true; - - $scope.errorMessage = response.data.error_message; - - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.installationDetailsForm = false; - $scope.applicationInstallerLoading = true; - $scope.installationFailed = true; - $scope.installationSuccessfull = true; - $scope.couldNotConnect = false; - - } - - }; - - $scope.installJoomla = function () { - - - $scope.installationDetailsFormJoomla = false; - $scope.applicationInstallerLoading = false; - $scope.installationFailed = true; - $scope.installationSuccessfull = true; - $scope.couldNotConnect = true; - - var domain = $("#domainNamePage").text(); - var path = $scope.installPath; - var username = 'admin'; - var password = $scope.password; - var prefix = $scope.prefix; - - - url = "/websites/installJoomla"; - - var home = "1"; - - if (typeof path != 'undefined') { - home = "0"; - } - - - var data = { - domain: domain, - siteName: $scope.siteName, - home: home, - path: path, - password: password, - prefix: prefix, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.installStatus === 1) { - if (typeof path != 'undefined') { - $scope.installationURL = "http://" + domain + "/" + path; - } else { - $scope.installationURL = domain; - } - - $scope.installationDetailsFormJoomla = false; - $scope.applicationInstallerLoading = true; - $scope.installationFailed = true; - $scope.installationSuccessfull = false; - $scope.couldNotConnect = true; - - } else { - - $scope.installationDetailsFormJoomla = false; - $scope.applicationInstallerLoading = true; - $scope.installationFailed = false; - $scope.installationSuccessfull = true; - $scope.couldNotConnect = true; - - $scope.errorMessage = response.data.error_message; - - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.installationDetailsFormJoomla = false; - $scope.applicationInstallerLoading = true; - $scope.installationFailed = true; - $scope.installationSuccessfull = true; - $scope.couldNotConnect = false; - - } - - }; - - - //////// SSL Part - - $scope.sslSaved = true; - $scope.couldNotSaveSSL = true; - $scope.hidsslconfigs = true; - $scope.couldNotConnect = true; - - - $scope.hidesslbtn = function () { - $scope.hidsslconfigs = true; - }; - - $scope.addSSL = function () { - $scope.hidsslconfigs = false; - $scope.configurationsBox = true; - $scope.configurationsBoxRewrite = true; - $scope.changePHPView = true; - }; - - $scope.saveSSL = function () { - - - $scope.configFileLoading = false; - - url = "/websites/saveSSL"; - - var virtualHost = $("#domainNamePage").text(); - var cert = $scope.cert; - var key = $scope.key; - - - var data = { - virtualHost: virtualHost, - cert: cert, - key: key - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.sslStatus === 1) { - - $scope.sslSaved = false; - $scope.couldNotSaveSSL = true; - $scope.couldNotConnect = true; - $scope.configFileLoading = true; - - - } else { - - $scope.sslSaved = true; - $scope.couldNotSaveSSL = false; - $scope.couldNotConnect = true; - $scope.configFileLoading = true; - - $scope.errorMessage = response.data.error_message; - - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.sslSaved = true; - $scope.couldNotSaveSSL = true; - $scope.couldNotConnect = false; - $scope.configFileLoading = true; - - - } - - }; - - //// Change PHP Master - - $scope.failedToChangePHPMaster = true; - $scope.phpChangedMaster = true; - $scope.couldNotConnect = true; - - $scope.changePHPView = true; - - - $scope.hideChangePHPMaster = function () { - $scope.changePHPView = true; - }; - - $scope.changePHPMaster = function () { - $scope.hidsslconfigs = true; - $scope.configurationsBox = true; - $scope.configurationsBoxRewrite = true; - $scope.changePHPView = false; - }; - - $scope.changePHPVersionMaster = function (childDomain, phpSelection) { - - // notifcations - - $scope.configFileLoading = false; - - var url = "/websites/changePHP"; - - var data = { - childDomain: $("#domainNamePage").text(), - phpSelection: $scope.phpSelectionMaster, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.changePHP === 1) { - - $scope.configFileLoading = true; - $scope.websiteDomain = $("#domainNamePage").text(); - - - // notifcations - - $scope.failedToChangePHPMaster = true; - $scope.phpChangedMaster = false; - $scope.couldNotConnect = true; - - - } else { - - $scope.configFileLoading = true; - $scope.errorMessage = response.data.error_message; - - // notifcations - - $scope.failedToChangePHPMaster = false; - $scope.phpChangedMaster = true; - $scope.couldNotConnect = true; - - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.configFileLoading = true; - - // notifcations - - $scope.failedToChangePHPMaster = true; - $scope.phpChangedMaster = true; - $scope.couldNotConnect = false; - - } - - }; - - ////// create domain part - - $("#domainCreationForm").hide(); - - $scope.showCreateDomainForm = function () { - $("#domainCreationForm").fadeIn(); - }; - - $scope.hideDomainCreationForm = function () { - $("#domainCreationForm").fadeOut(); - }; - - $scope.masterDomain = $("#domainNamePage").text(); - - // notifcations settings - $scope.domainLoading = true; - $scope.installationDetailsForm = false; - $scope.installationProgress = true; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - $scope.DomainCreateForm = true; - - var statusFile; - - - $scope.webselection = true; - $scope.WebsiteType = function () { - var type = $scope.websitetype; - if (type == 'Sub Domain') { - $scope.webselection = false; - $scope.DomainCreateForm = true; - - } else if (type == 'Addon Domain') { - $scope.DomainCreateForm = false; - $scope.webselection = true; - $scope.masterDomain = $('#defaultSite').html() - } - }; - - $scope.WebsiteSelection = function () { - $scope.DomainCreateForm = false; - }; - - $scope.createDomain = function () { - - $scope.domainLoading = false; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - $scope.currentStatus = "Starting creation.."; - $scope.DomainCreateForm = true; - - var ssl, dkimCheck, openBasedir, apacheBackend; - - if ($scope.sslCheck === true) { - ssl = 1; - } else { - ssl = 0 - } - - if ($scope.dkimCheck === true) { - dkimCheck = 1; - } else { - dkimCheck = 0 - } - - if ($scope.openBasedir === true) { - openBasedir = 1; - } else { - openBasedir = 0 - } - - - if ($scope.apacheBackend === true) { - apacheBackend = 1; - } else { - apacheBackend = 0 - } - - - url = "/websites/submitDomainCreation"; - var domainName = $scope.domainNameCreate; - var phpSelection = $scope.phpSelection; - - var path = $scope.docRootPath; - - if (typeof path === 'undefined') { - path = ""; - } - var package = $scope.packageForWebsite; - - // if (website_child_domain_check == 0) { - // var Part2_domainNameCreate = document.getElementById('Part2_domainNameCreate').value; - // var domainName = document.getElementById('TestDomainNameCreate').value + Part2_domainNameCreate; - // } - // if (website_child_domain_check == 1) { - // - // var domainName = $scope.own_domainNameCreate; - // } - var type = $scope.websitetype; - - var domainName = $scope.domainNameCreate; - - - var data = { - domainName: domainName, - phpSelection: phpSelection, - ssl: ssl, - path: path, - masterDomain: $scope.masterDomain, - dkimCheck: dkimCheck, - openBasedir: openBasedir, - apacheBackend: apacheBackend - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - // console.log(data) - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.createWebSiteStatus === 1) { - statusFile = response.data.tempStatusPath; - getCreationStatus(); - } else { - - $scope.domainLoading = true; - $scope.installationDetailsForm = true; - $scope.DomainCreateForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = false; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = false; - - $scope.errorMessage = response.data.error_message; - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.domainLoading = true; - $scope.installationDetailsForm = true; - $scope.DomainCreateForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = false; - $scope.goBackDisable = false; - - } - - - }; - - $scope.goBack = function () { - $scope.domainLoading = true; - $scope.installationDetailsForm = false; - $scope.DomainCreateForm = true; - $scope.installationProgress = true; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = true; - $scope.goBackDisable = true; - $scope.DomainCreateForm = 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.domainLoading = 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.domainLoading = true; - $scope.installationDetailsForm = true; - $scope.DomainCreateForm = 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 { - $("#installProgress").css("width", response.data.installationProgress + "%"); - $scope.installPercentage = response.data.installationProgress; - $scope.currentStatus = response.data.currentStatus; - $timeout(getCreationStatus, 1000); - } - - } - - function cantLoadInitialDatas(response) { - - $scope.domainLoading = true; - $scope.installationDetailsForm = true; - $scope.DomainCreateForm = true; - $scope.installationProgress = false; - $scope.errorMessageBox = true; - $scope.success = true; - $scope.couldNotConnect = false; - $scope.goBackDisable = false; - - } - - - } - - - ////// List Domains Part - - //////////////////////// - - // notifcations - - $scope.phpChanged = true; - $scope.domainError = true; - $scope.couldNotConnect = true; - $scope.domainDeleted = true; - $scope.sslIssued = true; - $scope.childBaseDirChanged = true; - - $("#listDomains").hide(); - - - $scope.showListDomains = function () { - fetchDomains(); - $("#listDomains").fadeIn(); - }; - - $scope.hideListDomains = function () { - $("#listDomains").fadeOut(); - }; - - function fetchDomains() { - $scope.domainLoading = false; - - var url = "/websites/fetchDomains"; - - var data = { - masterDomain: $("#domainNamePage").text(), - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.fetchStatus === 1) { - - $scope.childDomains = JSON.parse(response.data.data); - $scope.domainLoading = true; - - - } else { - $scope.domainError = false; - $scope.errorMessage = response.data.error_message; - $scope.domainLoading = true; - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.couldNotConnect = false; - - } - - } - - $scope.changePHP = function (childDomain, phpSelection) { - - // notifcations - - $scope.phpChanged = true; - $scope.domainError = true; - $scope.couldNotConnect = true; - $scope.domainDeleted = true; - $scope.sslIssued = true; - $scope.domainLoading = false; - $scope.childBaseDirChanged = true; - - var url = "/websites/changePHP"; - - var data = { - childDomain: childDomain, - phpSelection: phpSelection, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.changePHP === 1) { - - $scope.domainLoading = true; - - $scope.changedPHPVersion = phpSelection; - - - // notifcations - - $scope.phpChanged = false; - $scope.domainError = true; - $scope.couldNotConnect = true; - $scope.domainDeleted = true; - $scope.sslIssued = true; - $scope.childBaseDirChanged = true; - - - } else { - $scope.errorMessage = response.data.error_message; - $scope.domainLoading = true; - - // notifcations - - $scope.phpChanged = true; - $scope.domainError = false; - $scope.couldNotConnect = true; - $scope.domainDeleted = true; - $scope.sslIssued = true; - $scope.childBaseDirChanged = true; - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.domainLoading = true; - - // notifcations - - $scope.phpChanged = true; - $scope.domainError = false; - $scope.couldNotConnect = true; - $scope.domainDeleted = true; - $scope.sslIssued = true; - $scope.childBaseDirChanged = true; - - } - - }; - - $scope.changeChildBaseDir = function (childDomain, openBasedirValue) { - - // notifcations - - $scope.phpChanged = true; - $scope.domainError = true; - $scope.couldNotConnect = true; - $scope.domainDeleted = true; - $scope.sslIssued = true; - $scope.domainLoading = false; - $scope.childBaseDirChanged = true; - - - var url = "/websites/changeOpenBasedir"; - - var data = { - domainName: childDomain, - openBasedirValue: openBasedirValue - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.changeOpenBasedir === 1) { - - $scope.phpChanged = true; - $scope.domainError = true; - $scope.couldNotConnect = true; - $scope.domainDeleted = true; - $scope.sslIssued = true; - $scope.domainLoading = true; - $scope.childBaseDirChanged = false; - - } else { - - $scope.phpChanged = true; - $scope.domainError = false; - $scope.couldNotConnect = true; - $scope.domainDeleted = true; - $scope.sslIssued = true; - $scope.domainLoading = true; - $scope.childBaseDirChanged = true; - - $scope.errorMessage = response.data.error_message; - - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.phpChanged = true; - $scope.domainError = true; - $scope.couldNotConnect = false; - $scope.domainDeleted = true; - $scope.sslIssued = true; - $scope.domainLoading = true; - $scope.childBaseDirChanged = true; - - - } - - } - - $scope.deleteChildDomain = function (childDomain) { - $scope.domainLoading = false; - - // notifcations - - $scope.phpChanged = true; - $scope.domainError = true; - $scope.couldNotConnect = true; - $scope.domainDeleted = true; - $scope.sslIssued = true; - - url = "/websites/submitDomainDeletion"; - - var data = { - websiteName: childDomain, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.websiteDeleteStatus === 1) { - - $scope.domainLoading = true; - $scope.deletedDomain = childDomain; - - fetchDomains(); - - - // notifications - - $scope.phpChanged = true; - $scope.domainError = true; - $scope.couldNotConnect = true; - $scope.domainDeleted = false; - $scope.sslIssued = true; - - - } else { - $scope.errorMessage = response.data.error_message; - $scope.domainLoading = true; - - // notifcations - - $scope.phpChanged = true; - $scope.domainError = false; - $scope.couldNotConnect = true; - $scope.domainDeleted = true; - $scope.sslIssued = true; - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.domainLoading = true; - - // notifcations - - $scope.phpChanged = true; - $scope.domainError = true; - $scope.couldNotConnect = false; - $scope.domainDeleted = true; - $scope.sslIssued = true; - - } - - }; - - $scope.issueSSL = function (childDomain, path) { - $scope.domainLoading = false; - - // notifcations - - $scope.phpChanged = true; - $scope.domainError = true; - $scope.couldNotConnect = true; - $scope.domainDeleted = true; - $scope.sslIssued = true; - $scope.childBaseDirChanged = true; - - var url = "/manageSSL/issueSSL"; - - - var data = { - virtualHost: childDomain, - path: path, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.SSL === 1) { - - $scope.domainLoading = true; - - // notifcations - - $scope.phpChanged = true; - $scope.domainError = true; - $scope.couldNotConnect = true; - $scope.domainDeleted = true; - $scope.sslIssued = false; - $scope.childBaseDirChanged = true; - - - $scope.sslDomainIssued = childDomain; - - - } else { - $scope.domainLoading = true; - - $scope.errorMessage = response.data.error_message; - - // notifcations - - $scope.phpChanged = true; - $scope.domainError = false; - $scope.couldNotConnect = true; - $scope.domainDeleted = true; - $scope.sslIssued = true; - $scope.childBaseDirChanged = true; - - } - - - } - - function cantLoadInitialDatas(response) { - - // notifcations - - $scope.phpChanged = true; - $scope.domainError = true; - $scope.couldNotConnect = false; - $scope.domainDeleted = true; - $scope.sslIssued = true; - $scope.childBaseDirChanged = true; - - - } - - - }; - - - /// Open_basedir protection - - $scope.baseDirLoading = true; - $scope.operationFailed = true; - $scope.operationSuccessfull = true; - $scope.couldNotConnect = true; - $scope.openBaseDirBox = true; - - - $scope.openBaseDirView = function () { - $scope.openBaseDirBox = false; - }; - - $scope.hideOpenBasedir = function () { - $scope.openBaseDirBox = true; - }; - - $scope.applyOpenBasedirChanges = function (childDomain, phpSelection) { - - // notifcations - - $scope.baseDirLoading = false; - $scope.operationFailed = true; - $scope.operationSuccessfull = true; - $scope.couldNotConnect = true; - $scope.openBaseDirBox = false; - - - var url = "/websites/changeOpenBasedir"; - - var data = { - domainName: $("#domainNamePage").text(), - openBasedirValue: $scope.openBasedirValue - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.changeOpenBasedir === 1) { - - $scope.baseDirLoading = true; - $scope.operationFailed = true; - $scope.operationSuccessfull = false; - $scope.couldNotConnect = true; - $scope.openBaseDirBox = false; - - } else { - - $scope.baseDirLoading = true; - $scope.operationFailed = false; - $scope.operationSuccessfull = true; - $scope.couldNotConnect = true; - $scope.openBaseDirBox = false; + $scope.openBaseDirChanged = false; $scope.errorMessage = response.data.error_message; @@ -12094,87 +13111,150 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind } $scope.showWPSites = function(domain) { + console.log('showWPSites called for domain:', domain); + + // Make sure domain is defined + if (!domain) { + console.error('Domain is undefined'); + return; + } + + // Find the website in the list + var site = $scope.WebSitesList.find(function(website) { + return website.domain === domain; + }); + + if (!site) { + console.error('Website not found:', domain); + return; + } + + // Set loading state + site.loadingWPSites = true; + + // Toggle visibility + site.showWPSites = !site.showWPSites; + + // If we're hiding, just return + if (!site.showWPSites) { + site.loadingWPSites = false; + return; + } + var config = { headers: { + 'Content-Type': 'application/x-www-form-urlencoded', 'X-CSRFToken': getCookie('csrftoken') } }; - var data = { + var data = $.param({ domain: domain - }; + }); - var url = '/websites/GetWPSitesByDomain'; - - $http.post(url, data, config).then(function(response) { - if (response.data.status === 1) { - // Find the website in the list and update its WordPress sites - for (var i = 0; i < $scope.WebSitesList.length; i++) { - if ($scope.WebSitesList[i].domain === domain) { - $scope.WebSitesList[i].wp_sites = response.data.data; - $scope.WebSitesList[i].showWPSites = !$scope.WebSitesList[i].showWPSites; - break; - } + $http.post('/websites/fetchWPDetails', data, config) + .then(function(response) { + console.log('Response received:', response); + if (response.data.status === 1 && response.data.fetchStatus === 1) { + site.wp_sites = response.data.sites || []; + // Initialize loading states for each WP site + site.wp_sites.forEach(function(wp) { + wp.loading = false; + wp.loadingPlugins = false; + wp.loadingTheme = false; + }); + $("#listFail").hide(); + } else { + $("#listFail").fadeIn(); + site.showWPSites = false; + $scope.errorMessage = response.data.error_message || 'Failed to fetch WordPress sites'; + console.error('Error in response:', response.data.error_message); + new PNotify({ + title: 'Error!', + text: response.data.error_message || 'Failed to fetch WordPress sites', + type: 'error' + }); } - } else { - console.error('Error fetching WordPress sites:', response.data.error_message); + }) + .catch(function(error) { + console.error('Request failed:', error); + site.showWPSites = false; + $("#listFail").fadeIn(); + $scope.errorMessage = error.message || 'An error occurred while fetching WordPress sites'; new PNotify({ title: 'Error!', - text: response.data.error_message, + text: error.message || 'Could not connect to server', type: 'error' }); - } - }, function(error) { - console.error('Error fetching WordPress sites:', error); - new PNotify({ - title: 'Error!', - text: 'Failed to fetch WordPress sites. Please try again.', - type: 'error' + }) + .finally(function() { + site.loadingWPSites = false; }); - }); }; - $scope.updateSetting = function(wpId, setting, value) { + $scope.updateSetting = function(wp, setting) { + var settingMap = { + 'search-indexing': 'searchIndex', + 'debugging': 'debugging', + 'password-protection': 'passwordProtection', + 'maintenance-mode': 'maintenanceMode' + }; + + // Toggle the state before sending request + wp[settingMap[setting]] = wp[settingMap[setting]] === 1 ? 0 : 1; + + var data = { + siteId: wp.id, + setting: setting, + value: wp[settingMap[setting]] + }; + var config = { headers: { 'X-CSRFToken': getCookie('csrftoken') } }; - var data = { - siteId: wpId, - setting: setting, - value: value - }; - - var url = '/websites/UpdateWPSettings'; - - $http.post(url, data, config).then(function(response) { + $http.post('/websites/UpdateWPSettings', data, config).then(function(response) { if (response.data.status === 1) { new PNotify({ - title: 'Success!', + title: 'Success', text: 'Setting updated successfully.', type: 'success' }); + if (setting === 'password-protection' && wp[settingMap[setting]] === 1) { + // Show password protection modal if enabling + wp.PPUsername = ""; + wp.PPPassword = ""; + $scope.currentWP = wp; + $('#passwordProtectionModal').modal('show'); + } } else { - console.error('Error updating setting:', response.data.error_message); + // Revert the change if update failed + wp[settingMap[setting]] = wp[settingMap[setting]] === 1 ? 0 : 1; new PNotify({ - title: 'Error!', - text: response.data.error_message, + title: 'Error', + text: response.data.error_message || 'Failed to update setting.', type: 'error' }); } - }, function(error) { - console.error('Error updating setting:', error); + }).catch(function(error) { + // Revert the change on error + wp[settingMap[setting]] = wp[settingMap[setting]] === 1 ? 0 : 1; new PNotify({ - title: 'Error!', - text: 'Failed to update setting. Please try again.', + title: 'Error', + text: 'Connection failed while updating setting.', type: 'error' }); }); }; - $scope.visitSite = function(url) { + $scope.visitSite = function(wp) { + var url = wp.url || wp.domain; + if (!url) return; + if (!url.startsWith('http://') && !url.startsWith('https://')) { + url = 'https://' + url; + } window.open(url, '_blank'); }; @@ -12186,15 +13266,20 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind window.location.href = '/websites/listWPsites?wpID=' + wpId; }; - $scope.cyberPanelLoading = true; + $scope.saveRewriteRules = function () { - $scope.issueSSL = function (virtualHost) { - $scope.cyberPanelLoading = false; + $scope.configFileLoading = false; + + + url = "/websites/saveRewriteRules"; + + var virtualHost = $("#childDomain").text(); + var rewriteRules = $scope.rewriteRules; - url = "/websites/issueSSL"; var data = { - virtualHost: virtualHost + virtualHost: virtualHost, + rewriteRules: rewriteRules, }; var config = { @@ -12205,34 +13290,69 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + function ListInitialDatas(response) { - if (response.data.status === 1) { - $scope.cyberPanelLoading = true; - $scope.sslIssued = false; - $scope.couldNotIssueSSL = true; - $scope.couldNotConnect = true; + + if (response.data.rewriteStatus == 1) { + + $scope.configurationsBoxRewrite = false; + $scope.rewriteRulesFetched = true; + $scope.couldNotFetchRewriteRules = true; + $scope.rewriteRulesSaved = false; + $scope.couldNotSaveRewriteRules = true; + $scope.fetchedRewriteRules = true; + $scope.saveRewriteRulesBTN = true; + $scope.configFileLoading = true; + + } else { - $scope.cyberPanelLoading = true; - $scope.sslIssued = true; - $scope.couldNotIssueSSL = false; - $scope.couldNotConnect = true; + $scope.configurationsBoxRewrite = false; + $scope.rewriteRulesFetched = false; + $scope.couldNotFetchRewriteRules = true; + $scope.rewriteRulesSaved = true; + $scope.couldNotSaveRewriteRules = false; + $scope.fetchedRewriteRules = true; + $scope.saveRewriteRulesBTN = false; + + $scope.configFileLoading = true; + + $scope.errorMessage = response.data.error_message; + } + + } function cantLoadInitialDatas(response) { - $scope.cyberPanelLoading = true; - $scope.sslIssued = true; - $scope.couldNotIssueSSL = true; + + $scope.configurationsBoxRewrite = false; + $scope.rewriteRulesFetched = false; + $scope.couldNotFetchRewriteRules = true; + $scope.rewriteRulesSaved = true; + $scope.couldNotSaveRewriteRules = true; + $scope.fetchedRewriteRules = true; + $scope.saveRewriteRulesBTN = false; + + $scope.configFileLoading = true; + $scope.couldNotConnect = false; + + } + + }; + + //////// SSL Part + $scope.sslSaved = true; $scope.couldNotSaveSSL = true; $scope.hidsslconfigs = true; $scope.couldNotConnect = true; + $scope.hidesslbtn = function () { $scope.hidsslconfigs = true; }; @@ -12244,7 +13364,10 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind $scope.changePHPView = true; }; + $scope.saveSSL = function () { + + $scope.configFileLoading = false; url = "/websites/saveSSL"; @@ -12253,6 +13376,7 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind var cert = $scope.cert; var key = $scope.key; + var data = { virtualHost: virtualHost, cert: cert, @@ -12267,34 +13391,53 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + function ListInitialDatas(response) { + if (response.data.sslStatus === 1) { + $scope.sslSaved = false; $scope.couldNotSaveSSL = true; $scope.couldNotConnect = true; $scope.configFileLoading = true; + + } else { + $scope.sslSaved = true; $scope.couldNotSaveSSL = false; $scope.couldNotConnect = true; $scope.configFileLoading = true; + $scope.errorMessage = response.data.error_message; + } + + } function cantLoadInitialDatas(response) { + $scope.sslSaved = true; $scope.couldNotSaveSSL = true; $scope.couldNotConnect = false; $scope.configFileLoading = true; + + } + }; + + //// Change PHP Master + $scope.failedToChangePHPMaster = true; $scope.phpChangedMaster = true; $scope.couldNotConnect = true; + $scope.changePHPView = true; + $scope.hideChangePHPMaster = function () { $scope.changePHPView = true; }; @@ -12306,7 +13449,11 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind $scope.changePHPView = false; }; + $scope.changePHPVersionMaster = function (childDomain, phpSelection) { + + // notifcations + $scope.configFileLoading = false; var url = "/websites/changePHP"; @@ -12324,36 +13471,63 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + function ListInitialDatas(response) { + + if (response.data.changePHP === 1) { + $scope.configFileLoading = true; $scope.websiteDomain = $("#childDomain").text(); + + + // notifcations + $scope.failedToChangePHPMaster = true; $scope.phpChangedMaster = false; $scope.couldNotConnect = true; + + } else { + $scope.configFileLoading = true; $scope.errorMessage = response.data.error_message; + + // notifcations + $scope.failedToChangePHPMaster = false; $scope.phpChangedMaster = true; $scope.couldNotConnect = true; + } + + } function cantLoadInitialDatas(response) { + $scope.configFileLoading = true; + + // notifcations + $scope.failedToChangePHPMaster = true; $scope.phpChangedMaster = true; $scope.couldNotConnect = false; + } + }; + + /// Open_basedir protection + $scope.baseDirLoading = true; $scope.operationFailed = true; $scope.operationSuccessfull = true; $scope.couldNotConnect = true; $scope.openBaseDirBox = true; + $scope.openBaseDirView = function () { $scope.openBaseDirBox = false; }; @@ -12363,12 +13537,16 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind }; $scope.applyOpenBasedirChanges = function (childDomain, phpSelection) { + + // notifcations + $scope.baseDirLoading = false; $scope.operationFailed = true; $scope.operationSuccessfull = true; $scope.couldNotConnect = true; $scope.openBaseDirBox = false; + var url = "/websites/changeOpenBasedir"; var data = { @@ -12384,36 +13562,52 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + function ListInitialDatas(response) { + + if (response.data.changeOpenBasedir === 1) { + $scope.baseDirLoading = true; $scope.operationFailed = true; $scope.operationSuccessfull = false; $scope.couldNotConnect = true; $scope.openBaseDirBox = false; + } else { + $scope.baseDirLoading = true; $scope.operationFailed = false; $scope.operationSuccessfull = true; $scope.couldNotConnect = true; $scope.openBaseDirBox = false; + $scope.errorMessage = response.data.error_message; + } + + } function cantLoadInitialDatas(response) { + $scope.baseDirLoading = true; $scope.operationFailed = true; $scope.operationSuccessfull = true; $scope.couldNotConnect = false; $scope.openBaseDirBox = false; + + } + } + }); /* Application Installer */ app.controller('installWordPressCTRL', function ($scope, $http, $timeout) { + $scope.installationDetailsForm = false; $scope.installationProgress = true; $scope.installationFailed = true; @@ -12426,6 +13620,7 @@ app.controller('installWordPressCTRL', function ($scope, $http, $timeout) { var domain = $("#domainNamePage").text(); var path; + $scope.goBack = function () { $scope.installationDetailsForm = false; $scope.installationProgress = true; @@ -12438,6 +13633,7 @@ app.controller('installWordPressCTRL', function ($scope, $http, $timeout) { }; $scope.installWordPress = function () { + $scope.installationDetailsForm = true; $scope.installationProgress = false; $scope.installationFailed = true; @@ -12449,6 +13645,7 @@ app.controller('installWordPressCTRL', function ($scope, $http, $timeout) { path = $scope.installPath; + url = "/websites/installWordpress"; var home = "1"; @@ -12457,6 +13654,7 @@ app.controller('installWordPressCTRL', function ($scope, $http, $timeout) { home = "0"; } + var data = { domain: domain, home: home, @@ -12475,11 +13673,14 @@ app.controller('installWordPressCTRL', function ($scope, $http, $timeout) { $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + function ListInitialDatas(response) { + if (response.data.installStatus === 1) { statusFile = response.data.tempStatusPath; getInstallStatus(); } else { + $scope.installationDetailsForm = true; $scope.installationProgress = false; $scope.installationFailed = false; @@ -12487,15 +13688,23 @@ app.controller('installWordPressCTRL', function ($scope, $http, $timeout) { $scope.couldNotConnect = true; $scope.wpInstallLoading = true; $scope.goBackDisable = false; + $scope.errorMessage = response.data.error_message; + } + + } function cantLoadInitialDatas(response) { + + } + }; function getInstallStatus() { + url = "/websites/installWordpressStatus"; var data = { @@ -12509,11 +13718,17 @@ app.controller('installWordPressCTRL', function ($scope, $http, $timeout) { } }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + function ListInitialDatas(response) { + + if (response.data.abort === 1) { + if (response.data.installStatus === 1) { + $scope.installationDetailsForm = true; $scope.installationProgress = false; $scope.installationFailed = true; @@ -12528,11 +13743,14 @@ app.controller('installWordPressCTRL', function ($scope, $http, $timeout) { $scope.installationURL = domain; } + $("#installProgress").css("width", "100%"); $scope.installPercentage = "100"; $scope.currentStatus = response.data.currentStatus; $timeout.cancel(); + } else { + $scope.installationDetailsForm = true; $scope.installationProgress = false; $scope.installationFailed = false; @@ -12545,21 +13763,33 @@ app.controller('installWordPressCTRL', function ($scope, $http, $timeout) { $("#installProgress").css("width", "0%"); $scope.installPercentage = "0"; + } + } else { $("#installProgress").css("width", response.data.installationProgress + "%"); $scope.installPercentage = response.data.installationProgress; $scope.currentStatus = response.data.currentStatus; $timeout(getInstallStatus, 1000); + + } + } function cantLoadInitialDatas(response) { + $scope.canNotFetch = true; $scope.couldNotConnect = false; + + } + + } + + }); app.controller('installJoomlaCTRL', function ($scope, $http, $timeout) { @@ -13305,8 +14535,8 @@ app.controller('installMauticCTRL', function ($scope, $http, $timeout) { $scope.installationDetailsForm = true; $scope.installationProgress = false; - $scope.installationFailed = false; - $scope.installationSuccessfull = true; + $scope.installationFailed = true; + $scope.installationSuccessfull = false; $scope.couldNotConnect = true; $scope.wpInstallLoading = true; $scope.goBackDisable = false; @@ -13804,350 +15034,6 @@ app.controller('cloneWebsite', function ($scope, $http, $timeout, $window) { }); /* Java script code to cloneWebsite ends here */ - -/* Java script code to syncWebsite */ -app.controller('syncWebsite', function ($scope, $http, $timeout, $window) { - - $scope.cyberpanelLoading = true; - $scope.installationDetailsForm = false; - $scope.installationProgress = true; - $scope.goBackDisable = true; - - var statusFile; - - $scope.startSyncing = function () { - - $scope.cyberpanelLoading = false; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.goBackDisable = true; - - $scope.currentStatus = "Cloning started.."; - - url = "/websites/startSync"; - - - var data = { - childDomain: $("#childDomain").text(), - eraseCheck: $scope.eraseCheck, - dbCheck: $scope.dbCheck, - copyChanged: $scope.copyChanged - - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - function ListInitialDatas(response) { - - if (response.data.status === 1) { - statusFile = response.data.tempStatusPath; - getCreationStatus(); - } else { - - $scope.cyberpanelLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.goBackDisable = false; - - $scope.currentStatus = response.data.error_message; - } - - - } - - function cantLoadInitialDatas(response) { - - $scope.cyberpanelLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.goBackDisable = false; - - } - - }; - $scope.goBack = function () { - $scope.cyberpanelLoading = true; - $scope.installationDetailsForm = false; - $scope.installationProgress = 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.cyberpanelLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.goBackDisable = false; - - $("#installProgress").css("width", "100%"); - $scope.installPercentage = "100"; - $scope.currentStatus = response.data.currentStatus; - $timeout.cancel(); - - } else { - - $scope.cyberpanelLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.goBackDisable = false; - - $scope.currentStatus = response.data.error_message; - - $("#installProgress").css("width", "0%"); - $scope.installPercentage = "0"; - $scope.goBackDisable = false; - - } - - } else { - $("#installProgress").css("width", response.data.installationProgress + "%"); - $scope.installPercentage = response.data.installationProgress; - $scope.currentStatus = response.data.currentStatus; - $timeout(getCreationStatus, 1000); - } - - } - - function cantLoadInitialDatas(response) { - - $scope.cyberpanelLoading = true; - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.goBackDisable = false; - - } - - - } - -}); -/* Java script code to syncWebsite ends here */ - - -app.controller('installMagentoCTRL', function ($scope, $http, $timeout) { - - $scope.installationDetailsForm = false; - $scope.installationProgress = true; - $scope.installationFailed = true; - $scope.installationSuccessfull = true; - $scope.couldNotConnect = true; - $scope.wpInstallLoading = true; - $scope.goBackDisable = true; - - $scope.databasePrefix = 'ps_'; - - var statusFile; - var domain = $("#domainNamePage").text(); - var path; - - - $scope.goBack = function () { - $scope.installationDetailsForm = false; - $scope.installationProgress = true; - $scope.installationFailed = true; - $scope.installationSuccessfull = true; - $scope.couldNotConnect = true; - $scope.wpInstallLoading = true; - $scope.goBackDisable = true; - $("#installProgress").css("width", "0%"); - }; - - function getInstallStatus() { - - url = "/websites/installWordpressStatus"; - - var data = { - statusFile: statusFile, - domainName: domain - }; - - 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.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.installationFailed = true; - $scope.installationSuccessfull = false; - $scope.couldNotConnect = true; - $scope.wpInstallLoading = true; - $scope.goBackDisable = false; - - if (typeof path !== 'undefined') { - $scope.installationURL = "http://" + domain + "/" + path; - } else { - $scope.installationURL = domain; - } - - - $("#installProgress").css("width", "100%"); - $scope.installPercentage = "100"; - $scope.currentStatus = response.data.currentStatus; - $timeout.cancel(); - - } else { - - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.installationFailed = false; - $scope.installationSuccessfull = true; - $scope.couldNotConnect = true; - $scope.wpInstallLoading = true; - $scope.goBackDisable = false; - - $scope.errorMessage = response.data.error_message; - - $("#installProgress").css("width", "0%"); - $scope.installPercentage = "0"; - - } - - } else { - $("#installProgress").css("width", response.data.installationProgress + "%"); - $scope.installPercentage = response.data.installationProgress; - $scope.currentStatus = response.data.currentStatus; - - $timeout(getInstallStatus, 1000); - - - } - - } - - function cantLoadInitialDatas(response) { - - $scope.canNotFetch = true; - $scope.couldNotConnect = false; - - - } - - - } - - $scope.installMagento = function () { - - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.installationFailed = true; - $scope.installationSuccessfull = true; - $scope.couldNotConnect = true; - $scope.wpInstallLoading = false; - $scope.goBackDisable = true; - $scope.currentStatus = "Starting installation.."; - - path = $scope.installPath; - - - url = "/websites/magentoInstall"; - - var home = "1"; - - if (typeof path !== 'undefined') { - home = "0"; - } - var sampleData; - if ($scope.sampleData === true) { - sampleData = 1; - } else { - sampleData = 0 - } - - - var data = { - domain: domain, - home: home, - path: path, - firstName: $scope.firstName, - lastName: $scope.lastName, - username: $scope.username, - email: $scope.email, - passwordByPass: $scope.password, - sampleData: sampleData - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - if (response.data.installStatus === 1) { - statusFile = response.data.tempStatusPath; - getInstallStatus(); - } else { - - $scope.installationDetailsForm = true; - $scope.installationProgress = false; - $scope.installationFailed = false; - $scope.installationSuccessfull = true; - $scope.couldNotConnect = true; - $scope.wpInstallLoading = true; - $scope.goBackDisable = false; - - $scope.errorMessage = response.data.error_message; - - } - - - } - - function cantLoadInitialDatas(response) { - } - - }; - - -}); - /* Java script code to git tracking */ app.controller('manageGIT', function ($scope, $http, $timeout, $window) { @@ -14748,108 +15634,16 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) { } }; - $scope.showWPSites = function(domain) { - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + $scope.fetchGitignore = function () { + + $scope.cyberpanelLoading = false; + + url = "/websites/fetchGitignore"; + var data = { - domain: domain - }; - - var url = '/websites/GetWPSitesByDomain'; - - $http.post(url, data, config).then(function(response) { - if (response.data.status === 1) { - // Find the website in the list and update its WordPress sites - for (var i = 0; i < $scope.WebSitesList.length; i++) { - if ($scope.WebSitesList[i].domain === domain) { - $scope.WebSitesList[i].wp_sites = response.data.data; - $scope.WebSitesList[i].showWPSites = !$scope.WebSitesList[i].showWPSites; - break; - } - } - } else { - console.error('Error fetching WordPress sites:', response.data.error_message); - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type: 'error' - }); - } - }, function(error) { - console.error('Error fetching WordPress sites:', error); - new PNotify({ - title: 'Error!', - text: 'Failed to fetch WordPress sites. Please try again.', - type: 'error' - }); - }); - }; - - $scope.updateSetting = function(wpId, setting, value) { - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - var data = { - siteId: wpId, - setting: setting, - value: value - }; - - var url = '/websites/UpdateWPSettings'; - - $http.post(url, data, config).then(function(response) { - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Setting updated successfully.', - type: 'success' - }); - } else { - console.error('Error updating setting:', response.data.error_message); - new PNotify({ - title: 'Error!', - text: response.data.error_message, - type: 'error' - }); - } - }, function(error) { - console.error('Error updating setting:', error); - new PNotify({ - title: 'Error!', - text: 'Failed to update setting. Please try again.', - type: 'error' - }); - }); - }; - - $scope.visitSite = function(url) { - window.open(url, '_blank'); - }; - - $scope.wpLogin = function(wpId) { - window.open('/websites/wpLogin?wpID=' + wpId, '_blank'); - }; - - $scope.manageWP = function(wpId) { - window.location.href = '/websites/listWPsites?wpID=' + wpId; - }; - - $scope.cyberPanelLoading = true; - - $scope.issueSSL = function (virtualHost) { - $scope.cyberPanelLoading = false; - - url = "/websites/issueSSL"; - - var data = { - virtualHost: virtualHost + domain: $("#domain").text(), + folder: $scope.folder }; var config = { @@ -14861,65 +15655,1051 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) { $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); function ListInitialDatas(response) { - $scope.cyberPanelLoading = true; + $scope.cyberpanelLoading = true; if (response.data.status === 1) { - $scope.sslIssued = false; - $scope.couldNotIssueSSL = true; - $scope.couldNotConnect = true; + new PNotify({ + title: 'Success', + text: 'Successfully fetched.', + type: 'success' + }); + $scope.gitIgnoreContent = response.data.gitIgnoreContent; } else { - $scope.sslIssued = true; - $scope.couldNotIssueSSL = false; - $scope.couldNotConnect = true; - $scope.errorMessage = response.data.error_message; + 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.saveGitIgnore = function () { + + $scope.cyberpanelLoading = false; + + url = "/websites/saveGitIgnore"; + + + var data = { + domain: $("#domain").text(), + folder: $scope.folder, + gitIgnoreContent: $scope.gitIgnoreContent + + }; + + 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 saved.', + 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.fetchCommits = function () { + + $scope.cyberpanelLoading = false; + + url = "/websites/fetchCommits"; + + + var data = { + domain: $("#domain").text(), + folder: $scope.folder + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + $scope.gitCommitsTable = false; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Successfully fetched.', + type: 'success' + }); + $scope.commits = JSON.parse(response.data.commits); + } 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' + }); + + + } + }; + + var currentComit; + var fetchFileCheck = 0; + var initial = 1; + + $scope.fetchFiles = function (commit) { + + currentComit = commit; + $scope.cyberpanelLoading = false; + + if (initial === 1) { + initial = 0; + } else { + fetchFileCheck = 1; + } + + url = "/websites/fetchFiles"; + + + var data = { + domain: $("#domain").text(), + folder: $scope.folder, + commit: commit + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + $scope.gitCommitsTable = false; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Successfully fetched.', + type: 'success' + }); + $scope.files = response.data.files; + } 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.fileStatus = true; + + $scope.fetchChangesInFile = function () { + $scope.fileStatus = true; + + if (fetchFileCheck === 1) { + fetchFileCheck = 0; + return 0; + } + + $scope.cyberpanelLoading = false; + $scope.currentSelectedFile = $scope.changeFile; + + url = "/websites/fetchChangesInFile"; + + var data = { + domain: $("#domain").text(), + folder: $scope.folder, + file: $scope.changeFile, + commit: currentComit + }; + + 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 fetched.', + type: 'success' + }); + $scope.fileStatus = false; + document.getElementById("fileChangedContent").innerHTML = response.data.fileChangedContent; + } else { + $scope.fileStatus = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); } } function cantLoadInitialDatas(response) { - $scope.cyberPanelLoading = true; - $scope.sslIssued = true; - $scope.couldNotIssueSSL = true; - $scope.couldNotConnect = false; + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + + } }; + + $scope.saveGitConfigurations = function () { + + $scope.cyberpanelLoading = false; + + url = "/websites/saveGitConfigurations"; + + var data = { + domain: $("#domain").text(), + folder: $scope.folder, + autoCommit: $scope.autoCommit, + autoPush: $scope.autoPush, + emailLogs: $scope.emailLogs, + commands: document.getElementById("currentCommands").value, + webhookCommand: $scope.webhookCommand + }; + + if ($scope.autoCommit === undefined) { + $scope.autoCommitCurrent = 'Never'; + } else { + $scope.autoCommitCurrent = $scope.autoCommit; + } + + if ($scope.autoPush === undefined) { + $scope.autoPushCurrent = 'Never'; + } else { + $scope.autoPushCurrent = $scope.autoPush; + } + + if ($scope.emailLogs === undefined) { + $scope.emailLogsCurrent = false; + } else { + $scope.emailLogsCurrent = $scope.emailLogs; + } + + if ($scope.webhookCommand === undefined) { + $scope.webhookCommandCurrent = false; + } else { + $scope.webhookCommandCurrent = $scope.webhookCommand; + } + + 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 saved.', + 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.currentPage = 1; + $scope.recordsToShow = 10; + + $scope.fetchGitLogs = function () { + $scope.cyberpanelLoading = false; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + domain: $("#domain").text(), + folder: $scope.folder, + page: $scope.currentPage, + recordsToShow: $scope.recordsToShow + }; + + + dataurl = "/websites/fetchGitLogs"; + + $http.post(dataurl, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Successfully fetched.', + type: 'success' + }); + $scope.logs = JSON.parse(response.data.logs); + $scope.pagination = 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' + }); + + + } + + + }; + }); -/* Java script code to delete website ends here */ +/* Java script code to git tracking ends here */ -/* Java script code to modify package ends here */ -/* Java script code to suspend/un-suspend ends here */ +app.controller('ApacheManager', function ($scope, $http, $timeout) { + $scope.cyberpanelloading = true; + $scope.apacheOLS = true; + $scope.pureOLS = true; + $scope.lswsEnt = true; -/* Java script code to manage cron */ + var apache = 1, ols = 2, lsws = 3; + var statusFile; -/* Java script code to manage cron ends here */ + $scope.getSwitchStatus = function () { + $scope.cyberpanelloading = false; + url = "/websites/getSwitchStatus"; -/* Java script code to manage cron */ + var data = { + domainName: $("#domainNamePage").text() + }; -/* Java script code to syncWebsite ends here */ + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; -/* Application Installer */ + $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); -app.controller('installWordPressCTRL', function ($scope, $http, $timeout) { + + function ListInitialData(response) { + $scope.cyberpanelloading = true; + if (response.data.status === 1) { + if (response.data.server === apache) { + $scope.apacheOLS = false; + $scope.pureOLS = true; + $scope.lswsEnt = true; + $scope.configData = response.data.configData; + + $scope.pmMaxChildren = response.data.pmMaxChildren; + $scope.pmStartServers = response.data.pmStartServers; + $scope.pmMinSpareServers = response.data.pmMinSpareServers; + $scope.pmMaxSpareServers = response.data.pmMaxSpareServers; + $scope.phpPath = response.data.phpPath; + + + } else if (response.data.server === ols) { + $scope.apacheOLS = true; + $scope.pureOLS = false; + $scope.lswsEnt = true; + } else { + $scope.apacheOLS = true; + $scope.pureOLS = true; + $scope.lswsEnt = false; + } + //$scope.records = JSON.parse(response.data.data); + } 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.getSwitchStatus(); + + $scope.switchServer = function (server) { + $scope.cyberpanelloading = false; + $scope.functionProgress = {"width": "0%"}; + $scope.functionStatus = 'Starting conversion..'; + + url = "/websites/switchServer"; + + var data = { + domainName: $("#domainNamePage").text(), + phpSelection: $scope.phpSelection, + server: server + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); + + function ListInitialData(response) { + if (response.data.status === 1) { + statusFile = response.data.tempStatusPath; + statusFunc(); + + } else { + $scope.cyberpanelloading = true; + 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' + }); + } + + + }; + + function statusFunc() { + $scope.cyberpanelloading = false; + url = "/websites/statusFunc"; + + var data = { + statusFile: statusFile + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); + + + function ListInitialData(response) { + if (response.data.status === 1) { + if (response.data.abort === 1) { + $scope.functionProgress = {"width": "100%"}; + $scope.functionStatus = response.data.currentStatus; + $scope.cyberpanelloading = true; + $timeout.cancel(); + $scope.getSwitchStatus(); + } else { + $scope.functionProgress = {"width": response.data.installationProgress + "%"}; + $scope.functionStatus = response.data.currentStatus; + $timeout(statusFunc, 3000); + } + + } else { + $scope.cyberpanelloading = true; + $scope.functionStatus = response.data.error_message; + $scope.functionProgress = {"width": response.data.installationProgress + "%"}; + $timeout.cancel(); + } + + } + + function cantLoadInitialData(response) { + $scope.functionProgress = {"width": response.data.installationProgress + "%"}; + $scope.functionStatus = 'Could not connect to server, please refresh this page.'; + $timeout.cancel(); + } + + } + + + $scope.tuneSettings = function () { + $scope.cyberpanelloading = false; + + url = "/websites/tuneSettings"; + + var data = { + domainName: $("#domainNamePage").text(), + pmMaxChildren: $scope.pmMaxChildren, + pmStartServers: $scope.pmStartServers, + pmMinSpareServers: $scope.pmMinSpareServers, + pmMaxSpareServers: $scope.pmMaxSpareServers, + phpPath: $scope.phpPath + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, 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' + }); + + } else { + $scope.cyberpanelloading = true; + 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.saveApacheConfig = function () { + $scope.cyberpanelloading = false; + + url = "/websites/saveApacheConfigsToFile"; + + var data = { + domainName: $("#domainNamePage").text(), + configData: $scope.configData + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, 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' + }); + + } else { + $scope.cyberpanelloading = true; + 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' + }); + } + + + }; + +}); + + +app.controller('createDockerPackage', function ($scope, $http, $window) { + $scope.cyberpanelLoading = true; + + $scope.createdockerpackage = function () { + + $scope.cyberpanelLoading = false; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + name: $scope.packagesname, + cpu: $scope.CPU, + Memory: $scope.Memory, + Bandwidth: $scope.Bandwidth, + disk: $scope.disk + }; + + + dataurl = "/websites/AddDockerpackage"; + + $http.post(dataurl, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Successfully Saved.', + 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.Getpackage = function (packid) { + + $scope.cyberpanelLoading = false; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + id: packid, + }; + + + dataurl = "/websites/Getpackage"; + + $http.post(dataurl, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + $scope.U_Name = response.data.error_message.obj.Name + $scope.U_CPU = response.data.error_message.obj.CPU + $scope.U_Memory = response.data.error_message.obj.Memory + $scope.U_Bandwidth = response.data.error_message.obj.Bandwidth + $scope.U_DiskSpace = response.data.error_message.obj.DiskSpace + + $scope.EidtID = packid; + + } 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.SaveUpdate = function () { + + $scope.cyberpanelLoading = false; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + id: $scope.EidtID, + CPU: $scope.U_CPU, + RAM: $scope.U_Memory, + Bandwidth: $scope.U_Bandwidth, + DiskSpace: $scope.U_DiskSpace, + }; + + + dataurl = "/websites/Updatepackage"; + + $http.post(dataurl, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Successfully Updated.', + 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' + }); + + + } + } + + var FinalDeletepackageURL; + $scope.Deletepackage = function (url) { + FinalDeletepackageURL = url; + // console.log(FinalDeletepackageURL); + } + + $scope.ConfirmDelete = function () { + window.location.href = FinalDeletepackageURL + } + +}) +app.controller('AssignPackage', function ($scope, $http,) { + $scope.cyberpanelLoading = true; + $scope.AddAssignment = function () { + $scope.cyberpanelLoading = false; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + package: $('#packageSelection').val(), + user: $scope.userSelection, + }; + + + dataurl = "/websites/AddAssignment"; + + $http.post(dataurl, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Successfully saved.', + 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' + }); + + + } + } + + var FinalDeletepackageURL; + $scope.Deleteassingment = function (url) { + FinalDeletepackageURL = url; + // console.log(FinalDeletepackageURL); + } + + $scope.ConfirmDelete = function () { + window.location.href = FinalDeletepackageURL + } + +}) +app.controller('createDockerSite', function ($scope, $http, $timeout) { + $scope.cyberpanelLoading = true; $scope.installationDetailsForm = false; $scope.installationProgress = true; - $scope.installationFailed = true; - $scope.installationSuccessfull = true; + $scope.errorMessageBox = true; + $scope.success = true; $scope.couldNotConnect = true; - $scope.wpInstallLoading = true; $scope.goBackDisable = true; var statusFile; - var domain = $("#domainNamePage").text(); - var path; + $scope.createdockersite = function () { + + $scope.cyberpanelLoading = false; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + + $scope.currentStatus = "Starting creation.."; + + + url = "/websites/submitDockerSiteCreation"; + + var package = $scope.packageForWebsite; + + + var data = { + sitename: $scope.siteName, + Owner: $scope.userSelection, + Domain: $scope.domainNameCreate, + MysqlCPU: $scope.CPUMysql, + MYsqlRam: $scope.rammysql, + SiteCPU: $scope.CPUSite, + SiteRam: $scope.RamSite, + App: $scope.App, + WPusername: $scope.WPUsername, + WPemal: $scope.wpEmail, + WPpasswd: $scope.WPpassword + }; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + console.log('.........................') + if (response.data.installStatus === 1) { + console.log(response.data.installsatus) + statusFile = response.data.tempStatusPath; + getCreationStatus(); + } else { + + $scope.cyberpanelLoading = 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; + } + + + } + + function cantLoadInitialDatas(response) { + + $scope.cyberpanelLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + }; $scope.goBack = function () { + $scope.cyberpanelLoading = true; $scope.installationDetailsForm = false; $scope.installationProgress = true; - $scope.installationFailed = true; - $scope.installationSuccessfull = true; + $scope.errorMessageBox = true; + $scope.success = true; $scope.couldNotConnect = true; - $scope.wpInstallLoading = true; - $scope.goBackDisable = false; + $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.cyberpanelLoading = 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"; @@ -15086,477 +16866,6 @@ app.controller('listDockersite', function ($scope, $http) { }); -app.controller('ListDockersitecontainer', function ($scope, $http) { - $scope.cyberPanelLoading = true; - $scope.conatinerview = true - $('#cyberpanelLoading').hide(); - - - $scope.getcontainer = function () { - $('#cyberpanelLoading').show(); - url = "/docker/getDockersiteList"; - - var data = {'name': $('#sitename').html()}; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $('#cyberpanelLoading').hide(); - if (response.data.status === 1) { - - $scope.cyberPanelLoading = true; - - var finalData = JSON.parse(response.data.data[1]); - - $scope.ContainerList = finalData; - $("#listFail").hide(); - } else { - $("#listFail").fadeIn(); - $scope.errorMessage = response.data.error_message; - - - } - } - - function cantLoadInitialData(response) { - $scope.cyberPanelLoading = true; - $('#cyberpanelLoading').hide(); - - new PNotify({ - title: 'Operation Failed!', - text: 'Connect disrupted, refresh the page.', - type: 'error' - }); - } - } - - $scope.getcontainer() - $scope.cyberPanelLoading = true; - - - $scope.Lunchcontainer = function (containerid) { - // $scope.listcontainerview = true - $scope.cyberpanelLoading = false - $('#cyberpanelLoading').show(); - var url = "/docker/getContainerAppinfo"; - - var data = { - 'name': $('#sitename').html(), - 'id': containerid - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.cyberpanelLoading = true - $('#cyberpanelLoading').hide(); - // console.log(response); - - if (response.data.status === 1) { - console.log(response.data.data); - $scope.cid = response.data.data[1].id - $scope.status = response.data.data[1].status - $scope.appcpuUsage = 5 - $scope.appmemoryUsage = 9 - $scope.cName = response.data.data[1].name - $scope.port = response.data.data[1].name - $scope.getcontainerlog(containerid) - } else { - - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - } - - function cantLoadInitialData(response) { - $scope.cyberpanelLoading = true - $('#cyberpanelLoading').hide(); - new PNotify({ - title: 'Operation Failed!', - text: 'Connect disrupted, refresh the page.', - type: 'error' - }); - } - } - - - $scope.getcontainerlog = function (containerid) { - $scope.cyberpanelLoading = false - - - var url = "/docker/getContainerApplog"; - - var data = { - 'name': $('#sitename').html(), - 'id': containerid - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.cyberpanelLoading = true - $scope.conatinerview = false - $('#cyberpanelLoading').hide(); - $scope.logs = response.data.data[1]; - - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Container info fetched.', - type: 'success' - }); - } else { - - new PNotify({ - title: 'Operation Failed!', - text: response.data.error_message, - type: 'error' - }); - - } - } - - function cantLoadInitialData(response) { - $scope.cyberpanelLoading = true - $('#cyberpanelLoading').hide(); - $scope.conatinerview = false - - new PNotify({ - title: 'Operation Failed!', - text: 'Connect disrupted, refresh the page.', - type: 'error' - }); - } - } - - - $scope.recreateappcontainer = function () { - $scope.cyberPanelLoading = false; - var url = "/docker/recreateappcontainer"; - - var data = { - 'name': $('#sitename').html(), - 'WPusername': $scope.WPUsername, - 'WPemail': $scope.adminEmail, - 'WPpasswd': $scope.WPPassword, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.conatinerview = false - $scope.cyberPanelLoading = true; - - $scope.getcontainer() - - - if (response.data.status === 1) { - new PNotify({ - title: 'Success!', - text: 'Container recreated', - 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: 'Connect disrupted, refresh the page.', - type: 'error' - }); - } - } - - - $scope.refreshStatus = function () { - $('#actionLoading').show(); - url = "/docker/getContainerStatus"; - var data = {name: $scope.cName}; - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); - - function ListInitialData(response) { - $('#actionLoading').hide(); - if (response.data.containerStatus === 1) { - console.log(response.data.status); - $scope.status = response.data.status; - } else { - new PNotify({ - title: 'Unable to complete request', - text: response.data.error_message, - type: 'error' - }); - - } - } - - function cantLoadInitialData(response) { - $('#actionLoading').hide(); - PNotify.error({ - title: 'Unable to complete request', - text: "Problem in connecting to server" - }); - } - - }; - - $scope.restarthStatus = function () { - $('#actionLoading').show(); - url = "/docker/RestartContainerAPP"; - var data = { - name: $scope.cName, - id: $scope.cid - }; - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); - - function ListInitialData(response) { - $('#actionLoading').hide(); - if (response.data.status === 1) { - if (response.data.data[0] === 1) { - new PNotify({ - title: 'Success!', - text: 'Action completed', - type: 'success' - }); - $scope.Lunchcontainer($scope.cid); - } else { - new PNotify({ - title: 'Error!', - text: response.data.data[1], - type: 'error' - }); - } - } else { - new PNotify({ - title: 'Unable to complete request', - text: response.data.error_message, - type: 'error' - }); - - } - } - - function cantLoadInitialData(response) { - $('#actionLoading').hide(); - PNotify.error({ - title: 'Unable to complete request', - text: "Problem in connecting to server" - }); - } - - }; - $scope.StopContainerAPP = function () { - $('#actionLoading').show(); - url = "/docker/StopContainerAPP"; - var data = { - name: $scope.cName, - id: $scope.cid - }; - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); - - function ListInitialData(response) { - $('#actionLoading').hide(); - if (response.data.status === 1) { - console.log(response.data.status); - if (response.data.data[0] === 1) { - new PNotify({ - title: 'Success!', - text: 'Action completed', - type: 'success' - }); - $scope.Lunchcontainer($scope.cid); - } else { - new PNotify({ - title: 'Error!', - text: response.data.data[1], - type: 'error' - }); - } - } else { - new PNotify({ - title: 'Unable to complete request', - text: response.data.error_message, - type: 'error' - }); - - } - } - - function cantLoadInitialData(response) { - $('#actionLoading').hide(); - - PNotify.error({ - title: 'Unable to complete request', - text: "Problem in connecting to server" - }); - } - - }; - $scope.cAction = function (action) { - $('#actionLoading').show(); - url = "/docker/doContainerAction"; - var data = {name: $scope.cName, action: action}; - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - console.log(response); - - if (response.data.containerActionStatus === 1) { - new PNotify({ - title: 'Success!', - text: 'Action completed', - type: 'success' - }); - $scope.status = response.data.status; - $scope.refreshStatus() - } else { - new PNotify({ - title: 'Unable to complete request', - text: response.data.error_message, - type: 'error' - }); - - } - $('#actionLoading').hide(); - } - - function cantLoadInitialData(response) { - PNotify.error({ - title: 'Unable to complete request', - text: "Problem in connecting to server" - }); - $('#actionLoading').hide(); - } - - }; - $scope.cRemove = function () { - (new PNotify({ - title: 'Confirmation Needed', - text: 'Are you sure?', - icon: 'fa fa-question-circle', - hide: false, - confirm: { - confirm: true - }, - buttons: { - closer: false, - sticker: false - }, - history: { - history: false - } - })).get().on('pnotify.confirm', function () { - $('#actionLoading').show(); - - url = "/docker/delContainer"; - var data = {name: $scope.cName, unlisted: false}; - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); - - function ListInitialData(response) { - if (response.data.delContainerStatus === 1) { - new PNotify({ - title: 'Container deleted!', - text: 'Redirecting...', - type: 'success' - }); - window.location.href = '/docker/listContainers'; - } else { - new PNotify({ - title: 'Unable to complete request', - text: response.data.error_message, - type: 'error' - }); - } - $('#actionLoading').hide(); - } - - function cantLoadInitialData(response) { - PNotify.error({ - title: 'Unable to complete request', - text: "Problem in connecting to server" - }); - $('#actionLoading').hide(); - } - }) - }; - - -}) - app.controller('BuyAddons', function ($scope, $http) { @@ -15577,7 +16886,6 @@ app.controller('BuyAddons', function ($scope, $http) { // 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, @@ -15587,7 +16895,6 @@ app.controller('BuyAddons', function ($scope, $http) { months: months }); - // Build the complete URL with query string const fullURL = `${baseURL}?${params.toString()}`; @@ -15597,268 +16904,4 @@ app.controller('BuyAddons', function ($scope, $http) { } - - $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; - - } - - - - - }) \ No newline at end of file diff --git a/websiteFunctions/templates/websiteFunctions/DockerSiteHome.html b/websiteFunctions/templates/websiteFunctions/DockerSiteHome.html index c28b88923..2d699ef0d 100644 --- a/websiteFunctions/templates/websiteFunctions/DockerSiteHome.html +++ b/websiteFunctions/templates/websiteFunctions/DockerSiteHome.html @@ -7,24 +7,1058 @@ {% get_current_language as LANGUAGE_CODE %} + + -
+
-
-

{% trans "Containers" %} - Create -

-

{% trans "Manage containers on server" %}

+
+
+

+ {% trans "Containers" %} + + Loading + +

+

{% trans "Manage containers on server" %}

+
+ + {% trans "Create Container" %} +
-
+

{% trans "Containers" %} {{ dockerSite.SiteName }}

-
+
+
+
- +
+

{% trans "Error message:" %} {$ errorMessage $}

+
+ +
+ +
+ + + + +
+ + +
+ + {% if showUnlistedContainer %} +

+ {% trans "Unlisted Containers" %} + +

+ +
- - - - {# #} - {# #} - {# #} -{# #} - - - - - - - - {# #} - {# #} - {# #} -{# #} - - - -
NameLaunchOwnerImageTagActions
- #} -{# #} - {# #} -{#
- - -
-

{% trans "Error message:" %} {$ errorMessage $}

-
- -
- -
- - - - -
- - -
- - {% if showUnlistedContainer %} -

- {% trans "Unlisted Containers" %} -

- - - - - - + + {% for container in unlistedContainers %} - + {% endfor %} + +
Name Status Actions
{{ container.name }}{{ container.status }} - - - + + + {{ container.status }} + + + + +
- - + {% endif %} - {% endif %} - - - - - -
-
-
-
-
- - -
-

{% trans "Currently managing: " %} {$ cName $} - -

-

- {% trans "Container ID" %}: {$ cid $} -

- -
- - -
- -
- -

- {% trans "Container Information" %} - -

- - -
-
- -
-
-
-
-

- {% trans "Memory Usage" %} -

-
-
-
-
- -
-
-
- - -

- {% trans "CPU Usage" %} -

-
-
-
-
-
-
- - -
- -
-
-
- -
-
-
-
-

Main Actions - -

- Status: - -
- - - - -
-
-
-
- - -
-
- - -
-
- - - -
- -
- -

- {% trans "Logs" %} - -

- - -
-
- -
-
- -
-
-
- - - +
+
+
+ +
+
+ +
+
+

+ + n8n Container: {$ web.name $} + + Debug - Environment: {$ web.environment | json $} + + + + + + {$ web.status $} + +

+
+ + + +
+
+ +
+
+
+
+

+ + Resource Usage +

+
+
+
Memory Usage
+
{$ web.memoryUsage $}
+
+
+
+
+
+
+
CPU Usage
+
{$ web.cpuUsagePercent | number:1 $}%
+
+
+
+
+
+
+
Container Uptime
+
{$ web.uptime $}
+
+
+
+ +
+

Network & Ports

+
+ + + + + + + + + + + + + +
Container PortHost Binding
{$ containerPort $} + + {$ binding.HostIp || '0.0.0.0' $}:{$ binding.HostPort $} + +
+
+
+

No ports exposed

+
+
+
+ +
+
+

Volumes

+
+ + + + + + + + + + + + + +
SourceDestination
{$ volume.Source $}{$ volume.Destination $}
+
+
+

No volumes mounted

+
+
+ +
+

Environment Variables

+
+ + + + + + + + + + + + + +
VariableValue
{$ env.split('=')[0] $} + {$ env.split('=')[1] $} + {$ env.split('=')[1] $} +
+
+
+
+
+ +
+

+ {% trans "Logs" %} + +

+ +
+
+
+ + +
+
+

+ {% trans "Container: " %} {$ web.name $} + + + + {$ web.status $} + +

+
+ + + +
+
+ +
+
+
+
+

Basic Information

+ + + + + + + + + + + + + + + +
Container ID:{$ web.id $}
Created:{$ web.created | date:'medium' $}
Uptime:{$ web.uptime $}
+
+ +
+

Resource Usage

+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+

Network & Ports

+
+ + + + + + + + + + + + + +
Container PortHost Binding
{$ containerPort $} + + {$ binding.HostIp || '0.0.0.0' $}:{$ binding.HostPort $} + +
+
+
+

No ports exposed

+
+
+ +
+

Volumes

+
+ + + + + + + + + + + + + +
SourceDestination
{$ volume.Source $}{$ volume.Destination $}
+
+
+

No volumes mounted

+
+
+
+
+ +
+
+
+

Environment Variables

+
+ + + + + + + + + + + + + +
VariableValue
{$ env.split('=')[0] $} + {$ env.split('=')[1] $} + {$ env.split('=')[1] $} +
+
+
+
+
+ +
+

+ {% trans "Logs" %} + +

+ +
+
+
+
+
+ +