fixed response events pandora_enterprise#9423

This commit is contained in:
Daniel Barbero 2022-09-23 13:55:01 +02:00
parent d14bcfe616
commit 225646cd9d
5 changed files with 479 additions and 534 deletions

View File

@ -64,7 +64,8 @@ $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_massive = (bool) get_parameter('get_response_massive');
$get_row_response_action = (bool) get_parameter('get_row_response_action');
$get_response_params = (bool) get_parameter('get_response_params');
$get_response_description = (bool) get_parameter('get_response_description');
$meta = get_parameter('meta', 0);
@ -1090,50 +1091,6 @@ if ($get_response_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')) {
@ -1142,62 +1099,21 @@ 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);
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 +1122,9 @@ 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
);
} catch (\Exception $e) {
// Unexistent agent.
@ -1237,10 +1142,121 @@ 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
);
$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
);
}
}
} else {
foreach ($idEvents as $idEvent) {
$event_response_targets[$idEvent]['target'] = get_events_get_response_target(
$idEvent,
$event_response
);
}
}
$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 +1336,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 +1359,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 = '<br>> ';
switch ($event_response['type']) {
case 'command':
$display_command = (bool) $event_response['display_command'];
$command_str = ($display_command === true) ? $command : '';
if ($massive) {
echo "<div class='left'>";
echo $prompt.sprintf(
'(Event #'.$event_id.') '.__(
'Executing command: %s',
$command_str
)
);
echo '</div><br>';
echo "<div id='response_loading_command_".$out_iterator."' style='display: none'>";
echo html_print_image(
'images/spinner.gif',
true
);
echo '</div><br>';
echo "<br><div id='response_out_".$out_iterator."'><br><br></div><br>";
if ($end) {
echo "<br><div id='re_exec_command_".$out_iterator."' style='display: none'><br>";
html_print_button(
__('Execute again'),
'btn_str',
false,
'execute_event_response(false);',
"class='sub next'"
);
echo "<span id='execute_again_loading' style='display: none'>";
echo html_print_image(
'images/spinner.gif',
true
);
echo '</span>';
echo '</div>';
}
} else {
echo "<div class='left'>";
echo $prompt.'Executing command: '.$command_str;
echo '</div><br>';
echo "<div id='response_loading_command' style='display:none'>";
echo html_print_image('images/spinner.gif', true);
echo '</div>';
echo "<br><br><br><div id='response_out' class='left'></div>";
echo "<br><div id='re_exec_command' style='display:none'><br><br>";
html_print_button(
__('Execute again'),
'btn_str',
false,
"perform_response({'target':'".$command."','event_id':".$event_id.",'server_id':".$server_id.'}, '.$response_id.');',
"class='sub next'"
);
echo '</div>';
}
echo get_row_response_action(
$event_response,
$response_id
);
break;
case 'url':

View File

@ -3430,7 +3430,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
);
@ -3438,6 +3438,7 @@ function events_page_responses($event)
$table_responses->data[] = $data;
// TODO quitar el async: false. get_response_params and get_response_description.
$responses_js = "<script>
$('#select_custom_response').change(function() {
var id_response = $('#select_custom_response').val();
@ -3477,7 +3478,7 @@ function events_page_responses($event)
*/
function events_get_response_target(
int $event_id,
int $response_id
array $event_response
) {
global $config;
@ -3490,9 +3491,7 @@ 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']);
if (strpos($target, '_agent_alias_') !== false) {
$agente_table_name = 'tagente';
$filter = ['id_agente' => $event['id_agente']];
@ -5464,3 +5463,101 @@ function events_get_criticity_class($criticity)
return 'datos_blue';
}
}
// TODO
function get_row_response_action(
array $event_response,
?int $response_id,
$end=false,
$index=null
) {
$output = '<div class="container-massive-events-response-cell">';
$display_command = (bool) $event_response['display_command'];
$command_str = ($display_command === true) ? $event_response['target'] : '';
// String command.
$output .= '<div class="container-massive-events-response-command">';
$output .= '<b>';
$output .= __('Event # %d', $event_response['event_id']);
if (empty($command_str) === false) {
$output .= ' ';
$output .= __('Executing command: ');
}
$output .= '</b>';
$output .= '<span>'.$command_str.'</span>';
$output .= '</div>';
// Spinner.
$output .= '<div id="response_loading_command'.$index.'" style="display:none">';
$output .= html_print_image(
'images/spinner.gif',
true
);
$output .= '</div>';
// Output.
$output .= '<div id="response_out'.$index.'" class="container-massive-events-response-output"></div>';
// Butom.
$output .= '<div id="re_exec_command'.$index.'" style="display:none" class="container-massive-events-response-execute">';
$output .= html_print_button(
__('Execute again'),
'btn_str',
false,
'perform_response(\''.base64_encode(json_encode($event_response)).'\','.$response_id.',\''.trim($index).'\')',
"class='sub next'",
true
);
$output .= '</div>';
$output .= '</div>';
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
) {
try {
if (is_metaconsole() === true
&& $server_id > 0
) {
$node = new Node($server_id);
$node->connect();
}
return events_get_response_target(
$event_id,
$event_response
);
} 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();
}
}
}

View File

@ -3402,7 +3402,7 @@ function ui_print_datatable(array $parameters)
$filter .= '</li>';
$filter .= '</ul><div id="both"></div></form>';
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 .= '<th id="'.$column['id'].'" class="'.$column['class'].'" ';
$table .= 'title="'.__($column['title']).'" ';
if (isset($column['title']) === true) {
$table .= 'title="'.__($column['title']).'" ';
}
$table .= ' style="'.$column['style'].'">'.__($column['text']);
$table .= $column['extra'];
$table .= '</th>';

View File

@ -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,129 @@ 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);
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 });
// If cannot get response abort it
if (response == null) {
return;
}
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["target"] = get_response_target(event_id, response_id, server_id);
response["event_id"] = event_id;
response["server_id"] = server_id;
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);
}
}
});
}
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) {
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) });
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;
perform_response(
btoa(JSON.stringify(response)),
response_id,
event_id + "-" + server_id
);
}
});
}
});
}
});
}
//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,7 +233,7 @@ 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"]
@ -174,89 +243,6 @@ function show_response_dialog(response_id, response) {
});
}
//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"]);
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;
@ -315,120 +301,38 @@ function add_row_param(id_table, param) {
);
}
// Get an event response from db
function get_response_target(
event_id,
response_id,
server_id,
response_command
) {
var target = "";
// 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("");
// 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, "<br>");
$("#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, "<br>");
$("#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();
}
});
@ -594,54 +498,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");
@ -838,58 +694,14 @@ 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;
}
// 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();
});
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);
});
});
} 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);
}
} else {
// It is not a custom response
@ -964,15 +776,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) {
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('<div class="container-massive-events-response"></div>')
.dialog({
title: $("#response_id option:selected").html(),
resizable: true,
draggable: true,
modal: false,
open: function() {
check_execute_response_massive(response_id);
},
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) {
var events = [];
$(".container-massive-events-response").empty();
$(".chk_val:checked").each(function() {
var event_id = $(this).val();
var meta = $("#hidden-meta").val();
@ -981,23 +841,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);
}
function event_widget_options() {

View File

@ -396,3 +396,36 @@ 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;
}