From d6fc15f0bfb25d55d3915932cb8efa84214a5534 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 6 Jun 2022 11:14:09 +0200 Subject: [PATCH] #8763 Added filter groups --- pandora_console/general/logon_ok.php | 11 +--- .../include/functions_tactical.php | 29 ++++++++-- .../lib/Dashboard/Widgets/tactical.php | 53 ++++++++++++++++++- pandora_console/mobile/operation/tactical.php | 2 +- .../operation/agentes/tactical.php | 2 +- 5 files changed, 82 insertions(+), 15 deletions(-) diff --git a/pandora_console/general/logon_ok.php b/pandora_console/general/logon_ok.php index d836d9f22c..67007073bb 100644 --- a/pandora_console/general/logon_ok.php +++ b/pandora_console/general/logon_ok.php @@ -42,17 +42,10 @@ if (tags_has_user_acl_tags()) { ui_print_tags_warning(); } -$user_strict = (bool) db_get_value( - 'strict_acl', - 'tusuario', - 'id_user', - $config['id_user'] -); $all_data = tactical_status_modules_agents( $config['id_user'], - $user_strict, - 'AR', - $user_strict + false, + 'AR' ); $data = []; diff --git a/pandora_console/include/functions_tactical.php b/pandora_console/include/functions_tactical.php index bfd556981b..5f67be70d4 100644 --- a/pandora_console/include/functions_tactical.php +++ b/pandora_console/include/functions_tactical.php @@ -471,7 +471,14 @@ function tactical_get_data($id_user=false, $user_strict=false, $acltags, $return $list['_monitors_alerts_fired_'] = tactical_monitor_fired_alerts(explode(',', $user_groups_ids), $user_strict, explode(',', $user_groups_ids)); $list['_monitors_alerts_'] = tactical_monitor_alerts($user_strict); - $total_agentes = agents_get_agents(false, ['count(DISTINCT id_agente) as total_agents'], 'AR', false, false, 1); + $total_agentes = agents_get_agents( + ['id_grupo' => explode(',', $user_groups_ids)], + ['count(DISTINCT id_agente) as total_agents'], + 'AR', + false, + false, + 1 + ); $list['_total_agents_'] = $total_agentes[0]['total_agents']; $list['_monitor_checks_'] = ($list['_monitors_not_init_'] + $list['_monitors_unknown_'] + $list['_monitors_warning_'] + $list['_monitors_critical_'] + $list['_monitors_ok_']); @@ -486,16 +493,32 @@ function tactical_get_data($id_user=false, $user_strict=false, $acltags, $return } -function tactical_status_modules_agents($id_user=false, $user_strict=false, $access='AR', $force_group_and_tag=true) +function tactical_status_modules_agents($id_user=false, $user_strict=false, $access='AR', $groups=[]) { global $config; - if ($id_user == false) { + if ($id_user === false) { $id_user = $config['id_user']; } + if (empty($groups) === false) { + if (is_array($groups) === false) { + $groups = explode(',', (string) $groups); + // Group id as key. + $groups = array_flip($groups); + } + + if (isset($groups[0]) === true) { + $groups = []; + } + } + $acltags = tags_get_user_groups_and_tags($id_user, $access, $user_strict); + if (empty($groups) === false) { + $acltags = array_intersect_key($acltags, $groups); + } + $result_list = tactical_get_data($id_user, $user_strict, $acltags); return $result_list; diff --git a/pandora_console/include/lib/Dashboard/Widgets/tactical.php b/pandora_console/include/lib/Dashboard/Widgets/tactical.php index 74d72d0c5c..063dd9c960 100755 --- a/pandora_console/include/lib/Dashboard/Widgets/tactical.php +++ b/pandora_console/include/lib/Dashboard/Widgets/tactical.php @@ -185,6 +185,7 @@ class TacticalWidget extends Widget if (empty($this->values['statusMonitor']) === true && empty($this->values['serverPerformance']) === true && empty($this->values['summary']) === true + && empty($this->values['groupId']) === true ) { $this->configurationRequired = true; } @@ -226,6 +227,18 @@ class TacticalWidget extends Widget $values['summary'] = $decoder['summary']; } + if (isset($decoder['id_groups']) === true) { + if (is_array($decoder['id_groups']) === true) { + $decoder['id_groups'][0] = implode(',', $decoder['id_groups']); + } + + $values['groupId'] = $decoder['id_groups']; + } + + if (isset($decoder['groupId']) === true) { + $values['groupId'] = $decoder['groupId']; + } + return $values; } @@ -292,6 +305,43 @@ class TacticalWidget extends Widget ], ]; + // Groups. + $return_all_group = false; + + // Restrict access to group. + $selected_groups = []; + if ($values['groupId']) { + $selected_groups = explode(',', $values['groupId'][0]); + + if (users_can_manage_group_all('AR') === true + || ($selected_groups[0] !== '' + && in_array(0, $selected_groups) === true) + ) { + // Return all group if user has permissions + // or it is a currently selected group. + $return_all_group = true; + } + } else { + if (users_can_manage_group_all('AR') === true) { + $return_all_group = true; + } + } + + $inputs[] = [ + 'label' => __('Groups'), + 'arguments' => [ + 'type' => 'select_groups', + 'name' => 'groupId[]', + 'returnAllGroup' => true, + 'privilege' => 'AR', + 'selected' => $selected_groups, + 'return' => true, + 'multiple' => true, + 'returnAllGroup' => $return_all_group, + 'required' => true, + ], + ]; + return $inputs; } @@ -311,6 +361,7 @@ class TacticalWidget extends Widget 'serverPerformance' ); $values['summary'] = \get_parameter_switch('summary'); + $values['groupId'] = \get_parameter('groupId', []); return $values; } @@ -327,7 +378,7 @@ class TacticalWidget extends Widget $output = ''; - $all_data = \tactical_status_modules_agents($config['id_user']); + $all_data = \tactical_status_modules_agents($config['id_user'], false, 'AR', $this->values['groupId'][0]); $data = []; diff --git a/pandora_console/mobile/operation/tactical.php b/pandora_console/mobile/operation/tactical.php index 51709c9abb..3651187833 100755 --- a/pandora_console/mobile/operation/tactical.php +++ b/pandora_console/mobile/operation/tactical.php @@ -109,7 +109,7 @@ class Tactical $ui->beginContent(); $ui->contentBeginGrid('responsive'); // ~ $data = reporting_get_group_stats(); - $all_data = tactical_status_modules_agents($config['id_user'], $user_strict, 'AR', $user_strict); + $all_data = tactical_status_modules_agents($config['id_user'], false, 'AR'); $data = []; diff --git a/pandora_console/operation/agentes/tactical.php b/pandora_console/operation/agentes/tactical.php index 2b331e6df7..ce334d873e 100755 --- a/pandora_console/operation/agentes/tactical.php +++ b/pandora_console/operation/agentes/tactical.php @@ -86,7 +86,7 @@ ui_print_standard_header( // Currently this function makes loading this page is impossible. Change // and create new function. -$all_data = tactical_status_modules_agents($config['id_user'], $user_strict, 'AR', $user_strict); +$all_data = tactical_status_modules_agents($config['id_user'], false, 'AR'); $data = [];