From db056100e2f7807f6c701d8887694d2904569838 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 25 Oct 2017 17:44:59 +0200 Subject: [PATCH] [Console > Tree view] Added a filter by group name and improved the filter by group id --- pandora_console/include/class/Tree.class.php | 70 +++++++++++--------- pandora_console/operation/tree.php | 21 +++--- 2 files changed, 53 insertions(+), 38 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 6dc52ea68d..21d201a6d4 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -23,6 +23,7 @@ class Tree { protected $filter = array(); protected $childrenMethod = "on_demand"; + protected $userGroupsACL; protected $userGroups; protected $strictACL = false; @@ -36,45 +37,54 @@ class Tree { $this->id = $id; $this->rootID = !empty($rootID) ? $rootID : $id; $this->serverID = $serverID; - $this->childrenMethod = $childrenMethod; - $this->access = $access; - - $userGroups = users_get_groups(false, $this->access); + $this->childrenMethod = $childrenMethod; + $this->access = $access; - if (empty($userGroups)) - $this->userGroups = false; - else - $this->userGroups = $userGroups; + $userGroupsACL = users_get_groups(false, $this->access); + $this->userGroupsACL = empty($userGroupsACL) ? false : $userGroupsACL; + $this->userGroups = $this->userGroupsACL; global $config; include_once($config['homedir']."/include/functions_servers.php"); include_once($config['homedir']."/include/functions_modules.php"); require_once($config['homedir']."/include/functions_tags.php"); - if (is_metaconsole()) - enterprise_include_once("meta/include/functions_ui_meta.php"); + if (is_metaconsole()) enterprise_include_once("meta/include/functions_ui_meta.php"); $this->strictACL = (bool) db_get_value("strict_acl", "tusuario", "id_user", $config['id_user']); $this->acltags = tags_get_user_module_and_tags($config['id_user'], $this->access); } - public function setType($type) { - $this->type = $type; - } - public function setFilter($filter) { + // Filter the user groups + if (!empty($filter['groupID'])) { + $group_id = $filter['groupID']; + $this->userGroups = isset($this->userGroupsACL[$group_id]) + ? array($group_id => $this->userGroupsACL[$group_id]) + : array(); + } + else if (!empty($filter['searchGroup'])) { + $groups = db_get_all_rows_filter('tgrupo', array('nombre' => '%' . $filter['searchGroup'] . '%')); + + // Save the groups which intersect + $userGroupsACL = $this->userGroupsACL; + $this->userGroups = array_reduce($groups, function ($userGroups, $group) use ($userGroupsACL) { + $group_id = $group['id_grupo']; + if (isset($userGroupsACL[$group_id])) { + $userGroups[$group_id] = $userGroupsACL[$group_id]; + } + + return $userGroups; + }, array()); + } + else { + $this->userGroups = $this->userGroupsACL; + } + $this->filter = $filter; } - public function isStrict () { - return $this->strictACL; - } - - public function setStrict ($value) { - $this->strictACL = (bool) $value; - } - protected function getAgentStatusFilter ($status = -1) { if ($status == -1) $status = $this->filter['statusAgent']; @@ -323,7 +333,7 @@ class Tree { case 'group': // ACL Group $user_groups_str = "-1"; - $group_acl = ""; + $group_filter = ""; if (!$this->strictACL) { if (empty($this->userGroups)) { return; @@ -338,7 +348,7 @@ class Tree { // Asking for all groups. else { $user_groups_str = implode(",", array_keys($this->userGroups)); - $group_acl = "AND ta.id_grupo IN ($user_groups_str)"; + $group_filter = "AND ta.id_grupo IN ($user_groups_str)"; } } else { @@ -356,7 +366,7 @@ class Tree { } } } - $group_acl = "AND ta.id_grupo IN ($user_groups_str)"; + $group_filter = "AND ta.id_grupo IN ($user_groups_str)"; } switch ($type) { @@ -390,7 +400,7 @@ class Tree { $module_status_join WHERE ta.disabled = 0 AND ta.id_grupo = $item_for_count - $group_acl + $group_filter $agent_search_filter $agent_status_filter"; $sql = $this->getAgentCountersSql($agent_table); @@ -411,7 +421,7 @@ class Tree { FROM tmetaconsole_agent ta WHERE ta.disabled = 0 AND ta.id_grupo = $item_for_count - $group_acl + $group_filter $agent_search_filter $agent_status_filter"; $sql = $this->getAgentCountersSql($agent_table); @@ -439,7 +449,7 @@ class Tree { $module_status_join WHERE ta.disabled = 0 AND ta.id_grupo = $rootID - $group_acl + $group_filter $agent_search_filter $agent_status_filter GROUP BY $group_by_fields @@ -456,7 +466,7 @@ class Tree { FROM tmetaconsole_agent ta WHERE ta.disabled = 0 AND ta.id_grupo = $rootID - $group_acl + $group_filter $agent_search_filter $agent_status_filter ORDER BY $order_fields"; @@ -498,7 +508,7 @@ class Tree { ON ta.disabled = 0 AND tam.id_agente = ta.id_agente AND ta.id_grupo = $rootID - $group_acl + $group_filter $agent_search_filter $agent_status_filter WHERE tam.disabled = 0 diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index c7a23fb0fd..993f95c4fe 100755 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -18,6 +18,7 @@ global $config; $pure = get_parameter('pure', 0); $tab = get_parameter('tab', 'group'); +$search_group = get_parameter('searchGroup', ''); $search_agent = get_parameter('searchAgent', ''); $status_agent = get_parameter('statusAgent', AGENT_STATUS_ALL); $search_module = get_parameter('searchModule', ''); @@ -135,13 +136,16 @@ $agent_status_arr[AGENT_STATUS_UNKNOWN] = __('Unknown'); $agent_status_arr[AGENT_STATUS_NOT_INIT] = __('Not init'); $row = array(); +$row[] = __('Search group'); +$row[] = html_print_input_text("search_group", $search_group, '', is_metaconsole() ? 70 : 40, 30, true); + +$table->data[] = $row; + +$row = array(); +$row[] = __('Search agent'); +$row[] = html_print_input_text("search_agent", $search_agent, '', is_metaconsole() ? 70 : 40, 30, true); $row[] = __('Agent status'); $row[] = html_print_select($agent_status_arr, "status_agent", $status_agent, '', '', 0, true); -$row[] = __('Search agent'); -if (is_metaconsole()) - $row[] = html_print_input_text("search_agent", $search_agent, '', 70, 30, true); -else - $row[] = html_print_input_text("search_agent", $search_agent, '', 40, 30, true); // Button $row[] = html_print_submit_button(__('Filter'), "uptbutton", false, 'class="sub search"', true); @@ -160,10 +164,10 @@ if (!is_metaconsole()) { $module_status_arr[AGENT_MODULE_STATUS_NOT_INIT] = __('Not init'); $row = array(); - $row[] = __('Module status'); - $row[] = html_print_select($module_status_arr, "status_module", $status_module, '', '', 0, true); $row[] = __('Search module'); $row[] = html_print_input_text("search_module", $search_module, '', 40, 30, true); + $row[] = __('Module status'); + $row[] = html_print_select($module_status_arr, "status_module", $status_module, '', '', 0, true); $table->data[] = $row; } @@ -240,8 +244,9 @@ enterprise_hook('close_meta_frame'); var parameters = {}; parameters['page'] = "include/ajax/tree.ajax"; parameters['getChildren'] = 1; - parameters['filter'] = {}; parameters['type'] = ""; + parameters['filter'] = {}; + parameters['filter']['searchGroup'] = $("input#text-search_group").val(); parameters['filter']['searchAgent'] = $("input#text-search_agent").val(); parameters['filter']['statusAgent'] = $("select#status_agent").val(); parameters['filter']['searchModule'] = $("input#text-search_module").val();