Skip to content

Commit

Permalink
Add name resolution capabilites (with caching) for web interface
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <dl6er@dl6er.de>
  • Loading branch information
DL6ER committed Feb 25, 2018
1 parent 937a76b commit 02f14ce
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
28 changes: 4 additions & 24 deletions api_FTL.php
Expand Up @@ -155,14 +155,7 @@
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);
Expand All @@ -184,14 +177,7 @@
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);
Expand Down Expand Up @@ -240,6 +226,7 @@
foreach($return as $line)
{
$tmp = explode(" ",$line);
$tmp[3] = resolveHostname($tmp[3]);
array_push($allQueries,$tmp);
}

Expand Down Expand Up @@ -318,14 +305,7 @@
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);
Expand Down
26 changes: 26 additions & 0 deletions scripts/pi-hole/php/FTL.php
Expand Up @@ -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;
}
?>

1 comment on commit 02f14ce

@pralor-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Pi-hole Userspace. There might be relevant details there:

https://discourse.pi-hole.net/t/fedora-27-ftldns-upgrade-spinning-arrows-clients-over-time-chart-will-not-load/8300/14

Please sign in to comment.