From bcbcd763a14dab21687dcea2bc0ee4b823b155d3 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Mon, 29 Apr 2019 15:04:14 +0200 Subject: [PATCH 1/2] fixed double load of events in event list Former-commit-id: ea1294c680b5dbe3b069110012e2b54db5312fd1 --- pandora_console/operation/events/events.php | 89 +++++++++++++++---- .../operation/events/events_list.php | 19 +++- 2 files changed, 87 insertions(+), 21 deletions(-) diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index b259e35e66..291454d962 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -285,8 +285,38 @@ if (!$meta) { } } +$id_filter = db_get_value( + 'id_filter', + 'tusuario', + 'id_user', + $config['id_user'] +); + +// If user has event filter retrieve filter values. +if (!empty($id_filter)) { + $apply_filter = true; + + $event_filter = events_get_event_filter($id_filter); + + $event_filter['search'] = io_safe_output($event_filter['search']); + $event_filter['id_name'] = io_safe_output($event_filter['id_name']); + $event_filter['tag_with'] = base64_encode( + io_safe_output($event_filter['tag_with']) + ); + $event_filter['tag_without'] = base64_encode( + io_safe_output($event_filter['tag_without']) + ); +} + +$is_filtered = get_parameter('is_filtered', false); $offset = (int) get_parameter('offset', 0); + +if ($event_filter['id_group'] == '') { + $event_filter['id_group'] = 0; +} + $id_group = (int) get_parameter('id_group', 0); + // 0 all // ********************************************************************** // TODO @@ -297,38 +327,59 @@ $id_group = (int) get_parameter('id_group', 0); // ********************************************************************** $recursion = (bool) get_parameter('recursion', true); // Flag show in child groups. -$event_type = get_parameter('event_type', ''); +if (empty($event_filter['event_type'])) { + $event_filter['event_type'] = ''; +} + +$event_type = ($apply_filter === true && $is_filtered === false) ? $event_filter['event_type'] : get_parameter('event_type', ''); + // 0 all. -$severity = (int) get_parameter('severity', -1); +$severity = ($apply_filter === true && $is_filtered === false) ? (int) $event_filter['severity'] : (int) get_parameter('severity', -1); // -1 all. -$status = (int) get_parameter('status', 3); +if ($event_filter['status'] == -1) { + $event_filter['status'] = 3; +} + +$status = ($apply_filter === true && $is_filtered === false) ? (int) $event_filter['status'] : (int) get_parameter('status', 3); // -1 all, 0 only new, 1 only validated, // 2 only in process, 3 only not validated. -$id_agent = (int) get_parameter('id_agent', 0); -$pagination = (int) get_parameter('pagination', $config['block_size']); -$event_view_hr = (int) get_parameter( +$id_agent = ($apply_filter === true && $is_filtered === false) ? (int) $event_filter['id_agent'] : (int) get_parameter('id_agent', 0); +$pagination = ($apply_filter === true && $is_filtered === false) ? (int) $event_filter['pagination'] : (int) get_parameter('pagination', $config['block_size']); + +if (empty($event_filter['event_view_hr'])) { + $event_filter['event_view_hr'] = ($history) ? 0 : $config['event_view_hr']; +} + +$event_view_hr = ($apply_filter === true && $is_filtered === false) ? (int) $event_filter['event_view_hr'] : (int) get_parameter( 'event_view_hr', ($history) ? 0 : $config['event_view_hr'] ); -$id_user_ack = get_parameter('id_user_ack', 0); -$group_rep = (int) get_parameter('group_rep', 1); + + +$id_user_ack = ($apply_filter === true && $is_filtered === false) ? $event_filter['id_user_ack'] : get_parameter('id_user_ack', 0); +$group_rep = ($apply_filter === true && $is_filtered === false) ? (int) $event_filter['group_rep'] : (int) get_parameter('group_rep', 1); $delete = (bool) get_parameter('delete'); $validate = (bool) get_parameter('validate', 0); $section = (string) get_parameter('section', 'list'); -$filter_only_alert = (int) get_parameter('filter_only_alert', -1); +$filter_only_alert = ($apply_filter === true && $is_filtered === false) ? (int) $event_filter['filter_only_alert'] : (int) get_parameter('filter_only_alert', -1); $filter_id = (int) get_parameter('filter_id', 0); -$id_name = (string) get_parameter('id_name', ''); + +if (empty($event_filter['id_name'])) { + $event_filter['id_name'] = ''; +} + +$id_name = ($apply_filter === true && $is_filtered === false) ? (string) $event_filter['id_name'] : (string) get_parameter('id_name', ''); $open_filter = (int) get_parameter('open_filter', 0); -$date_from = (string) get_parameter('date_from', ''); -$date_to = (string) get_parameter('date_to', ''); +$date_from = ($apply_filter === true && $is_filtered === false) ? (string) $event_filter['date_from'] : (string) get_parameter('date_from', ''); +$date_to = ($apply_filter === true && $is_filtered === false) ? (string) $event_filter['date_to'] : (string) get_parameter('date_to', ''); $time_from = (string) get_parameter('time_from', ''); $time_to = (string) get_parameter('time_to', ''); $server_id = (int) get_parameter('server_id', 0); -$text_agent = (string) get_parameter('text_agent'); +$text_agent = ($apply_filter === true && $is_filtered === false) ? (string) $event_filter['text_agent'] : (string) get_parameter('text_agent'); $refr = (int) get_parameter('refresh'); -$id_extra = (string) get_parameter('id_extra'); -$user_comment = (string) get_parameter('user_comment'); -$source = (string) get_parameter('source'); +$id_extra = ($apply_filter === true && $is_filtered === false) ? (string) $event_filter['id_extra'] : (string) get_parameter('id_extra'); +$user_comment = ($apply_filter === true && $is_filtered === false) ? (string) $event_filter['user_comment'] : (string) get_parameter('user_comment'); +$source = ($apply_filter === true && $is_filtered === false) ? (string) $event_filter['source'] : (string) get_parameter('source'); if ($id_agent != 0) { $text_agent = agents_get_alias($id_agent); @@ -343,7 +394,7 @@ if ($id_agent != 0) { } $text_module = (string) get_parameter('module_search', ''); -$id_agent_module = get_parameter( +$id_agent_module = ($apply_filter === true && $is_filtered === false) ? $event_filter['id_agent_module'] : get_parameter( 'module_search_hidden', get_parameter('id_agent_module', 0) ); @@ -363,7 +414,7 @@ if ($id_agent_module != 0) { -$tag_with_json = base64_decode(get_parameter('tag_with', '')); +$tag_with_json = ($apply_filter === true && $is_filtered === false) ? base64_decode($event_filter['tag_with']) : base64_decode(get_parameter('tag_with', '')); $tag_with_json_clean = io_safe_output($tag_with_json); $tag_with_base64 = base64_encode($tag_with_json_clean); $tag_with = json_decode($tag_with_json_clean, true); @@ -373,7 +424,7 @@ if (empty($tag_with)) { $tag_with = array_diff($tag_with, [0 => 0]); -$tag_without_json = base64_decode(get_parameter('tag_without', '')); +$tag_without_json = ($apply_filter === true && $is_filtered === false) ? base64_decode($event_filter['tag_without']) : base64_decode(get_parameter('tag_without', '')); $tag_without_json_clean = io_safe_output($tag_without_json); $tag_without_base64 = base64_encode($tag_without_json_clean); $tag_without = json_decode($tag_without_json_clean, true); diff --git a/pandora_console/operation/events/events_list.php b/pandora_console/operation/events/events_list.php index 2146447272..fc48e19563 100644 --- a/pandora_console/operation/events/events_list.php +++ b/pandora_console/operation/events/events_list.php @@ -706,6 +706,9 @@ if (is_metaconsole()) { // Hidden field with the loaded filter name. $events_filter .= html_print_input_hidden('id_name', $id_name, true); +// Hidden field that signals filter has been applied. +$events_filter .= html_print_input_hidden('is_filtered', 'true', true); + // Hidden open filter flag // If autoupdate is in use collapse filter. if ($open_filter) { @@ -1039,6 +1042,20 @@ $events_filter .= $botom_update; $events_filter .= ''; // This is the filter div. +$user_filter = db_get_value( + 'id_filter', + 'tusuario', + 'id_user', + $config['id_user'] +); +$user_default_filter = db_get_all_rows_filter( + 'tevent_filter', + ['id_filter' => $user_filter] +); +$user_default_filter = $user_default_filter[0]; + +$id_name = $user_default_filter['id_name']; + $filter_resume['title'] = empty($id_name) ? __('No filter loaded') : __('Filter loaded').': '.$id_name; if (is_metaconsole()) { @@ -1321,8 +1338,6 @@ $(document).ready( function() { // Update the info with the loaded filter $('#filter_loaded_span').html($('#filter_loaded_text').html() + ': ' + $("#hidden-id_name").val()); - // Update the view with the loaded filter - $('#submit-update').trigger('click'); }, "json" ); From a622dcc9d4a5d878688d31e42849430fe14d2086 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Mon, 6 May 2019 15:06:26 +0200 Subject: [PATCH 2/2] add condition to avoid trying to retrieve a non existing event filter when synchronizing meta and node Former-commit-id: 83a1f9ad1c99de0e29a880de4ed6c518884bda31 --- .../operation/events/events_list.php | 106 +++++++++--------- 1 file changed, 54 insertions(+), 52 deletions(-) diff --git a/pandora_console/operation/events/events_list.php b/pandora_console/operation/events/events_list.php index fc48e19563..8333ca5b0d 100644 --- a/pandora_console/operation/events/events_list.php +++ b/pandora_console/operation/events/events_list.php @@ -232,68 +232,70 @@ if ($user_filter != 0 && empty($id_name) && !$update_from_filter_table) { ); $user_default_filter = $user_default_filter[0]; - // FORM. - $id_name = $user_default_filter['id_name']; - $id_group = $user_default_filter['id_group']; - if ($user_default_filter['event_type'] != '') { - $event_type = $user_default_filter['event_type']; - } + if (!empty($user_default_filter)) { + // FORM. + $id_name = $user_default_filter['id_name']; + $id_group = $user_default_filter['id_group']; + if ($user_default_filter['event_type'] != '') { + $event_type = $user_default_filter['event_type']; + } - $severity = $user_default_filter['severity']; - $status = $user_default_filter['status']; - $event_view_hr = $user_default_filter['event_view_hr']; - $group_rep = $user_default_filter['group_rep']; - $id_extra = $user_default_filter['id_extra']; - $user_comment = $user_default_filter['user_comment']; - $source = $user_default_filter['source']; + $severity = $user_default_filter['severity']; + $status = $user_default_filter['status']; + $event_view_hr = $user_default_filter['event_view_hr']; + $group_rep = $user_default_filter['group_rep']; + $id_extra = $user_default_filter['id_extra']; + $user_comment = $user_default_filter['user_comment']; + $source = $user_default_filter['source']; - if ($user_default_filter['search'] != '') { - $search = $user_default_filter['search']; - } + if ($user_default_filter['search'] != '') { + $search = $user_default_filter['search']; + } - if ($user_default_filter['id_user_ack'] != 0) { - $id_user_ack = $user_default_filter['id_user_ack']; - } + if ($user_default_filter['id_user_ack'] != 0) { + $id_user_ack = $user_default_filter['id_user_ack']; + } - if ($user_default_filter['id_agent_module'] != 0) { - $id_agent_module = $user_default_filter['id_agent_module']; - } + if ($user_default_filter['id_agent_module'] != 0) { + $id_agent_module = $user_default_filter['id_agent_module']; + } - if ($user_default_filter['id_agent'] != 0) { - $id_agent = $user_default_filter['id_agent']; - $text_agent = agents_get_alias($id_agent); - } + if ($user_default_filter['id_agent'] != 0) { + $id_agent = $user_default_filter['id_agent']; + $text_agent = agents_get_alias($id_agent); + } - if ($user_default_filter['filter_only_alert'] != -1) { - $filter_only_alert = $user_default_filter['filter_only_alert']; - } + if ($user_default_filter['filter_only_alert'] != -1) { + $filter_only_alert = $user_default_filter['filter_only_alert']; + } - if ($user_default_filter['pagination'] != 20) { - $pagination = $user_default_filter['pagination']; - } + if ($user_default_filter['pagination'] != 20) { + $pagination = $user_default_filter['pagination']; + } - if ($user_default_filter['date_from'] != '0000-00-00') { - $date_from = $user_default_filter['date_from']; - } + if ($user_default_filter['date_from'] != '0000-00-00') { + $date_from = $user_default_filter['date_from']; + } - if ($user_default_filter['date_to'] != '0000-00-00') { - $date_to = $user_default_filter['date_to']; - } + if ($user_default_filter['date_to'] != '0000-00-00') { + $date_to = $user_default_filter['date_to']; + } - if (io_safe_output($user_default_filter['tag_with']) != '[]' - && io_safe_output($user_default_filter['tag_with']) != '["0"]' - ) { - $tag_with = $user_default_filter['tag_with']; - $tag_with_clean = io_safe_output($tag_with); - $tag_with = json_decode($tag_with_clean, true); - } + if (io_safe_output($user_default_filter['tag_with']) != '[]' + && io_safe_output($user_default_filter['tag_with']) != '["0"]' + ) { + $tag_with = $user_default_filter['tag_with']; + $tag_with_clean = io_safe_output($tag_with); + $tag_with = json_decode($tag_with_clean, true); + } - if (io_safe_output($user_default_filter['tag_without']) != '[]' - && io_safe_output($user_default_filter['tag_without']) != '["0"]' - ) { - $tag_without = $user_default_filter['tag_without']; - $tag_without_clear = io_safe_output($tag_without); - $tag_without = json_decode($tag_without_clear, true); + if (io_safe_output($user_default_filter['tag_without']) != '[]' + && io_safe_output($user_default_filter['tag_without']) != '["0"]' + ) { + $tag_without = $user_default_filter['tag_without']; + $tag_without_clear = io_safe_output($tag_without); + $tag_without = json_decode($tag_without_clear, true); + } } } @@ -1043,7 +1045,7 @@ $events_filter .= $botom_update; $events_filter .= ''; // This is the filter div. $user_filter = db_get_value( - 'id_filter', + 'default_event_filter', 'tusuario', 'id_user', $config['id_user']