From b8e8a16e7dfe1dd422a66c04476d5c7489ecae4e Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Tue, 5 Sep 2023 10:11:15 +0200 Subject: [PATCH 1/4] #11537 Fix search with space entitites --- .../include/class/ConfigPEN.class.php | 3 ++- .../include/functions_custom_graphs.php | 4 ++-- .../include/functions_inventory.php | 6 ++--- .../operation/inventory/inventory.php | 5 ++++ .../operation/search_agents.getdata.php | 22 ++++++++--------- .../operation/search_alerts.getdata.php | 20 ++++++++-------- .../operation/search_graphs.getdata.php | 2 +- pandora_console/operation/search_main.php | 20 ++++++++-------- .../operation/search_maps.getdata.php | 2 +- .../operation/search_modules.getdata.php | 12 +++++----- .../operation/search_policies.getdata.php | 2 +- .../operation/search_reports.getdata.php | 8 +++---- .../operation/search_users.getdata.php | 24 +++++++++---------- 13 files changed, 68 insertions(+), 62 deletions(-) diff --git a/pandora_console/include/class/ConfigPEN.class.php b/pandora_console/include/class/ConfigPEN.class.php index cea6123f08..4e4975e64d 100644 --- a/pandora_console/include/class/ConfigPEN.class.php +++ b/pandora_console/include/class/ConfigPEN.class.php @@ -118,7 +118,7 @@ class ConfigPEN extends HTML if (is_array($filter)) { if (!empty($filter['free_search'])) { $sql_filters[] = vsprintf( - ' AND (lower(`manufacturer`) like lower("%%%s%%") + ' AND (lower(REPLACE(manufacturer, " ", " ")) like lower("%%%s%%") OR pen = "%s") ', array_fill(0, 2, $filter['free_search']) ); @@ -184,6 +184,7 @@ class ConfigPEN extends HTML return db_get_value_sql($sql); } + hd($sql, true); return db_get_all_rows_sql($sql); } diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php index 500b668a24..f76dc7c0f7 100644 --- a/pandora_console/include/functions_custom_graphs.php +++ b/pandora_console/include/functions_custom_graphs.php @@ -194,11 +194,11 @@ function custom_graphs_get_user($id_user=0, $only_names=false, $returnAllGroup=t function custom_graphs_search($id_group, $search) { if ($id_group != '' && $search != '') { - $all_graphs = db_get_all_rows_sql('select * from tgraph where id_group = '.$id_group.' AND (name LIKE "%'.$search.'%" OR description LIKE "'.$search.'")'); + $all_graphs = db_get_all_rows_sql('select * from tgraph where id_group = '.$id_group.' AND (REPLACE(name, " ", " ") LIKE "%'.$search.'%" OR REPLACE(description, " ", " ") LIKE "'.$search.'")'); } else if ($id_group != '') { $all_graphs = db_get_all_rows_sql('select * from tgraph where id_group = '.$id_group.''); } else { - $all_graphs = db_get_all_rows_sql('select * from tgraph where name LIKE "%'.$search.'%" OR description LIKE "'.$search.'"'); + $all_graphs = db_get_all_rows_sql('select * from tgraph where REPLACE(name, " ", " ") LIKE "%'.$search.'%" OR REPLACE(description, " ", " ") LIKE "'.$search.'"'); } if ($all_graphs === false) { diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index 8e69da7445..aac94a9b52 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -77,7 +77,7 @@ function inventory_get_data( } if ($inventory_search_string != '') { - array_push($where, "tagent_module_inventory.data LIKE '%".$inventory_search_string."%'"); + array_push($where, "REPLACE(tagent_module_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'"); } $offset = (int) get_parameter('offset'); @@ -746,7 +746,7 @@ function inventory_get_datatable( } if ($inventory_search_string != '') { - array_push($where, "tagent_module_inventory.data LIKE '%".$inventory_search_string."%'"); + array_push($where, "REPLACE(tagent_module_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'"); } if ($utimestamp > 0) { @@ -889,7 +889,7 @@ function get_data_basic_info_sql($params, $count=false) if ($params['search'] > 0) { $where .= sprintf( - ' AND ( alias LIKE "%%%s%%" )', + ' AND ( REPLACE(alias, " ", " ") LIKE "%%%s%%" )', $params['search'] ); } diff --git a/pandora_console/operation/inventory/inventory.php b/pandora_console/operation/inventory/inventory.php index c753bd599b..e9d2e312d9 100755 --- a/pandora_console/operation/inventory/inventory.php +++ b/pandora_console/operation/inventory/inventory.php @@ -1280,6 +1280,10 @@ if ($inventory_module !== 'basic') { $style = 'width: 100%'; $ordering = true; $searching = false; + $search = []; + if (strlen($inventory_search_string) > 0) { + $search['value'] = $inventory_search_string; + } $columns = [ 'alias', @@ -1329,6 +1333,7 @@ if ($inventory_module !== 'basic') { 'get_data_basic_info' => 1, 'id_agent' => $id_agente, 'id_group' => $inventory_id_group, + 'search' => $search, ], 'zeroRecords' => __('Agent info not found'), 'emptyTable' => __('Agent info not found'), diff --git a/pandora_console/operation/search_agents.getdata.php b/pandora_console/operation/search_agents.getdata.php index ea63506fa4..9809f0f3d9 100644 --- a/pandora_console/operation/search_agents.getdata.php +++ b/pandora_console/operation/search_agents.getdata.php @@ -74,15 +74,15 @@ if ($searchAgents) { $sql = "SELECT DISTINCT taddress_agent.id_agent FROM taddress INNER JOIN taddress_agent ON taddress.id_a = taddress_agent.id_a - WHERE taddress.ip LIKE '$stringSearchSQL'"; + WHERE LOWER(REPLACE(taddress.ip, ' ', ' ')) LIKE LOWER('$stringSearchSQL')"; $id = db_get_all_rows_sql($sql); if ($id != '') { $aux = $id[0]['id_agent']; - $search_sql = " t1.nombre LIKE '".$stringSearchSQL."' OR - t2.nombre LIKE '".$stringSearchSQL."' OR - t1.alias LIKE '".$stringSearchSQL."' OR - t1.comentarios LIKE '".$stringSearchSQL."' OR + $search_sql = " LOWER(REPLACE(t1.nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR + LOWER(REPLACE(t2.nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR + LOWER(REPLACE(t1.alias, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR + LOWER(REPLACE(t1.comentarios, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR t1.id_agente =".$aux; $idCount = count($id); @@ -94,16 +94,16 @@ if ($searchAgents) { } } } else { - $search_sql = " t1.nombre LIKE '".$stringSearchSQL."' OR - t2.nombre LIKE '".$stringSearchSQL."' OR - t1.direccion LIKE '".$stringSearchSQL."' OR - t1.comentarios LIKE '".$stringSearchSQL."' OR - t1.alias LIKE '".$stringSearchSQL."'"; + $search_sql = " LOWER(REPLACE(t1.nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR + LOWER(REPLACE(t2.nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR + LOWER(REPLACE(t1.direccion, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR + LOWER(REPLACE(t1.comentarios, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR + LOWER(REPLACE(t1.alias, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."')"; } if ($has_secondary === true) { $search_sql .= " OR (tasg.id_group IS NOT NULL AND - tasg.id_group IN (SELECT id_grupo FROM tgrupo WHERE nombre LIKE '".$stringSearchSQL."'))"; + tasg.id_group IN (SELECT id_grupo FROM tgrupo WHERE LOWER(REPLACE(nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."')))"; } $sql = " diff --git a/pandora_console/operation/search_alerts.getdata.php b/pandora_console/operation/search_alerts.getdata.php index cebb13919c..eea9f70324 100644 --- a/pandora_console/operation/search_alerts.getdata.php +++ b/pandora_console/operation/search_alerts.getdata.php @@ -139,64 +139,64 @@ if ($searchAlerts) { switch ($config['dbtype']) { case 'mysql': $whereAlerts = 'AND ( - id_alert_template IN (SELECT id FROM talert_templates WHERE name LIKE "%'.$stringSearchSQL.'%") OR + id_alert_template IN (SELECT id FROM talert_templates WHERE REPLACE(name, " ", " ") LIKE "%'.$stringSearchSQL.'%") OR id_alert_template IN ( SELECT id FROM talert_templates WHERE id_alert_action IN ( SELECT id FROM talert_actions - WHERE name LIKE "%'.$stringSearchSQL.'%")) OR + WHERE REPLACE(name, " ", " ") LIKE "%'.$stringSearchSQL.'%")) OR talert_template_modules.id IN ( SELECT id_alert_template_module FROM talert_template_module_actions WHERE id_alert_action IN ( SELECT id FROM talert_actions - WHERE name LIKE "%'.$stringSearchSQL.'%")) OR + WHERE REPLACE(name, " ", " ") LIKE "%'.$stringSearchSQL.'%")) OR id_agent_module IN ( SELECT id_agente_modulo FROM tagente_modulo - WHERE nombre LIKE "%'.$stringSearchSQL.'%") OR + WHERE REPLACE(nombre, " ", " ") LIKE "%'.$stringSearchSQL.'%") OR id_agent_module IN ( SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente IN ( SELECT id_agente FROM tagente - WHERE nombre LIKE "%'.$stringSearchSQL.'%" '.$extra_sql.')) + WHERE REPLACE(nombre, " ", " ") LIKE "%'.$stringSearchSQL.'%" '.$extra_sql.')) )'; break; case 'postgresql': case 'oracle': $whereAlerts = 'AND ( - id_alert_template IN (SELECT id FROM talert_templates WHERE upper(name) LIKE \'%'.strtolower($stringSearchSQL).'%\') OR + id_alert_template IN (SELECT id FROM talert_templates WHERE upper(REPLACE(name, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\') OR id_alert_template IN ( SELECT id FROM talert_templates WHERE id_alert_action IN ( SELECT id FROM talert_actions - WHERE upper(name) LIKE \'%'.strtolower($stringSearchSQL).'%\')) OR + WHERE upper(REPLACE(name, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\')) OR talert_template_modules.id IN ( SELECT id_alert_template_module FROM talert_template_module_actions WHERE id_alert_action IN ( SELECT id FROM talert_actions - WHERE upper(name) LIKE \'%'.strtolower($stringSearchSQL).'%\')) OR + WHERE upper(REPLACE(name, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\')) OR id_agent_module IN ( SELECT id_agente_modulo FROM tagente_modulo - WHERE upper(nombre) LIKE \'%'.strtolower($stringSearchSQL).'%\') OR + WHERE upper(REPLACE(nombre, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\') OR id_agent_module IN ( SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente IN ( SELECT id_agente FROM tagente - WHERE upper(nombre) LIKE \'%'.strtolower($stringSearchSQL).'%\' '.$extra_sql.')) + WHERE upper(REPLACE(nombre, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\' '.$extra_sql.')) )'; $agents = false; break; diff --git a/pandora_console/operation/search_graphs.getdata.php b/pandora_console/operation/search_graphs.getdata.php index f4b5fdf171..7037274b08 100644 --- a/pandora_console/operation/search_graphs.getdata.php +++ b/pandora_console/operation/search_graphs.getdata.php @@ -31,7 +31,7 @@ if ($searchGraphs) { } $filter = []; - $filter[] = "(upper(name) LIKE '%".strtolower($stringSearchSQL)."%' OR upper(description) LIKE '%$".strtolower($stringSearchSQL)."%')"; + $filter[] = "(upper(REPLACE(name, ' ', ' ')) LIKE '%".strtolower($stringSearchSQL)."%' OR upper(REPLACE(description, ' ', ' ')) LIKE '%$".strtolower($stringSearchSQL)."%')"; $filter['id_graph'] = $usergraphs_id; $columns = [ diff --git a/pandora_console/operation/search_main.php b/pandora_console/operation/search_main.php index e5f136f457..ac841fa703 100644 --- a/pandora_console/operation/search_main.php +++ b/pandora_console/operation/search_main.php @@ -62,10 +62,10 @@ $sql = "SELECT DISTINCT taddress_agent.id_agent FROM taddress $id = db_get_all_rows_sql($sql); if ($id != '') { $aux = $id[0]['id_agent']; - $search_sql = " t1.nombre LIKE '".$stringSearchSQL."' OR - t2.nombre LIKE '".$stringSearchSQL."' OR - t1.alias LIKE '".$stringSearchSQL."' OR - t1.comentarios LIKE '".$stringSearchSQL."' OR + $search_sql = " REPLACE(t1.nombre, ' ', ' ') LIKE '".$stringSearchSQL."' OR + REPLACE(t2.nombre, ' ', ' ') LIKE '".$stringSearchSQL."' OR + REPLACE(t1.alias, ' ', ' ') LIKE '".$stringSearchSQL."' OR + REPLACE(t1.comentarios, ' ', ' ') LIKE '".$stringSearchSQL."' OR t1.id_agente =".$aux; $idCount = count($id); @@ -77,16 +77,16 @@ if ($id != '') { } } } else { - $search_sql = " t1.nombre LIKE '".$stringSearchSQL."' OR - t2.nombre LIKE '".$stringSearchSQL."' OR - t1.direccion LIKE '".$stringSearchSQL."' OR - t1.comentarios LIKE '".$stringSearchSQL."' OR - t1.alias LIKE '".$stringSearchSQL."'"; + $search_sql = " REPLACE(t1.nombre, ' ', ' ') LIKE '".$stringSearchSQL."' OR + REPLACE(t2.nombre, ' ', ' ') LIKE '".$stringSearchSQL."' OR + REPLACE(t1.direccion, ' ', ' ') LIKE '".$stringSearchSQL."' OR + REPLACE(t1.comentarios, ' ', ' ') LIKE '".$stringSearchSQL."' OR + REPLACE(t1.alias, ' ', ' ') LIKE '".$stringSearchSQL."'"; } if ($has_secondary === true) { $search_sql .= " OR (tasg.id_group IS NOT NULL AND - tasg.id_group IN (SELECT id_grupo FROM tgrupo WHERE nombre LIKE '".$stringSearchSQL."'))"; + tasg.id_group IN (SELECT id_grupo FROM tgrupo WHERE REPLACE(nombre, ' ', ' ') LIKE '".$stringSearchSQL."'))"; } $sql = " diff --git a/pandora_console/operation/search_maps.getdata.php b/pandora_console/operation/search_maps.getdata.php index 6f3456ef5b..60cd83f556 100644 --- a/pandora_console/operation/search_maps.getdata.php +++ b/pandora_console/operation/search_maps.getdata.php @@ -32,7 +32,7 @@ if ((bool) $searchMaps === true) { FROM tlayout tl LEFT JOIN tlayout_data tld ON tl.id = tld.id_layout - WHERE tl.name LIKE "%%%s%%" + WHERE REPLACE(tl.name, " ", " ") LIKE "%%%s%%" AND tl.id_group IN (%s) GROUP BY tl.id, tl.name, tl.id_group', $stringSearchSQL, diff --git a/pandora_console/operation/search_modules.getdata.php b/pandora_console/operation/search_modules.getdata.php index e83c6035ef..f4f3f896df 100644 --- a/pandora_console/operation/search_modules.getdata.php +++ b/pandora_console/operation/search_modules.getdata.php @@ -134,8 +134,8 @@ if ($searchModules) { ) ) AND - (t1.nombre LIKE "%'.$stringSearchSQL.'%" OR - t3.nombre LIKE "%'.$stringSearchSQL.'%") + (REPLACE(t1.nombre, " ", " ") LIKE "%'.$stringSearchSQL.'%" OR + REPLACE(t3.nombre, " ", " ") LIKE "%'.$stringSearchSQL.'%") AND t1.disabled = 0'; break; @@ -164,8 +164,8 @@ if ($searchModules) { ) ) ) AND - (t1.nombre LIKE \'%'.$stringSearchSQL.'%\' OR - t3.nombre LIKE \'%'.$stringSearchSQL.'%\')'; + (REPLACE(t1.nombre, " ", " ") LIKE \'%'.$stringSearchSQL.'%\' OR + REPLACE(t3.nombre, " ", " ") LIKE \'%'.$stringSearchSQL.'%\')'; break; case 'oracle': @@ -193,8 +193,8 @@ if ($searchModules) { ) ) ) AND - (LOWER(t1.nombre) LIKE \'%'.strtolower($stringSearchSQL).'%\' OR - LOWER(t3.nombre) LIKE \'%'.strtolower($stringSearchSQL).'%\')'; + (LOWER(REPLACE(t1.nombre, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\' OR + LOWER(REPLACE(t3.nombre, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\')'; break; } diff --git a/pandora_console/operation/search_policies.getdata.php b/pandora_console/operation/search_policies.getdata.php index cc6f0dca45..cc4c844ea0 100644 --- a/pandora_console/operation/search_policies.getdata.php +++ b/pandora_console/operation/search_policies.getdata.php @@ -207,7 +207,7 @@ if ($searchpolicies === true) { $sql = "SELECT id, name, description, id_group, status FROM tpolicies - WHERE name LIKE '$stringSearchSQL' + WHERE REPLACE(name, ' ', ' ') LIKE '$stringSearchSQL' AND id_group IN ($id_user_groups_str) "; } diff --git a/pandora_console/operation/search_reports.getdata.php b/pandora_console/operation/search_reports.getdata.php index 082d9914cc..3cf83bacbc 100644 --- a/pandora_console/operation/search_reports.getdata.php +++ b/pandora_console/operation/search_reports.getdata.php @@ -46,13 +46,13 @@ if ($searchReports) { case 'postgresql': $sql = "SELECT id_report, name, description FROM treport - WHERE (name LIKE '%".$stringSearchSQL."%' OR description LIKE '%".$stringSearchSQL."%')".$reports_condition; + WHERE (REPLACE(name, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR REPLACE(description, ' ', ' ') LIKE '%".$stringSearchSQL."%')".$reports_condition; break; case 'oracle': $sql = "SELECT id_report, name, description FROM treport - WHERE (upper(name) LIKE '%".strtolower($stringSearchSQL)."%' OR description LIKE '%".strtolower($stringSearchSQL)."%')".$reports_condition; + WHERE (upper(REPLACE(name, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR REPLACE(description, ' ', ' ') LIKE '%".strtolower($stringSearchSQL)."%')".$reports_condition; break; } @@ -77,13 +77,13 @@ if ($searchReports) { case 'postgresql': $sql_count = "SELECT COUNT(id_report) AS count FROM treport - WHERE (name LIKE '%".$stringSearchSQL."%' OR description LIKE '%".$stringSearchSQL."%')".$reports_condition; + WHERE (REPLACE(name, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR REPLACE(description, ' ', ' ') LIKE '%".$stringSearchSQL."%')".$reports_condition; break; case 'oracle': $sql_count = "SELECT COUNT(id_report) AS count FROM treport - WHERE (upper(name) LIKE '%".strtolower($stringSearchSQL)."%' OR upper(description) LIKE '%".strtolower($stringSearchSQL)."%')".$reports_condition; + WHERE (upper(REPLACE(name, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR upper(REPLACE(description, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%')".$reports_condition; break; } diff --git a/pandora_console/operation/search_users.getdata.php b/pandora_console/operation/search_users.getdata.php index 212eb8a493..1e8932c4bc 100644 --- a/pandora_console/operation/search_users.getdata.php +++ b/pandora_console/operation/search_users.getdata.php @@ -179,23 +179,23 @@ if ($searchUsers) { case 'mysql': case 'postgresql': $sql = "SELECT id_user, fullname, firstname, lastname, middlename, email, last_connect, is_admin, comments FROM tusuario - WHERE fullname LIKE '%".$stringSearchSQL."%' OR - id_user LIKE '%".$stringSearchSQL."%' OR - firstname LIKE '%".$stringSearchSQL."%' OR - lastname LIKE '%".$stringSearchSQL."%' OR - middlename LIKE '%".$stringSearchSQL."%' OR - email LIKE '%".$stringSearchSQL."%' + WHERE REPLACE(fullname, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR + REPLACE(id_user, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR + REPLACE(firstname, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR + REPLACE(lastname, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR + REPLACE(middlename, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR + REPLACE(email, ' ', ' ') LIKE '%".$stringSearchSQL."%' ORDER BY ".$order['field'].' '.$order['order']; break; case 'oracle': $sql = "SELECT id_user, fullname, firstname, lastname, middlename, email, last_connect, is_admin, comments FROM tusuario - WHERE upper(fullname) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(id_user) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(firstname) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(lastname) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(middlename) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(email) LIKE '%".strtolower($stringSearchSQL)."%' + WHERE upper(REPLACE(fullname, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR + upper(REPLACE(id_user, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR + upper(REPLACE(firstname, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR + upper(REPLACE(lastname, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR + upper(REPLACE(middlename, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR + upper(REPLACE(email, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' ORDER BY ".$order['field'].' '.$order['order']; break; } From 25175ce22e8bf4486d735e988b5d11ae876d4a10 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Tue, 5 Sep 2023 13:05:12 +0200 Subject: [PATCH 2/4] #11537 Fix inventory --- pandora_console/include/functions_inventory.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index aac94a9b52..0becb94fec 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -77,6 +77,8 @@ function inventory_get_data( } if ($inventory_search_string != '') { + hd(1, true); + hd($inventory_search_string, true); array_push($where, "REPLACE(tagent_module_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'"); } @@ -746,7 +748,9 @@ function inventory_get_datatable( } if ($inventory_search_string != '') { - array_push($where, "REPLACE(tagent_module_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'"); + hd(2, true); + hd($inventory_search_string, true); + array_push($where, "REPLACE(tagente_datos_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'"); } if ($utimestamp > 0) { @@ -786,7 +790,6 @@ function inventory_get_datatable( } $rows = db_get_all_rows_sql($sql); - if ($order_by_agent === false) { $modules = []; foreach ($rows as $row) { @@ -796,7 +799,7 @@ function inventory_get_datatable( $data_rows = explode(PHP_EOL, $row['data_inventory']); foreach ($data_rows as $data_key => $data_value) { - if (empty($data_value) === false) { + if (empty($data_value) === false && strpos(str_replace(' ', ' ', $data_value), $inventory_search_string)) { $row['data'] = $data_value; $modules[$row['name']][$row['name_agent'].'-'.$data_key.'-'.$data_value] = $row; } @@ -892,6 +895,8 @@ function get_data_basic_info_sql($params, $count=false) ' AND ( REPLACE(alias, " ", " ") LIKE "%%%s%%" )', $params['search'] ); + hd(3, true); + hd($params['search'], true); } if ($params['utimestamp'] > 0 && $count === false) { From 3bb4567dc3051d5734538c9417ed92f57951a4f9 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Tue, 5 Sep 2023 13:44:54 +0200 Subject: [PATCH 3/4] #11537 Fix searchs --- .../godmode/agentes/modificar_agente.php | 16 ++++++++-------- .../godmode/agentes/module_manager.php | 2 +- .../modules/manage_network_components.php | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index a14bff4b92..17596b28ab 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -566,10 +566,10 @@ if ($search != '') { if ($id != '') { $aux = $id[0]['id_agent']; $search_sql = sprintf( - ' AND ( nombre LIKE "%%%s%%" - OR alias LIKE "%%%s%%" - OR comentarios LIKE "%%%s%%" - OR EXISTS (SELECT * FROM tagent_custom_data WHERE id_agent = id_agente AND description LIKE "%%%s%%") + ' AND ( REPLACE(nombre, " ", " ") LIKE "%%%s%%" + OR REPLACE(alias, " ", " ") LIKE "%%%s%%" + OR REPLACE(comentarios, " ", " ") LIKE "%%%s%%" + OR EXISTS (SELECT * FROM tagent_custom_data WHERE id_agent = id_agente AND REPLACE(description, " ", " ") LIKE "%%%s%%") OR tagente.id_agente = %d', $search, $search, @@ -591,10 +591,10 @@ if ($search != '') { $search_sql .= ')'; } else { $search_sql = sprintf( - ' AND ( nombre - LIKE "%%%s%%" OR alias - LIKE "%%%s%%" OR comentarios LIKE "%%%s%%" - OR EXISTS (SELECT * FROM tagent_custom_data WHERE id_agent = id_agente AND description LIKE "%%%s%%"))', + ' AND ( REPLACE(nombre, " ", " ") + LIKE "%%%s%%" OR REPLACE(alias, " ", " ") + LIKE "%%%s%%" OR REPLACE(comentarios, " ", " ") LIKE "%%%s%%" + OR EXISTS (SELECT * FROM tagent_custom_data WHERE id_agent = id_agente AND REPLACE(description, " ", " ") LIKE "%%%s%%"))', $search, $search, $search, diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 5c21fa71a0..60739b792a 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -574,7 +574,7 @@ $where = sprintf('delete_pending = 0 AND id_agente = %s', $id_agente); $search_string_entities = io_safe_input($search_string); $basic_where = sprintf( - "(nombre LIKE '%%%s%%' OR nombre LIKE '%%%s%%' OR descripcion LIKE '%%%s%%' OR descripcion LIKE '%%%s%%') AND", + "(REPLACE(nombre, ' ', ' ') LIKE '%%%s%%' OR REPLACE(nombre, ' ', ' ') LIKE '%%%s%%' OR REPLACE(descripcion, ' ', ' ') LIKE '%%%s%%' OR REPLACE(descripcion, ' ', ' ') LIKE '%%%s%%') AND", $search_string, $search_string_entities, $search_string, diff --git a/pandora_console/godmode/modules/manage_network_components.php b/pandora_console/godmode/modules/manage_network_components.php index 53318517d7..d1d5f5687f 100644 --- a/pandora_console/godmode/modules/manage_network_components.php +++ b/pandora_console/godmode/modules/manage_network_components.php @@ -729,7 +729,7 @@ if ($search_id_group) { } if ($search_string != '') { - $filter[] = '(name LIKE '."'%".$search_string."%'".'OR description LIKE '."'%".$search_string."%'".'OR tcp_send LIKE '."'%".$search_string."%'".'OR tcp_rcv LIKE '."'%".$search_string."%'".')'; + $filter[] = '(REPLACE(name, " ", " ") LIKE '."'%".$search_string."%'".' OR REPLACE(REPLACE(description, " ", " "), " ", " ")LIKE '."'%".$search_string."%'".' OR REPLACE(tcp_send, " ", " ") LIKE '."'%".$search_string."%'".'OR REPLACE(tcp_rcv, " ", " ") LIKE '."'%".$search_string."%'".')'; } $total_components = network_components_get_network_components( From f8f13227f87096a15c7fc431c64bf278079704e5 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Wed, 6 Sep 2023 10:28:44 +0200 Subject: [PATCH 4/4] #11537 Fix metaconsole inventory and hd traces --- pandora_console/include/class/ConfigPEN.class.php | 1 - pandora_console/include/functions_inventory.php | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pandora_console/include/class/ConfigPEN.class.php b/pandora_console/include/class/ConfigPEN.class.php index 4e4975e64d..6e2f7ec1f6 100644 --- a/pandora_console/include/class/ConfigPEN.class.php +++ b/pandora_console/include/class/ConfigPEN.class.php @@ -184,7 +184,6 @@ class ConfigPEN extends HTML return db_get_value_sql($sql); } - hd($sql, true); return db_get_all_rows_sql($sql); } diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index 0becb94fec..afa61c3811 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -77,8 +77,6 @@ function inventory_get_data( } if ($inventory_search_string != '') { - hd(1, true); - hd($inventory_search_string, true); array_push($where, "REPLACE(tagent_module_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'"); } @@ -748,8 +746,6 @@ function inventory_get_datatable( } if ($inventory_search_string != '') { - hd(2, true); - hd($inventory_search_string, true); array_push($where, "REPLACE(tagente_datos_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'"); } @@ -799,7 +795,13 @@ function inventory_get_datatable( $data_rows = explode(PHP_EOL, $row['data_inventory']); foreach ($data_rows as $data_key => $data_value) { - if (empty($data_value) === false && strpos(str_replace(' ', ' ', $data_value), $inventory_search_string)) { + if (empty($inventory_search_string) !== true) { + $search_check = strpos(str_replace(' ', ' ', $data_value), $inventory_search_string); + } else { + $search_check = true; + } + + if (empty($data_value) === false && $search_check !== false) { $row['data'] = $data_value; $modules[$row['name']][$row['name_agent'].'-'.$data_key.'-'.$data_value] = $row; } @@ -895,8 +897,6 @@ function get_data_basic_info_sql($params, $count=false) ' AND ( REPLACE(alias, " ", " ") LIKE "%%%s%%" )', $params['search'] ); - hd(3, true); - hd($params['search'], true); } if ($params['utimestamp'] > 0 && $count === false) {