From df7435132ae80aa46c62efddf7fb73953abe2c60 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Fri, 16 Feb 2024 10:10:38 +0100 Subject: [PATCH] change regex search in events --- pandora_console/extras/mr/70.sql | 11 ++++ pandora_console/include/ajax/events.php | 7 +-- pandora_console/include/functions_events.php | 12 ++++- pandora_console/operation/events/events.php | 53 ++++++++------------ pandora_console/pandoradb.sql | 2 +- 5 files changed, 47 insertions(+), 38 deletions(-) create mode 100644 pandora_console/extras/mr/70.sql diff --git a/pandora_console/extras/mr/70.sql b/pandora_console/extras/mr/70.sql new file mode 100644 index 0000000000..4a9d0eb75e --- /dev/null +++ b/pandora_console/extras/mr/70.sql @@ -0,0 +1,11 @@ +START TRANSACTION; + +-- Watch out! The following field migration must be done before altering the corresponding table. +UPDATE `tevent_filter` +SET `search` = `regex` +WHERE `regex` IS NOT NULL AND `regex` != ''; + +-- Watch out! The following alter command must be done after the previous update of this table. +ALTER TABLE `tevent_filter` MODIFY COLUMN `regex` TINYINT unsigned NOT NULL DEFAULT 0; + +COMMIT; \ No newline at end of file diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 72e77e73dc..be66681064 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -646,7 +646,7 @@ function load_form_filter() { if (i == 'search') $('#text-search').val(val); if (i == 'regex') - $('#text-regex').val(val); + $('#checkbox-regex').val(val); if (i == 'not_search') $('#checkbox-not_search').val(val); if (i == 'text_agent') @@ -977,7 +977,7 @@ function save_new_filter() { "severity" : $("#severity").val(), "status" : $("#status").val(), "search" : $("#text-search").val(), - "regex" : $('#text-regex').val(), + "regex" : $('#checkbox-regex').val(), "not_search" : $("#checkbox-not_search").val(), "text_agent" : $("#text_id_agent").val(), "id_agent" : $('input:hidden[name=id_agent]').val(), @@ -1058,7 +1058,7 @@ function save_update_filter() { "severity" : $("#severity").val(), "status" : $("#status").val(), "search" : $("#text-search").val(), - "regex" : $('#text-regex').val(), + "regex" : $('#checkbox-regex').val(), "not_search" : $("#checkbox-not_search").val(), "text_agent" : $("#text_id_agent").val(), "id_agent" : $('input:hidden[name=id_agent]').val(), @@ -2594,6 +2594,7 @@ if ($get_events_fired) { 'severity' => -1, 'status' => -1, 'search' => '', + 'regex' => 0, 'not_search' => 0, 'text_agent' => '', 'id_agent' => 0, diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index abd3e8d59f..cd6163c875 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1177,14 +1177,22 @@ function events_get_all( $array_search[] = 'lower(ta.alias)'; } + if ((bool) $filter['regex'] === true) { + $comp_pattern = 'REGEXP "%s"'; + } else { + $comp_pattern = 'LIKE lower("%%%s%%")'; + } + + $comp_string = sprintf($comp_pattern, $filter['search']); + $sql_search = ' AND ('; foreach ($array_search as $key => $field) { $sql_search .= sprintf( - '%s %s %s like lower("%%%s%%")', + '%s %s %s %s', ($key === 0) ? '' : $nexo, $field, $not_search, - $filter['search'] + $comp_string ); $sql_search .= ' '; } diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 8da1863bf4..7f83fcc302 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -130,11 +130,11 @@ $severity = get_parameter( 'filter[severity]', ($filter['severity'] ?? '') ); -$regex = get_parameter( +$regex = (bool) get_parameter( 'filter[regex]', - (io_safe_output($filter['regex']) ?? '') + ($filter['regex'] ?? false) ); -unset($filter['regex']); + $status = get_parameter( 'filter[status]', ($filter['status'] ?? '') @@ -1229,27 +1229,7 @@ if (is_ajax() === true) { } } - $regex_validation = false; - if (empty($tmp) === false && $regex !== '') { - foreach (json_decode(json_encode($tmp), true) as $key => $field) { - if ($key === 'b64') { - continue; - } - - $field = strip_tags($field); - - if (preg_match('/'.$regex.'/', $field)) { - $regex_validation = true; - } - } - - if ($regex_validation === true) { - $carry[] = $tmp; - } - } else { - $carry[] = $tmp; - } - + $carry[] = $tmp; return $carry; } ); @@ -2083,6 +2063,23 @@ $data .= ui_print_help_tip( __('Search for elements NOT containing given text.'), true ); + +$data .= '   '; + +$data .= html_print_checkbox_switch( + 'regex', + $regex, + $regex, + true, + false, + 'checked_slide_events(this);', + true +); +$data .= ui_print_help_tip( + __('Search by regular expression.'), + true +); + $data .= ''; $in = '