mirror of
https://github.com/pi-hole/web.git
synced 2025-12-24 20:55:28 +00:00
Add name resolution capabilites (with caching) for web interface
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
28
api_FTL.php
28
api_FTL.php
@@ -155,14 +155,7 @@ if ((isset($_GET['topClients']) || isset($_GET['getQuerySources'])) && $auth)
|
||||
foreach($return as $line)
|
||||
{
|
||||
$tmp = explode(" ",$line);
|
||||
if(count($tmp) == 4)
|
||||
{
|
||||
$top_clients[$tmp[3]."|".$tmp[2]] = intval($tmp[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$top_clients[$tmp[2]] = intval($tmp[1]);
|
||||
}
|
||||
$top_clients[resolveHostname($tmp[2])] = intval($tmp[1]);
|
||||
}
|
||||
|
||||
$result = array('top_sources' => $top_clients);
|
||||
@@ -184,14 +177,7 @@ if (isset($_GET['getForwardDestinations']) && $auth)
|
||||
foreach($return as $line)
|
||||
{
|
||||
$tmp = explode(" ",$line);
|
||||
if(count($tmp) == 4)
|
||||
{
|
||||
$forward_dest[$tmp[3]."|".$tmp[2]] = floatval($tmp[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$forward_dest[$tmp[2]] = floatval($tmp[1]);
|
||||
}
|
||||
$forward_dest[resolveHostname($tmp[2])] = floatval($tmp[1]);
|
||||
}
|
||||
|
||||
$result = array('forward_destinations' => $forward_dest);
|
||||
@@ -240,6 +226,7 @@ if (isset($_GET['getAllQueries']) && $auth)
|
||||
foreach($return as $line)
|
||||
{
|
||||
$tmp = explode(" ",$line);
|
||||
$tmp[3] = resolveHostname($tmp[3]);
|
||||
array_push($allQueries,$tmp);
|
||||
}
|
||||
|
||||
@@ -318,14 +305,7 @@ if (isset($_GET['getClientNames']) && $auth)
|
||||
foreach($return as $line)
|
||||
{
|
||||
$tmp = explode(" ",$line);
|
||||
if(count($tmp) == 4)
|
||||
{
|
||||
$forward_dest[$tmp[3]."|".$tmp[2]] = floatval($tmp[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$forward_dest[$tmp[2]] = floatval($tmp[1]);
|
||||
}
|
||||
$forward_dest[resolveHostname($tmp[2])] = floatval($tmp[1]);
|
||||
}
|
||||
|
||||
$result = array('clients' => $forward_dest);
|
||||
|
||||
@@ -138,4 +138,30 @@ function disconnectFTL($quiet=true)
|
||||
echo "OK.\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
$clients = [];
|
||||
function resolveHostname($c)
|
||||
{
|
||||
if(array_key_exists($c, $clients))
|
||||
{
|
||||
// Entry already exists
|
||||
$c = $clients[$c];
|
||||
}
|
||||
else
|
||||
{
|
||||
if(filter_var($c, FILTER_VALIDATE_IP))
|
||||
{
|
||||
// Get host name of client and convert to lower case
|
||||
$c = strtolower(gethostbyaddr($c));
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is already a host name
|
||||
$c = strtolower($c);
|
||||
}
|
||||
// Buffer result
|
||||
$clients[$c] = $c;
|
||||
}
|
||||
return $c;
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user