diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 80203764..047c8b05 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -8,4 +8,4 @@ Changes proposed in this pull request: - -@pihole/dashboard +@pi-hole/dashboard diff --git a/api.php b/api.php index ea74ca5f..85b282ea 100644 --- a/api.php +++ b/api.php @@ -47,6 +47,18 @@ $data = array_merge($data, getAllQueries()); } - + function filterArray(&$a) { + $sanArray = array(); + foreach ($a as $k=>$v) { + if (is_array($v)) { + $sanArray[htmlspecialchars($k)] = filterArray($v); + } else { + $sanArray[htmlspecialchars($k)] = htmlspecialchars($v); + } + } + return $sanArray; + } + + $data = filterArray($data); echo json_encode($data); ?> diff --git a/data.php b/data.php index 3802707f..1082a254 100644 --- a/data.php +++ b/data.php @@ -1,14 +1,13 @@ $sources + ); } function getAllQueries() { $allQueries = array("data" => array()); $log = readInLog(); - $dns_queries = getDnsQueries($log); - - $fileName = '/etc/pihole/gravity.list'; - $file = file_get_contents($fileName); - + $dns_queries = getDnsQueriesAll($log); + foreach ($dns_queries as $query) { $time = date_create(substr($query, 0, 16)); $exploded = explode(" ", trim($query)); - - $searchString = " {$exploded[6]}\n"; - - if (strpos($file,$searchString)) { - $extra="Pi-holed"; - } - else { - $extra="OK"; - }; - - array_push($allQueries['data'], array( + $tmp = $exploded[count($exploded)-4]; + + if (substr($tmp, 0, 5) == "query"){ + $type = substr($exploded[count($exploded)-4], 6, -1); + $domain = $exploded[count($exploded)-3]; + $client = $exploded[count($exploded)-1]; + $status = ""; + } + elseif (substr($tmp, 0, 9) == "forwarded" ){ + $status="OK"; + } + elseif (substr($tmp, strlen($tmp) - 12, 12) == "gravity.list" && $exploded[count($exploded)-5] != "read"){ + $status="Pi-holed"; + } + + if ( $status != ""){ + array_push($allQueries['data'], array( $time->format('Y-m-d\TH:i:s'), - substr($exploded[5], 6, -1), - $exploded[6], - $exploded[8], - $extra, - )); + $type, + $domain, + hasHostName($client), + $status, + )); + } + + } - return $allQueries; } /******** Private Members ********/ - function readInBlockList() { - global $domains; - return count($domains) > 1 ? $domains : - file("/etc/pihole/gravity.list"); + function gravityCount() { + //returns count of domains in blocklist. + $gravity="/etc/pihole/gravity.list"; + $swallowed = 0; + $NGC4889 = fopen($gravity, "r"); + while ($stars = fread($NGC4889, 1024000)) { + $swallowed += substr_count($stars, "\n"); + } + fclose($NGC4889); + + return $swallowed; + } function readInLog() { global $log; @@ -164,6 +178,9 @@ function getDnsQueries($log) { return array_filter($log, "findQueries"); } + function getDnsQueriesAll($log) { + return array_filter($log, "findQueriesAll"); + } function getBlockedQueries($log) { return array_filter($log, "findAds"); } @@ -209,7 +226,7 @@ function alignTimeArrays(&$times1, &$times2) { $max = max(array(max(array_keys($times1)), max(array_keys($times2)))); $min = min(array(min(array_keys($times1)), min(array_keys($times2)))); - + for ($i = $min; $i <= $max; $i++) { if (!isset($times2[$i])) { $times2[$i] = 0; @@ -238,30 +255,34 @@ return array_reverse($recent); } + function findQueriesAll($var) { + return strpos($var, ": query[") || strpos($var, "gravity.list") || strpos($var, ": forwarded") !== false; + } + function findQueries($var) { return strpos($var, ": query[") !== false; } function findAds($var) { - return strpos($var, "gravity.list") !== false; + $exploded = explode(" ", $var); + $tmp = $exploded[count($exploded)-4]; + $tmp2 = $exploded[count($exploded)-5]; + //filter out bad names and host file reloads: + return (substr($tmp, strlen($tmp) - 12, 12) == "gravity.list" && $tmp2 != "read") ; } function findForwards($var) { return strpos($var, ": forwarded") !== false; } -/* - $data = array( - 'domains_being_blocked' => $domains_being_blocked, - 'dns_queries_today' => $dns_queries_today, - 'ads_blocked_today' => $ads_blocked_today, - 'ads_percentage_today' => $ads_percentage_today, - 'top_queries' => $topQueries, - 'top_ads' => $topAds, - 'domains_over_time' => $domains_over_time, - 'ads_over_time' => $ads_over_time, - 'recent_queries' => getRecent($dns_queries, 20), - ); - - */ + function hasHostName($var){ + global $hosts; + foreach ($hosts as $host){ + $x = preg_split('/\s+/', $host); + if ( $var == $x[0] ){ + $var = $x[1] . "($var)"; + } + } + return $var; + } ?> diff --git a/header.html b/header.html index 9e904bea..189a7c81 100644 --- a/header.html +++ b/header.html @@ -104,7 +104,14 @@

Status

- Nominal + "0") { + echo ' Active'; + } else { + echo ' Offline'; + } + ?>
@@ -123,17 +130,21 @@ + +
  • diff --git a/index.php b/index.php index 32b7ce36..0ee052b7 100644 --- a/index.php +++ b/index.php @@ -86,7 +86,7 @@
    -
    +

    Query Types

    @@ -102,23 +102,7 @@
    -
    -
    -
    -

    Top Clients

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

    Forward Destinations

    @@ -137,7 +121,7 @@
    -
    +

    Top Domains

    @@ -160,7 +144,7 @@
    -
    +

    Top Advertisers

    @@ -185,6 +169,29 @@
    +
    +
    +
    +

    Top Clients

    +
    + +
    + + + + + + +
    ClientRequestsFrequency
    +
    +
    + +
    + +
    + +
    +
    @@ -243,7 +250,7 @@ return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows()); } }; - var animate = !isMobile.any(); + var animate = false; var ctx = document.getElementById("queryOverTimeChart").getContext("2d"); timeLineChart = new Chart(ctx).Line(chartData, { @@ -268,20 +275,6 @@ animation : animate } ); - - var radarChartData = { - labels: [], - datasets: [ - { - label: "Top Clients", - fillColor: "rgba(220,220,220,0.5)", - strokeColor: "rgba(0, 166, 90,.8)", - data: [] - } - ] - }; - ctx = document.getElementById("topClientsChart").getContext("2d"); - topClientsChart = new Chart(ctx).Radar(radarChartData, {animation : animate}); }); // Functions to oupdate data in page @@ -328,14 +321,15 @@ } function updateTopClientsChart() { - $.getJSON("api.php?getQuerySources", function(data) { - console.log(data); - $.each(data, function(key, value) { - topClientsChart.addData([value], key); - }); - - $('#top-clients .overlay').remove(); - //$('#queries-over-time').append(timeLineChart.generateLegend()); + $.getJSON("api.php?summaryRaw&getQuerySources", function(data) { + var clienttable = $('#client-frequency').find('tbody:last'); + for (domain in data.top_sources) { + clienttable.append(' ' + domain + + ' ' + data.top_sources[domain] + '
    '); + } + + $('#client-frequency .overlay').remove(); }); } @@ -375,6 +369,7 @@ $.getJSON("api.php?summaryRaw&topItems", function(data) { var domaintable = $('#domain-frequency').find('tbody:last'); var adtable = $('#ad-frequency').find('tbody:last'); + for (domain in data.top_queries) { domaintable.append(' ' + domain + ' ' + data.top_queries[domain] + '
    \ No newline at end of file +