Edit file File name : main.js Content :/* * A2 Optimized cPanel Plugin * main.js * */ var scope; var mainModule = angular.module('ui.bootstrap.a2opt', ['ui.bootstrap','angularSpinner','ngSanitize','ui.utils']); document.title = "cPanel - A2 Optimized"; var a2_optimized_main_controller = mainModule.controller('A2OptMainController', ['$scope','$modal','$log','$http','$timeout','$location',function ($scope, $modal, $log, $http, $timeout, $location) { $scope.loading_stack = []; if($location.hash() != ""){ $location.hash(""); return; } $scope.back = function(){ var hash = $location.hash(); if ( hash == "" ) { window.location.href = "./../"; return; } else { window.history.back(); } } $scope.$log = $log; $scope.resold = 1; $scope.loading = false; $scope.litespeed = 0; $scope.theme = 0; $scope.$watch( function () { return $location.hash(); }, function (value) { if(value == ""){ $scope.vars.selectedApp = null; $scope.vars.currentController = "A2 Optimized"; $scope.vars.open = []; }else if($scope.controller_stack.length >= value) { var state = $scope.controller_stack[value - 1]; $scope.vars.currentController = state.controller; if ($scope.vars.selectedApp.path != state.app.path) { $scope.vars.selectedApp = state.app; $scope.vars.open = []; var app; var i = 0; for (app in $scope.vars.apps) { if ($scope.vars.apps[app].path == $scope.vars.selectedApp.path) { $scope.vars.open[i] = true; } else { $scope.vars.open[i] = false; } i++; } } } }); $scope.forward = function(){ window.history.forward(); } $scope.replace_schema = function(url){ var url = url.replace("http://","").replace("https://","").split("/"); var domain = url.shift(); var schema = "http://"; for(var i=0; i< $scope.vars.selectedApp.ssl_domains.length;i++){ if(domain == $scope.vars.selectedApp.ssl_domains[i]){ schema = "https://"; } } return schema+domain+"/"+url.join("/"); } $scope.vars = { 'apps': [], 'selectedApp':null, 'loading': false, 'currentController': "A2 Optimized", 'collapseApp':true, 'open': [], 'certs': [], 'ssl_domains': [], 'version': '' }; $scope.controller_stack = [];//$cookies.getObject("stack_controller"); $scope.appControllers = { 'WordPress' : ['Overview','SwiftCache','Optimize'], 'Drupal' : ['Overview','SwiftCache','Optimize'], 'Drupal 9' : ['Overview','SwiftCache','Optimize'], 'Magento' : ['Overview','SwiftCache','Optimize'], 'Joomla' : ['Overview','SwiftCache','Optimize'], 'PrestaShop' : ['Overview','SwiftCache','Optimize'], 'OpenCart' : ['Overview',"SwiftCache","Optimize"] }; $scope.action_file = 'action.live.php'; $http.get($scope.action_file, { params: { action:'is_resold' } }).success(function(data, status, headers, config) { $scope.resold = data; }).error(function(data, status, headers, config) { $scope.resold = 1; }); $http.get($scope.action_file, { params: { action:'get_theme' } }).success(function(data, status, headers, config) { $scope.theme = data; }).error(function(data, status, headers, config) { $scope.theme = "x3"; }); $http.get($scope.action_file, { params: { action:'get_version' } }).success(function(data, status, headers, config) { $scope.vars.version = data; }).error(function(data, status, headers, config) { $scope.vars.version = "-"; }); $http.get($scope.action_file, { params: { action:'is_litespeed' } }).success(function(data, status, headers, config) { $scope.litespeed = data; }).error(function(data, status, headers, config) { $scope.litespeed = 0; }); $scope.is_loading = function(truthiness){ if(truthiness){ $scope.loading_stack.push(true); } else{ var top = $scope.loading_stack.pop(); } if($scope.loading_stack.length > 0){ $scope.loading = true; } else{ $scope.loading = false; } }; $scope.isloading = function(){ $scope.is_loading(true); } $scope.notloading = function(){ $scope.is_loading(false); } $scope.error_count = 0; $scope.error = function(data,loading){ if( !(loading != null && loading === false) ){ $scope.notloading(); } if(data != null && data.error != null){ $scope.add_alert('danger',data.error,10000); } else if(typeof data == 'String'){ $scope.add_alert('danger',data,10000); } else { $scope.add_alert('danger','An error has occurred. Please submit a support ticket at <a href="https://my.a2hosting.com/submitticket.php">my.a2hosting.com</a> with the steps to reproduce.', 30000); $scope.error_count++; if($scope.error_count > 2){ $scope.error_count = 0; $http.get($scope.action_file, { params: { action: 'alert_dev', app: $scope.vars.selectedApp, controller: $scope.vars.currentController } }); } } }; $scope.alert = function(string){ alert('string'); }; $scope.isset = function(val) { if(angular.isDefined(val) && angular.isArray(val)){ for(var i=0;i<val.length;i++){ if(angular.isUndefined(val[i])){ return false; } } } else{ if(angular.isUndefined(val)){ return false; } } return true; }; $scope.is_enter = function(event,item) { if(event.keyCode == 13){ event.target.blur(); } }; $scope.alert_timer = null; $scope.alerts = []; $scope.add_alert = function(type,message,time) { time = time || 5000; var alert = { 'type' : type, 'message': message, 'class': "fade-out" }; $scope.alerts.unshift(alert); $timeout(function(){ alert.class = "fade-in"; }, 166); $timeout(function(){ alert.class = "fade-out" }, time).then( function(){ $timeout(function(){ $scope.alerts.pop(); }, 1000); } ); } $scope.news_items = [ 'A2 Optimized is in constant development, please leave as much feedback as possible in our <a target="_blank" href="https://my.a2hosting.com/a2-suggestion-box.php">suggestion box</a>.', 'A2 Optimized has already identified installations of popular content management systems. All Installations are listed on left side of this page. Click on an application in the left navigation menu to get started.' ] $scope.app_logos = { 'WordPress': 'wordpress.png', 'PrestaShop': 'prestashop.png', 'Drupal': 'drupal.png', 'Drupal 9': 'drupal9.png', 'Joomla': 'joomla.png', 'Magento': 'magento.png', 'OpenCart': 'opencart.png', } $scope.go_to_ssl = function(){ window.open("../ssl/index.html"); } $scope.isController = function(ctrl, type){ return (!($scope.appControllers[type].indexOf(ctrl) === false)); } $scope.subControllers = { 'SwiftCache': { 'WordPress' : ['Memcached','TurboCache'], 'PrestaShop' : ['Memcached','TurboCache'], 'Drupal' : ['Memcached','TurboCache'], 'Drupal 9' : ['TurboCache'], 'Joomla' : ['Memcached','TurboCache'], 'Magento' : ['Memcached'], 'OpenCart' : ['Memcached','TurboCache'], } }; $scope.icons = { 'SwiftCache': 'glyphicon-flash', 'Overview': 'glyphicon-info-sign', 'Optimize': 'glyphicon-cog' }; $scope.set_currentController = function(value) { if($scope.vars.currentController != value){ $scope.vars.currentController = value; } $scope.collect_state(); }; $scope.get_selectedApp = function(){ return $scope.vars.selectedApp; }; $scope.get_currentController = function(){ return $scope.vars.currentController; }; $scope.set_selectedApp = function(app,overview) { $scope.vars.selectedApp = app; if(overview == null || overview === true){ $scope.vars.currentController = 'Overview'; } }; $scope.toggle_selectedApp = function(app,overview) { if(overview == null){ overview = true; } if($scope.vars.selectedApp == app) { $scope.vars.collapseApp = !$scope.vars.collapseApp; } else{ $scope.vars.collapseApp = false; } $scope.vars.selectedApp = app; if(typeof $scope.vars.selectedApp == 'undefined' || overview === true){ $scope.vars.currentController = "Overview"; } $scope.collect_state(); }; $scope.collect_state = function(){ var hash = $location.hash(); if(hash == ""){ hash = 1; } if($scope.controller_stack.length == 0){ $scope.controller_stack.push({'app':null,'controller':"A2 Optimized"}); hash = 1; } var state = $scope.controller_stack[hash-1]; if(!( angular.isDefined(state.controller) && state.controller == $scope.vars.currentController && angular.isDefined(state.app) && state.app.path == $scope.vars.selectedApp.path )) { if(hash != $scope.controller_stack.length){ $scope.controller_stack = $scope.controller_stack.slice(0,hash); } $scope.controller_stack.push({ 'app': $scope.vars.selectedApp, 'controller': $scope.vars.currentController + "", 'open': $scope.vars.open.concat([]) }); $location.hash(Math.round(hash)+1); } } $scope.set_apps = function(apps) { $scope.vars.apps = apps; }; $scope.add_app = function(app) { $scope.vars.apps.push(app); }; }]); var a2_optimized_app_controller = mainModule.controller('A2OptAppController', ['$scope','$modal','$log','$http','$timeout',function ($scope, $modal, $log, $http, $timeout) { scope = $scope; $scope.login = function(app){ var modalInstance = $modal.open({ animation: $scope.animationsEnabled, app: $scope.selectedApp, scope: $scope, templateUrl: 'Login.html', controller: 'A2OptLoginController', size: 'md' }); } $scope.$watchCollection('open',function(newval,oldval){ if(newval != null) { var index = 0; for (var i = 0; i < newval.length; i++) { if (newval[i]) { index = i; } } i = 0; angular.forEach($scope.apps,function(value,key){ if(index == i++) { $scope.toggle_selectedApp(value); } }); } }); $scope.install_application_popup = function(){ var modalInstance = $modal.open({ animation: $scope.animationsEnabled, templateUrl: 'InstallApp.html', controller: 'A2OptInstallAppController', size: 'md' }); }; $scope.refresh_apps = function(alert){ if(alert == null){ alert = false; } $scope.add_alert("info","Finding Applications.",15000) $scope.isloading(); $http.get($scope.action_file, { params: { action:'refresh_app_list' } }).success(function(data, status, headers, config) { $scope.set_apps(data); $scope.notloading(); $scope.alerts.shift(); if($scope.vars.apps.length > 0){ for(var app in $scope.vars.apps) { if (typeof app == 'string' ) { $scope.is_optimized($scope.vars.apps[app]); } } } }).error(function(data, status, headers, config) { $scope.error(data); }); }; $scope.get_apps = function(alert){ if(alert == null){ alert = false; } $scope.isloading(); $http.get($scope.action_file, { params: { action:'find_apps' } }).success(function(data, status, headers, config) { $scope.set_apps(data); $scope.notloading(); if($scope.vars.apps.length > 0){ for(var app in $scope.vars.apps) { if (typeof app == 'string' ) { $scope.is_optimized($scope.vars.apps[app]); } } } }).error(function(data, status, headers, config) { $scope.error(data); }); }; $scope.get_apps(); $scope.get_certs = function(){ $http.get($scope.action_file, { params: { action:'get_certs' } }).success(function(data, status, headers, config) { $scope.vars.certs = data; }).error(function(data, status, headers, config) { $scope.error(data,false); }); }; $scope.get_certs(); $scope.save_app = function(app) { $http.get($scope.action_file, { params: { action:'save_app', app: app } }).success(function(data, status, headers, config) { $scope.add_alert('success',"Saved."); }).error(function(data, status, headers, config) { $scope.add_alert('success',"There was an error saving the application"); }); }; $scope.save_app_title = function(app) { $scope.save_app(app); }; $scope.is_optimized = function(app){ $http.get('optimize.live.php', { params: { action:'is_optimized', 'app': app } }).success(function(data, status, headers, config) { if(!$scope.isset(app.optimize)){ app.optimize = {}; } app.optimize.optimized = data.optimized; app.optimize.percent = data.optimized_percent; }).error(function(data, status, headers, config) { $scope.error(data,false); }); }; $scope.init_app = function(app){ $scope.is_optimized(app); }; $scope.change_admin_password = function(app,password){ $scope.isloading(); $http.get($scope.action_file, { params: { action:'change_admin_password', 'app': app, 'password':password } }).success(function(data, status, headers, config) { $scope.add_alert('success',"Password changed successfully for user login "+data); $scope.passwd = ''; $scope.notloading(); }).error(function(data, status, headers, config) { $scope.error(data); }); } $scope.$watch('selectedApp',function(){ if($scope.vars.selectedApp != null) { //$scope.is_optimized($scope.vars.selectedApp); } }); $scope.update_swiftcache = function(swiftcache){ if(angular.isUndefined(swiftcache.turbocache)){ swiftcache.turbocache = {'enabled':false}; } if(angular.isUndefined(swiftcache.memcached)){ swiftcache.memcached = {'enabled':false}; } $scope.vars.selectedApp.swiftcache = swiftcache; }; } ]); var a2_optimized_wp_controller = mainModule.controller('A2OptWPController', ['$scope','$modal','$log','$http','$timeout',function ($scope, $modal, $log, $http, $timeout) { } ]); var a2_optimized_swiftcache_controller = mainModule.controller('A2OptSwiftCacheController', ['$scope','$modal','$log','$http','$timeout',function ($scope, $modal, $log, $http, $timeout) { } ]); var a2_optimized_overview_controller = mainModule.controller('A2OptOverviewController', ['$scope','$modal','$log','$http','$timeout',function ($scope, $modal, $log, $http, $timeout) { } ]); var a2_optimized_title_controller = mainModule.controller('A2OptTitleController', ['$scope','$modal','$log','$http','$timeout',function ($scope, $modal, $log, $http, $timeout) { } ]); var a2_optimized_install_app_controller = mainModule.controller('A2OptInstallAppController', ['$scope','$modalInstance','$modal','$log','$http','$timeout',function ($scope, $modalInstance, $modal, $log, $http, $timeout) { $scope.install_app_ok = function(){ var url = String(document.location); window.open(url.substring(0,url.indexOf("a2-optimized"))+"softaculous/"); $scope.cancel(); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; } ]); var a2_optimized_login_controller = mainModule.controller('A2OptLoginController', ['$scope','$modalInstance','$modal','$log','$http','$timeout',function ($scope, $modalInstance, $modal, $log, $http, $timeout) { $scope.token = null; $scope.init = function(){ $scope.token_loading = true; $scope.token_error = false; switch($scope.vars.selectedApp.type){ case 'WordPress': $http.get($scope.action_file, { params: { action: 'get_token', app: $scope.vars.selectedApp, } }).success(function(data, status, headers, config) { $scope.token = data; $scope.token_loading = false; }).error(function(data, status, headers, config) { $scope.error(data,false); $scope.token_loading = false; $scope.token_error = true; }); } } $scope.login_ok = function(){ // Create a form var loginForm = document.createElement("form"); loginForm.target = "_blank"; loginForm.method = "post"; loginForm.action = $scope.vars.selectedApp.homeurl+"/a2_wp_authenticate.php"; // Create an input var loginInput = document.createElement("input"); loginInput.type = "hidden"; loginInput.name = "token"; loginInput.value = $scope.token; // Add the input to the form loginForm.appendChild(loginInput); // Add the form to dom document.body.appendChild(loginForm); loginForm.submit(); $scope.token = null; $scope.cancel(); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; } ]); /** * A generic confirmation for risky actions. * Usage: Add attributes: ng-really-message="Are you sure"? ng-really-click="takeAction()" function */ angular.module('ui.bootstrap.a2opt').directive('ngReallyClick', [function() { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { scope.$on('$destroy', function() { element.off('click'); }); var message = attrs.ngReallyMessage; if (message && confirm(message)) { scope.$apply(attrs.ngReallyClick); } }); } } }]); mainModule.directive('focusMe', function($timeout, $parse) { return { link: function(scope, element, attrs) { var model = $parse(attrs.focusMe); scope.$watch(model, function(value) { if(value === true) { $timeout(function() { element[0].focus(); }); } }); element.bind('blur', function() { scope.$apply(model.assign(scope, false)); }) } }; }); mainModule.directive('sticky', function() { var linkFn = function(scope , elem, attrs) { var mediaQuery = scope.mediaQuery || null, stickyClass = scope.stickyClass || '', bodyClass = scope.bodyClass || '', $elem = elem, elem = $elem[0], $window = angular.element(window), $body = angular.element(document.body), doc = document.documentElement, initial = { offsetWidth: elem.offsetWidth, top: $elem.css('top'), width: $elem.css('width'), position: $elem.css('position'), marginTop: $elem.css('margin-top'), }, isPositionFixed = false, isSticking = false, stickyLine; var offset = typeof scope.offset === 'string' ? parseInt( scope.offset.replace(/px;?/, '') ) : 0; // Watchers // var prevOffset = _getTopOffset(elem); scope.$watch( function() { if ( isSticking ) return prevOffset; prevOffset = _getTopOffset(elem); return prevOffset; }, function(newVal, oldVal) { if ( newVal !== oldVal || typeof stickyLine === 'undefined' ) { stickyLine = newVal - offset; checkIfShouldStick(); } }); // checks if the window has passed the sticky line function checkIfShouldStick() { if ( mediaQuery && !matchMedia('('+mediaQuery+')').matches) return; var scrollTop = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0); var shouldStick = scrollTop >= stickyLine; // Switch the sticky modes if the element has crossed the sticky line if ( shouldStick && !isSticking ) stickElement(); else if ( !shouldStick && isSticking ) unstickElement(); } function stickElement() { isSticking = true; bodyClass && $body.addClass(bodyClass); stickyClass && $elem.addClass(stickyClass); $elem .css('position', 'fixed') .css('top', offset+'px') .css('width', initial.offsetWidth) .css('margin-top', 0); }; function unstickElement() { isSticking = false; bodyClass && $body.removeClass(bodyClass); stickyClass && $elem.removeClass(stickyClass); $elem .css('top', initial.top) .css('position', initial.position) .css('margin-top', initial.marginTop); }; function _getTopOffset (element) { var pixels = 0; if (element.offsetParent) { do { pixels += element.offsetTop; element = element.offsetParent; } while (element); } return pixels; } // Listeners // $window.on('scroll', checkIfShouldStick); $window.on('resize', scope.$apply.bind(scope, onResize)); scope.$on('$destroy', onDestroy); function onResize() { if ( !initial.width ) { var parent = window.getComputedStyle(elem.parentElement.this(), null); var initialOffsetWidth = elem.parentElement.offsetWidth - parent.getPropertyValue('padding-right').replace("px", "") - parent.getPropertyValue('padding-left').replace("px", ""); $elem.css("width", initialOffsetWidth); } }; function onDestroy() { $window.off('scroll', checkIfShouldStick); $window.off('resize', onResize); }; }; // Directive definition // return { scope: { offset: '@', // top offset mediaQuery: '@', // minimum width required for sticky to come in stickyClass: '@', // class to be applied to the element on sticky bodyClass: '@' // class to be applied to the body on sticky }, restrict: 'A', // sticky can only be used as an ('A') attribute. link: linkFn }; }); angular.module("template/accordion/accordion-group.html", []).run(["$templateCache", function($templateCache) { $templateCache.put("template/accordion/accordion-group.html", "<div class=\"panel panel-default\">\n" + " <div class=\"panel-heading\" ng-click=\"toggleOpen()\" style=\"cursor:pointer;padding:0\" >\n" + " <h4 class=\"panel-title\" >\n" + " <a class=\"accordion-toggle\" accordion-transclude=\"heading\"><span ng-class=\"{'text-muted': isDisabled}\">{{heading}}</span></a>\n" + " </h4>\n" + " </div>\n" + " <div class=\"panel-collapse\" collapse=\"!isOpen\">\n" + " <div class=\"panel-body\" ng-transclude></div>\n" + " </div>\n" + "</div>"); }]); Save