From 604633dd35a4ce12ef5473184edb454004f25201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Tue, 22 Feb 2022 12:37:01 +0100 Subject: [PATCH] Fixed issues with interfaces view and limited to show only agents with ifaces --- pandora_console/include/functions_agents.php | 9 ++++++-- .../operation/agentes/interface_view.php | 3 ++- .../operation/agentes/ver_agente.php | 23 +++++++++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 4de4aa94b7..cde89f1b7b 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1243,6 +1243,11 @@ function agents_get_group_agents( unset($search['string']); } + if (isset($search['matchIds']) === true && is_array($search['matchIds']) === true) { + $filter[] = sprintf('id_agente IN (%s)', implode(', ', $search['matchIds'])); + unset($search['matchIds']); + } + if (isset($search['name']) === true) { $name = io_safe_input($search['name']); $filter[] = "nombre LIKE '$name'"; @@ -3223,8 +3228,8 @@ function agents_get_network_interfaces($agents=false, $agents_filter=false) $ni_by_agents = []; foreach ($agents as $agent) { $agent_id = (isset($agent['id_agente'])) ? $agent['id_agente'] : $agent; - $agent_group_id = $agent['id_grupo']; - $agent_name = $agent['alias']; + $agent_group_id = (isset($agent['id_grupo']) === true) ? $agent['id_grupo'] : ''; + $agent_name = (isset($agent['alias']) === true) ? $agent['alias'] : ''; $agent_interfaces = []; $accepted_module_types = []; diff --git a/pandora_console/operation/agentes/interface_view.php b/pandora_console/operation/agentes/interface_view.php index 5a76a6afe3..1bba44ddc5 100644 --- a/pandora_console/operation/agentes/interface_view.php +++ b/pandora_console/operation/agentes/interface_view.php @@ -176,6 +176,7 @@ function load_agents_selector(group) { { "page" : "operation/agentes/ver_agente", "get_agents_group_json" : 1, + "get_agents_also_interfaces" : 1, "id_group" : group, "privilege" : "AW", "keys_prefix" : "_", @@ -216,6 +217,7 @@ $("#checkbox-recursion").change (function () { jQuery.post ("ajax.php", {"page" : "operation/agentes/ver_agente", "get_agents_group_json" : 1, + "get_agents_also_interfaces" : 1, "id_group" : $("#group_id").val(), "privilege" : "AW", "keys_prefix" : "_", @@ -226,7 +228,6 @@ $("#checkbox-recursion").change (function () { $("#module").html(''); jQuery.each (data, function (id, value) { id = id.substring(1); - option = $("") .attr ("value", value["id_agente"]) .html (value["alias"]); diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 5020d389f3..bca69043e2 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -49,6 +49,7 @@ if (is_ajax()) { $get_agent_modules_json = (bool) get_parameter('get_agent_modules_json'); $get_agent_status_tooltip = (bool) get_parameter('get_agent_status_tooltip'); $get_agents_group_json = (bool) get_parameter('get_agents_group_json'); + $get_agents_also_interfaces = (bool) get_parameter('get_agents_also_interfaces'); $get_modules_group_json = (bool) get_parameter('get_modules_group_json'); $filter_modules_group_json = (bool) get_parameter('filter_modules_group_json'); $get_modules_group_value_name_json = (bool) get_parameter('get_modules_group_value_name_json'); @@ -103,15 +104,15 @@ if (is_ajax()) { // Build filter. $filter = []; - if (!empty($id_os)) { + if (empty($id_os) === false) { $filter['id_os'] = $id_os; } - if (!empty($agent_name)) { + if (empty($agent_name) === false) { $filter['nombre'] = '%'.$agent_name.'%'; } - if (!empty($agent_alias)) { + if (empty($agent_alias) === false) { $filter['alias'] = '%'.$agent_alias.'%'; } @@ -147,6 +148,20 @@ if (is_ajax()) { } } + if ($get_agents_also_interfaces === true) { + $listAgentsWithIface = db_get_all_rows_sql("SELECT DISTINCT id_agente FROM tagente_modulo WHERE nombre LIKE '%_ifOperStatus'"); + if (empty($listAgentsWithIface) === false) { + $filter['matchIds'] = array_reduce( + $listAgentsWithIface, + function ($carry, $item) { + $carry[] = $item['id_agente']; + return $carry; + }, + [] + ); + } + } + // Perform search. $agents = agents_get_group_agents( // Id_group. @@ -171,7 +186,7 @@ if (is_ajax()) { (bool) is_metaconsole() ); - if (empty($agents)) { + if (empty($agents) === true) { $agents = []; }