From 64013c04161f75c488a47b63ee67ce36b3643c68 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Tue, 23 Apr 2024 16:56:28 +0200 Subject: [PATCH] #13264 added regex in sql --- pandora_console/include/functions_events.php | 46 +++++++++++++------- pandora_console/operation/events/events.php | 31 +++---------- 2 files changed, 36 insertions(+), 41 deletions(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 6e6068f386..6e3d2e1f01 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1155,7 +1155,7 @@ function events_get_all( } // Free search. - if (empty($filter['search']) === false && (bool) $filter['regex'] === false) { + if (empty($filter['search']) === false) { if (isset($config['dbconnection']->server_version) === true && $config['dbconnection']->server_version > 50600 ) { @@ -1185,23 +1185,39 @@ function events_get_all( $array_search[] = 'lower(ta.alias)'; } - // Disregard repeated whitespaces when searching. - $collapsed_spaces_search = preg_replace('/( )+/', ' ', $filter['search']); + if ((bool) $filter['regex'] === true) { + $sql_search = ' AND ('; + foreach ($array_search as $key => $field) { + $sql_search .= sprintf( + '%s %s %s REGEXP "%s" ', + ($key === 0) ? '' : $nexo, + $field, + $not_search, + io_safe_output($filter['search']) + ); + $sql_search .= ' '; + } - $sql_search = ' AND ('; - foreach ($array_search as $key => $field) { - $sql_search .= sprintf( - '%s LOWER(REGEXP_REPLACE(%s, "( )+", " ")) %s like LOWER("%%%s%%")', - ($key === 0) ? '' : $nexo, - $field, - $not_search, - $collapsed_spaces_search - ); - $sql_search .= ' '; + $sql_search .= ' )'; + } else { + // Disregard repeated whitespaces when searching. + $collapsed_spaces_search = preg_replace('/( )+/', ' ', $filter['search']); + + $sql_search = ' AND ('; + foreach ($array_search as $key => $field) { + $sql_search .= sprintf( + '%s LOWER(REGEXP_REPLACE(%s, "( )+", " ")) %s like LOWER("%%%s%%")', + ($key === 0) ? '' : $nexo, + $field, + $not_search, + $collapsed_spaces_search + ); + $sql_search .= ' '; + } + + $sql_search .= ' )'; } - $sql_search .= ' )'; - $sql_filters[] = $sql_search; } diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 7c5f1b1210..22f4908b07 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -1249,27 +1249,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('/'.io_safe_output($regex).'/', $field)) { - $regex_validation = true; - } - } - - if ($regex_validation === true) { - $carry[] = $tmp; - } - } else { - $carry[] = $tmp; - } - + $carry[] = $tmp; return $carry; } ); @@ -1289,11 +1269,10 @@ if (is_ajax() === true) { // RecordsTotal && recordsfiltered resultados totales. echo json_encode( [ - 'data' => ($data ?? []), - 'buffers' => $buffers, - 'recordsTotal' => $count, - 'recordsFiltered' => $count, - 'showAlwaysPagination' => (empty($regex) === false) ? true : false, + 'data' => ($data ?? []), + 'buffers' => $buffers, + 'recordsTotal' => $count, + 'recordsFiltered' => $count, ] ); } catch (Exception $e) {