From fafe4bc9b470a61fddc7e0cc300f6e01812b5f06 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 23 Nov 2023 17:21:37 +0100 Subject: [PATCH] #10316 new function return_agent_macros --- .../godmode/agentes/module_manager.php | 12 +++- pandora_console/include/ajax/module.php | 19 +++++- pandora_console/include/functions_macros.php | 61 +++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 pandora_console/include/functions_macros.php diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 3e76a1baef..c3772c00d3 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -38,6 +38,7 @@ $isFunctionPolicies = enterprise_include_once('include/functions_policies.php'); require_once $config['homedir'].'/include/functions_modules.php'; require_once $config['homedir'].'/include/functions_agents.php'; require_once $config['homedir'].'/include/functions_servers.php'; +require_once $config['homedir'].'/include/functions_macros.php'; $search_string = get_parameter('search_string'); @@ -953,7 +954,16 @@ if ($modules !== false) { if ($module['ip_target'][0] == '_' && $module['ip_target'][(strlen($module['ip_target']) - 1)] == '_') { $custom_field_name = substr($module['ip_target'], 1, -1); $custom_value = agents_get_agent_custom_field($id_agente, $custom_field_name); - $title .= '
IP: '.$custom_value; + if (isset($custom_value) && $custom_value !== false) { + $title .= '
IP: '.$custom_value; + } else { + $array_macros = return_agent_macros($id_agente); + if (isset($array_macros[$module['ip_target']])) { + $title .= '
IP: '.$array_macros[$module['ip_target']]; + } else { + $title .= '
IP: '.$module['ip_target']; + } + } } else { $title .= '
IP: '.$module['ip_target']; } diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 78daacb0a0..620e4a6588 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -35,6 +35,7 @@ if (check_login()) { include_once $config['homedir'].'/include/functions_agents.php'; include_once $config['homedir'].'/include/functions_modules.php'; include_once $config['homedir'].'/include/functions_ui.php'; + include_once $config['homedir'].'/include/functions_macros.php'; enterprise_include_once('include/functions_metaconsole.php'); $get_plugin_macros = get_parameter('get_plugin_macros'); @@ -1197,7 +1198,23 @@ if (check_login()) { ); if (strlen($module['ip_target']) !== 0) { - $title .= '
IP: '.$module['ip_target']; + // Check if value is custom field. + if ($module['ip_target'][0] == '_' && $module['ip_target'][(strlen($module['ip_target']) - 1)] == '_') { + $custom_field_name = substr($module['ip_target'], 1, -1); + $custom_value = agents_get_agent_custom_field($id_agente, $custom_field_name); + if (isset($custom_value) && $custom_value !== false) { + $title .= '
IP: '.$custom_value; + } else { + $array_macros = return_agent_macros($id_agente); + if (isset($array_macros[$module['ip_target']])) { + $title .= '
IP: '.$array_macros[$module['ip_target']]; + } else { + $title .= '
IP: '.$module['ip_target']; + } + } + } else { + $title .= '
IP: '.$module['ip_target']; + } } $last_status_change_text = __('Time elapsed since last status change: '); diff --git a/pandora_console/include/functions_macros.php b/pandora_console/include/functions_macros.php new file mode 100644 index 0000000000..bba0bd1898 --- /dev/null +++ b/pandora_console/include/functions_macros.php @@ -0,0 +1,61 @@ + ($agente['nombre']) ?: '', + '_agentalias_' => ($agente['alias']) ?: '', + '_agent_' => ($agente['alias']) ?: (($agente['nombre']) ?: ''), + '_agentcustomid_' => ($agente['custom_id']) ?: '', + '_agentdescription_' => ($agente['comentarios']) ?: '', + '_agentgroup_' => ($grupo['nombre']) ?: '', + '_agentos_' => ($agente['id_os']) ?: '', + '_address_' => ($agente['direccion']) ?: '', + '_homeurl_' => ($config['public_url']) ?: '', + '_groupcontact_' => ($agente['contact']) ?: '', + '_groupcustomid_' => ($agente['custom_id']) ?: '', + '_groupother_' => ($agente['other']) ?: '', + '_server_ip_' => ($server_ip) ?: '', + '_server_name_' => ($agente['server_name']) ?: '', + ]; + + return $array_macros; +}