Fix ARP search on all ARP pages. Adapt ARP search page to use a common search variable.

This commit is contained in:
Tony Murray
2015-12-24 12:09:01 -06:00
parent fe86b998bf
commit 6f84a287b6
2 changed files with 22 additions and 12 deletions

View File

@@ -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);

View File

@@ -71,9 +71,9 @@ if ($_POST['searchby'] == 'ip') {
"</select>"+
"</div>"+
"<div class=\"form-group\">"+
"<input type=\"text\" name=\"address\" id=\"address\" value=\""+
"<input type=\"text\" name=\"searchPhrase\" id=\"address\" value=\""+
<?php
echo '"'.$_POST['address'].'"+';
echo '"'.$_POST['searchPhrase'].'"+';
?>
"\" class=\"form-control input-sm\" placeholder=\"Address\" />"+
@@ -88,7 +88,7 @@ echo '"'.$_POST['address'].'"+';
id: "arp-search",
device_id: '<?php echo htmlspecialchars($_POST['device_id']); ?>',
searchby: '<?php echo mres($_POST['searchby']); ?>',
address: '<?php echo mres($_POST['address']); ?>'
searchPhrase: '<?php echo mres($_POST['searchPhrase']); ?>'
};
},
url: "ajax_table.php"