fixed response events pandora_enterprise#9423
This commit is contained in:
parent
225646cd9d
commit
fbce8b7533
|
@ -66,8 +66,7 @@ $perform_event_response = (bool) get_parameter('perform_event_response');
|
|||
$get_response = (bool) get_parameter('get_response');
|
||||
$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');
|
||||
$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);
|
||||
|
@ -1055,43 +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", '<br>', $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 === true) {
|
||||
if (! check_acl($config['id_user'], 0, 'EW')) {
|
||||
echo 'unauthorized';
|
||||
|
@ -1101,6 +1063,12 @@ if ($get_response === true) {
|
|||
$response_id = get_parameter('response_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
|
||||
);
|
||||
|
||||
$event_response = db_get_row(
|
||||
'tevent_response',
|
||||
|
@ -1124,7 +1092,8 @@ if ($get_response === true) {
|
|||
|
||||
$event_response['target'] = events_get_response_target(
|
||||
$event_id,
|
||||
$event_response
|
||||
$event_response,
|
||||
$response_parameters
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
// Unexistent agent.
|
||||
|
@ -1168,7 +1137,6 @@ if ($get_response_massive === true) {
|
|||
return [];
|
||||
}
|
||||
|
||||
|
||||
$events = json_decode(
|
||||
io_safe_output(
|
||||
get_parameter('events', '')
|
||||
|
@ -1176,6 +1144,13 @@ if ($get_response_massive === true) {
|
|||
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) {
|
||||
|
@ -1183,15 +1158,18 @@ if ($get_response_massive === true) {
|
|||
$event_response_targets[$idEvent.'|'.$server_id]['target'] = get_events_get_response_target(
|
||||
$idEvent,
|
||||
$event_response,
|
||||
$server_id
|
||||
$server_id,
|
||||
$response_parameters
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($idEvents as $idEvent) {
|
||||
foreach ($events as $idEvent) {
|
||||
$event_response_targets[$idEvent]['target'] = get_events_get_response_target(
|
||||
$idEvent,
|
||||
$event_response
|
||||
$event_response,
|
||||
0,
|
||||
$response_parameters
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -2491,3 +2469,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 .= '<div>';
|
||||
$output .= '<h5>';
|
||||
$output .= $event_response['description'];
|
||||
$output .= '</h5>';
|
||||
$output .= '</div>';
|
||||
} else {
|
||||
$output .= '<tr class="params_rows">';
|
||||
$output .= '<td>';
|
||||
$output .= __('Description');
|
||||
$output .= '</td>';
|
||||
$output .= '<td class="height_30px" colspan="2">';
|
||||
$output .= $event_response['description'];
|
||||
$output .= '</td>';
|
||||
$output .= '</tr>';
|
||||
}
|
||||
|
||||
if (empty($event_response['params']) === false) {
|
||||
$response_params = explode(',', $event_response['params']);
|
||||
if (is_array($response_params) === true) {
|
||||
if ($massive === true) {
|
||||
$output .= '<div>';
|
||||
} else {
|
||||
$output .= '<tr class="params_rows">';
|
||||
$output .= '<td class="left pdd_l_20px height_30px" colspan="3">';
|
||||
$output .= __('Parameters');
|
||||
$output .= '</td>';
|
||||
$output .= '</tr>';
|
||||
}
|
||||
|
||||
foreach ($response_params as $param) {
|
||||
$param = trim(io_safe_output($param));
|
||||
if ($massive === true) {
|
||||
$output .= '<div>';
|
||||
$output .= '<label>';
|
||||
$output .= $param;
|
||||
$output .= '</label>';
|
||||
$output .= '<input type="text" name="values_params_'.$param.'" />';
|
||||
$output .= '</div>';
|
||||
} else {
|
||||
$output .= '<tr class="params_rows">';
|
||||
$output .= '<td style="text-align:left; padding-left:40px; font-weight: normal; font-style: italic;">';
|
||||
$output .= $param;
|
||||
$output .= '</td>';
|
||||
$output .= '<td style="text-align:left" colspan="2">';
|
||||
$output .= '<input type="text" name="values_params_'.$param.'" />';
|
||||
$output .= '</td>';
|
||||
$output .= '</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($massive === true) {
|
||||
$output .= '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo $output;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -3438,31 +3438,18 @@ 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();
|
||||
var params = get_response_params(id_response);
|
||||
var description = get_response_description(id_response);
|
||||
$('.params_rows').remove();
|
||||
$('#responses_table')
|
||||
.append('<tr class=\"params_rows\"><td>".__('Description')."</td><td class=\"height_30px\" colspan=\"2\">'+description+'</td></tr>');
|
||||
|
||||
if (params.length == 1 && params[0] == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$('#responses_table')
|
||||
.append('<tr class=\"params_rows\"><td class=\"left pdd_l_20px height_30px\" colspan=\"3\">".__('Parameters')."</td></tr>');
|
||||
|
||||
for (i = 0; i < params.length; i++) {
|
||||
add_row_param('responses_table',params[i]);
|
||||
}
|
||||
table_info_response_event(id_response,".$event['id_evento'].','.$event['server_id'].");
|
||||
});
|
||||
$('#select_custom_response').trigger('change');
|
||||
</script>";
|
||||
|
||||
$responses = '<div id="extended_event_responses_page" class="extended_event_pages">'.html_print_table($table_responses, true).$responses_js.'</div>';
|
||||
$responses = '<div id="extended_event_responses_page" class="extended_event_pages">';
|
||||
$responses .= html_print_table($table_responses, true);
|
||||
$responses .= $responses_js;
|
||||
$responses .= '</div>';
|
||||
|
||||
return $responses;
|
||||
}
|
||||
|
@ -3471,14 +3458,16 @@ 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.
|
||||
*
|
||||
* @return string The response text with the macros applied.
|
||||
*/
|
||||
function events_get_response_target(
|
||||
int $event_id,
|
||||
array $event_response
|
||||
array $event_response,
|
||||
?array $response_parameters=null
|
||||
) {
|
||||
global $config;
|
||||
|
||||
|
@ -3492,6 +3481,35 @@ function events_get_response_target(
|
|||
|
||||
$event = db_get_row('tevento', 'id_evento', $event_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']];
|
||||
|
@ -5465,7 +5483,16 @@ function events_get_criticity_class($criticity)
|
|||
}
|
||||
|
||||
|
||||
// TODO
|
||||
/**
|
||||
* 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,
|
||||
|
@ -5530,7 +5557,8 @@ function get_row_response_action(
|
|||
function get_events_get_response_target(
|
||||
$event_id,
|
||||
$event_response,
|
||||
$server_id=0
|
||||
$server_id=0,
|
||||
$response_parameters=[]
|
||||
) {
|
||||
try {
|
||||
if (is_metaconsole() === true
|
||||
|
@ -5542,7 +5570,8 @@ function get_events_get_response_target(
|
|||
|
||||
return events_get_response_target(
|
||||
$event_id,
|
||||
$event_response
|
||||
$event_response,
|
||||
$response_parameters
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
// Unexistent agent.
|
||||
|
|
|
@ -96,12 +96,28 @@ 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_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);
|
||||
});
|
||||
}
|
||||
|
||||
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)
|
||||
});
|
||||
|
||||
jQuery.ajax({
|
||||
data: params,
|
||||
|
@ -126,12 +142,13 @@ function execute_response(event_id, server_id) {
|
|||
}
|
||||
|
||||
// Check the response type and open it in a modal dialog or new window
|
||||
function execute_response_massive(events, response_id) {
|
||||
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,
|
||||
|
@ -193,10 +210,16 @@ function execute_response_massive(events, response_id) {
|
|||
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,
|
||||
event_id + "-" + server_id
|
||||
indexstr
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -236,71 +259,14 @@ function show_response_dialog(response_id, response) {
|
|||
perform_response(btoa(JSON.stringify(response)), response_id, "");
|
||||
},
|
||||
width: response["modal_width"],
|
||||
height: response["modal_height"]
|
||||
height: response["modal_height"],
|
||||
buttons: []
|
||||
})
|
||||
.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 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(
|
||||
'<tr class="params_rows"><td style="text-align:left; padding-left:40px; font-weight: normal; font-style: italic;">' +
|
||||
param +
|
||||
'</td><td style="text-align:left" colspan="2"><input type="text" name="' +
|
||||
param +
|
||||
'" id="' +
|
||||
param +
|
||||
'"></td></tr>'
|
||||
);
|
||||
}
|
||||
|
||||
// Perform a response and put the output into a div
|
||||
function perform_response(response, response_id, index) {
|
||||
$("#re_exec_command" + index).hide();
|
||||
|
@ -670,8 +636,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 =
|
||||
"<h4 style = 'text-align: center; color:black' > Are you sure?</h4> ";
|
||||
"<h4 style = 'text-align: center; color:black' > Are you sure?</h4> <div id='massive-parameters-response'></div> ";
|
||||
confirmDialog({
|
||||
title: "ATTENTION",
|
||||
message: message,
|
||||
|
@ -683,8 +654,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.
|
||||
|
@ -694,14 +663,28 @@ function execute_event_response(event_list_btn) {
|
|||
}
|
||||
|
||||
if (!isNaN(response_id)) {
|
||||
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_parameters = JSON.stringify(response_parameters);
|
||||
|
||||
if (event_list_btn) {
|
||||
$("#button-submit_event_response").hide(function() {
|
||||
$("#response_loading_dialog").show(function() {
|
||||
show_response_dialog_massive(response_id);
|
||||
show_response_dialog_massive(response_id, response_parameters);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
check_execute_response_massive(response_id);
|
||||
check_execute_response_massive(response_id, response_parameters);
|
||||
}
|
||||
} else {
|
||||
// It is not a custom response
|
||||
|
@ -776,7 +759,7 @@ function execute_event_response(event_list_btn) {
|
|||
});
|
||||
}
|
||||
|
||||
function show_response_dialog_massive(response_id) {
|
||||
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 });
|
||||
|
@ -803,7 +786,7 @@ function show_response_dialog_massive(response_id) {
|
|||
draggable: true,
|
||||
modal: false,
|
||||
open: function() {
|
||||
check_execute_response_massive(response_id);
|
||||
check_execute_response_massive(response_id, response_parameters);
|
||||
},
|
||||
close: function() {
|
||||
$("#checkbox-all_validate_box").prop("checked", false);
|
||||
|
@ -830,7 +813,7 @@ function show_response_dialog_massive(response_id) {
|
|||
});
|
||||
}
|
||||
|
||||
function check_execute_response_massive(response_id) {
|
||||
function check_execute_response_massive(response_id, response_parameters) {
|
||||
var events = [];
|
||||
$(".container-massive-events-response").empty();
|
||||
$(".chk_val:checked").each(function() {
|
||||
|
@ -852,7 +835,7 @@ function check_execute_response_massive(response_id) {
|
|||
}
|
||||
});
|
||||
|
||||
execute_response_massive(events, response_id);
|
||||
execute_response_massive(events, response_id, response_parameters);
|
||||
}
|
||||
|
||||
function event_widget_options() {
|
||||
|
@ -1136,3 +1119,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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -429,3 +429,26 @@ div.multi-response-buttons {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue