diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index dcc92fa446..0d0b77ffd4 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -64,9 +64,9 @@ $add_comment = (bool) get_parameter('add_comment'); $dialogue_event_response = (bool) get_parameter('dialogue_event_response'); $perform_event_response = (bool) get_parameter('perform_event_response'); $get_response = (bool) get_parameter('get_response'); -$get_response_target = (bool) get_parameter('get_response_target'); -$get_response_params = (bool) get_parameter('get_response_params'); -$get_response_description = (bool) get_parameter('get_response_description'); +$get_response_massive = (bool) get_parameter('get_response_massive'); +$get_row_response_action = (bool) get_parameter('get_row_response_action'); +$draw_row_response_info = (bool) get_parameter('draw_row_response_info', false); $meta = get_parameter('meta', 0); $history = get_parameter('history', 0); $table_events = get_parameter('table_events', 0); @@ -1054,87 +1054,6 @@ $(document).ready(function (){ } -if ($get_response_description) { - $response_id = get_parameter('response_id'); - - $description = db_get_value('description', 'tevent_response', 'id', $response_id); - - if ($description === false) { - return; - } - - $description = io_safe_output($description); - $description = str_replace("\r\n", '
', $description); - - echo $description; - - return; -} - -if ($get_response_params) { - if (! check_acl($config['id_user'], 0, 'EW')) { - echo 'unauthorized'; - return; - } - - $response_id = get_parameter('response_id'); - - $params = db_get_value('params', 'tevent_response', 'id', $response_id); - - if ($params === false) { - return; - } - - echo json_encode(explode(',', $params)); - - return; -} - -if ($get_response_target === true) { - if (! check_acl($config['id_user'], 0, 'EW')) { - echo 'unauthorized'; - return; - } - - $response_id = (int) get_parameter('response_id'); - $event_id = (int) get_parameter('event_id'); - $server_id = (int) get_parameter('server_id'); - - try { - if (is_metaconsole() === true - && $server_id > 0 - ) { - $node = new Node($server_id); - $node->connect(); - } - - $event_response = db_get_row('tevent_response', 'id', $response_id); - - if (empty($event_response) === true) { - return; - } - - echo events_get_response_target($event_id, $response_id); - } catch (\Exception $e) { - // Unexistent agent. - if (is_metaconsole() === true - && $server_id > 0 - ) { - $node->disconnect(); - } - - return; - } finally { - if (is_metaconsole() === true - && $server_id > 0 - ) { - $node->disconnect(); - } - } - - return; -} - if ($get_response === true) { if (! check_acl($config['id_user'], 0, 'EW')) { echo 'unauthorized'; @@ -1142,62 +1061,27 @@ if ($get_response === true) { } $response_id = get_parameter('response_id'); - $server_id = (int) get_parameter('server_id'); + $server_id = (int) get_parameter('server_id', 0); + $event_id = (int) get_parameter('event_id', 0); + $response_parameters = json_decode( + io_safe_output( + get_parameter('response_parameters', '') + ), + true + ); - try { - if (is_metaconsole() === true - && $server_id > 0 - ) { - $node = new Node($server_id); - $node->connect(); - } - - $event_response = db_get_row( - 'tevent_response', - 'id', - $response_id - ); - } catch (\Exception $e) { - // Unexistent agent. - if (is_metaconsole() === true - && $server_id > 0 - ) { - $node->disconnect(); - } - - return; - } finally { - if (is_metaconsole() === true - && $server_id > 0 - ) { - $node->disconnect(); - } - } + $event_response = db_get_row( + 'tevent_response', + 'id', + $response_id + ); if (empty($event_response) === true) { - return; + return []; } - echo json_encode($event_response); - return; -} - -if ($perform_event_response === true) { - global $config; - - if (! check_acl($config['id_user'], 0, 'EW')) { - echo 'unauthorized'; - return; - } - - $target = get_parameter('target', ''); - $response_id = get_parameter('response_id'); - $event_id = (int) get_parameter('event_id'); - $server_id = (int) get_parameter('server_id', 0); - - $event_response = false; - if (empty($target) === true) { + if (empty($event_id) === false) { try { if (is_metaconsole() === true && $server_id > 0 @@ -1206,20 +1090,12 @@ if ($perform_event_response === true) { $node->connect(); } - $event_response = db_get_row( - 'tevent_response', - 'id', - $response_id - ); - - if (empty($event_response) === true) { - return; - } - - $command = events_get_response_target( + $event_response['target'] = events_get_response_target( $event_id, - $response_id, - $server_id + $event_response, + $response_parameters, + $server_id, + ($server_id !== 0) ? $node->server_name() : 'Metaconsole' ); } catch (\Exception $e) { // Unexistent agent. @@ -1237,10 +1113,130 @@ if ($perform_event_response === true) { $node->disconnect(); } } - } else { - $command = $target; } + echo json_encode($event_response); + + return; +} + + +if ($get_response_massive === true) { + if (! check_acl($config['id_user'], 0, 'EW')) { + echo 'unauthorized'; + return; + } + + $response_id = get_parameter('response_id'); + + $event_response = db_get_row( + 'tevent_response', + 'id', + $response_id + ); + + if (empty($event_response) === true) { + return []; + } + + $events = json_decode( + io_safe_output( + get_parameter('events', '') + ), + true + ); + + $response_parameters = json_decode( + io_safe_output( + get_parameter('response_parameters', '') + ), + true + ); + + $event_response_targets = []; + if (is_metaconsole() === true) { + foreach ($events as $server_id => $idEvents) { + foreach ($idEvents as $idEvent) { + $event_response_targets[$idEvent.'|'.$server_id]['target'] = get_events_get_response_target( + $idEvent, + $event_response, + $server_id, + $response_parameters + ); + } + } + } else { + foreach ($events as $idEvent) { + $event_response_targets[$idEvent]['target'] = get_events_get_response_target( + $idEvent, + $event_response, + 0, + $response_parameters + ); + } + } + + $result = [ + 'event_response' => $event_response, + 'event_response_targets' => $event_response_targets, + ]; + + echo json_encode($result); + + return; +} + +if ($get_row_response_action === true) { + $response_id = get_parameter('response_id'); + $response = json_decode( + io_safe_output( + get_parameter('response', '') + ), + true + ); + + $end = (bool) get_parameter('end', false); + $index = $response['event_id']; + if (is_metaconsole() === true) { + $index .= '-'.$response['server_id']; + } + + echo get_row_response_action( + $response, + $response_id, + $end, + $index + ); + + return; +} + +if ($perform_event_response === true) { + global $config; + + if (! check_acl($config['id_user'], 0, 'EW')) { + echo __('unauthorized'); + return; + } + + $target = get_parameter('target', ''); + $response_id = get_parameter('response_id'); + $event_id = (int) get_parameter('event_id'); + $server_id = (int) get_parameter('server_id', 0); + $response = json_decode( + io_safe_output( + get_parameter('response', '') + ), + true + ); + + $event_response = $response; + if (empty($event_response) === true) { + echo __('No data'); + return; + } + + $command = $event_response['target']; $command_timeout = ($event_response !== false) ? $event_response['command_timeout'] : 90; if (enterprise_installed() === true) { if ($event_response !== false @@ -1320,7 +1316,7 @@ if ($perform_event_response === true) { break; } - system($timeout_bin.' '.$command_timeout.' '.io_safe_output($command).' 2>&1', $ret_val); + system($timeout_bin.' '.$command_timeout.' '.io_safe_output($command).' 2>&1', $ret_val); } if ($ret_val != 0) { @@ -1343,78 +1339,19 @@ if ($dialogue_event_response) { $event_id = get_parameter('event_id'); $response_id = get_parameter('response_id'); $command = get_parameter('target'); - $massive = get_parameter('massive'); - $end = get_parameter('end'); - $show_execute_again_btn = get_parameter('show_execute_again_btn'); - $out_iterator = get_parameter('out_iterator'); - $event_response = db_get_row('tevent_response', 'id', $response_id); - $server_id = get_parameter('server_id'); + $event_response = json_decode( + io_safe_output( + get_parameter('response', '') + ), + true + ); - $event = db_get_row('tevento', 'id_evento', $event_id); - - $prompt = '
> '; switch ($event_response['type']) { case 'command': - $display_command = (bool) $event_response['display_command']; - $command_str = ($display_command === true) ? $command : ''; - - if ($massive) { - echo "
"; - echo $prompt.sprintf( - '(Event #'.$event_id.') '.__( - 'Executing command: %s', - $command_str - ) - ); - echo '

'; - - echo "
'; - echo "



"; - - if ($end) { - echo "
'; - } - } else { - echo "
"; - - echo $prompt.'Executing command: '.$command_str; - echo '

'; - - echo "'; - echo "


"; - - echo "
'; - } + echo get_row_response_action( + $event_response, + $response_id + ); break; case 'url': @@ -2534,3 +2471,75 @@ if ($get_events_fired) { echo io_json_mb_encode($return); return; } + +if ($draw_row_response_info === true) { + $event_response = json_decode( + io_safe_output( + get_parameter('response', '') + ), + true + ); + + $massive = (bool) get_parameter('massive', false); + + $output .= ''; + if ($massive === true) { + $output .= '
'; + $output .= '
'; + $output .= $event_response['description']; + $output .= '
'; + $output .= '
'; + } else { + $output .= ''; + $output .= ''; + $output .= __('Description'); + $output .= ''; + $output .= ''; + $output .= $event_response['description']; + $output .= ''; + $output .= ''; + } + + if (empty($event_response['params']) === false) { + $response_params = explode(',', $event_response['params']); + if (is_array($response_params) === true) { + if ($massive === true) { + $output .= '
'; + } else { + $output .= ''; + $output .= ''; + $output .= __('Parameters'); + $output .= ''; + $output .= ''; + } + + foreach ($response_params as $param) { + $param = trim(io_safe_output($param)); + if ($massive === true) { + $output .= '
'; + $output .= ''; + $output .= ''; + $output .= '
'; + } else { + $output .= ''; + $output .= ''; + $output .= $param; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + } + } + + if ($massive === true) { + $output .= '
'; + } + } + } + + echo $output; + return; +} diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index f1a71d7e1e..a9a5a7d676 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -3510,7 +3510,7 @@ function events_page_responses($event) __('Execute'), 'custom_response_button', false, - 'execute_response('.$event['id_evento'].','.$server_id.')', + 'execute_response('.$event['id_evento'].','.$server_id.',0)', "class='sub next w70p'", true ); @@ -3521,27 +3521,15 @@ function events_page_responses($event) $responses_js = ""; - $responses = '
'.html_print_table($table_responses, true).$responses_js.'
'; + $responses = '
'; + $responses .= html_print_table($table_responses, true); + $responses .= $responses_js; + $responses .= '
'; return $responses; } @@ -3550,14 +3538,20 @@ function events_page_responses($event) /** * Replace macros in the target of a response and return it. * - * @param integer $event_id Event identifier. - * @param integer $response_id Event response identifier. + * @param integer $event_id Event identifier. + * @param array $event_response Event Response. + * @param array|null $response_parameters If parameters response values. + * @param integer|null $server_id Server Id. + * @param string|null $server_name Name server. * * @return string The response text with the macros applied. */ function events_get_response_target( int $event_id, - int $response_id + array $event_response, + ?array $response_parameters=null, + ?int $server_id=0, + ?string $server_name='' ) { global $config; @@ -3570,9 +3564,36 @@ function events_get_response_target( } $event = db_get_row('tevento', 'id_evento', $event_id); - $event_response = db_get_row('tevent_response', 'id', $response_id); $target = io_safe_output($event_response['target']); + // Replace parameters response. + if (isset($response_parameters) === true + && empty($response_parameters) === false + ) { + $response_parameters = array_reduce( + $response_parameters, + function ($carry, $item) { + $carry[$item['name']] = $item['value']; + return $carry; + } + ); + } + + if (empty($event_response['params']) === false) { + $response_params = explode(',', $event_response['params']); + if (is_array($response_params) === true) { + foreach ($response_params as $param) { + $param = trim(io_safe_output($param)); + $target = str_replace( + '_'.$param.'_', + $response_parameters['values_params_'.$param], + $target + ); + } + } + } + + // Replace macros. if (strpos($target, '_agent_alias_') !== false) { $agente_table_name = 'tagente'; $filter = ['id_agente' => $event['id_agente']]; @@ -3898,6 +3919,26 @@ function events_get_response_target( ); } + if (is_metaconsole() === true + && strpos($target, '_node_id_') !== false + ) { + $target = str_replace( + '_node_id_', + $server_id, + $target + ); + } + + if (is_metaconsole() === true + && strpos($target, '_node_name_') !== false + ) { + $target = str_replace( + '_node_name_', + $server_name, + $target + ); + } + return $target; } @@ -5544,3 +5585,114 @@ function events_get_criticity_class($criticity) return 'datos_blue'; } } + + +/** + * Draw row response events. + * + * @param array $event_response Response. + * @param integer|null $response_id Id . + * @param boolean $end End block. + * @param integer|null $index Index block. + * + * @return string Html output. + */ +function get_row_response_action( + array $event_response, + ?int $response_id, + $end=false, + $index=null +) { + $output = '
'; + $display_command = (bool) $event_response['display_command']; + $command_str = ($display_command === true) ? $event_response['target'] : ''; + + // String command. + $output .= '
'; + $output .= ''; + $output .= __('Event # %d', $event_response['event_id']); + if (empty($command_str) === false) { + $output .= ' '; + $output .= __('Executing command: '); + } + + $output .= ''; + $output .= ''.$command_str.''; + $output .= '
'; + + // Spinner. + $output .= ''; + + // Output. + $output .= '
'; + + // Butom. + $output .= ''; + + $output .= '
'; + + return $output; +} + + +/** + * Get evet get response target. + * + * @param integer $event_id Id event. + * @param array $event_response Response. + * @param integer $server_id Server id. + * + * @return string + */ +function get_events_get_response_target( + $event_id, + $event_response, + $server_id=0, + $response_parameters=[] +) { + try { + if (is_metaconsole() === true + && $server_id > 0 + ) { + $node = new Node($server_id); + $node->connect(); + } + + return events_get_response_target( + $event_id, + $event_response, + $response_parameters, + $server_id, + ($server_id !== 0) ? $node->server_name() : 'Metaconsole' + ); + } catch (\Exception $e) { + // Unexistent agent. + if (is_metaconsole() === true + && $server_id > 0 + ) { + $node->disconnect(); + } + + return ''; + } finally { + if (is_metaconsole() === true + && $server_id > 0 + ) { + $node->disconnect(); + } + } +} diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 632069a397..1e9d9f8dd7 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -3402,7 +3402,7 @@ function ui_print_datatable(array $parameters) $filter .= ''; $filter .= '
'; - if (isset($parameters['form']['no_toggle']) === false && ($parameters['form']['no_toggle'] !== true)) { + if (isset($parameters['form']['no_toggle']) === false) { $filter = ui_toggle( $filter, __('Filter'), @@ -3466,7 +3466,10 @@ function ui_print_datatable(array $parameters) foreach ($names as $column) { if (is_array($column)) { $table .= ''.__($column['text']); $table .= $column['extra']; $table .= ''; diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index cd0796efee..f4cd5f6e2b 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -85,29 +85,6 @@ function show_event_dialog(event, dialog_page) { $("#refrcounter").countdown("pause"); $("div.vc-countdown").countdown("pause"); - /* - switch (result) { - case "comment_ok": - $("#notification_comment_success").show(); - break; - case "comment_error": - $("#notification_comment_error").show(); - break; - case "status_ok": - $("#notification_status_success").show(); - break; - case "status_error": - $("#notification_status_error").show(); - break; - case "owner_ok": - $("#notification_owner_success").show(); - break; - case "owner_error": - $("#notification_owner_error").show(); - break; - } - */ - forced_title_callback(); }, "html" @@ -119,37 +96,152 @@ function show_event_dialog(event, dialog_page) { function execute_response(event_id, server_id) { var response_id = $("#select_custom_response option:selected").val(); - var response = get_response(response_id, server_id); - - // If cannot get response abort it - if (response == null) { - return; + var response_parameters_list = $('input[name^="values_params_"]'); + var response_parameters = []; + if (response_parameters_list.length > 0) { + response_parameters_list.each(function() { + var acum = { + name: $(this).attr("name"), + value: $(this).val() + }; + response_parameters.push(acum); + }); } - response["target"] = get_response_target(event_id, response_id, server_id); - response["event_id"] = event_id; - response["server_id"] = server_id; + var params = []; + params.push({ name: "page", value: "include/ajax/events" }); + params.push({ name: "get_response", value: 1 }); + params.push({ name: "response_id", value: response_id }); + params.push({ name: "server_id", value: server_id }); + params.push({ name: "event_id", value: event_id }); + params.push({ + name: "response_parameters", + value: JSON.stringify(response_parameters) + }); - if (response["type"] == "url" && response["new_window"] == 1) { - window.open(response["target"], "_blank"); - } else { - show_response_dialog(response_id, response); - } + jQuery.ajax({ + data: params, + type: "POST", + url: $("#hidden-ajax_file").val(), + dataType: "json", + success: function(response) { + // If cannot get response abort it + if (response == null) { + return []; + } + + response["event_id"] = event_id; + response["server_id"] = server_id; + if (response["type"] == "url" && response["new_window"] == 1) { + window.open(response["target"], "_blank"); + } else { + show_response_dialog(response_id, response); + } + } + }); +} + +// Check the response type and open it in a modal dialog or new window +function execute_response_massive(events, response_id, response_parameters) { + var params = []; + params.push({ name: "page", value: "include/ajax/events" }); + params.push({ name: "get_response_massive", value: 1 }); + params.push({ name: "response_id", value: response_id }); + params.push({ name: "events", value: JSON.stringify(events) }); + params.push({ name: "response_parameters", value: response_parameters }); + + jQuery.ajax({ + data: params, + type: "POST", + url: $("#hidden-ajax_file").val(), + dataType: "json", + success: function(data) { + // If cannot get response abort it + if (data == null) { + return []; + } + + $(".container-massive-events-response").empty(); + + // Convert to array. + var array_data = Object.entries(data.event_response_targets); + var total_count = array_data.length; + + // Each input checkeds. + array_data.forEach(function(element, index) { + var id = element[0]; + var target = element[1].target; + var meta = $("#hidden-meta").val(); + var event_id = id; + var server_id = 0; + if (meta != 0) { + var split_id = id.split("|"); + event_id = split_id[0]; + server_id = split_id[1]; + } + + var end = 0; + if (total_count - 1 === index) { + end = 1; + } + + var response = data.event_response; + response["event_id"] = event_id; + response["server_id"] = server_id; + response["target"] = target; + if (response["type"] == "url" && response["new_window"] == 1) { + window.open(response["target"], "_blank"); + } else { + var params = []; + params.push({ name: "page", value: "include/ajax/events" }); + params.push({ name: "get_row_response_action", value: 1 }); + params.push({ name: "response_id", value: response_id }); + params.push({ name: "server_id", value: response.server_id }); + params.push({ name: "end", value: end }); + params.push({ name: "response", value: JSON.stringify(response) }); + + jQuery.ajax({ + data: params, + type: "POST", + url: $("#hidden-ajax_file").val(), + dataType: "html", + success: function(data) { + $(".container-massive-events-response").append(data); + response["event_id"] = event_id; + response["server_id"] = server_id; + response["target"] = target; + + var indexstr = event_id; + if (meta != 0) { + indexstr += "-" + server_id; + } + + perform_response( + btoa(JSON.stringify(response)), + response_id, + indexstr + ); + } + }); + } + }); + } + }); } //Show the modal window of an event response function show_response_dialog(response_id, response) { var params = []; - params.push("page=include/ajax/events"); - params.push("dialogue_event_response=1"); - params.push("massive=0"); - params.push("event_id=" + response["event_id"]); - params.push("target=" + encodeURIComponent(response["target"])); - params.push("response_id=" + response_id); - params.push("server_id=" + response["server_id"]); + params.push({ name: "page", value: "include/ajax/events" }); + params.push({ name: "dialogue_event_response", value: 1 }); + params.push({ name: "event_id", value: response.event_id }); + params.push({ name: "target", value: response.target }); + params.push({ name: "response_id", value: response_id }); + params.push({ name: "server_id", value: response.server_id }); + params.push({ name: "response", value: JSON.stringify(response) }); jQuery.ajax({ - data: params.join("&"), + data: params, type: "POST", url: $("#hidden-ajax_file").val(), dataType: "html", @@ -164,271 +256,49 @@ function show_response_dialog(response_id, response) { draggable: true, modal: false, open: function() { - perform_response(response, response_id); + perform_response(btoa(JSON.stringify(response)), response_id, ""); }, width: response["modal_width"], - height: response["modal_height"] + height: response["modal_height"], + buttons: [] }) .show(); } }); } -//Show the modal window of event responses when multiple events are selected -function show_massive_response_dialog( - response_id, - response, - out_iterator, - end -) { - var params = []; - params.push("page=include/ajax/events"); - params.push("dialogue_event_response=1"); - params.push("massive=1"); - params.push("end=" + end); - params.push("out_iterator=" + out_iterator); - params.push("event_id=" + response["event_id"]); - params.push("target=" + response["target"]); - params.push("response_id=" + response_id); - params.push("server_id=" + response["server_id"]); +// Perform a response and put the output into a div +function perform_response(response, response_id, index) { + $("#re_exec_command" + index).hide(); + $("#response_loading_command" + index).show(); + $("#response_out" + index).html(""); - jQuery.ajax({ - data: params.join("&"), - response_tg: response, - response_id: response_id, - out_iterator: out_iterator, - type: "POST", - url: $("#hidden-ajax_file").val(), - dataType: "html", - success: function(data) { - if (out_iterator === 0) $("#event_response_window").empty(); - - $("#event_response_window") - .hide() - .append(data) - .dialog({ - title: $("#select_custom_response option:selected").html(), - resizable: true, - draggable: true, - modal: false, - open: function() { - $("#response_loading_dialog").hide(); - $("#button-submit_event_response").show(); - }, - close: function() { - $("#checkbox-all_validate_box").prop("checked", false); - $(".chk_val").prop("checked", false); - }, - width: response["modal_width"], - height: response["modal_height"] - }) - .show(); - - perform_response_massive( - this.response_tg, - this.response_id, - this.out_iterator - ); - } - }); -} - -// Get an event response from db -function get_response(response_id, server_id) { - var response = ""; - - var params = []; - params.push("page=include/ajax/events"); - params.push("get_response=1"); - params.push("response_id=" + response_id); - params.push("server_id=" + server_id); - - jQuery.ajax({ - data: params.join("&"), - type: "POST", - url: $("#hidden-ajax_file").val(), - async: false, - dataType: "json", - success: function(data) { - response = data; - } - }); - - return response; -} - -// Get an event response params from db -function get_response_params(response_id) { - var response_params; - - var params = []; - params.push("page=include/ajax/events"); - params.push("get_response_params=1"); - params.push("response_id=" + response_id); - - jQuery.ajax({ - data: params.join("&"), - type: "POST", - url: $("#hidden-ajax_file").val(), - async: false, - dataType: "json", - success: function(data) { - response_params = data; - } - }); - - return response_params; -} - -// Get an event response description from db -function get_response_description(response_id) { - var response_description = ""; - - var params = []; - params.push("page=include/ajax/events"); - params.push("get_response_description=1"); - params.push("response_id=" + response_id); - - jQuery.ajax({ - data: params.join("&"), - type: "POST", - url: $("#hidden-ajax_file").val(), - async: false, - dataType: "html", - success: function(data) { - response_description = data; - } - }); - - return response_description; -} - -function add_row_param(id_table, param) { - $("#" + id_table).append( - '' + - param + - '' - ); -} - -// Get an event response from db -function get_response_target( - event_id, - response_id, - server_id, - response_command -) { - var target = ""; - - // Replace the main macros - var params = []; - params.push("page=include/ajax/events"); - params.push("get_response_target=1"); - params.push("event_id=" + event_id); - params.push("response_id=" + response_id); - params.push("server_id=" + server_id); - - jQuery.ajax({ - data: params.join("&"), - type: "POST", - url: $("#hidden-ajax_file").val(), - async: false, - dataType: "html", - success: function(data) { - target = data; - } - }); - - // Replace the custom params macros. - var response_params = get_response_params(response_id); - if (response_params.length > 1 || response_params[0] != "") { - for (var i = 0; i < response_params.length; i++) { - if (!response_command) { - var response_param = "_" + response_params[i] + "_"; - - if ( - response_params[i].startsWith("_") && - response_params[i].endsWith("_") - ) { - response_param = response_params[i]; - } - - target = target.replace( - response_param, - $("#" + response_params[i]).val() - ); - } else { - target = target.replace( - "_" + response_params[i] + "_", - response_command[response_params[i] + "-" + i] - ); - } - } + try { + response = JSON.parse(atob(response)); + } catch (e) { + console.error(e); + return; } - return target; -} - -// Perform a response and put the output into a div -function perform_response(response, response_id) { - $("#re_exec_command").hide(); - $("#response_loading_command").show(); - $("#response_out").html(""); - var params = []; - params.push("page=include/ajax/events"); - params.push("perform_event_response=1"); - params.push("target=" + encodeURIComponent(response["target"])); - params.push("response_id=" + response_id); - params.push("event_id=" + response["event_id"]); - params.push("server_id=" + response["server_id"]); + params.push({ name: "page", value: "include/ajax/events" }); + params.push({ name: "perform_event_response", value: 1 }); + params.push({ name: "target", value: response["target"] }); + params.push({ name: "response_id", value: response_id }); + params.push({ name: "event_id", value: response["event_id"] }); + params.push({ name: "server_id", value: response["server_id"] }); + params.push({ name: "response", value: JSON.stringify(response) }); jQuery.ajax({ - data: params.join("&"), + data: params, type: "POST", url: $("#hidden-ajax_file").val(), - async: true, dataType: "html", success: function(data) { var out = data.replace(/[\n|\r]/g, "
"); - $("#response_out").html(out); - $("#response_loading_command").hide(); - $("#re_exec_command").show(); - } - }); - - return false; -} - -// Perform a response and put the output into a div -function perform_response_massive(response, response_id, out_iterator) { - $("#re_exec_command").hide(); - $("#response_loading_command_" + out_iterator).show(); - $("#response_out_" + out_iterator).html(""); - - var params = []; - params.push("page=include/ajax/events"); - params.push("perform_event_response=1"); - params.push("target=" + response["target"]); - params.push("response_id=" + response_id); - params.push("event_id=" + response["event_id"]); - params.push("server_id=" + response["server_id"]); - - jQuery.ajax({ - data: params.join("&"), - type: "POST", - url: $("#hidden-ajax_file").val(), - async: true, - dataType: "html", - success: function(data) { - var out = data.replace(/[\n|\r]/g, "
"); - $("#response_out_" + out_iterator).html(out); - $("#response_loading_command_" + out_iterator).hide(); - $("#re_exec_command_" + out_iterator).show(); + $("#response_out" + index).html(out); + $("#response_loading_command" + index).hide(); + $("#re_exec_command" + index).show(); } }); @@ -600,54 +470,6 @@ function event_comment(current_event) { return false; } -function show_event_response_command_dialog(id, response, total_checked) { - var params = []; - params.push("page=include/ajax/events"); - params.push("get_table_response_command=1"); - params.push("event_response_id=" + id); - - jQuery.ajax({ - data: params.join("&"), - type: "POST", - url: $("#hidden-ajax_file").val(), - dataType: "html", - success: function(data) { - $("#event_response_command_window") - .hide() - .empty() - .append(data) - .dialog({ - resizable: true, - draggable: true, - modal: false, - open: function() { - $("#response_loading_dialog").hide(); - $("#button-submit_event_response").show(); - }, - width: 600, - height: 300 - }) - .show(); - - $("#submit-enter_command").on("click", function(e) { - e.preventDefault(); - var response_command = []; - - $(".response_command_input").each(function() { - response_command[$(this).attr("name")] = $(this).val(); - }); - - check_massive_response_event( - id, - response, - total_checked, - response_command - ); - }); - } - }); -} - var processed = 0; function update_event(table, id_evento, type, event_rep, row, server_id) { var inputs = $("#events_form :input"); @@ -820,8 +642,13 @@ function execute_delete_event_reponse( // Imported from old files. function execute_event_response(event_list_btn) { + var response_id = $("select[name=response_id]").val(); + if (!isNaN(response_id)) { + table_info_response_event(response_id, 0, 0, true); + } + var message = - "

Are you sure?

"; + "

Are you sure?

"; confirmDialog({ title: "ATTENTION", message: message, @@ -833,8 +660,6 @@ function execute_event_response(event_list_btn) { $("#max_custom_event_resp_msg").hide(); $("#max_custom_selected").hide(); - var response_id = $("select[name=response_id]").val(); - var total_checked = $(".chk_val:checked").length; // Check select an event. @@ -844,58 +669,28 @@ function execute_event_response(event_list_btn) { } if (!isNaN(response_id)) { - // It is a custom response - var response = get_response(response_id); - - // If cannot get response abort it - if (response == null) { - return; + var response_parameters_list = $('input[name^="values_params_"]'); + var response_parameters = []; + if (response_parameters_list.length > 0) { + response_parameters_list.each(function() { + var acum = { + name: $(this).attr("name"), + value: $(this).val() + }; + response_parameters.push(acum); + }); } - // Limit number of events to apply custom responses - // due performance reasons. - if (total_checked > $("#max_execution_event_response").val()) { - $("#max_custom_event_resp_msg").show(); - return; - } - - var response_command = []; - $(".response_command_input").each(function() { - response_command[$(this).attr("name")] = $(this).val(); - }); + response_parameters = JSON.stringify(response_parameters); if (event_list_btn) { $("#button-submit_event_response").hide(function() { $("#response_loading_dialog").show(function() { - var check_params = get_response_params(response_id); - - if (check_params[0] !== "") { - show_event_response_command_dialog( - response_id, - response, - total_checked - ); - } else { - check_massive_response_event( - response_id, - response, - total_checked, - response_command - ); - } + show_response_dialog_massive(response_id, response_parameters); }); }); } else { - $("#button-btn_str").hide(function() { - $("#execute_again_loading").show(function() { - check_massive_response_event( - response_id, - response, - total_checked, - response_command - ); - }); - }); + check_execute_response_massive(response_id, response_parameters); } } else { // It is not a custom response @@ -970,15 +765,63 @@ function execute_event_response(event_list_btn) { }); } -function check_massive_response_event( - response_id, - response, - total_checked, - response_command -) { - var counter = 0; - var end = 0; +function show_response_dialog_massive(response_id, response_parameters) { + var params = []; + params.push({ name: "page", value: "include/ajax/events" }); + params.push({ name: "get_response", value: 1 }); + params.push({ name: "response_id", value: response_id }); + jQuery.ajax({ + data: params, + type: "POST", + url: $("#hidden-ajax_file").val(), + dataType: "json", + success: function(response) { + // If cannot get response abort it + if (response == null) { + return []; + } + + $("#event_response_window") + .hide() + .empty() + .append('
') + .dialog({ + title: $("#response_id option:selected").html(), + resizable: true, + draggable: true, + modal: false, + open: function() { + check_execute_response_massive(response_id, response_parameters); + }, + close: function() { + $("#checkbox-all_validate_box").prop("checked", false); + $(".chk_val").prop("checked", false); + $("#response_loading_dialog").hide(); + $("#button-submit_event_response").show(); + }, + buttons: [ + { + text: "Execute All", + id: "execute-again-all", + class: + "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next", + click: function() { + execute_event_response(false); + } + } + ], + width: response["modal_width"], + height: response["modal_height"] + }) + .show(); + } + }); +} + +function check_execute_response_massive(response_id, response_parameters) { + var events = []; + $(".container-massive-events-response").empty(); $(".chk_val:checked").each(function() { var event_id = $(this).val(); var meta = $("#hidden-meta").val(); @@ -987,23 +830,18 @@ function check_massive_response_event( var split_id = event_id.split("|"); event_id = split_id[0]; server_id = split_id[1]; + + if (events[server_id] === undefined) { + events[server_id] = []; + } + + events[server_id].push(event_id); + } else { + events.push(event_id); } - - response["target"] = get_response_target( - event_id, - response_id, - server_id, - response_command - ); - response["server_id"] = server_id; - response["event_id"] = event_id; - - if (total_checked - 1 === counter) end = 1; - - show_massive_response_dialog(response_id, response, counter, end); - - counter++; }); + + execute_response_massive(events, response_id, response_parameters); } function event_widget_options() { @@ -1287,3 +1125,43 @@ function check_event_sound(settings) { "json" ); } + +function table_info_response_event(response_id, event_id, server_id, massive) { + var params = []; + params.push({ name: "page", value: "include/ajax/events" }); + params.push({ name: "get_response", value: 1 }); + params.push({ name: "response_id", value: response_id }); + params.push({ name: "server_id", value: server_id }); + params.push({ name: "event_id", value: event_id }); + + jQuery.ajax({ + data: params, + type: "POST", + url: $("#hidden-ajax_file").val(), + dataType: "json", + success: function(response) { + if (response) { + var params = []; + params.push({ name: "page", value: "include/ajax/events" }); + params.push({ name: "draw_row_response_info", value: 1 }); + params.push({ name: "massive", value: massive === true ? 1 : 0 }); + params.push({ name: "response", value: JSON.stringify(response) }); + + jQuery.ajax({ + data: params, + type: "POST", + url: $("#hidden-ajax_file").val(), + dataType: "html", + success: function(output) { + if (massive === true) { + $("#massive-parameters-response").append(output); + } else { + $(".params_rows").remove(); + $("#responses_table").append(output); + } + } + }); + } + } + }); +} diff --git a/pandora_console/include/styles/events.css b/pandora_console/include/styles/events.css index 2cb7d3a481..32317e3e4c 100644 --- a/pandora_console/include/styles/events.css +++ b/pandora_console/include/styles/events.css @@ -396,3 +396,59 @@ div.multi-response-buttons { .white_table_graph_header { align-items: center; } + +.container-massive-events-response { + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: flex-start; +} + +.container-massive-events-response-cell { + margin-bottom: 10px; + width: 100%; + display: flex; + flex-direction: column; + justify-content: flex-start; + align-content: flex-start; +} + +.container-massive-events-response-command > span { + font-style: italic; +} + +.container-massive-events-response-output { + /*border: 2px dashed #ddd;*/ + /*padding: 10px;*/ + margin: 10px; +} + +.container-massive-events-response-execute { + display: flex; + flex-direction: row; + justify-content: flex-end; + align-items: center; +} + +#massive-parameters-response { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +#massive-parameters-response > div { + width: 80%; +} + +#massive-parameters-response > div h5 { + text-align: center; +} + +#massive-parameters-response > div div { + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; + margin-bottom: 5px; +} diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 42d325e7f0..91714803f9 100755 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -564,7 +564,10 @@ for ($i = 0; $i < $custom_fields_count; $i++) { $columns = array_merge($first_column, $second_column); } else { $columns = $first_column; - $filas = count($table_data->data); + if ($table_data->data !== null) { + $filas = count($table_data->data); + } + $table_data->colspan[$filas][1] = 3; }