diff --git a/dockerManager/container.py b/dockerManager/container.py index ff41e790e..011453eed 100755 --- a/dockerManager/container.py +++ b/dockerManager/container.py @@ -1151,6 +1151,37 @@ class ContainerManager(multi.Thread): 'cpu_usage': container.stats(stream=False)['cpu_stats']['cpu_usage'].get('total_usage', 0) } + # Add N8N specific health metrics if this is an N8N container + if 'n8n' in container.name.lower(): + try: + # Get N8N port from environment variables or port bindings + n8n_port = None + for port_config in container_info.get('NetworkSettings', {}).get('Ports', {}).values(): + if port_config: + n8n_port = port_config[0].get('HostPort') + break + + if n8n_port: + # Try to get N8N health metrics from the API + health_url = f"http://localhost:{n8n_port}/api/v1/health" + response = requests.get(health_url, timeout=5) + if response.status_code == 200: + health_data = response.json() + details['n8nStats'] = { + 'dbConnected': health_data.get('db', {}).get('status') == 'ok', + 'activeWorkflows': len(health_data.get('activeWorkflows', [])), + 'queuedExecutions': health_data.get('executionQueue', {}).get('waiting', 0), + 'lastExecution': health_data.get('lastExecution') + } + except: + # If we can't get N8N stats, provide default values + details['n8nStats'] = { + 'dbConnected': None, + 'activeWorkflows': 0, + 'queuedExecutions': 0, + 'lastExecution': None + } + data_ret = {'status': 1, 'error_message': 'None', 'data': [1, details]} json_data = json.dumps(data_ret) return HttpResponse(json_data) @@ -1301,4 +1332,182 @@ class ContainerManager(multi.Thread): except BaseException as msg: data_ret = {'removeImageStatus': 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) - return HttpResponse(json_data) \ No newline at end of file + return HttpResponse(json_data) + + def _get_backup_dir(self, container_id): + """Helper method to get the backup directory for a container""" + return f"/home/docker/backups/{container_id}" + + def createBackup(self, userID=None, data=None): + try: + admin = Administrator.objects.get(pk=userID) + if admin.acl.adminStatus != 1: + return ACLManager.loadError() + + container_id = data['id'] + client = docker.from_env() + container = client.containers.get(container_id) + + # Create backup directory if it doesn't exist + backup_dir = self._get_backup_dir(container_id) + os.makedirs(backup_dir, exist_ok=True) + + # Create timestamp for backup + timestamp = datetime.now().strftime('%Y%m%d_%H%M%S') + backup_file = f"{backup_dir}/backup_{timestamp}.tar.gz" + + # Get N8N data directory from container mounts + n8n_data_dir = None + for mount in container.attrs.get('Mounts', []): + if mount.get('Destination', '').endswith('/.n8n'): + n8n_data_dir = mount.get('Source') + break + + if not n8n_data_dir: + raise Exception("N8N data directory not found in container mounts") + + # Create backup using tar + backup_cmd = f"tar -czf {backup_file} -C {n8n_data_dir} ." + result = subprocess.run(backup_cmd, shell=True, capture_output=True, text=True) + if result.returncode != 0: + raise Exception(f"Backup failed: {result.stderr}") + + data_ret = {'status': 1, 'error_message': 'None', 'backup_file': backup_file} + return HttpResponse(json.dumps(data_ret)) + + except Exception as e: + data_ret = {'status': 0, 'error_message': str(e)} + return HttpResponse(json.dumps(data_ret)) + + def listBackups(self, userID=None, data=None): + try: + admin = Administrator.objects.get(pk=userID) + if admin.acl.adminStatus != 1: + return ACLManager.loadError() + + container_id = data['id'] + backup_dir = self._get_backup_dir(container_id) + + if not os.path.exists(backup_dir): + backups = [] + else: + backups = [] + for file in os.listdir(backup_dir): + if file.startswith('backup_') and file.endswith('.tar.gz'): + file_path = os.path.join(backup_dir, file) + file_stat = os.stat(file_path) + backups.append({ + 'id': file, + 'date': datetime.fromtimestamp(file_stat.st_mtime).isoformat(), + 'size': file_stat.st_size + }) + + data_ret = {'status': 1, 'error_message': 'None', 'backups': backups} + return HttpResponse(json.dumps(data_ret)) + + except Exception as e: + data_ret = {'status': 0, 'error_message': str(e)} + return HttpResponse(json.dumps(data_ret)) + + def restoreBackup(self, userID=None, data=None): + try: + admin = Administrator.objects.get(pk=userID) + if admin.acl.adminStatus != 1: + return ACLManager.loadError() + + container_id = data['id'] + backup_id = data['backup_id'] + client = docker.from_env() + container = client.containers.get(container_id) + + backup_dir = self._get_backup_dir(container_id) + backup_file = os.path.join(backup_dir, backup_id) + + if not os.path.exists(backup_file): + raise Exception("Backup file not found") + + # Get N8N data directory from container mounts + n8n_data_dir = None + for mount in container.attrs.get('Mounts', []): + if mount.get('Destination', '').endswith('/.n8n'): + n8n_data_dir = mount.get('Source') + break + + if not n8n_data_dir: + raise Exception("N8N data directory not found in container mounts") + + # Stop the container + container.stop() + + try: + # Clear existing data + shutil.rmtree(n8n_data_dir) + os.makedirs(n8n_data_dir) + + # Restore from backup + restore_cmd = f"tar -xzf {backup_file} -C {n8n_data_dir}" + result = subprocess.run(restore_cmd, shell=True, capture_output=True, text=True) + if result.returncode != 0: + raise Exception(f"Restore failed: {result.stderr}") + + # Start the container + container.start() + + data_ret = {'status': 1, 'error_message': 'None'} + return HttpResponse(json.dumps(data_ret)) + + except Exception as e: + # Try to start the container even if restore failed + try: + container.start() + except: + pass + raise e + + except Exception as e: + data_ret = {'status': 0, 'error_message': str(e)} + return HttpResponse(json.dumps(data_ret)) + + def deleteBackup(self, userID=None, data=None): + try: + admin = Administrator.objects.get(pk=userID) + if admin.acl.adminStatus != 1: + return ACLManager.loadError() + + container_id = data['id'] + backup_id = data['backup_id'] + backup_dir = self._get_backup_dir(container_id) + backup_file = os.path.join(backup_dir, backup_id) + + if os.path.exists(backup_file): + os.remove(backup_file) + + data_ret = {'status': 1, 'error_message': 'None'} + return HttpResponse(json.dumps(data_ret)) + + except Exception as e: + data_ret = {'status': 0, 'error_message': str(e)} + return HttpResponse(json.dumps(data_ret)) + + def downloadBackup(self, userID=None, data=None): + try: + admin = Administrator.objects.get(pk=userID) + if admin.acl.adminStatus != 1: + return ACLManager.loadError() + + container_id = data['id'] + backup_id = data['backup_id'] + backup_dir = self._get_backup_dir(container_id) + backup_file = os.path.join(backup_dir, backup_id) + + if not os.path.exists(backup_file): + raise Exception("Backup file not found") + + with open(backup_file, 'rb') as f: + response = HttpResponse(f.read(), content_type='application/gzip') + response['Content-Disposition'] = f'attachment; filename="{backup_id}"' + return response + + except Exception as e: + data_ret = {'status': 0, 'error_message': str(e)} + return HttpResponse(json.dumps(data_ret)) \ No newline at end of file diff --git a/dockerManager/urls.py b/dockerManager/urls.py index 47ffc0d01..e12aba4de 100755 --- a/dockerManager/urls.py +++ b/dockerManager/urls.py @@ -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'), + path('createBackup', views.createBackup, name='createBackup'), + path('listBackups', views.listBackups, name='listBackups'), + path('restoreBackup', views.restoreBackup, name='restoreBackup'), + path('deleteBackup', views.deleteBackup, name='deleteBackup'), + path('downloadBackup', views.downloadBackup, name='downloadBackup'), ] diff --git a/dockerManager/views.py b/dockerManager/views.py index c16aeb59f..ab9c383e6 100755 --- a/dockerManager/views.py +++ b/dockerManager/views.py @@ -1,4 +1,4 @@ - # -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- from django.shortcuts import redirect, HttpResponse @@ -533,6 +533,96 @@ def StopContainerAPP(request): cm = ContainerManager() coreResult = cm.StopContainerAPP(userID, json.loads(request.body)) + return coreResult + except KeyError: + return redirect(loadLoginPage) + +@preDockerRun +def createBackup(request): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadErrorJson() + + cm = ContainerManager() + coreResult = cm.createBackup(userID, json.loads(request.body)) + + return coreResult + except KeyError: + return redirect(loadLoginPage) + +@preDockerRun +def listBackups(request): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadErrorJson() + + cm = ContainerManager() + coreResult = cm.listBackups(userID, json.loads(request.body)) + + return coreResult + except KeyError: + return redirect(loadLoginPage) + +@preDockerRun +def restoreBackup(request): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadErrorJson() + + cm = ContainerManager() + coreResult = cm.restoreBackup(userID, json.loads(request.body)) + + return coreResult + except KeyError: + return redirect(loadLoginPage) + +@preDockerRun +def deleteBackup(request): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadErrorJson() + + cm = ContainerManager() + coreResult = cm.deleteBackup(userID, json.loads(request.body)) + + return coreResult + except KeyError: + return redirect(loadLoginPage) + +@preDockerRun +def downloadBackup(request): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadErrorJson() + + cm = ContainerManager() + coreResult = cm.downloadBackup(userID, json.loads(request.body)) + return coreResult except KeyError: return redirect(loadLoginPage) \ No newline at end of file diff --git a/websiteFunctions/static/websiteFunctions/dockerController.js b/websiteFunctions/static/websiteFunctions/dockerController.js new file mode 100644 index 000000000..0f12725dc --- /dev/null +++ b/websiteFunctions/static/websiteFunctions/dockerController.js @@ -0,0 +1,349 @@ +app.controller('DockerContainerManager', function ($scope, $http) { + $scope.cyberpanelLoading = true; + $scope.conatinerview = true; + $scope.ContainerList = []; + $('#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]; + + // 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; + + // Resource Usage + var memoryBytes = containerInfo.memory_usage; + $scope.ContainerList[i].memoryUsage = formatBytes(memoryBytes); + $scope.ContainerList[i].memoryUsagePercent = (memoryBytes / (1024 * 1024 * 1024)) * 100; // Assuming 1GB limit + $scope.ContainerList[i].cpuUsagePercent = (containerInfo.cpu_usage / 10000000000) * 100; // Normalize to percentage + + // Network & Ports + $scope.ContainerList[i].ports = containerInfo.ports; + + // Volumes + $scope.ContainerList[i].volumes = containerInfo.volumes; + + // Environment Variables + $scope.ContainerList[i].environment = containerInfo.environment; + + // N8N Stats + $scope.ContainerList[i].n8nStats = containerInfo.n8nStats || { + dbConnected: null, + activeWorkflows: 0, + queuedExecutions: 0, + lastExecution: null + }; + + // Load backups + $scope.refreshBackups($scope.ContainerList[i].id); + break; + } + } + } + } + + function cantLoadInitialData(response) { + $scope.cyberpanelLoading = true; + $('#cyberpanelLoading').hide(); + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message || 'Could not connect to server', + type: 'error' + }); + } + }; + + $scope.createBackup = function(containerId) { + $scope.cyberpanelLoading = false; + $('#cyberpanelLoading').show(); + + var url = "/docker/createBackup"; + var data = { + 'name': $('#sitename').html(), + 'id': containerId + }; + + 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) { + // Refresh backups list + $scope.refreshBackups(containerId); + new PNotify({ + title: 'Success!', + text: 'Backup created successfully.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + }, function(error) { + $scope.cyberpanelLoading = true; + $('#cyberpanelLoading').hide(); + new PNotify({ + title: 'Error!', + text: 'Could not connect to server.', + type: 'error' + }); + }); + }; + + $scope.refreshBackups = function(containerId) { + var url = "/docker/listBackups"; + var data = { + 'name': $('#sitename').html(), + 'id': containerId + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(function(response) { + if (response.data.status === 1) { + // Find the container and update its backups + for (var i = 0; i < $scope.ContainerList.length; i++) { + if ($scope.ContainerList[i].id === containerId) { + $scope.ContainerList[i].backups = response.data.backups; + break; + } + } + } + }); + }; + + $scope.restoreBackup = function(containerId, backupId) { + if (!confirm("Are you sure you want to restore this backup? The container will be stopped during restoration.")) { + return; + } + + $scope.cyberpanelLoading = false; + $('#cyberpanelLoading').show(); + + var url = "/docker/restoreBackup"; + var data = { + 'name': $('#sitename').html(), + 'id': containerId, + 'backup_id': backupId + }; + + 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: 'Backup restored successfully.', + type: 'success' + }); + // Refresh container info + $scope.Lunchcontainer(containerId); + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + }, function(error) { + $scope.cyberpanelLoading = true; + $('#cyberpanelLoading').hide(); + new PNotify({ + title: 'Error!', + text: 'Could not connect to server.', + type: 'error' + }); + }); + }; + + $scope.deleteBackup = function(containerId, backupId) { + if (!confirm("Are you sure you want to delete this backup?")) { + return; + } + + var url = "/docker/deleteBackup"; + var data = { + 'name': $('#sitename').html(), + 'id': containerId, + 'backup_id': backupId + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(function(response) { + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Backup deleted successfully.', + type: 'success' + }); + // Refresh backups list + $scope.refreshBackups(containerId); + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + }, function(error) { + new PNotify({ + title: 'Error!', + text: 'Could not connect to server.', + type: 'error' + }); + }); + }; + + $scope.downloadBackup = function(containerId, backupId) { + window.location.href = "/docker/downloadBackup?name=" + encodeURIComponent($('#sitename').html()) + + "&id=" + encodeURIComponent(containerId) + + "&backup_id=" + encodeURIComponent(backupId); + }; + + $scope.openN8NEditor = function(container) { + // Find the N8N port from the container's port bindings + var n8nPort = null; + if (container.ports) { + for (var port in container.ports) { + if (container.ports[port] && container.ports[port].length > 0) { + n8nPort = container.ports[port][0].HostPort; + break; + } + } + } + + if (n8nPort) { + window.open("http://localhost:" + n8nPort, "_blank"); + } else { + new PNotify({ + title: 'Error!', + text: 'Could not find N8N port configuration.', + type: 'error' + }); + } + }; + + $scope.getcontainerlog = function (containerid) { + var url = "/docker/getContainerApplog"; + var data = { + 'name': $('#sitename').html(), + 'id': containerid + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(function(response) { + if (response.data.status === 1) { + // Find the container 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; + } + } + } + }); + }; +}); \ No newline at end of file diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index da77fd248..9ea67e946 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -3177,6 +3177,6434 @@ function selectpluginJs(val) { } +var DeletePluginURL; + +function DeletePluginBuucket(url) { + DeletePluginURL = url; +} + +function FinalDeletePluginBuucket() { + window.location.href = DeletePluginURL; +} + +/** + * 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; +} + +/** + * 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) + + } + }; + +}); + + +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 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) { + $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; +} + +/** + * 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) + + } + }; + +}); + + +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 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) { + $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) { diff --git a/websiteFunctions/templates/websiteFunctions/DockerSiteHome.html b/websiteFunctions/templates/websiteFunctions/DockerSiteHome.html index 86cfdb5bb..71c6c10e4 100644 --- a/websiteFunctions/templates/websiteFunctions/DockerSiteHome.html +++ b/websiteFunctions/templates/websiteFunctions/DockerSiteHome.html @@ -7,6 +7,8 @@ {% get_current_language as LANGUAGE_CODE %} + +