From f14b4747c7e6f9706f3ebd007616b5813cf8c6b3 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 15 Dec 2016 18:10:18 +0100 Subject: [PATCH 01/63] Try to resolve local IPs to hostnames if API_GET_CLIENT_HOSTNAME is true --- data.php | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/data.php b/data.php index 333907c0..b23b16ee 100644 --- a/data.php +++ b/data.php @@ -111,13 +111,27 @@ } + // Check for existance of variable + // and test it only if it exists + function istrue($argument) { + $ret = false; + if(isset($argument)) + { + if($argument) + { + $ret = true; + } + } + return $ret; + } + function getQuerySources() { global $log; $dns_queries = getDnsQueries($log); $sources = array(); foreach($dns_queries as $query) { $exploded = explode(" ", $query); - $ip = hasHostName(trim($exploded[count($exploded)-1])); + $ip = trim($exploded[count($exploded)-1]); if (isset($sources[$ip])) { $sources[$ip]++; } @@ -134,6 +148,25 @@ arsort($sources); $sources = array_slice($sources, 0, 10); + + if(istrue($setupVars["API_GET_CLIENT_HOSTNAME"])) + { + foreach ($sources as $key => $value) + { + $hostname = gethostbyaddr($key); + // If we found a hostname for the IP, replace it + if($hostname) + { + // Generate HOST entry + $sources[$hostname] = $sources[$key]; + // Remove IP entry + unset($sources[$key]); + } + } + // Have to repeat the sorting, since we changed the keys + arsort($sources); + } + return Array( 'top_sources' => $sources ); From 90bc298b9c8a5470df23a184ae1c2ddbd6573b8a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 15 Dec 2016 18:27:49 +0100 Subject: [PATCH 02/63] Implemented function resolveIPs(&$array) --- data.php | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/data.php b/data.php index b23b16ee..6ca94845 100644 --- a/data.php +++ b/data.php @@ -92,6 +92,23 @@ return $queryTypes; } + function resolveIPs(&$array) { + foreach ($array as $key => $value) + { + $hostname = gethostbyaddr($key); + // If we found a hostname for the IP, replace it + if($hostname) + { + // Generate HOST entry + $array[$hostname] = $array[$key]; + // Remove IP entry + unset($array[$key]); + } + } + // Have to repeat the sorting, since we changed the keys + arsort($array); + } + function getForwardDestinations() { global $log; $forwards = getForwards($log); @@ -151,20 +168,7 @@ if(istrue($setupVars["API_GET_CLIENT_HOSTNAME"])) { - foreach ($sources as $key => $value) - { - $hostname = gethostbyaddr($key); - // If we found a hostname for the IP, replace it - if($hostname) - { - // Generate HOST entry - $sources[$hostname] = $sources[$key]; - // Remove IP entry - unset($sources[$key]); - } - } - // Have to repeat the sorting, since we changed the keys - arsort($sources); + resolveIPs($sources); } return Array( From 433b3c634f30e476aa1744e1fff3e674ae4d20f1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 15 Dec 2016 18:28:16 +0100 Subject: [PATCH 03/63] Improved function getForwardDestinations() --- data.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data.php b/data.php index 6ca94845..9be2af33 100644 --- a/data.php +++ b/data.php @@ -115,7 +115,7 @@ $destinations = array(); foreach ($forwards as $forward) { $exploded = explode(" ", trim($forward)); - $dest = hasHostName($exploded[count($exploded) - 1]); + $dest = $exploded[count($exploded) - 1]; if (isset($destinations[$dest])) { $destinations[$dest]++; } @@ -124,6 +124,8 @@ } } + resolveIPs($destinations); + return $destinations; } From b6adeb50a8ceeed9afdef49100577ab2bbf291cd Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 15 Dec 2016 18:32:01 +0100 Subject: [PATCH 04/63] Add API_GET_UPSTREAM_DNS_HOSTNAME option --- data.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/data.php b/data.php index 9be2af33..70eaed82 100644 --- a/data.php +++ b/data.php @@ -124,7 +124,10 @@ } } - resolveIPs($destinations); + if(istrue($setupVars["API_GET_UPSTREAM_DNS_HOSTNAME"])) + { + resolveIPs($destinations); + } return $destinations; From cc7b03d3e74cccb172ff2477d14082fb961958d3 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 15 Dec 2016 18:48:24 +0100 Subject: [PATCH 05/63] Implemented the corresponding Settings part --- php/savesettings.php | 32 ++++++++++++++++++++++++++++++++ settings.php | 43 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/php/savesettings.php b/php/savesettings.php index 7460305c..87459ccd 100644 --- a/php/savesettings.php +++ b/php/savesettings.php @@ -9,6 +9,20 @@ function validIP($address){ return !filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false; } +// Check for existance of variable +// and test it only if it exists +function istrue($argument) { + $ret = false; + if(isset($argument)) + { + if($argument) + { + $ret = true; + } + } + return $ret; +} + // Credit: http://stackoverflow.com/a/4694816/2087442 function validDomain($domain_name) { @@ -208,6 +222,24 @@ function validDomain($domain_name) $success .= "No entries will be shown in Query Log"; } + if(isset($_POST["resolve-forward"])) + { + exec("sudo pihole -a resolve forward true"); + } + else + { + exec("sudo pihole -a resolve forward false"); + } + + if(isset($_POST["resolve-clients"])) + { + exec("sudo pihole -a resolve clients true"); + } + else + { + exec("sudo pihole -a resolve clients false"); + } + break; case "webUI": diff --git a/settings.php b/settings.php index 2743bc71..dd2fdfdc 100644 --- a/settings.php +++ b/settings.php @@ -379,6 +379,25 @@ } else { $queryLog = "all"; } + + if(istrue($setupVars["API_GET_UPSTREAM_DNS_HOSTNAME"])) + { + $resolveForward = true; + } + else + { + $resolveForward = false; + } + + if(istrue($setupVars["API_GET_CLIENT_HOSTNAME"])) + { + $resolveClients = true; + } + else + { + $resolveClients = false; + } + ?>
@@ -400,10 +419,28 @@
+

Reverse DNS lookup

+

Try to determine the domain name via querying the Pi-hole for

+
+
+
+
+
+
+
+
+
+

Query Log

-
-
-
+
+
+
+
+
+
+
+
+