Edit file File name : class.A2OptAction.php Content :<?php class A2OptAction extends A2OptBase { public function __construct() { parent::__construct(); if (!isset($_REQUEST['action'])) { $this->error('No "Action" was requested.');//exit if no action is specified } } public function apply_action() { global $cpanel; $this->connect_cpanel(); switch ($this->action) { case 'find_apps': $this->find_applications(); break; case 'refresh_app_list': $this->find_applications(true, true); break; case 'clear_apc_cache': //$this->apc_clear_cache(); break; case 'is_litespeed': echo $this->litespeed; break; case 'is_memcached': echo $this->memcached; break; case 'is_resold': $user_info = $cpanel->uapi( 'Variables', 'get_user_information', [ 'name-1' => 'owner', 'name-2' => 'user', ] ); $owner = $user_info['cpanelresult']['result']['data']['owner']; $user = $user_info['cpanelresult']['result']['data']['user']; if ($owner != 'root' && $owner != $user) { // Owner is not root (shared), Owner is not user = is a client on a reseller server echo '1'; } else { // Not resold echo '0'; } break; case 'save_app': $this->update_app_list(); break; case 'get_theme': $user_info = $cpanel->uapi( 'Variables', 'get_user_information', [ 'name-1' => 'theme', ] ); echo $user_info['cpanelresult']['result']['data']['theme']; break; case 'change_admin_password': $this->change_admin_password(); break; case 'alert_dev': $this->alert_dev(); break; case 'get_token': $this->get_login_token(); break; case 'is_ssl': $this->is_ssl(null, true); break; case 'get_certs': $this->show_certs(); break; case 'get_domains': $this->get_domains(); break; case 'get_version': $this->get_version(); break; default: $this->error('No valid action was given.'); } } private function alert_dev() { /* TODO: This function was mistakenly never called instead 'alert_ben' was trying to be called, which does not exist. It's probably too much to email dev@ for all errors in A2 Opt, and instead should be logged.... somewhere.... Maybe create a ticket in the future to handle these. $hostname = gethostname(); $to = 'dev@a2hosting.com'; $subject = 'Error Occurred in A2 Optimized'; $message = "An error occurred for user {$this->username} on {$hostname}. \n" . json_encode(['app' => json_decode($_GET['app']),'controller' => $_GET['controller']]); $headers = "From: a2optimized@{$hostname}" . "\r\n" . "Reply-To: nobody@{$hostname}" . "\r\n" . 'X-Mailer: PHP/' . phpversion(); date_default_timezone_set('America/New_York'); mail($to, $subject, $message, $headers); */ return true; } public function show_certs() { echo json_encode($this->get_certs()); } public function get_version() { header('Content-Type: text/plain;'); if (file_exists('/opt/a2-optimized/VERSION')) { echo file_get_contents('/opt/a2-optimized/VERSION'); } else { echo '-'; } } public function get_domains() { $docroots = $this->cpanel->api2('DomainLookup', 'getdocroots'); $addons = $this->cpanel->api2('AddonDomain', 'listaddondomains'); $parked = $this->cpanel->api2('Park', 'listparkeddomains'); $docroots = $docroots['cpanelresult']['data']; $addons = $addons['cpanelresult']['data']; $parked = $parked['cpanelresult']['data']; echo json_encode(['docroots' => $docroots,'addons' => $addons,'parked' => $parked]); exit(); } public function change_admin_password() { if (!isset($_GET['password']) || trim($_GET['password']) == '') { $this->error('The new password was not given'); } $user = ''; switch ($this->app->type) { case 'WordPress': $wp = new A2OptWordPress($this->app); $user = $wp->change_admin_password(trim($_GET['password'])); break; default: $this->error("{$this->app->type} cannot have the password changed."); } echo $user; } public function get_login_token() { $token = 'nee'; switch ($this->app->type) { case 'WordPress': $wp = new A2OptWordPress($this->app); $wp->set_exit_on_error(true); $token = $wp->get_login_token(); } echo $token; } public function find_application($folder, $domain) { $this->log_action('find_application for ' . $folder); $app_types = ['WordPress','Drupal','Drupal 9','Magento','PrestaShop','Joomla','opencart']; //$app_types = array('WordPress','Drupal','Magento','PrestaShop','Joomla'); if (file_exists("{$folder}/index.php")) { $index_content = file_get_contents("{$folder}/index.php"); $htaccess_content = file_exists("{$folder}/.htaccess") ? file_get_contents("{$folder}/.htaccess") : (file_exists("{$folder}/.htaccess.txt") ? file_get_contents("{$folder}/.htaccess.txt") : ''); foreach ($app_types as $i => $type) { if (!(strpos($index_content, $type) === false) || !(strpos($htaccess_content, $type) === false)) { $app = null; switch ($type) { case 'WordPress': $this->log_action('Detected WordPress for ' . $folder); $app = new A2OptWordPress((object) ['path' => $folder,'domain' => $domain]); if (is_null($app->type)) { $this->log_action('Unable to configure ' . $folder); $app = null; } break; case 'Drupal': case 'Drupal 9': $this->log_action('Detected Drupal for ' . $folder); $dr_ver = $this->get_drupal_version($folder); if ($dr_ver == 7) { $app = new A2OptDrupal((object) [ 'path' => $folder, 'domain' => $domain, 'dr_ver' => $dr_ver ]); if (is_null($app->type)) { $this->log_action('Unable to configure (v' . $dr_ver . ') ' . $folder); $app = null; } } elseif ($dr_ver == 8 || $dr_ver == 9) { $app = new A2OptDrupal8((object) [ 'path' => $folder, 'domain' => $domain, 'dr_ver' => $dr_ver ]); if (is_null($app->type)) { $this->log_action('Unable to configure (v' . $dr_ver . ') ' . $folder); $app = null; } } else { $this->log_action('Drupal 6 not supported, size of /includes/bootstrap.inc is ' . filesize("{$folder}/includes/bootstrap.inc") . ' for ' . $folder); $app = null; } break; case 'Magento': $this->log_action('Detected Magento for ' . $folder); if (!is_dir("{$folder}/js/mage")) { $this->log_action('No /js/mage folder ' . $folder); $app = null; } else { $app = new A2OptMagento((object) ['path' => $folder,'domain' => $domain]); if (is_null($app->type)) { $this->log_action('Unable to configure ' . $folder); $app = null; } } break; case 'PrestaShop': $this->log_action('Detected PrestaShop for ' . $folder); if (is_dir("{$folder}/tools")) { $content = file_get_contents("{$folder}/tools/index.php"); if (strpos($content, $type) === false) { $this->log_action('No /tools/index.php ' . $folder); $app = null; } else { $ps_ver = $this->get_prestashop_version($folder); $app = new A2OptPrestaShop((object) [ 'path' => $folder, 'domain' => $domain, 'ps_ver' => $ps_ver ]); if (is_null($app->type)) { $this->log_action('Unable to configure ' . $folder); $app = null; } } } else { $this->log_action('No /tools ' . $folder); $app = null; } break; case 'Joomla': $this->log_action('Detected Joomla for ' . $folder); // added checking for configuration.php and JConfig inside of it for more accuracy if (!(file_exists("{$folder}/configuration.php") && strpos(file_get_contents("{$folder}/index.php"), 'JConfig') == false)) { $this->log_action('No /configuration.php or does not contain JConfig ' . $folder); $app = null; } else { $app = new A2OptJoomla((object) ['path' => $folder,'domain' => $domain]); if (is_null($app->type)) { $this->log_action('Unable to configure ' . $folder); $app = null; } } break; case 'opencart': $this->log_action('Detected OpenCart for ' . $folder); if ( !( file_exists("{$folder}/config.php") && is_dir("{$folder}/system") && is_dir("{$folder}/catalog") ) ) { $this->log_action('No /config.php, /system, or /catalog for ' . $folder); $app = null; } else { $app = new A2OptOpenCart((object) ['path' => $folder,'domain' => $domain]); if (is_null($app->type)) { $this->log_action('Unable to configure ' . $folder); $app = null; } } } if (!is_null($app)) { $docroot = array_search($app->domain, $this->docroots); $c = count(explode('/', trim($docroot, '/'))); $f = implode('/', array_slice(explode('/', trim($app->path, '/')), $c - 1)); implode('/', array_diff(explode('/', $docroot), explode('/', $app->path))); $app_no_memcached = false; if (isset($app->no_memcached)) { $app_no_memcached = $app->no_memcached; } return (object) [ 'type' => $app->type, 'title' => $app->title, 'domain' => $app->domain, 'path' => $app->path, 'docroot' => $docroot, 'no_memcached' => $app_no_memcached, 'url' => "{$app->domain}/{$f}", 'siteurl' => isset($app->siteurl) ? $app->siteurl : $app->domain, 'homeurl' => isset($app->homeurl) ? $app->homeurl : $app->domain, 'loginurl' => isset($app->loginurl) ? $app->loginurl : '', 'can_login' => ((isset($app->can_login)) ? $app->can_login : false), 'a2_optimized' => ((isset($app->a2_optimized)) ? $app->a2_optimized : false), 'notes' => ((isset($app->notes)) ? $app->notes : false) ]; } } } } return null; } public function print_apps() { echo json_encode($this->get_apps()); } public function get_app_by_path($path) { $app_orm = ORM::for_table('apps')->where('app_path', $path)->find_one(); if ($app_orm) { $domains_orm = ORM::for_table('app_domains') ->where('app_id', $app_orm->id) ->find_many(); $domains = []; $ssl_domains = []; $a2_optimized = false; $can_login = false; $no_memcached = false; foreach ($domains_orm as $domain) { if ($domain->app_domain_isssl) { $ssl_domains[] = $domain->app_domain; } else { $domains[] = $domain->app_domain; } } if ($app_orm->app_a2optimized == 1) { $a2_optimized = true; } if ($app_orm->app_canlogin == 1) { $can_login = true; } if ($app_orm->app_nomemcached == 1) { $no_memcached = true; } $app = [ 'path' => $app_orm->app_path, 'docroot' => $app_orm->docroot, 'domains' => $domains, 'ssl_domains' => $ssl_domains, 'domain' => $app_orm->app_domain, 'type' => $app_orm->app_type, 'no_memcached' => $no_memcached, 'folder' => $app_orm->app_folder, 'title' => $app_orm->app_title, 'siteurl' => $app_orm->app_siteurl, 'homeurl' => $app_orm->app_homeurl, 'loginurl' => $app_orm->app_loginurl, 'can_login' => $can_login, 'a2_optimized' => $a2_optimized, 'notes' => $app_orm->app_notes, 'swiftcache' => (object) [ 'turbocache' => json_decode($app_orm->app_swiftcache_turbocache), ], ]; $this->app = (object) $app; return $app; } else { return false; } } public function get_active_app_paths() { $active_apps = []; $existing_apps_orm = ORM::for_table('apps')->find_many(); foreach ($existing_apps_orm as $app) { $active_apps[] = $app->app_path; } return $active_apps; } public function find_applications($echo = true, $refresh = false) { $active_app_paths = []; if ($refresh == false) { $active_app_paths = $this->get_active_app_paths(); } $app_list = []; $this->docroots = $this->cpanel->api2('DomainLookup', 'getdocroots'); $this->addons = $this->cpanel->api2('AddonDomain', 'listaddondomains'); $this->parked = $this->cpanel->api2('Park', 'listparkeddomains'); $this->docroots = $this->docroots['cpanelresult']['data']; $this->addons = $this->addons['cpanelresult']['data']; $this->parked = $this->parked['cpanelresult']['data']; $docroots = []; $ssl_domains = []; foreach ($this->docroots as $i => $docroot) { if ( isset($docroots[$docroot['docroot']]) ) { array_push($docroots[$docroot['docroot']], $docroot['domain']); } else { $docroots[$docroot['docroot']] = [$docroot['domain']]; } } $this->docroots = $docroots; ksort($this->docroots);//sorts the docroots array by folder foreach ($this->docroots as $path => $domains) { $tmp_domains = $domains; foreach ($tmp_domains as $i => $domain) { if (!in_array("www.{$domain}", $domains)) { array_push($domains, "www.{$domain}"); } } } foreach ($this->docroots as $path => $domains) { $app = []; if ($inodes = scandir($path)) { if (!in_array($path, $active_app_paths)) { if ($app = $this->find_application($path, $domains[0])) { $ssl_domains = []; foreach ($domains as $i => $domain) { if ($this->is_ssl($domain)) { array_push($ssl_domains, $domain); } } $app_list[$path] = [ 'path' => $path, 'docroot' => $path, 'domains' => $domains, 'ssl_domains' => $ssl_domains, 'domain' => $app->domain, 'type' => $app->type, 'no_memcached' => $app->no_memcached, 'folder' => '/', 'title' => $app->title, 'siteurl' => isset($app->siteurl) ? $app->siteurl : $app->domain, 'homeurl' => isset($app->homeurl) ? $app->homeurl : $app->domain, 'loginurl' => isset($app->loginurl) ? $app->loginurl : $app->domain, 'can_login' => ((isset($app->can_login)) ? $app->can_login : false), 'a2_optimized' => ((isset($app->a2_optimized)) ? $app->a2_optimized : false), 'notes' => ((isset($app->notes)) ? $app->notes : false) ]; } } else { // skipping $app_list[$path] = $this->get_app_by_path($path); } foreach ($inodes as $i => $name) { $fullpath = "{$path}/{$name}"; if (!isset($this->docroots[$fullpath])) { if ($name != '.' && $name != '..' && is_dir("{$path}/{$name}") && $this->is_not_docroot("{$path}/{$name}")) { if (!in_array($fullpath, $active_app_paths)) { if ($app = $this->find_application($fullpath, $domains[0])) { $ssl_domains = []; foreach ($domains as $j => $domain) { if ($this->is_ssl($domain)) { array_push($ssl_domains, $domain); } } $app_list[$fullpath] = [ 'path' => $fullpath, 'docroot' => $path, 'domains' => $domains, 'ssl_domains' => $ssl_domains, 'domain' => $app->domain, 'type' => $app->type, 'no_memcached' => $app->no_memcached, 'folder' => str_replace($path, '', $fullpath), 'title' => $app->title, 'siteurl' => isset($app->siteurl) ? $app->siteurl : $app->domain, 'homeurl' => isset($app->homeurl) ? $app->homeurl : $app->domain, 'loginurl' => isset($app->loginurl) ? $app->loginurl : $app->domain, 'can_login' => ((isset($app->can_login)) ? $app->can_login : false), 'a2_optimized' => ((isset($app->a2_optimized)) ? $app->a2_optimized : false), 'notes' => ((isset($app->notes)) ? $app->notes : false) ]; } } else { // skipping $app_list[$fullpath] = $this->get_app_by_path($fullpath); } } } } } } $this->apps = $this->get_apps(); foreach ($app_list as $path => $app) { if (isset($this->apps[$path]['nickname']) && $this->apps[$path]['nickname'] != null) { $app_list[$path]['nickname'] = $this->apps[$path]['nickname']; } else { unset($app_list[$path]['nickname']); } if (isset($this->apps[$path]['swiftcache'])) { $app_list[$path]['swiftcache'] = $this->apps[$path]['swiftcache']; } if (isset($this->apps[$path]['optimize'])) { $app_list[$path]['optimize'] = $this->apps[$path]['optimize']; } if (isset($this->apps[$path]['optimizations'])) { $app_list[$path]['optimizations'] = $this->apps[$path]['optimizations']; } $this->apps[$path] = $app_list[$path]; } $this->add_apps_to_db(); if ($echo) { echo json_encode($app_list); return $app_list; } else { return $app_list; } } public function find_certs() { global $cpanel; $certs = (object) $cpanel->api2( 'SSL', 'listcrts' ); $this->certs = $certs->cpanelresult->data; } } Save