diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 5f6f62568b..4867088c1f 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -90,9 +90,9 @@ if ($get_response_params) { } if ($get_response_target) { - $response_id = get_parameter('response_id'); - $event_id = get_parameter('event_id'); - $server_id = get_parameter('server_id', 0); + $response_id = (int) get_parameter('response_id'); + $event_id = (int) get_parameter('event_id'); + $server_id = (int) get_parameter('server_id'); $event_response = db_get_row('tevent_response', 'id', $response_id); @@ -101,7 +101,6 @@ if ($get_response_target) { } echo events_get_response_target($event_id, $response_id, $server_id); - return; } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 4cc54c5857..eb4d45d538 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -2089,27 +2089,34 @@ function events_page_responses($event, $childrens_ids=[]) } -// Replace macros in the target of a response and return it -// If server_id > 0, is a metaconsole query -function events_get_response_target($event_id, $response_id, $server_id, $history=false) -{ +/** + * Replace macros in the target of a response and return it. + * If server_id > 0, it's a metaconsole query. + * + * @param integer $event_id Event identifier. + * @param integer $response_id Event response identifier. + * @param integer $server_id Node identifier (for metaconsole). + * @param boolean $history Use the history database or not. + * + * @return string The response text with the macros applied. + */ +function events_get_response_target( + int $event_id, + int $response_id, + int $server_id=0, + bool $history=false +) { global $config; - $event_response = db_get_row('tevent_response', 'id', $response_id); - - if ($server_id > 0) { - $meta = true; - } else { - $meta = false; - } - + // If server_id > 0, it's a metaconsole query. + $meta = $server_id > 0; $event_table = events_get_events_table($meta, $history); - $event = db_get_row($event_table, 'id_evento', $event_id); + $event_response = db_get_row('tevent_response', 'id', $response_id); $target = io_safe_output($event_response['target']); - // Substitute each macro + // Substitute each macro. if (strpos($target, '_agent_address_') !== false) { if ($meta) { $agente_table_name = 'tmetaconsole_agent'; @@ -2123,7 +2130,7 @@ function events_get_response_target($event_id, $response_id, $server_id, $histor } $ip = db_get_value_filter('direccion', $agente_table_name, $filter); - // If agent has not an ip, display N/A + // If agent has not an IP, display N/A. if ($ip === false) { $ip = __('N/A'); } @@ -2288,7 +2295,7 @@ function events_get_response_target($event_id, $response_id, $server_id, $histor $target = str_replace('_group_custom_id_', $group_custom_id, $target); } - // Parse the event custom data + // Parse the event custom data. if (!empty($event['custom_data'])) { $custom_data = json_decode(base64_decode($event['custom_data'])); foreach ($custom_data as $key => $value) { @@ -2296,6 +2303,11 @@ function events_get_response_target($event_id, $response_id, $server_id, $histor } } + // This will replace the macro with the current logged user. + if (strpos($target, '_current_user_') !== false) { + $target = str_replace('_current_user_', $config['id_user'], $target); + } + return $target; } diff --git a/pandora_console/include/help/en/help_response_macros.php b/pandora_console/include/help/en/help_response_macros.php index 38aae0eeab..37abe115fa 100644 --- a/pandora_console/include/help/en/help_response_macros.php +++ b/pandora_console/include/help/en/help_response_macros.php @@ -32,7 +32,8 @@ The accepted macros are: