checkACL($this->acl)) { $this->correct_acl = true; } else { $this->correct_acl = false; } if ($system->getConfig('metaconsole') === 0) { $this->all_servers = true; } } public function ajax($parameter2=false) { $system = System::getInstance(); if (!$this->correct_acl) { return; } else { switch ($parameter2) { case 'get_server_status': $this->getFilters(); $page = $system->getRequest('page', 0); $servers = []; $end = 1; $listServers = $this->getListServers($page, true); if (!empty($listServers['servers'])) { $end = 0; $servers = $listServers['servers']; } echo json_encode(['end' => $end, 'servers' => $servers]); break; } } } public function setFilters($filters) { if (isset($filters['id_agent'])) { $this->id_agent = $filters['id_agent']; } if (isset($filters['all_servers'])) { $this->all_servers = $filters['all_servers']; } if (isset($filters['status'])) { $this->status = (int) $filters['status']; } if (isset($filters['name'])) { $this->name = $filters['name']; } } public function disabledColumns($columns=null) { if (!empty($columns)) { foreach ($columns as $column) { $this->columns[$column] = 0; } } } private function getFilters() { $system = System::getInstance(); $user = User::getInstance(); $this->default_filters['module_group'] = true; $this->default_filters['group'] = true; $this->default_filters['status'] = true; $this->default_filters['free_search'] = true; $this->default_filters['tag'] = true; $this->free_search = $system->getRequest('free_search', ''); if ($this->free_search != '') { $this->default = false; $this->default_filters['free_search'] = false; } $this->status = $system->getRequest('status', __('Status')); if (($this->status === __('Status')) || ((int) $this->status === AGENT_MODULE_STATUS_ALL)) { $this->status = AGENT_MODULE_STATUS_ALL; } else { $this->default = false; $this->default_filters['status'] = false; } $this->group = (int) $system->getRequest('group', __('Group')); if (!$user->isInGroup($this->acl, $this->group)) { $this->group = 0; } if (($this->group === __('Group')) || ($this->group == 0)) { $this->group = 0; } else { $this->default = false; $this->default_filters['group'] = false; } $this->module_group = (int) $system->getRequest('module_group', __('Module group')); if (($this->module_group === __('Module group')) || ($this->module_group === -1) || ($this->module_group == 0) ) { $this->module_group = -1; } else { $this->default = false; $this->module_group = (int) $this->module_group; $this->default_filters['module_group'] = false; } $this->tag = (int) $system->getRequest('tag', __('Tag')); if (($this->tag === __('Tag')) || ($this->tag == 0)) { $this->tag = 0; } else { $this->default = false; $this->default_filters['tag'] = false; } } public function show() { if (!$this->correct_acl) { $this->show_fail_acl(); } else { $this->getFilters(); $this->show_servers(); } } private function show_fail_acl() { $error['type'] = 'onStart'; $error['title_text'] = __('You don\'t have access to this page'); $error['content_text'] = System::getDefaultACLFailText(); if (class_exists('HomeEnterprise')) { $home = new HomeEnterprise(); } else { $home = new Home(); } $home->show($error); } private function show_servers() { $ui = Ui::getInstance(); $ui->createPage(); $ui->createDefaultHeader( __('Server status'), $ui->createHeaderButton( [ 'icon' => 'ui-icon-back', 'pos' => 'left', 'text' => __('Back'), 'href' => 'index.php?page=home', 'class' => 'header-button-left', ] ) ); $ui->showFooter(false); $ui->beginContent(); $this->listServersHtml(); $ui->endContent(); $ui->showPage(); } private function getListServers($page=0, $ajax=false) { global $config; $system = System::getInstance(); $user = User::getInstance(); $total = 0; $servers = []; $servers_db = []; if ($this->all_servers === true) { $sql_limit = ' LIMIT '.(int) ($page * $system->getPageSize()).','.(int) $system->getPageSize(); } if ($system->getConfig('metaconsole')) { $servers_info = servers_get_info(); $total = (int) count(servers_get_info()); foreach ($servers_info as $server_value) { $image_status = ui_print_status_image(STATUS_SERVER_OK, '', true); if ($server_value['status'] == -1) { $image_status = ui_print_status_image( STATUS_SERVER_CRASH, __('Server has crashed.'), true ); } else if ($server_value['status'] == 0) { $image_status = ui_print_status_image( STATUS_SERVER_DOWN, __('Server is stopped.'), true ); } // $row[__('Status')] = ''.$server_value['status'].''; $row[__('Status')] = ''.$image_status.''; $row[__('Image')] = ''.$server_value['img'].''; $row[__('Name')] = ''.$server_value['name'].''; $servers[$server_value['id_server'].'-'.$server_value['name']] = $row; } $meta_servers = metaconsole_get_servers(); if ($meta_servers === false) { $meta_servers = []; } foreach ($meta_servers as $server) { if (metaconsole_connect($server) != NOERR) { continue; } $servers_info = servers_get_info(); $total += (int) count(servers_get_info()); foreach ($servers_info as $server_value) { $image_status = ui_print_status_image(STATUS_SERVER_OK, '', true); if ($server_value['status'] == -1) { $image_status = ui_print_status_image( STATUS_SERVER_CRASH, __('Server has crashed.'), true ); } else if ($server_value['status'] == 0) { $image_status = ui_print_status_image( STATUS_SERVER_DOWN, __('Server is stopped.'), true ); } // $row[__('Status')] = ''.$server_value['status'].''; $row[__('Status')] = ''.$image_status.''; $row[__('Image')] = ''.$server_value['img'].''; $row[__('Name')] = ''.$server_value['name'].''; $servers[$server_value['id_server']] = $row; } metaconsole_restore_db(); } } else { $servers_info = servers_get_info(-1, $sql_limit); $total = count(servers_get_info()); foreach ($servers_info as $server_value) { $image_status = ui_print_status_image(STATUS_SERVER_OK, '', true); if ($server_value['status'] == -1) { $image_status = ui_print_status_image( STATUS_SERVER_CRASH, __('Server has crashed.'), true ); } else if ($server_value['status'] == 0) { $image_status = ui_print_status_image( STATUS_SERVER_DOWN, __('Server is stopped.'), true ); } // $row[__('Status')] = ''.$server_value['status'].''; $row[__('Status')] = ''.$image_status.''; $row[__('Image')] = ''.$server_value['img'].''; $row[__('Name')] = ''.$server_value['name'].''; $servers[$server_value['id_server']] = $row; } } return [ 'servers' => $servers, 'total' => $total, ]; } public function listServersHtml($page=0, $return=false) { $system = System::getInstance(); $ui = Ui::getInstance(); $listServers = $this->getListServers($page); if ($listServers['total'] == 0) { $html = '
'.__('No servers').'
'; if (!$return) { $ui->contentAddHtml($html); } else { return $html; } } else { if (!$return) { $table = new Table(); $table->id = 'list_servers'; $table->importFromHash($listServers['servers']); $ui->contentAddHtml('