From f4d5e21daba405d17ef9a170c38b64a726aeb5f3 Mon Sep 17 00:00:00 2001 From: Rosiak Date: Mon, 8 Feb 2016 22:15:24 +0100 Subject: [PATCH 1/4] Make Global Search Limit Configurable #2557 --- html/ajax_search.php | 29 +++++++++++++++-------------- includes/defaults.inc.php | 4 ++++ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/html/ajax_search.php b/html/ajax_search.php index cb8d012a3..77a65190c 100644 --- a/html/ajax_search.php +++ b/html/ajax_search.php @@ -16,6 +16,7 @@ if (!$_SESSION['authenticated']) { $device = array(); $ports = array(); $bgp = array(); +$limit = $config['global_search_result_limit']; if (isset($_REQUEST['search'])) { $search = mres($_REQUEST['search']); @@ -49,10 +50,10 @@ if (isset($_REQUEST['search'])) { else if ($_REQUEST['type'] == 'device') { // Device search if (is_admin() === true || is_read() === true) { - $results = dbFetchRows("SELECT * FROM `devices` WHERE `hostname` LIKE '%".$search."%' OR `location` LIKE '%".$search."%' ORDER BY hostname LIMIT 8"); + $results = dbFetchRows("SELECT * FROM `devices` WHERE `hostname` LIKE '%".$search."%' OR `location` LIKE '%".$search."%' ORDER BY hostname LIMIT ".$limit); } else { - $results = dbFetchRows("SELECT * FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` AND (`hostname` LIKE '%".$search."%' OR `location` LIKE '%".$search."%') ORDER BY hostname LIMIT 8", array($_SESSION['user_id'])); + $results = dbFetchRows("SELECT * FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` AND (`hostname` LIKE '%".$search."%' OR `location` LIKE '%".$search."%') ORDER BY hostname LIMIT ".$limit, array($_SESSION['user_id'])); } if (count($results)) { @@ -102,10 +103,10 @@ if (isset($_REQUEST['search'])) { else if ($_REQUEST['type'] == 'ports') { // Search ports if (is_admin() === true || is_read() === true) { - $results = dbFetchRows("SELECT `ports`.*,`devices`.* FROM `ports` LEFT JOIN `devices` ON `ports`.`device_id` = `devices`.`device_id` WHERE `ifAlias` LIKE '%".$search."%' OR `ifDescr` LIKE '%".$search."%' OR `ifName` LIKE '%".$search."%' ORDER BY ifDescr LIMIT 8"); + $results = dbFetchRows("SELECT `ports`.*,`devices`.* FROM `ports` LEFT JOIN `devices` ON `ports`.`device_id` = `devices`.`device_id` WHERE `ifAlias` LIKE '%".$search."%' OR `ifDescr` LIKE '%".$search."%' OR `ifName` LIKE '%".$search."%' ORDER BY ifDescr LIMIT ".$limit); } else { - $results = dbFetchRows("SELECT DISTINCT(`I`.`port_id`), `I`.*, `D`.`hostname` FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P`, `ports_perms` AS `PP` WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `D`.`device_id`)) AND `D`.`device_id` = `I`.`device_id` AND (`ifAlias` LIKE '%".$search."%' OR `ifDescr` LIKE '%".$search."%' OR `ifName` LIKE '%".$search."%') ORDER BY ifDescr LIMIT 8", array($_SESSION['user_id'], $_SESSION['user_id'])); + $results = dbFetchRows("SELECT DISTINCT(`I`.`port_id`), `I`.*, `D`.`hostname` FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P`, `ports_perms` AS `PP` WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `D`.`device_id`)) AND `D`.`device_id` = `I`.`device_id` AND (`ifAlias` LIKE '%".$search."%' OR `ifDescr` LIKE '%".$search."%' OR `ifName` LIKE '%".$search."%') ORDER BY ifDescr LIMIT ".$limit, array($_SESSION['user_id'], $_SESSION['user_id'])); } if (count($results)) { @@ -154,10 +155,10 @@ if (isset($_REQUEST['search'])) { else if ($_REQUEST['type'] == 'bgp') { // Search bgp peers if (is_admin() === true || is_read() === true) { - $results = dbFetchRows("SELECT `bgpPeers`.*,`devices`.* FROM `bgpPeers` LEFT JOIN `devices` ON `bgpPeers`.`device_id` = `devices`.`device_id` WHERE `astext` LIKE '%".$search."%' OR `bgpPeerIdentifier` LIKE '%".$search."%' OR `bgpPeerRemoteAs` LIKE '%".$search."%' ORDER BY `astext` LIMIT 8"); + $results = dbFetchRows("SELECT `bgpPeers`.*,`devices`.* FROM `bgpPeers` LEFT JOIN `devices` ON `bgpPeers`.`device_id` = `devices`.`device_id` WHERE `astext` LIKE '%".$search."%' OR `bgpPeerIdentifier` LIKE '%".$search."%' OR `bgpPeerRemoteAs` LIKE '%".$search."%' ORDER BY `astext` LIMIT ".$limit); } else { - $results = dbFetchRows("SELECT `bgpPeers`.*,`D`.* FROM `bgpPeers`, `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` AND `bgpPeers`.`device_id`=`D`.`device_id` AND (`astext` LIKE '%".$search."%' OR `bgpPeerIdentifier` LIKE '%".$search."%' OR `bgpPeerRemoteAs` LIKE '%".$search."%') ORDER BY `astext` LIMIT 8", array($_SESSION['user_id'])); + $results = dbFetchRows("SELECT `bgpPeers`.*,`D`.* FROM `bgpPeers`, `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` AND `bgpPeers`.`device_id`=`D`.`device_id` AND (`astext` LIKE '%".$search."%' OR `bgpPeerIdentifier` LIKE '%".$search."%' OR `bgpPeerRemoteAs` LIKE '%".$search."%') ORDER BY `astext` LIMIT ".$limit, array($_SESSION['user_id'])); } if (count($results)) { @@ -209,10 +210,10 @@ if (isset($_REQUEST['search'])) { else if ($_REQUEST['type'] == 'applications') { // Device search if (is_admin() === true || is_read() === true) { - $results = dbFetchRows("SELECT * FROM `applications` INNER JOIN `devices` ON devices.device_id = applications.device_id WHERE `app_type` LIKE '%".$search."%' OR `hostname` LIKE '%".$search."%' ORDER BY hostname LIMIT 8"); + $results = dbFetchRows("SELECT * FROM `applications` INNER JOIN `devices` ON devices.device_id = applications.device_id WHERE `app_type` LIKE '%".$search."%' OR `hostname` LIKE '%".$search."%' ORDER BY hostname LIMIT ".$limit); } else { - $results = dbFetchRows("SELECT * FROM `applications` INNER JOIN `devices` AS `D` ON `D`.`device_id` = `applications`.`device_id` INNER JOIN `devices_perms` AS `P` ON `P`.`device_id` = `D`.`device_id` WHERE `P`.`user_id` = ? AND (`app_type` LIKE '%".$search."%' OR `hostname` LIKE '%".$search."%') ORDER BY hostname LIMIT 8", array($_SESSION['user_id'])); + $results = dbFetchRows("SELECT * FROM `applications` INNER JOIN `devices` AS `D` ON `D`.`device_id` = `applications`.`device_id` INNER JOIN `devices_perms` AS `P` ON `P`.`device_id` = `D`.`device_id` WHERE `P`.`user_id` = ? AND (`app_type` LIKE '%".$search."%' OR `hostname` LIKE '%".$search."%') ORDER BY hostname LIMIT ".$limit, array($_SESSION['user_id'])); } if (count($results)) { @@ -255,10 +256,10 @@ if (isset($_REQUEST['search'])) { else if ($_REQUEST['type'] == 'munin') { // Device search if (is_admin() === true || is_read() === true) { - $results = dbFetchRows("SELECT * FROM `munin_plugins` INNER JOIN `devices` ON devices.device_id = munin_plugins.device_id WHERE `mplug_type` LIKE '%".$search."%' OR `mplug_title` LIKE '%".$search."%' OR `hostname` LIKE '%".$search."%' ORDER BY hostname LIMIT 8"); + $results = dbFetchRows("SELECT * FROM `munin_plugins` INNER JOIN `devices` ON devices.device_id = munin_plugins.device_id WHERE `mplug_type` LIKE '%".$search."%' OR `mplug_title` LIKE '%".$search."%' OR `hostname` LIKE '%".$search."%' ORDER BY hostname LIMIT ".$limit); } else { - $results = dbFetchRows("SELECT * FROM `munin_plugins` INNER JOIN `devices` AS `D` ON `D`.`device_id` = `munin_plugins`.`device_id` INNER JOIN `devices_perms` AS `P` ON `P`.`device_id` = `D`.`device_id` WHERE `P`.`user_id` = ? AND (`mplug_type` LIKE '%".$search."%' OR `mplug_title` LIKE '%".$search."%' OR `hostname` LIKE '%".$search."%') ORDER BY hostname LIMIT 8", array($_SESSION['user_id'])); + $results = dbFetchRows("SELECT * FROM `munin_plugins` INNER JOIN `devices` AS `D` ON `D`.`device_id` = `munin_plugins`.`device_id` INNER JOIN `devices_perms` AS `P` ON `P`.`device_id` = `D`.`device_id` WHERE `P`.`user_id` = ? AND (`mplug_type` LIKE '%".$search."%' OR `mplug_title` LIKE '%".$search."%' OR `hostname` LIKE '%".$search."%') ORDER BY hostname LIMIT ".$limit, array($_SESSION['user_id'])); } if (count($results)) { @@ -301,10 +302,10 @@ if (isset($_REQUEST['search'])) { else if ($_REQUEST['type'] == 'iftype') { // Device search if (is_admin() === true || is_read() === true) { - $results = dbFetchRows("SELECT `ports`.ifType FROM `ports` WHERE `ifType` LIKE '%".$search."%' GROUP BY ifType ORDER BY ifType LIMIT 8"); + $results = dbFetchRows("SELECT `ports`.ifType FROM `ports` WHERE `ifType` LIKE '%".$search."%' GROUP BY ifType ORDER BY ifType LIMIT ".$limit); } else { - $results = dbFetchRows("SELECT `I`.ifType FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P`, `ports_perms` AS `PP` WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `D`.`device_id`)) AND `D`.`device_id` = `I`.`device_id` AND (`ifType` LIKE '%".$search."%') GROUP BY ifType ORDER BY ifType LIMIT 8", array($_SESSION['user_id'], $_SESSION['user_id'])); + $results = dbFetchRows("SELECT `I`.ifType FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P`, `ports_perms` AS `PP` WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `D`.`device_id`)) AND `D`.`device_id` = `I`.`device_id` AND (`ifType` LIKE '%".$search."%') GROUP BY ifType ORDER BY ifType LIMIT ".$limit, array($_SESSION['user_id'], $_SESSION['user_id'])); } if (count($results)) { $found = 1; @@ -323,10 +324,10 @@ if (isset($_REQUEST['search'])) { else if ($_REQUEST['type'] == 'bill') { // Device search if (is_admin() === true || is_read() === true) { - $results = dbFetchRows("SELECT `bills`.bill_id, `bills`.bill_name FROM `bills` WHERE `bill_name` LIKE '%".$search."%' OR `bill_notes` LIKE '%".$search."%' LIMIT 8"); + $results = dbFetchRows("SELECT `bills`.bill_id, `bills`.bill_name FROM `bills` WHERE `bill_name` LIKE '%".$search."%' OR `bill_notes` LIKE '%".$search."%' LIMIT ".$limit); } else { - $results = dbFetchRows("SELECT `bills`.bill_id, `bills`.bill_name FROM `bills` INNER JOIN `bill_perms` ON `bills`.bill_id = `bill_perms`.bill_id WHERE `bill_perms`.user_id = ? AND (`bill_name` LIKE '%".$search."%' OR `bill_notes` LIKE '%".$search."%') LIMIT 8", array($_SESSION['user_id'])); + $results = dbFetchRows("SELECT `bills`.bill_id, `bills`.bill_name FROM `bills` INNER JOIN `bill_perms` ON `bills`.bill_id = `bill_perms`.bill_id WHERE `bill_perms`.user_id = ? AND (`bill_name` LIKE '%".$search."%' OR `bill_notes` LIKE '%".$search."%') LIMIT ".$limit, array($_SESSION['user_id'])); } $json = json_encode($results); die($json); diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index bed0b577d..b4c2730d1 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -861,3 +861,7 @@ $config['default_port_association_mode'] = 'ifIndex'; // Ignore ports which can't be mapped using a devices port_association_mode // See include/polling/ports.inc.php for a lenghty explanation. $config['ignore_unmapable_port'] = False; + +// Default Global Search result limit +$config['global_search_result_limit'] = 8; + From 1c630b0b8d372af4e74ff406aa73261b80bf3b10 Mon Sep 17 00:00:00 2001 From: Rosiak Date: Sat, 13 Feb 2016 21:09:45 +0100 Subject: [PATCH 2/4] Move function to WebUI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on Neil’s suggestion. --- html/ajax_search.php | 2 +- html/pages/settings/webui.inc.php | 24 ++++++++++++++++++++++++ includes/defaults.inc.php | 3 --- sql-schema/103.sql | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 html/pages/settings/webui.inc.php create mode 100644 sql-schema/103.sql diff --git a/html/ajax_search.php b/html/ajax_search.php index 77a65190c..ba9dc79b7 100644 --- a/html/ajax_search.php +++ b/html/ajax_search.php @@ -16,7 +16,7 @@ if (!$_SESSION['authenticated']) { $device = array(); $ports = array(); $bgp = array(); -$limit = $config['global_search_result_limit']; +$limit = $config['webui']['global_search_result_limit']; if (isset($_REQUEST['search'])) { $search = mres($_REQUEST['search']); diff --git a/html/pages/settings/webui.inc.php b/html/pages/settings/webui.inc.php new file mode 100644 index 000000000..a5b6bf7f2 --- /dev/null +++ b/html/pages/settings/webui.inc.php @@ -0,0 +1,24 @@ + 'webui.global_search_result_limit', + 'descr' => 'Set the max search result limit', + 'type' => 'text', + ), +); + +echo ' +
+
+'; + +echo generate_dynamic_config_panel('Search settings',true,$config_groups,$search_conf); + +echo ' +
+
+'; diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index b4c2730d1..3eefe80a7 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -862,6 +862,3 @@ $config['default_port_association_mode'] = 'ifIndex'; // See include/polling/ports.inc.php for a lenghty explanation. $config['ignore_unmapable_port'] = False; -// Default Global Search result limit -$config['global_search_result_limit'] = 8; - diff --git a/sql-schema/103.sql b/sql-schema/103.sql new file mode 100644 index 000000000..c1f56b5f6 --- /dev/null +++ b/sql-schema/103.sql @@ -0,0 +1 @@ +INSERT INTO `config` (`config_name`,`config_value`,`config_default`,`config_descr`,`config_group`,`config_group_order`,`config_sub_group`,`config_sub_group_order`,`config_hidden`,`config_disabled`) VALUES ('webui.global_search_result_limit','8','8','Global search results limit','webui',0,'search',0,'1','0'); From fd3c7f4fa73e8232767cb38aee528b5a01f3dddf Mon Sep 17 00:00:00 2001 From: Rosiak Date: Sun, 14 Feb 2016 22:47:22 +0100 Subject: [PATCH 3/4] Remove space --- includes/defaults.inc.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 3eefe80a7..bed0b577d 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -861,4 +861,3 @@ $config['default_port_association_mode'] = 'ifIndex'; // Ignore ports which can't be mapped using a devices port_association_mode // See include/polling/ports.inc.php for a lenghty explanation. $config['ignore_unmapable_port'] = False; - From b7d2a27be41a4aa8175e7ea4d518dd16fb8718ee Mon Sep 17 00:00:00 2001 From: Rosiak Date: Sat, 20 Feb 2016 11:06:12 +0100 Subject: [PATCH 4/4] Move schema --- sql-schema/{103.sql => 102.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sql-schema/{103.sql => 102.sql} (100%) diff --git a/sql-schema/103.sql b/sql-schema/102.sql similarity index 100% rename from sql-schema/103.sql rename to sql-schema/102.sql