From 2ece84495d75f7e73b32aabfd5890721b89ea639 Mon Sep 17 00:00:00 2001 From: Adam Winberg Date: Sat, 7 Apr 2018 21:14:28 +0200 Subject: [PATCH] webui: Improved fdb search (#8251) * sort fdb search by number of mac addresses/port to show most likely endpoint switchport first in list. Also add IP search to fdb search * fix style check error --- html/includes/table/fdb-search.inc.php | 35 +++++++++++++++++++++----- html/pages/search/fdb.inc.php | 10 +++++++- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/html/includes/table/fdb-search.inc.php b/html/includes/table/fdb-search.inc.php index 8c51ce76ff..d4e43e13ce 100644 --- a/html/includes/table/fdb-search.inc.php +++ b/html/includes/table/fdb-search.inc.php @@ -1,7 +1,7 @@ 4096) ) { @@ -49,16 +56,27 @@ if (isset($vars['searchPhrase']) && !empty($vars['searchPhrase'])) { $total = (int)dbFetchCell("SELECT COUNT(*) $sql $where", $param); -// Don't use ipv4_mac in count it will inflate the rows unless we aggregate it and it isn't used for search -$sql .= " LEFT JOIN `ipv4_mac` AS `M` USING (`mac_address`, `device_id`)"; +// Don't use ipv4_mac in count it will inflate the rows unless we aggregate it +// Except for 'ip' search. +if ($vars['searchby'] != 'ip') { + $sql .= " LEFT JOIN `ipv4_mac` AS `M` USING (`mac_address`)"; +} $sql .= $where; $sql .= " GROUP BY `device_id`, `port_id`, `mac_address`, `vlan`, `hostname`, `ifAlias`,"; $sql .= " `ifAdminStatus`, `ifDescr`, `ifOperStatus`, `ifInErrors`, `ifOutErrors`"; -if (!isset($sort) || empty($sort)) { - $sort = '`F`.`port_id` ASC'; +// Get most likely endpoint port_id, used to add a visual marker for this element +// in the list +if (isset($vars['searchby']) && !empty($vars['searchPhrase']) && $vars['searchby'] != 'vlan') { + $countsql .= " ORDER BY `C`.`portCount` ASC LIMIT 1"; + foreach (dbFetchRows($select . $sql . $countsql, $param) as $entry) { + $endpoint_portid = $entry['port_id']; + } } +if (!isset($sort) || empty($sort)) { + $sort = '`C`.`portCount` ASC'; +} $sql .= " ORDER BY $sort"; if (isset($current)) { @@ -83,12 +101,17 @@ foreach (dbFetchRows($select . $sql, $param) as $entry) { } else { $error_img = ''; } + if ($entry['port_id'] == $endpoint_portid) { + $endpoint_img = ""; + } else { + $endpoint_img = ''; + } $response[] = array( 'device' => generate_device_link(device_by_id_cache($entry['device_id'])), 'mac_address' => formatMac($entry['mac_address']), 'ipv4_address' => $entry['ipv4_address'], - 'interface' => generate_port_link($entry, makeshortif(fixifname($entry['label']))).' '.$error_img, + 'interface' => generate_port_link($entry, makeshortif(fixifname($entry['label']))).' '.$error_img.' '.$endpoint_img, 'vlan' => $entry['vlan'], ); }//end if diff --git a/html/pages/search/fdb.inc.php b/html/pages/search/fdb.inc.php index f35fc1d37c..3f07e96c1a 100644 --- a/html/pages/search/fdb.inc.php +++ b/html/pages/search/fdb.inc.php @@ -5,7 +5,7 @@ - + @@ -61,6 +61,14 @@ if ($_POST['searchby'] == 'mac') { ?> ">MAC Address"+ + ""+ "