Fixed arp api network query (#10085)

It was using a non-existent function

DO NOT DELETE THIS TEXT

#### Please note

> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.

- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)

#### Testers

If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
After you are done testing, you can remove the changes with `./scripts/github-remove`.  If there are schema changes, you can ask on discord how to revert.
This commit is contained in:
Tony Murray
2019-04-10 16:33:25 -05:00
committed by Neil Lathwood
parent 54c7ed3d0d
commit 8926d7cfe6

View File

@@ -15,6 +15,8 @@
use LibreNMS\Alerting\QueryBuilderParser;
use LibreNMS\Authentication\LegacyAuth;
use LibreNMS\Config;
use LibreNMS\Exceptions\InvalidIpException;
use LibreNMS\Util\IPv4;
function authToken(\Slim\Route $route)
{
@@ -2137,7 +2139,7 @@ function list_arp()
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$ip = $router['ip'];
$hostname = mres($_GET['device']);
$hostname = $_GET['device'];
$total = 0;
if (empty($ip)) {
api_error(400, "No valid IP provided");
@@ -2147,15 +2149,19 @@ function list_arp()
if ($ip === "all") {
$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));
$arp = dbFetchRows("SELECT `ipv4_mac`.* FROM `ipv4_mac` LEFT JOIN `ports` ON `ipv4_mac`.`port_id` = `ports`.`port_id` WHERE `ports`.`device_id` = ?", [$device_id]);
} elseif (str_contains($ip, '/')) {
list($net, $cidr) = explode('/', $ip, 2);
$arp = dbFetchRows(
'SELECT * FROM `ipv4_mac` WHERE (inet_aton(`ipv4_address`) & ?) = ?',
array(cidr2long($cidr), ip2long($net))
);
try {
$ip = new IPv4($ip);
$arp = dbFetchRows(
'SELECT * FROM `ipv4_mac` WHERE (inet_aton(`ipv4_address`) & ?) = ?',
[ip2long($ip->getNetmask()), ip2long($ip->getNetworkAddress())]
);
} catch (InvalidIpException $e) {
api_error(400, "Invalid Network Address");
}
} else {
$arp = dbFetchRows("SELECT * FROM `ipv4_mac` WHERE `ipv4_address`=?", array($ip));
$arp = dbFetchRows("SELECT * FROM `ipv4_mac` WHERE `ipv4_address`=?", [$ip]);
}
api_success($arp, 'arp');
}