Added support for searching for arp entry

This commit is contained in:
laf
2016-06-27 14:48:07 +01:00
parent 692c29cbd8
commit 0b8f06efa3
3 changed files with 83 additions and 0 deletions

View File

@ -1323,3 +1323,37 @@ function list_ipsec() {
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
function list_arp() {
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$status = 'error';
$code = 404;
$message = '';
$ip = $router['ip'];
if (empty($ip)) {
$message = "No valid IP provided";
}
else {
$code = 200;
$status = 'ok';
if ($ip === "all") {
$hostname = mres($_GET['device']);
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
$arp = dbFetchRows("SELECT `ipv4_mac`.* FROM `ipv4_mac` LEFT JOIN `ports` ON `ipv4_mac`.`port_id` = `ports`.`port_id` WHERE `ports`.`device_id` = ?", array($device_id));
}
else {
$arp = dbFetchRows("SELECT * FROM `ipv4_mac` WHERE `ipv4_address`=?", array($ip));
}
$total = count($arp);
}
$output = array(
'status' => $status,
'err-msg' => $message,
'count' => $total,
'arp' => $arp,
);
$app->response->setStatus($code);
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}