From 5a8e46d608c88f58ab0961572125de2c1f13925c Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Mon, 14 Jan 2019 12:10:43 +0100 Subject: [PATCH 1/5] modify the way event responses are executed in event list Former-commit-id: 14ef545eef10427d95f96484e8d6b8d9656bd53c --- pandora_console/include/ajax/events.php | 46 ++++-- .../include/javascript/pandora_events.js | 87 ++++++++++- .../operation/events/events.build_table.php | 138 +++++++++++++++++- 3 files changed, 254 insertions(+), 17 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index afdd2fc759..4138b048f6 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -193,25 +193,49 @@ 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); $event = db_get_row('tevento','id_evento',$event_id); $prompt = "
> "; - switch($event_response['type']) { case 'command': - echo "
"; - echo $prompt.sprintf(__('Executing command: %s',$command)); - echo "

"; + - echo ""; - echo "
"; - - echo "
"; + if ($massive) { + echo "
"; + echo $prompt.sprintf("(Event #$event_id) ".__('Executing command: %s',$command)); + echo "

"; + + echo ""; + echo "
"; + + if ($end) { + + echo "
"; + } + } + else { + + echo "
"; + echo $prompt.sprintf(__('Executing command: %s',$command)); + echo "

"; + + echo ""; + echo "
"; + + echo "
"; + } + break; case 'url': $command = str_replace("localhost",$_SERVER['SERVER_NAME'],$command); diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 02eac5553c..5c680a319d 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -158,10 +158,11 @@ function show_response_dialog(event_id, 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="+event_id); params.push("target="+response['target']); params.push("response_id="+response_id); - + jQuery.ajax ({ data: params.join ("&"), type: 'POST', @@ -187,6 +188,54 @@ function show_response_dialog(event_id, response_id, response) { }); } +//Show the modal window of event responses when multiple events are selected +function show_massive_response_dialog(event_id, response_id, response, out_iterator, end) { + var ajax_file = $('#hidden-ajax_file').val(); + + 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="+event_id); + params.push("target="+response['target']); + params.push("response_id="+response_id); + + + jQuery.ajax ({ + data: params.join ("&"), + response_tg: response['target'], + response_id: response_id, + out_iterator: out_iterator, + type: 'POST', + url: action=ajax_file, + 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(event, ui) { + $('#response_loading_dialog').hide(); + $('#button-submit_event_response').show(); + }, + 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) { var ajax_file = $('#hidden-ajax_file').val(); @@ -371,6 +420,42 @@ function perform_response(target, response_id) { return false; } +// Perform a response and put the output into a div +function perform_response_massive(target, response_id, out_iterator) { + var ajax_file = $('#hidden-ajax_file').val(); + + $('#re_exec_command').hide(); + $('#response_loading_command_'+out_iterator).show(); + $('#response_out_'+out_iterator).html(''); + + var finished = 0; + var time = Math.round(+new Date()/1000); + var timeout = time + 10; + + var params = []; + params.push("page=include/ajax/events"); + params.push("perform_event_response=1"); + params.push("target="+target); + params.push("response_id="+response_id) + + jQuery.ajax ({ + data: params.join ("&"), + type: 'POST', + url: action=ajax_file, + async: true, + timeout: 10000, + 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(); + } + }); + + return false; +} + // Change the status of an event to new, in process or validated function event_change_status(event_ids) { var ajax_file = $('#hidden-ajax_file').val(); diff --git a/pandora_console/operation/events/events.build_table.php b/pandora_console/operation/events/events.build_table.php index 92b7eecad8..881ea4ac32 100644 --- a/pandora_console/operation/events/events.build_table.php +++ b/pandora_console/operation/events/events.build_table.php @@ -20,6 +20,8 @@ require_once ($config["homedir"] . "/include/functions_ui.php"); $sort_field = get_parameter("sort_field", "timestamp"); $sort = get_parameter("sort", "down"); +$response_id = get_parameter ("response_id", ""); + $table = new stdClass(); if(!isset($table->width)) { $table->width = '100%'; @@ -887,9 +889,8 @@ else { echo '
'; if (!$readonly && $show_validate_button) { - html_print_button(__('In progress selected'), 'validate_button', false, 'validate_selected(2);', 'class="sub ok"'); - echo " "; - html_print_button(__('Validate selected'), 'validate_button', false, 'validate_selected(1);', 'class="sub ok"'); + $array_events_actions['in_progress_selected'] = 'In progress selected'; + $array_events_actions['validate_selected'] = 'Validate selected'; // Fix: validated_selected JS function has to be included with the proper user ACLs ?> '; echo ''; + + $sql_event_resp = "SELECT id, name FROM tevent_response WHERE type LIKE 'command'"; + $event_responses = db_get_all_rows_sql ($sql_event_resp); + + foreach ($event_responses as $val) + $array_events_actions[$val['id']] = $val['name']; + + echo '
'; + echo '
'; + html_print_select($array_events_actions, 'response_id', '', '', '', 0, false, false, false); + echo '  '; + html_print_button(__('Execute event response'), 'submit_event_response', false, 'execute_event_response(true);', 'class="sub next"'); + echo ""; + echo '
'; + echo ''; + echo '
'; } + + ?> + + ' . __('No events') . '
'; } echo ''; } -?> +?> \ No newline at end of file From efa2e5332ff70f427018548ccc08694f2f7fd10f Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Mon, 14 Jan 2019 13:40:49 +0100 Subject: [PATCH 2/5] fix massive custom event responses Former-commit-id: 24db40167b05bfd7fe4de88060f03a7a0ec38e73 --- .../operation/events/events.build_table.php | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/pandora_console/operation/events/events.build_table.php b/pandora_console/operation/events/events.build_table.php index 881ea4ac32..064a26d294 100644 --- a/pandora_console/operation/events/events.build_table.php +++ b/pandora_console/operation/events/events.build_table.php @@ -971,14 +971,6 @@ else { $('#button-submit_event_response').hide(function() { $('#response_loading_dialog').show(function() { - var total_checked = $(".chk_val:checked").length; - - // Limit number of events to apply custom responses to for performance reasons - if (total_checked > 10) { - $('#max_custom_event_resp_msg').show(); - return; - } - $(".chk_val").each(function() { if ($(this).is(":checked")) { @@ -1002,14 +994,6 @@ else { $('#button-btn_str').hide(function() { $('#execute_again_loading').show(function() { - var total_checked = $(".chk_val:checked").length; - - // Limit number of events to apply custom responses to for performance reasons - if (total_checked > 10) { - $('#max_custom_event_resp_msg').show(); - return; - } - $(".chk_val").each(function() { if ($(this).is(":checked")) { From 1ed90180c9eb388fe0c4699d8a242a0d5c6a27f3 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Tue, 15 Jan 2019 11:27:05 +0100 Subject: [PATCH 3/5] disable actions in event list when centralized mode is enabled and improve behavior of checkboxes when a massive action is applied Former-commit-id: 11f4606d2e7dd9b91c918323dc8a3dada0c8f765 --- pandora_console/include/javascript/pandora_events.js | 3 +++ pandora_console/operation/events/events.build_table.php | 2 ++ 2 files changed, 5 insertions(+) diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 5c680a319d..c2fda51dfb 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -226,6 +226,9 @@ function show_massive_response_dialog(event_id, response_id, response, out_itera $('#response_loading_dialog').hide(); $('#button-submit_event_response').show(); }, + close: function(event, ui) { + $( ".chk_val" ).prop( "checked", false ); + }, width: response['modal_width'], height: response['modal_height'] }) diff --git a/pandora_console/operation/events/events.build_table.php b/pandora_console/operation/events/events.build_table.php index 064a26d294..ee0dde9431 100644 --- a/pandora_console/operation/events/events.build_table.php +++ b/pandora_console/operation/events/events.build_table.php @@ -1027,6 +1027,8 @@ else { delete_selected(); break; } + + $( ".chk_val" ).prop( "checked", false ); } } From 5235b62c0d3fe07d53310ec254e0b93b56b0526f Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Tue, 15 Jan 2019 11:29:12 +0100 Subject: [PATCH 4/5] fix disable actions in event list when centralized mode is enabled Former-commit-id: d5f16b4453b1e291ba051cd381fc6c09ce0bd027 --- .../operation/events/events.build_table.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pandora_console/operation/events/events.build_table.php b/pandora_console/operation/events/events.build_table.php index ee0dde9431..bf674d88a6 100644 --- a/pandora_console/operation/events/events.build_table.php +++ b/pandora_console/operation/events/events.build_table.php @@ -927,15 +927,17 @@ else { foreach ($event_responses as $val) $array_events_actions[$val['id']] = $val['name']; - echo '
'; - echo '
'; - html_print_select($array_events_actions, 'response_id', '', '', '', 0, false, false, false); - echo '  '; - html_print_button(__('Execute event response'), 'submit_event_response', false, 'execute_event_response(true);', 'class="sub next"'); - echo ""; - echo '
'; - echo ''; - echo '
'; + if (!$config["centralized_management"]) { + echo '
'; + echo '
'; + html_print_select($array_events_actions, 'response_id', '', '', '', 0, false, false, false); + echo '  '; + html_print_button(__('Execute event response'), 'submit_event_response', false, 'execute_event_response(true);', 'class="sub next"'); + echo ""; + echo '
'; + echo ''; + echo '
'; + } } ?> From 9048a138402a5b6ca8c39e0a104d3a3e6c061cc1 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Tue, 15 Jan 2019 13:27:14 +0100 Subject: [PATCH 5/5] fix bug: in progress events deleting on event view massive deletion Former-commit-id: 4c4f0a387ad3abd7cfea913b45c885ab3af4ecc6 --- .../operation/events/events.build_table.php | 6 +++--- pandora_console/operation/events/events.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pandora_console/operation/events/events.build_table.php b/pandora_console/operation/events/events.build_table.php index bf674d88a6..dab7d5439c 100644 --- a/pandora_console/operation/events/events.build_table.php +++ b/pandora_console/operation/events/events.build_table.php @@ -900,10 +900,12 @@ else { validate_event_advanced($(this).val(), new_status); } }); + location.reload(); } @@ -927,7 +929,7 @@ else { foreach ($event_responses as $val) $array_events_actions[$val['id']] = $val['name']; - if (!$config["centralized_management"]) { + if ($config['event_replication'] != 1) { echo '
'; echo '
'; html_print_select($array_events_actions, 'response_id', '', '', '', 0, false, false, false); @@ -1029,8 +1031,6 @@ else { delete_selected(); break; } - - $( ".chk_val" ).prop( "checked", false ); } } diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index ad692695ae..5f76201864 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -559,6 +559,18 @@ if ($validate) { if ($delete) { $ids = (array) get_parameter ("validate_ids", -1); + // Discard deleting in progress events + $in_process_status = db_get_all_rows_sql(" + SELECT id_evento + FROM tevento + WHERE estado=2"); + + foreach ($in_process_status as $val) { + if (($key = array_search($val['id_evento'], $ids)) !== false) { + unset($ids[$key]); + } + } + if ($ids[0] != -1) { $return = events_delete_event ($ids, ($group_rep == 1), $meta); ui_print_result_message ($return,