From f319ec6cfa137107bd3cbb825a6814aa43523cea Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 6 Sep 2016 09:08:12 +0100 Subject: [PATCH] Suppress `pi.hole` and hostname pulled from `/etc/hostname` from the stats, as they're not really ads. --- data.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/data.php b/data.php index 1082a254..47621964 100644 --- a/data.php +++ b/data.php @@ -122,6 +122,7 @@ $allQueries = array("data" => array()); $log = readInLog(); $dns_queries = getDnsQueriesAll($log); + $hostname = trim(file_get_contents("/etc/hostname"), "\x00..\x1F"); foreach ($dns_queries as $query) { $time = date_create(substr($query, 0, 16)); @@ -134,7 +135,7 @@ $client = $exploded[count($exploded)-1]; $status = ""; } - elseif (substr($tmp, 0, 9) == "forwarded" ){ + elseif (substr($tmp, 0, 9) == "forwarded" || $exploded[count($exploded)-3] == "pi.hole" || $exploded[count($exploded)-3] == $hostname){ $status="OK"; } elseif (substr($tmp, strlen($tmp) - 12, 12) == "gravity.list" && $exploded[count($exploded)-5] != "read"){ @@ -267,8 +268,11 @@ $exploded = explode(" ", $var); $tmp = $exploded[count($exploded)-4]; $tmp2 = $exploded[count($exploded)-5]; + $tmp3 = $exploded[count($exploded) -3]; + $hostname = trim(file_get_contents("/etc/hostname"), "\x00..\x1F"); + //filter out bad names and host file reloads: - return (substr($tmp, strlen($tmp) - 12, 12) == "gravity.list" && $tmp2 != "read") ; + return (substr($tmp, strlen($tmp) - 12, 12) == "gravity.list" && $tmp2 != "read" && $tmp3 != "pi.hole" && $tmp3 != $hostname) ; } function findForwards($var) {