list_status = array( -1 => __('All'), AGENT_MODULE_STATUS_CRITICAL_BAD => __('Critical'), AGENT_MODULE_STATUS_NORMAL => __('Normal'), AGENT_MODULE_STATUS_WARNING => __('Warning'), AGENT_MODULE_STATUS_UNKNOWN => __('Unknown')); if ($system->checkACL($this->acl)) { $this->correct_acl = true; } else { $this->correct_acl = false; } } public function ajax($parameter2 = false) { $system = System::getInstance(); if (!$this->correct_acl) { return; } else { switch ($parameter2) { case 'get_agents': $this->getFilters(); $page = $system->getRequest('page', 0); $agents = array(); $end = 1; $listAgents = $this->getListAgents($page, true); if (!empty($listAgents['agents'])) { $end = 0; $agents = array(); foreach ($listAgents['agents'] as $key => $agent) { $agent[0] = '' . __('Agent') . '' . $agent[0]; //~ $agent[1] = '' . //~ __('Description') . '' . $agent[1]; $agent[2] = '' . __('OS') . '' . $agent[2]; $agent[3] = '' . __('Group') . '' . $agent[3]; //~ $agent[4] = '' . //~ __('Interval') . '' . $agent[4]; $agent[5] = '' . __('Modules') . '' . $agent[5]; $agent[6] = '' . __('Status') . '' . $agent[6]; $agent[7] = '' . __('Alerts') . '' . $agent[7]; $agent[8] = '' . __('Last contact') . '' . $agent[8]; $agents[$key] = $agent; } } echo json_encode(array('end' => $end, 'agents' => $agents)); break; } } } private function getFilters() { $system = System::getInstance(); $user = User::getInstance(); $this->default_filters['group'] = true; $this->default_filters['status'] = true; $this->default_filters['free_search'] = 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")) || ($this->status == -1)) { $this->status = -1; } 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; } } public function show() { if (!$this->correct_acl) { $this->show_fail_acl(); } else { $this->getFilters(); $this->show_agents(); } } private function show_fail_acl() { $error['type'] = 'onStart'; $error['title_text'] = __('You don\'t have access to this page'); $error['content_text'] = __('Access to this page is restricted to authorized users only, please contact system administrator if you need assistance.

Please know that all attempts to access this page are recorded in security logs of Pandora System Database'); if (class_exists("HomeEnterprise")) $home = new HomeEnterprise(); else $home = new Home(); $home->show($error); } private function show_agents() { $ui = Ui::getInstance(); $ui->createPage(); $ui->createDefaultHeader(__("Agents"), $ui->createHeaderButton( array('icon' => 'back', 'pos' => 'left', 'text' => __('Back'), 'href' => 'index.php?page=home'))); $ui->showFooter(false); $ui->beginContent(); $filter_title = sprintf(__('Filter Agents by %s'), $this->filterEventsGetString()); $ui->contentBeginCollapsible($filter_title); $ui->beginForm("index.php?page=agents"); $system = System::getInstance(); $groups = users_get_groups_for_select( $system->getConfig('id_user'), "AR", true, true, false, 'id_grupo'); $options = array( 'name' => 'group', 'title' => __('Group'), 'label' => __('Group'), 'items' => $groups, 'selected' => $this->group ); $ui->formAddSelectBox($options); $options = array( 'name' => 'status', 'title' => __('Status'), 'label' => __('Status'), 'items' => $this->list_status, 'selected' => $this->status ); $ui->formAddSelectBox($options); $options = array( 'name' => 'free_search', 'value' => $this->free_search, 'placeholder' => __('Free search') ); $ui->formAddInputSearch($options); $options = array( 'icon' => 'refresh', 'icon_pos' => 'right', 'text' => __('Apply Filter') ); $ui->formAddSubmitButton($options); $html = $ui->getEndForm(); $ui->contentCollapsibleAddItem($html); $ui->contentEndCollapsible(); $this->listAgentsHtml(); $ui->endContent(); $ui->showPage(); } private function getListAgents($page = 0, $ajax = false) { $system = System::getInstance(); $total = 0; $agents = array(); $search_sql = ''; if (!empty($this->free_search)) { $search_sql = " AND ( nombre COLLATE utf8_general_ci LIKE '%" . $this->free_search . "%' OR direccion LIKE '%" . $this->free_search . "%' OR comentarios LIKE '%" . $this->free_search . "%') "; } $total = agents_get_agents(array( 'disabled' => 0, 'id_grupo' => $this->group, 'search' => $search_sql, 'status' => $this->status), array ('COUNT(*) AS total'), 'AR', false); $total = isset($total[0]['total']) ? $total[0]['total'] : 0; $order = array('field' => 'nombre COLLATE utf8_general_ci', 'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC'); $agents_db = agents_get_agents(array( 'disabled' => 0, 'id_grupo' => $this->group, 'search' => $search_sql, 'status' => $this->status, 'offset' => (int) $page * $system->getPageSize(), 'limit' => (int) $system->getPageSize()), array ('id_agente', 'id_grupo', 'id_os', 'nombre', 'ultimo_contacto', 'intervalo', 'comentarios description', 'quiet', 'normal_count', 'warning_count', 'critical_count', 'unknown_count', 'notinit_count', 'total_count', 'fired_count'), 'AR', $order); if (empty($agents_db)) $agents_db = array(); foreach ($agents_db as $agent) { $row = array(); $img_status = agents_tree_view_status_img ($agent["critical_count"], $agent["warning_count"], $agent["unknown_count"], $agent['total_count'], $agent['notinit_count']); $img_alert = agents_tree_view_alert_img ($agent["fired_count"]); $row[0] = $row[__('Agent')] = '' . $img_status . '' . '' . ui_print_truncate_text(io_safe_output($agent['nombre']), 30, false) . ''; //~ $row[1] = $row[__('Description')] = '' . //~ ui_print_truncate_text($agent["description"], 'description', false, true) . //~ ''; $row[2] = $row[__('OS')] = ui_print_os_icon ($agent["id_os"], false, true); $row[3] = $row[__('Group')] = ui_print_group_icon ($agent["id_grupo"], true, "groups_small", '', false); //~ $row[4] = $row[__('Interval')] = '' . //~ '' . human_time_description_raw($agent["intervalo"]) . ''; $row[5] = $row[__('Status')] = '' . $img_status; $row[6] = $row[__('Alerts')] = '' . $img_alert; $row[7] = $row[__('Modules')] = '' . '' . reporting_tiny_stats($agent, true) . ' '; $last_time = strtotime ($agent["ultimo_contacto"]); $now = time (); $diferencia = $now - $last_time; $time = ui_print_timestamp ($last_time, true, array('style' => 'font-size: 12px; margin-left: 20px;', 'units' => 'tiny')); $style = ''; if ($diferencia > ($agent["intervalo"] * 2)) $row[8] = $row[__('Last contact')] = ''.$time.''; else $row[8] = $row[__('Last contact')] = $time; $row[8] = $row[__('Last contact')] = '' . '' . $row[__('Last contact')] . ''; if (!$ajax) { unset($row[0]); unset($row[1]); unset($row[2]); unset($row[3]); unset($row[4]); unset($row[5]); unset($row[6]); unset($row[7]); unset($row[8]); } $agents[$agent['id_agente']] = $row; } return array('agents' => $agents, 'total' => $total); } private function listAgentsHtml($page = 0) { $system = System::getInstance(); $ui = Ui::getInstance(); $listAgents = $this->getListAgents($page); if ($listAgents['total'] == 0) { $ui->contentAddHtml('

' . __('No agents') . '

'); } else { $table = new Table(); $table->id = 'list_agents'; $table->importFromHash($listAgents['agents']); $ui->contentAddHtml($table->getHTML()); if ($system->getPageSize() < $listAgents['total']) { $ui->contentAddHtml('
' . html_print_image('images/spinner.gif', true) . ' ' . __('Loading...') . '
'); $this->addJavascriptAddBottom(); } } $ui->contentAddLinkListener('list_agents'); } private function addJavascriptAddBottom() { $ui = Ui::getInstance(); $ui->contentAddHtml(""); } private function filterEventsGetString() { if ($this->default) { return __("(Default)"); } else { $filters_to_serialize = array(); if (!$this->default_filters['group']) { $filters_to_serialize[] = sprintf(__("Group: %s"), groups_get_name($this->group, true)); } if (!$this->default_filters['status']) { $filters_to_serialize[] = sprintf(__("Status: %s"), $this->list_status[$this->status]); } if (!$this->default_filters['free_search']) { $filters_to_serialize[] = sprintf(__("Free Search: %s"), $this->free_search); } $string = '(' . implode(' - ', $filters_to_serialize) . ')'; //~ $status = $this->list_status[$this->status]; //~ $group = groups_get_name($this->group, true); //~ //~ //~ $string = sprintf( //~ __("(Status: %s - Group: %s - Free Search: %s)"), //~ $status, $group, $this->free_search); return $string; } } } ?>