From eadbb50695f8d0f7aeb5f2251d55a092a15a75c6 Mon Sep 17 00:00:00 2001 From: f0o Date: Sun, 4 Jan 2015 19:58:37 +0000 Subject: [PATCH 1/3] Added Package Search --- html/includes/print-menubar.php | 1 + html/pages/search.inc.php | 3 +- html/pages/search/packages.inc.php | 180 +++++++++++++++++++++++++++++ 3 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 html/pages/search/packages.inc.php diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 43090f2796..1bea0cbb0a 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -387,6 +387,7 @@ if ($packages) diff --git a/html/pages/search.inc.php b/html/pages/search.inc.php index 034196dae6..bd2918bf12 100644 --- a/html/pages/search.inc.php +++ b/html/pages/search.inc.php @@ -2,7 +2,7 @@ $pagetitle[] = "Search"; -$sections = array('ipv4' => 'IPv4 Address', 'ipv6' => 'IPv6 Address', 'mac' => 'MAC Address', 'arp' => 'ARP Table'); +$sections = array('packages' => 'Packages', 'ipv4' => 'IPv4 Address', 'ipv6' => 'IPv6 Address', 'mac' => 'MAC Address', 'arp' => 'ARP Table'); if (!isset($vars['search'])) { $vars['search'] = "ipv4"; } @@ -32,6 +32,7 @@ print_optionbar_end('', ''); switch ($vars['search']) { + case 'packages': case 'ipv4': case 'ipv6': case 'mac': diff --git a/html/pages/search/packages.inc.php b/html/pages/search/packages.inc.php new file mode 100644 index 0000000000..1daf09f6a1 --- /dev/null +++ b/html/pages/search/packages.inc.php @@ -0,0 +1,180 @@ + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + +/** + * Package Search + * @author Daniel Preussker + * @copyright 2014 f0o, LibreNMS + * @license GPL + * @package LibreNMS + * @subpackage Search + */ + +print_optionbar_start(28); +?> +
+
+ + +
+
+ + +
+
+ + +
+ +
+ 0) { + $results = $_POST['results']; +} else { + $results = 50; +} + +?> +
+ + + + + + + + + + + + +$entry ) { + $vers = array(); + $arch = array(); + $devs = array(); + foreach( $entry as $variation ) { + if( !in_array($variation['version'], $vers) && (empty($ver) || version_compare($variation['version'],$ver,$opt)) ) { + $vers[] = $variation['version']; + } + if( !in_array($variation['arch'], $arch) ) { + $arch[] = $variation['arch']; + } + if( !in_array($variation['hostname'], $devs) ) { + unset($variation['version']); + $devs[] = generate_device_link($variation); + } + } + if( sizeof($arch) > 0 && sizeof($vers) > 0 ) { + ?> + + + + + + + 0 && $count != $results ) { + ?> + + + + +
Packages
PackageVersionArchDevice
',$vers); ?>',$arch); ?>',$devs); ?>
+ + + + + +
+ From a5b643d251a767faf0fa155a0d9f0af969d43f80 Mon Sep 17 00:00:00 2001 From: f0o Date: Sun, 4 Jan 2015 20:42:59 +0000 Subject: [PATCH 2/3] Scrut fixes --- html/pages/search/packages.inc.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/html/pages/search/packages.inc.php b/html/pages/search/packages.inc.php index 1daf09f6a1..67f969b882 100644 --- a/html/pages/search/packages.inc.php +++ b/html/pages/search/packages.inc.php @@ -72,6 +72,9 @@ $count_query = "SELECT COUNT(*) FROM ( "; $full_query = ""; $query = 'SELECT packages.name FROM packages,devices WHERE packages.device_id = devices.device_id AND packages.name LIKE "%'.mres($_POST['package']).'%" GROUP BY packages.name'; $where = ''; +$param = array(); +$ver = ""; +$opt = ""; if( !empty($_POST['arch']) ) { $where .= ' AND packages.arch = ?'; From 75d37fe478f19054eff1c78503e75b9f4bf0f406 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 7 Jan 2015 09:22:39 +0000 Subject: [PATCH 3/3] Replace Packages-link in menubar with Packages-Search. Rewrote inclusion code in `html/pages/search.inc.php`. Added replacement for `:` character in versions to level out debian-version oddities. --- html/includes/print-menubar.php | 14 +++----------- html/pages/search.inc.php | 22 +++++++++------------- html/pages/search/packages.inc.php | 3 ++- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 1bea0cbb0a..207756afdb 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -378,18 +378,10 @@ if ($_SESSION['userlevel'] >= '5' && ($routing_count['bgp']+$routing_count['ospf - -
  • + Packages
  • 'Packages', 'ipv4' => 'IPv4 Address', 'ipv6' => 'IPv6 Address', 'mac' => 'MAC Address', 'arp' => 'ARP Table'); +$sections = array('ipv4' => 'IPv4 Address', 'ipv6' => 'IPv6 Address', 'mac' => 'MAC Address', 'arp' => 'ARP Table'); + +if( dbFetchCell("SELECT 1 from `packages` LIMIT 1") ) { + $sections['packages'] = 'Packages'; +} if (!isset($vars['search'])) { $vars['search'] = "ipv4"; } @@ -30,18 +34,10 @@ unset ($sep); print_optionbar_end('', ''); -switch ($vars['search']) -{ - case 'packages': - case 'ipv4': - case 'ipv6': - case 'mac': - case 'arp': - include('pages/search/'.$vars['search'].'.inc.php'); - break; - default: - echo(report_this('Unknown search type '.$vars['search'])); - break; +if( file_exists('pages/search/'.$vars['search'].'.inc.php') ) { + include('pages/search/'.$vars['search'].'.inc.php'); +} else { + echo(report_this('Unknown search type '.$vars['search'])); } ?> diff --git a/html/pages/search/packages.inc.php b/html/pages/search/packages.inc.php index 67f969b882..20b463d563 100644 --- a/html/pages/search/packages.inc.php +++ b/html/pages/search/packages.inc.php @@ -26,7 +26,7 @@ print_optionbar_start(28); ?>
    - +
    @@ -130,6 +130,7 @@ foreach( $ordered as $name=>$entry ) { $arch = array(); $devs = array(); foreach( $entry as $variation ) { + $variation['version'] = str_replace(":",".",$variation['version']); if( !in_array($variation['version'], $vers) && (empty($ver) || version_compare($variation['version'],$ver,$opt)) ) { $vers[] = $variation['version']; }