Revize 8f55a2a5
Přidáno uživatelem Michal Kliment před více než 9 roky(ů)
application/controllers/json.php | ||
---|---|---|
|
||
if ($gateway && $gateway->id && valid::ip($ip_address))
|
||
{
|
||
// first try SNMP
|
||
if (module::e('snmp'))
|
||
$mac_address = '';
|
||
|
||
// first try CGI scripts
|
||
if (module::e('cgi'))
|
||
{
|
||
$vars = arr::to_object(array
|
||
(
|
||
'GATEWAY_IP_ADDRESS' => $gateway->ip_address,
|
||
'IP_ADDRESS' => $ip_address
|
||
));
|
||
|
||
$url = text::object_format($vars, Settings::get('cgi_arp_url'));
|
||
|
||
$mac_address = trim(@file_get_contents($url));
|
||
}
|
||
|
||
// now try SNMP
|
||
if (!valid::mac_address($mac_address) && module::e('snmp'))
|
||
{
|
||
try
|
||
{
|
||
... | ... | |
|
||
// try find MAC address in DHCP
|
||
$mac_address = $snmp->getDHCPMacAddressOf($ip_address);
|
||
|
||
die(json_encode(array
|
||
(
|
||
'state' => 1,
|
||
'mac' => $mac_address
|
||
)));
|
||
}
|
||
// MAC table is not in DHCP
|
||
catch (DHCPMacAddressException $e)
|
||
... | ... | |
{
|
||
// try find MAC address in ARP table
|
||
$mac_address = $snmp->getARPMacAddressOf($ip_address);
|
||
|
||
die(json_encode(array
|
||
(
|
||
'state' => 1,
|
||
'mac' => $mac_address
|
||
)));
|
||
}
|
||
catch(Exception $e)
|
||
{
|
||
Log::add_exception($e);
|
||
die(json_encode(array
|
||
(
|
||
'state' => 0,
|
||
'message' => $e->getMessage()
|
||
)));
|
||
}
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
Log::add_exception($e);
|
||
die(json_encode(array
|
||
(
|
||
'state' => 0,
|
||
'message' => $e->getMessage()
|
||
)));
|
||
}
|
||
}
|
||
// now try CGI scripts
|
||
else if (module::e('cgi'))
|
||
{
|
||
$vars = arr::to_object(array
|
||
|
||
if (valid::mac_address($mac_address))
|
||
{
|
||
die(json_encode(array
|
||
(
|
||
'GATEWAY_IP_ADDRESS' => $gateway->ip_address,
|
||
'IP_ADDRESS' => $ip_address
|
||
));
|
||
|
||
$url = text::object_format($vars, Settings::get('cgi_arp_url'));
|
||
|
||
$mac_address = @file_get_contents($url);
|
||
|
||
if ($mac_address !== FALSE)
|
||
{
|
||
die(json_encode(array
|
||
(
|
||
'state' => 1,
|
||
'mac' => $mac_address
|
||
)));
|
||
}
|
||
else
|
||
{
|
||
die(json_encode(array
|
||
(
|
||
'state' => 0,
|
||
'message' => __('Invalid output data')
|
||
)));
|
||
}
|
||
'state' => 1,
|
||
'mac' => $mac_address
|
||
)));
|
||
}
|
||
else
|
||
{
|
||
die(json_encode(array
|
||
(
|
||
'state' => 0,
|
||
'message' => __('SNMP or CGI scripts not enabled')
|
||
'message' => __('MAC not found')
|
||
)));
|
||
}
|
||
}
|
Také k dispozici: Unified diff
Release 1.1.6