From 6f84a287b6602c6b07cda10fe6c9209c07a40df9 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Thu, 24 Dec 2015 12:09:01 -0600 Subject: [PATCH] Fix ARP search on all ARP pages. Adapt ARP search page to use a common search variable. --- html/includes/table/arp-search.inc.php | 28 +++++++++++++++++--------- html/pages/search/arp.inc.php | 6 +++--- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/html/includes/table/arp-search.inc.php b/html/includes/table/arp-search.inc.php index b595029c0c..0e1484c760 100644 --- a/html/includes/table/arp-search.inc.php +++ b/html/includes/table/arp-search.inc.php @@ -12,15 +12,6 @@ if (is_admin() === false && is_read() === false) { $sql .= " WHERE M.port_id = P.port_id AND P.device_id = D.device_id $where "; -if (isset($_POST['searchby']) && $_POST['searchby'] == 'ip') { - $sql .= ' AND `ipv4_address` LIKE ?'; - $param[] = '%'.trim($_POST['address']).'%'; -} -else if (isset($_POST['searchby']) && $_POST['searchby'] == 'mac') { - $sql .= ' AND `mac_address` LIKE ?'; - $param[] = '%'.str_replace(array(':', ' ', '-', '.', '0x'), '', mres($_POST['address'])).'%'; -} - if (is_numeric($_POST['device_id'])) { $sql .= ' AND P.device_id = ?'; $param[] = $_POST['device_id']; @@ -31,6 +22,25 @@ if (is_numeric($_POST['port_id'])) { $param[] = $_POST['port_id']; } +if (isset($_POST['searchPhrase']) && !empty($_POST['searchPhrase'])) { + $ip_search = '%'.mres(trim($_POST['searchPhrase'])).'%'; + $mac_search = '%'.str_replace(array(':', ' ', '-', '.', '0x'), '', mres($_POST['searchPhrase'])).'%'; + + if (isset($_POST['searchby']) && $_POST['searchby'] == 'ip') { + $sql .= ' AND `ipv4_address` LIKE ?'; + $param[] = $ip_search; + } + else if (isset($_POST['searchby']) && $_POST['searchby'] == 'mac') { + $sql .= ' AND `mac_address` LIKE ?'; + $param[] = $mac_search; + } + else { + $sql .= ' AND (`ipv4_address` LIKE ? OR `mac_address` LIKE ?)'; + $param[] = $ip_search; + $param[] = $mac_search; + } +} + $count_sql = "SELECT COUNT(`M`.`port_id`) $sql"; $total = dbFetchCell($count_sql, $param); diff --git a/html/pages/search/arp.inc.php b/html/pages/search/arp.inc.php index 9f2ed062fa..f6c6492d6b 100644 --- a/html/pages/search/arp.inc.php +++ b/html/pages/search/arp.inc.php @@ -71,9 +71,9 @@ if ($_POST['searchby'] == 'ip') { ""+ ""+ "
"+ - " "\" class=\"form-control input-sm\" placeholder=\"Address\" />"+ @@ -88,7 +88,7 @@ echo '"'.$_POST['address'].'"+'; id: "arp-search", device_id: '', searchby: '', - address: '' + searchPhrase: '' }; }, url: "ajax_table.php"