From 293d2e7d21c4b73c51aca34e79d98d9735be1a3d Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Thu, 14 Jan 2016 23:26:58 -0600 Subject: [PATCH 01/21] Added top domains for queries and ads --- api.php | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/api.php b/api.php index 0611d835..dac2a580 100644 --- a/api.php +++ b/api.php @@ -1,13 +1,46 @@ $domains_being_blocked, 'dns_queries_today' => $dns_queries_today, 'ads_blocked_today' => $ads_blocked_today, - 'ads_percentage_today' => $ads_percentage_today + 'ads_percentage_today' => $ads_percentage_today, + 'top_queries' => topItems($dns_queries), + 'top_ads' => topItems($ads_blocked), ); header('Content-type: application/json'); From f018e0f6f90431613dca63887ba550ec3de18a4f Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Fri, 15 Jan 2016 22:29:18 -0600 Subject: [PATCH 02/21] Added lists of top domains/ads. Moved data collection to separate file. --- api.php | 46 ++----------------------------- data.php | 46 +++++++++++++++++++++++++++++++ index.php | 82 +++++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 118 insertions(+), 56 deletions(-) create mode 100644 data.php diff --git a/api.php b/api.php index dac2a580..b142b672 100644 --- a/api.php +++ b/api.php @@ -1,48 +1,6 @@ $domains_being_blocked, - 'dns_queries_today' => $dns_queries_today, - 'ads_blocked_today' => $ads_blocked_today, - 'ads_percentage_today' => $ads_percentage_today, - 'top_queries' => topItems($dns_queries), - 'top_ads' => topItems($ads_blocked), - ); + include('data.php'); header('Content-type: application/json'); - echo json_encode($arr); + echo json_encode($data); ?> diff --git a/data.php b/data.php new file mode 100644 index 00000000..96fde1a9 --- /dev/null +++ b/data.php @@ -0,0 +1,46 @@ + $domains_being_blocked, + 'dns_queries_today' => $dns_queries_today, + 'ads_blocked_today' => $ads_blocked_today, + 'ads_percentage_today' => $ads_percentage_today, + 'top_queries' => topItems($dns_queries), + 'top_ads' => topItems($ads_blocked), + ); + +?> diff --git a/index.php b/index.php index 4b6bcf40..af23c402 100644 --- a/index.php +++ b/index.php @@ -1,8 +1,6 @@ @@ -125,13 +123,12 @@
-

+

Ads Blocked Today

- More info
@@ -139,13 +136,12 @@
-

+

DNS Queries Today

- More info
@@ -153,13 +149,12 @@
-

%

+

%

Of Today's Traffic Is Ads

- More info
@@ -167,17 +162,80 @@
-

+

Domains Being Blocked

- More info
+
+
+
+
+

Top Domains

+
+ +
+ + + + + + + $value): ?> + + + + + + +
DomainHitsPercent
+
+
+
+
+
+ +
+ +
+ +
+
+
+

Top Advertisers

+
+ +
+ + + + + + + $value): ?> + + + + + + +
DomainHitsPercentage
+
+
+
+
+
+ +
+ +
+ +
From 81a81c517e12d6795caca0a25203fb295e6a5483 Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Fri, 15 Jan 2016 23:40:15 -0600 Subject: [PATCH 03/21] Added chart of queries over time --- data.php | 18 +++++++++++++++++- index.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/data.php b/data.php index 96fde1a9..193dd021 100644 --- a/data.php +++ b/data.php @@ -24,7 +24,7 @@ $exploded = explode(" ", $query); $domain = trim($exploded[5]); if (isset($splitQueries[$domain])) { - $splitQueries[$domain] = $splitQueries[$domain] + 1; + $splitQueries[$domain]++; } else { $splitQueries[$domain] = 1; @@ -34,6 +34,20 @@ return array_slice($splitQueries, 0, 10); } + function overTime($entries) { + $byTime = array(); + foreach ($entries as $entry) { + $hour = substr($entry, 7, 2); + if (isset($byTime[$hour])) { + $byTime[$hour]++; + } + else { + $byTime[$hour] = 1; + } + } + return $byTime; + } + $data = array( 'domains_being_blocked' => $domains_being_blocked, 'dns_queries_today' => $dns_queries_today, @@ -41,6 +55,8 @@ 'ads_percentage_today' => $ads_percentage_today, 'top_queries' => topItems($dns_queries), 'top_ads' => topItems($ads_blocked), + 'domains_over_time' => overTime($dns_queries), + 'ads_over_time' => overTime($ads_blocked) ); ?> diff --git a/index.php b/index.php index af23c402..a66321b8 100644 --- a/index.php +++ b/index.php @@ -21,6 +21,35 @@ + + +
@@ -172,6 +201,21 @@
+
+
+
+
+

Queries over time

+
+
+
+ +
+
+ +
+
+
From 96d4254e8b776429e82da906ced1a8786ce751bf Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Fri, 15 Jan 2016 23:42:00 -0600 Subject: [PATCH 04/21] Changed "Percentage" to Frequency --- index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index a66321b8..087ef950 100644 --- a/index.php +++ b/index.php @@ -228,7 +228,7 @@ Domain Hits - Percent + Frequency $value): ?> @@ -259,7 +259,7 @@ Domain Hits - Percentage + Frequency $value): ?> From 6cafb226d5bcd262a30b87a31dc920ebc09a1b52 Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Mon, 25 Jan 2016 20:41:46 -0600 Subject: [PATCH 05/21] Fixed bugs in over-time graph --- data.php | 42 ++++++++++++++++++++++++++++++++---------- index.php | 7 ++++--- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/data.php b/data.php index 193dd021..b4a05966 100644 --- a/data.php +++ b/data.php @@ -1,11 +1,4 @@ SetTimeZone(new DateTimeZone(date_default_timezone_get())); + $hour = $time->format('G'); + if (isset($byTime[$hour])) { $byTime[$hour]++; } @@ -48,6 +47,29 @@ return $byTime; } + function alignTimeArrays(&$times1, &$times2) { + foreach (array_keys($times1) as $time) { + if (!isset($times2[$time])) { + $times2[$time] = 0; + } + } + foreach (array_keys($times2) as $time) { + if (!isset($times1[$time])) { + $times1[$time] = 0; + } + } + ksort($times1); + ksort($times2); + } + + function findQueries($var) { + return strpos($var, "query") != false; + } + + function findAds($var) { + return strpos($var, "gravity.list") != false; + } + $data = array( 'domains_being_blocked' => $domains_being_blocked, 'dns_queries_today' => $dns_queries_today, @@ -55,8 +77,8 @@ 'ads_percentage_today' => $ads_percentage_today, 'top_queries' => topItems($dns_queries), 'top_ads' => topItems($ads_blocked), - 'domains_over_time' => overTime($dns_queries), - 'ads_over_time' => overTime($ads_blocked) + 'domains_over_time' => $domains_over_time, + 'ads_over_time' => $ads_over_time, ); ?> diff --git a/index.php b/index.php index 087ef950..56f7f3a1 100644 --- a/index.php +++ b/index.php @@ -3,6 +3,7 @@ include('data.php'); ?> + <%?= print_r($data); ?> @@ -25,20 +26,20 @@ - diff --git a/index.php b/index.php index 4beb6c5f..5de8d78e 100644 --- a/index.php +++ b/index.php @@ -172,3 +172,32 @@ + + From 21741094f1734809448d5c6a7afe756a7dacb9a7 Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Tue, 2 Feb 2016 22:27:42 -0600 Subject: [PATCH 09/21] Moved data retrieval to Ajax call. Fixed ipv6 number. Fixed top domains/advertisers tables. --- api.php | 23 ++++++++++- data.php | 105 ++++++++++++++++++++++++++++++++++++++++---------- index.php | 112 +++++++++++++++++++++++++++--------------------------- 3 files changed, 164 insertions(+), 76 deletions(-) diff --git a/api.php b/api.php index b142b672..a82a775a 100644 --- a/api.php +++ b/api.php @@ -1,6 +1,27 @@ diff --git a/data.php b/data.php index 01b74fcb..ae9fdcd1 100644 --- a/data.php +++ b/data.php @@ -1,28 +1,91 @@ $domains_being_blocked, + 'dns_queries_today' => $dns_queries_today, + 'ads_blocked_today' => $ads_blocked_today, + 'ads_percentage_today' => $ads_percentage_today, + ); + } - function topItems($queries, $exclude = array()) { + function getOverTimeData() { + $domains = readInBlockList(); + $log = readInLog(); + $dns_queries = getDnsQueries($log); + $ads_blocked = getBlockedQueries($log); + + $domains_over_time = overTime($dns_queries); + $ads_over_time = overTime($ads_blocked); + alignTimeArrays($ads_over_time, $domains_over_time); + return Array( + 'domains_over_time' => $domains_over_time, + 'ads_over_time' => $ads_over_time, + ); + } + + function getTopItems() { + $domains = readInBlockList(); + $log = readInLog(); + $dns_queries = getDnsQueries($log); + $ads_blocked = getBlockedQueries($log); + + $topAds = topItems($ads_blocked); + $topQueries = topItems($dns_queries, $topAds); + + return Array( + 'top_queries' => $topQueries, + 'top_ads' => $topAds, + ); + } + + function getRecentItems($qty) { + $log = readInLog(); + $dns_queries = getDnsQueries($log); + return Array( + 'recent_queries' => getRecent($dns_queries, $qty) + ); + } + + /******** Private Members ********/ + function readInBlockList() { + global $domains; + return count($domains) > 1 ? $domains : + file("/etc/pihole/gravity.list"); + } + function readInLog() { + global $log; + return count($log) > 1 ? $log : + file("/var/log/pihole.log"); + } + function getDnsQueries($log) { + return array_filter($log, "findQueries"); + } + function getBlockedQueries($log) { + return array_filter($log, "findAds"); + } + + + function topItems($queries, $exclude = array(), $qty=10) { $splitQueries = array(); foreach ($queries as $query) { $exploded = explode(" ", $query); - $domain = trim($exploded[5]); + $domain = trim($exploded[6]); if (!isset($exclude[$domain])) { if (isset($splitQueries[$domain])) { $splitQueries[$domain]++; @@ -33,7 +96,7 @@ } } arsort($splitQueries); - return array_slice($splitQueries, 0, 10); + return array_slice($splitQueries, 0, $qty); } function overTime($entries) { @@ -74,10 +137,11 @@ $exploded = explode(" ", $query); $time = date_create(substr($query, 0, 16), new DateTimeZone('GMT'))->SetTimeZone(new DateTimeZone(date_default_timezone_get())); - $queryArray['time'] = $time->format('h:m:s'); - $queryArray['domain'] = trim($exploded[5]); - $queryArray['ip'] = trim($exploded[7]); + $queryArray['time'] = $time->format('h:i:s a'); + $queryArray['domain'] = trim($exploded[6]); + $queryArray['ip'] = trim($exploded[8]); array_push($recent, $queryArray); + } return array_reverse($recent); } @@ -89,7 +153,7 @@ function findAds($var) { return strpos($var, "gravity.list") != false; } - +/* $data = array( 'domains_being_blocked' => $domains_being_blocked, 'dns_queries_today' => $dns_queries_today, @@ -102,4 +166,5 @@ 'recent_queries' => getRecent($dns_queries, 20), ); + */ ?> diff --git a/index.php b/index.php index 5de8d78e..fca76f38 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,7 @@ @@ -10,7 +11,7 @@
-

+

Ads Blocked Today

@@ -23,7 +24,7 @@
-

+

DNS Queries Today

@@ -36,7 +37,7 @@
-

%

+

%

Of Today's Traffic Is Ads

@@ -49,7 +50,7 @@
-

+

Domains Being Blocked

@@ -82,23 +83,12 @@
- +
- $value): ?> - - - - - -
Domain Hits Frequency
-
-
-
-
@@ -113,23 +103,12 @@
- +
- $value): ?> - - - - - -
Domain Hits Frequency
-
-
-
-
@@ -147,19 +126,12 @@
- +
- $value): ?> - - - - - -
Time Domain Source Ip
@@ -174,27 +146,57 @@ ?> From 83cc057e7a774dc7c1c79cf0853aab0e60d853e0 Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Sat, 6 Feb 2016 22:45:39 -0600 Subject: [PATCH 11/21] Added placeholder for summary stats while ajax is loading. Added loading indicators to all other boxes. --- index.php | 54 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/index.php b/index.php index 76829a3f..24e96bc8 100644 --- a/index.php +++ b/index.php @@ -8,7 +8,7 @@
-

+

---

Ads Blocked Today

@@ -21,7 +21,7 @@
-

+

---

DNS Queries Today

@@ -34,7 +34,7 @@
-

+

---

Of Today's Traffic Is Ads

@@ -47,7 +47,7 @@
-

+

---

Domains Being Blocked

@@ -59,7 +59,7 @@
-
+

Queries over time

@@ -68,19 +68,22 @@
+
+ +
-
+

Top Domains

- +
@@ -88,19 +91,22 @@
Domain Hits
+
+ +
-
+

Top Advertisers

- +
@@ -108,6 +114,9 @@
Domain Hits
+
+ +
@@ -117,13 +126,13 @@
-
+

Recent Queries

- +
@@ -131,6 +140,9 @@
Time Domain
+
+ +
@@ -148,7 +160,7 @@ $(document).ready(function() { updateSummaryData(); - summaryDataIntervalId = window.setInterval(updateSummaryData, 20000); + //summaryDataIntervalId = window.setTimeout(updateSummaryData, 20000); updateQueriesOverTime(); @@ -178,8 +190,8 @@ timeLineChart = new Chart(ctx).Line(chartData, {pointDot : false }); }); - function updateSummaryData() { - $.getJSON("api.php?summary", function(data) { + function updateSummaryData(runOnce) { + $.getJSON("api.php?summary", function LoadSummaryData(data) { //$("h3.statistic").addClass("glow"); if ($("h3#ads_blocked_today").text() != data.ads_blocked_today) { $("h3#ads_blocked_today").addClass("glow"); @@ -198,7 +210,15 @@ $("h3#ads_percentage_today").text(data.ads_percentage_today + "%"); $("h3.statistic.glow").removeClass("glow") }, 500); - }); + }).done(function() { + if (runOnce !== true) { + setTimeout(updateSummaryData, 10000); + } + }).fail(function() { + if (runOnce !== true) { + setTimeout(updateSummaryData, (1000 * 60 * 5)); + } + });; } function updateQueriesOverTime() { @@ -206,6 +226,7 @@ for (hour in data.ads_over_time) { timeLineChart.addData([data.domains_over_time[hour], data.ads_over_time[hour]], hour + ":00"); } + $('#queries-over-time .overlay').remove(); }); } @@ -224,6 +245,8 @@ data.top_ads[domain] / data.ads_blocked_today * 100 + '%">
'); } + $('#domain-frequency .overlay').remove(); + $('#ad-frequency .overlay').remove(); }); } @@ -233,6 +256,7 @@ for (query in data.recent_queries) { recenttable.append(' ' + data.recent_queries[query].time + ' ' + data.recent_queries[query].domain + ' ' + data.recent_queries[query].ip + ' '); } + $('#recent-queries .overlay').remove(); }); } From f72d28d45ef7235dca65fdc9d009e7249377f312 Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Tue, 9 Feb 2016 18:50:47 -0600 Subject: [PATCH 12/21] Changed array indexing to be more robust --- data.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data.php b/data.php index ae9fdcd1..802302c5 100644 --- a/data.php +++ b/data.php @@ -85,7 +85,7 @@ $splitQueries = array(); foreach ($queries as $query) { $exploded = explode(" ", $query); - $domain = trim($exploded[6]); + $domain = trim($exploded[count($exploded) - 3]); if (!isset($exclude[$domain])) { if (isset($splitQueries[$domain])) { $splitQueries[$domain]++; @@ -138,8 +138,8 @@ $time = date_create(substr($query, 0, 16), new DateTimeZone('GMT'))->SetTimeZone(new DateTimeZone(date_default_timezone_get())); $queryArray['time'] = $time->format('h:i:s a'); - $queryArray['domain'] = trim($exploded[6]); - $queryArray['ip'] = trim($exploded[8]); + $queryArray['domain'] = trim($exploded[count($exploded) - 3]); + $queryArray['ip'] = trim($exploded[count($exploded)-1]); array_push($recent, $queryArray); } From 5d68c72477ec6b790699840f5472cd4a5f3339b1 Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Wed, 10 Feb 2016 23:18:11 -0600 Subject: [PATCH 13/21] Added query types graph --- api.php | 4 ++++ data.php | 23 ++++++++++++++++++++-- index.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 81 insertions(+), 4 deletions(-) diff --git a/api.php b/api.php index 395be210..e0341c15 100644 --- a/api.php +++ b/api.php @@ -31,6 +31,10 @@ } } + if (isset($_GET['getQueryTypes'])) { + $data = array_merge($data, getIpvType()); + } + echo json_encode($data); ?> diff --git a/data.php b/data.php index 802302c5..c86c299c 100644 --- a/data.php +++ b/data.php @@ -62,6 +62,25 @@ ); } + function getIpvType() { + $log = readInLog(); + $dns_queries = getDnsQueries($log); + $queryTypes = array(); + + foreach($dns_queries as $query) { + $info = trim(explode(": ", $query)[1]); + $queryType = explode(" ", $info)[0]; + if (isset($queryTypes[$queryType])) { + $queryTypes[$queryType]++; + } + else { + $queryTypes[$queryType] = 1; + } + } + + return $queryTypes; + } + /******** Private Members ********/ function readInBlockList() { global $domains; @@ -147,11 +166,11 @@ } function findQueries($var) { - return strpos($var, "query") != false; + return strpos($var, ": query[") !== false; } function findAds($var) { - return strpos($var, "gravity.list") != false; + return strpos($var, "gravity.list") !== false; } /* $data = array( diff --git a/index.php b/index.php index 24e96bc8..b62fc9d9 100644 --- a/index.php +++ b/index.php @@ -57,6 +57,7 @@
+
@@ -75,6 +76,26 @@
+ +
+
+
+
+

Query Types

+
+
+
+ +
+
+
+ +
+ +
+
+
+
@@ -160,16 +181,17 @@ $(document).ready(function() { updateSummaryData(); - //summaryDataIntervalId = window.setTimeout(updateSummaryData, 20000); updateQueriesOverTime(); + updateQueryTypes(); + updateTopLists(); updateRecentQueries(); - // Create chart + // Create line chart var chartData = { labels: [], datasets: [ @@ -188,6 +210,23 @@ }; var ctx = document.getElementById("queryOverTimeChart").getContext("2d"); timeLineChart = new Chart(ctx).Line(chartData, {pointDot : false }); + + /* + // Create radar chart + chartData = { + labels: [], + datasets: [ + { + label: "Query Types", + fillColor: "rgba(220,220,220,0.5)", + strokeColor: "rgba(0, 166, 90,.8)", + data: [] + }, + ] + }; + */ + var ctx = document.getElementById("queryTypeChart").getContext("2d"); + queryTypeChart = new Chart(ctx).Doughnut([],{legendTemplate: "HELLO"}); }); function updateSummaryData(runOnce) { @@ -230,6 +269,21 @@ }); } + function updateQueryTypes() { + $.getJSON("api.php?getQueryTypes", function(data) { + var colors = []; + $.each($.AdminLTE.options.colors, function(key, value) { colors.push(value); }); + $.each(data, function(key , value) { + queryTypeChart.addData({ + value: value, + color: colors.shift(), + label: key + }); + }); + $('#query-types .overlay').remove(); + }); + } + function updateTopLists() { $.getJSON("api.php?summaryRaw&topItems", function(data) { var domaintable = $('#domain-frequency').find('tbody:last'); From 0544cfb39856b1ee9c64726e6d45387462640caa Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Wed, 10 Feb 2016 23:40:20 -0600 Subject: [PATCH 14/21] Added forwarding destination chart --- api.php | 4 ++++ data.php | 27 +++++++++++++++++++++++++++ index.php | 54 ++++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 69 insertions(+), 16 deletions(-) diff --git a/api.php b/api.php index e0341c15..87246f43 100644 --- a/api.php +++ b/api.php @@ -35,6 +35,10 @@ $data = array_merge($data, getIpvType()); } + if (isset($_GET['getForwardDestinations'])) { + $data = array_merge($data, getForwardDestinations()); + } + echo json_encode($data); ?> diff --git a/data.php b/data.php index c86c299c..2a7a128c 100644 --- a/data.php +++ b/data.php @@ -81,6 +81,25 @@ return $queryTypes; } + function getForwardDestinations() { + $log = readInLog(); + $forwards = getForwards($log); + $destinations = array(); + foreach ($forwards as $forward) { + $exploded = explode(" ", trim($forward)); + $dest = $exploded[count($exploded) - 1]; + if (isset($destinations[$dest])) { + $destinations[$dest]++; + } + else { + $destinations[$dest] = 0; + } + } + + return $destinations; + + } + /******** Private Members ********/ function readInBlockList() { global $domains; @@ -98,6 +117,9 @@ function getBlockedQueries($log) { return array_filter($log, "findAds"); } + function getForwards($log) { + return array_filter($log, "findForwards"); + } function topItems($queries, $exclude = array(), $qty=10) { @@ -172,6 +194,11 @@ function findAds($var) { return strpos($var, "gravity.list") !== false; } + + function findForwards($var) { + return strpos($var, ": forwarded") !== false; + } + /* $data = array( 'domains_being_blocked' => $domains_being_blocked, diff --git a/index.php b/index.php index b62fc9d9..f46009c2 100644 --- a/index.php +++ b/index.php @@ -94,6 +94,22 @@
+
+
+
+

Forward Destinations

+
+
+
+ +
+
+
+ +
+ +
+
@@ -186,6 +202,8 @@ updateQueryTypes(); + updateForwardDestinations(); + updateTopLists(); updateRecentQueries(); @@ -211,22 +229,11 @@ var ctx = document.getElementById("queryOverTimeChart").getContext("2d"); timeLineChart = new Chart(ctx).Line(chartData, {pointDot : false }); - /* - // Create radar chart - chartData = { - labels: [], - datasets: [ - { - label: "Query Types", - fillColor: "rgba(220,220,220,0.5)", - strokeColor: "rgba(0, 166, 90,.8)", - data: [] - }, - ] - }; - */ - var ctx = document.getElementById("queryTypeChart").getContext("2d"); - queryTypeChart = new Chart(ctx).Doughnut([],{legendTemplate: "HELLO"}); + ctx = document.getElementById("queryTypeChart").getContext("2d"); + queryTypeChart = new Chart(ctx).Doughnut([],{}); + + ctx = document.getElementById("forwardDestinationChart").getContext("2d"); + forwardDestinationChart = new Chart(ctx).Doughnut([],{}); }); function updateSummaryData(runOnce) { @@ -284,6 +291,21 @@ }); } + function updateForwardDestinations() { + $.getJSON("api.php?getForwardDestinations", function(data) { + var colors = []; + $.each($.AdminLTE.options.colors, function(key, value) { colors.push(value); }); + $.each(data, function(key , value) { + forwardDestinationChart.addData({ + value: value, + color: colors.shift(), + label: key + }); + }); + $('#forward-destinations .overlay').remove(); + }); + } + function updateTopLists() { $.getJSON("api.php?summaryRaw&topItems", function(data) { var domaintable = $('#domain-frequency').find('tbody:last'); From e5b73c31cf771bc02a6e9db9faaafcf8818370e2 Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Wed, 10 Feb 2016 23:55:06 -0600 Subject: [PATCH 15/21] Added some legends --- index.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index f46009c2..7757531e 100644 --- a/index.php +++ b/index.php @@ -227,13 +227,14 @@ ] }; var ctx = document.getElementById("queryOverTimeChart").getContext("2d"); - timeLineChart = new Chart(ctx).Line(chartData, {pointDot : false }); + timeLineChart = new Chart(ctx).Line(chartData, {pointDot : false, legendTemplate : "
    -legend\"><% for (var i=0; i
  • \"><%if(datasets[i].label){%><%=datasets[i].label%><%}%>
  • <%}%>
" + }); ctx = document.getElementById("queryTypeChart").getContext("2d"); - queryTypeChart = new Chart(ctx).Doughnut([],{}); + queryTypeChart = new Chart(ctx).Doughnut([],{ legendTemplate : "
    -legend\"><% for (var i=0; i
  • \"><%if(segments[i].label){%><%=segments[i].label%><%}%>
  • <%}%>
" }); ctx = document.getElementById("forwardDestinationChart").getContext("2d"); - forwardDestinationChart = new Chart(ctx).Doughnut([],{}); + forwardDestinationChart = new Chart(ctx).Doughnut([],{ legendTemplate : "
    -legend\"><% for (var i=0; i
  • \"><%if(segments[i].label){%><%=segments[i].label%><%}%>
  • <%}%>
" }); }); function updateSummaryData(runOnce) { @@ -273,6 +274,7 @@ timeLineChart.addData([data.domains_over_time[hour], data.ads_over_time[hour]], hour + ":00"); } $('#queries-over-time .overlay').remove(); + $('#queries-over-time').append(timeLineChart.generateLegend()); }); } @@ -288,6 +290,7 @@ }); }); $('#query-types .overlay').remove(); + $('#query-types').append(queryTypeChart.generateLegend()); }); } @@ -303,6 +306,7 @@ }); }); $('#forward-destinations .overlay').remove(); + $('#forward-destinations').append(forwardDestinationChart.generateLegend()); }); } From 4fa6b3dc6b03b0d685ab7bd1dc1be77f8364c8a8 Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Thu, 11 Feb 2016 23:41:31 -0600 Subject: [PATCH 16/21] Added radar graph for top clients --- api.php | 4 ++++ data.php | 17 +++++++++++++++++ index.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/api.php b/api.php index 87246f43..d9f22550 100644 --- a/api.php +++ b/api.php @@ -39,6 +39,10 @@ $data = array_merge($data, getForwardDestinations()); } + if (isset($_GET['getQuerySources'])) { + $data = array_merge($data, getQuerySources()); + } + echo json_encode($data); ?> diff --git a/data.php b/data.php index 2a7a128c..06ec811b 100644 --- a/data.php +++ b/data.php @@ -100,6 +100,23 @@ } + function getQuerySources() { + $log = readInLog(); + $dns_queries = getDnsQueries($log); + $sources = array(); + foreach($dns_queries as $query) { + $exploded = explode(" ", $query); + $ip = trim($exploded[count($exploded)-1]); + if (isset($sources[$ip])) { + $sources[$ip]++; + } + else { + $sources[$ip] = 1; + } + } + return $sources; + } + /******** Private Members ********/ function readInBlockList() { global $domains; diff --git a/index.php b/index.php index 7757531e..dbd66c17 100644 --- a/index.php +++ b/index.php @@ -95,6 +95,22 @@
+
+
+

Top Clients

+
+
+
+ +
+
+
+ +
+ +
+
+

Forward Destinations

@@ -202,6 +218,8 @@ updateQueryTypes(); + updateTopClientsChart(); + updateForwardDestinations(); updateTopLists(); @@ -235,6 +253,20 @@ ctx = document.getElementById("forwardDestinationChart").getContext("2d"); forwardDestinationChart = new Chart(ctx).Doughnut([],{ legendTemplate : "
    -legend\"><% for (var i=0; i
  • \"><%if(segments[i].label){%><%=segments[i].label%><%}%>
  • <%}%>
" }); + + 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, {}); }); function updateSummaryData(runOnce) { @@ -278,6 +310,18 @@ }); } + 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()); + }); + } + function updateQueryTypes() { $.getJSON("api.php?getQueryTypes", function(data) { var colors = []; From 01276cbe4d69b9aefaf0aaa2050cf37443c87f74 Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Thu, 11 Feb 2016 23:52:30 -0600 Subject: [PATCH 17/21] Removed legends from charts --- index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index dbd66c17..2f38becf 100644 --- a/index.php +++ b/index.php @@ -306,7 +306,7 @@ timeLineChart.addData([data.domains_over_time[hour], data.ads_over_time[hour]], hour + ":00"); } $('#queries-over-time .overlay').remove(); - $('#queries-over-time').append(timeLineChart.generateLegend()); + //$('#queries-over-time').append(timeLineChart.generateLegend()); }); } @@ -334,7 +334,7 @@ }); }); $('#query-types .overlay').remove(); - $('#query-types').append(queryTypeChart.generateLegend()); + //$('#query-types').append(queryTypeChart.generateLegend()); }); } @@ -350,7 +350,7 @@ }); }); $('#forward-destinations .overlay').remove(); - $('#forward-destinations').append(forwardDestinationChart.generateLegend()); + //$('#forward-destinations').append(forwardDestinationChart.generateLegend()); }); } From e73ba8b28c9dd0b0f7054a57cbb1ed94279911d9 Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Fri, 12 Feb 2016 22:54:09 -0600 Subject: [PATCH 18/21] Added fix for time gaps in log for the 'over time' graph --- data.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/data.php b/data.php index 06ec811b..1eb647ce 100644 --- a/data.php +++ b/data.php @@ -174,16 +174,18 @@ } function alignTimeArrays(&$times1, &$times2) { - foreach (array_keys($times1) as $time) { - if (!isset($times2[$time])) { - $times2[$time] = 0; - } - } - foreach (array_keys($times2) as $time) { - if (!isset($times1[$time])) { - $times1[$time] = 0; + $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; + } + if (!isset($times1[$i])) { + $times1[$i] = 0; } } + ksort($times1); ksort($times2); } @@ -194,7 +196,6 @@ $queryArray = array(); $exploded = explode(" ", $query); $time = date_create(substr($query, 0, 16), new DateTimeZone('GMT'))->SetTimeZone(new DateTimeZone(date_default_timezone_get())); - $queryArray['time'] = $time->format('h:i:s a'); $queryArray['domain'] = trim($exploded[count($exploded) - 3]); $queryArray['ip'] = trim($exploded[count($exploded)-1]); From b80c373cfacdc321f0322cac1d36d24af9a5b1bf Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Sat, 13 Feb 2016 00:01:50 -0600 Subject: [PATCH 19/21] Added page to view daily query log history --- api.php | 4 ++++ data.php | 20 ++++++++++++++++ footer.html | 3 ++- header.html | 14 +++++++---- queries.php | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 queries.php diff --git a/api.php b/api.php index d9f22550..9b6c0da3 100644 --- a/api.php +++ b/api.php @@ -43,6 +43,10 @@ $data = array_merge($data, getQuerySources()); } + if (isset($_GET['getAllQueries'])) { + $data = array_merge($data, getAllQueries()); + } + echo json_encode($data); ?> diff --git a/data.php b/data.php index 1eb647ce..e57f2fc4 100644 --- a/data.php +++ b/data.php @@ -117,6 +117,26 @@ return $sources; } + function getAllQueries() { + $allQueries = array("data" => array()); + $log = readInLog(); + $dns_queries = getDnsQueries($log); + + foreach ($dns_queries as $query) { + $time = date_create(substr($query, 0, 16), new DateTimeZone('GMT'))->SetTimeZone(new DateTimeZone(date_default_timezone_get())); + + $exploded = explode(" ", trim($query)); + array_push($allQueries['data'], array( + $time->format('Y-m-d\TH:i:s'), + substr($exploded[4], 6, -1), + $exploded[5], + $exploded[7], + )); + } + + return $allQueries; + } + /******** Private Members ********/ function readInBlockList() { global $domains; diff --git a/footer.html b/footer.html index 70029a1f..593fe100 100644 --- a/footer.html +++ b/footer.html @@ -14,7 +14,8 @@ - + + diff --git a/header.html b/header.html index 04a52b6a..3d18992a 100644 --- a/header.html +++ b/header.html @@ -9,7 +9,7 @@ - + @@ -112,10 +112,10 @@ Main Page - +
  • - - Donate + + Query Log
  • @@ -130,6 +130,12 @@ Blacklist + +
  • + + Donate + +
  • diff --git a/queries.php b/queries.php new file mode 100644 index 00000000..301c4182 --- /dev/null +++ b/queries.php @@ -0,0 +1,69 @@ + + + +
    +
    +
    +
    +

    Recent Queries

    +
    + +
    + + + + + + + + + + + + + + + + + +
    TimeTypeDomainClient
    TimeTypeDomainClient
    +
    + +
    + +
    +
    + + + + + + From 0d1e4a33c29af0187a5c854d451ede52f542c8b6 Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Sat, 13 Feb 2016 12:13:48 -0600 Subject: [PATCH 20/21] Removed recent queries from main page --- index.php | 43 ++++++------------------------------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/index.php b/index.php index 2f38becf..0efb2bd4 100644 --- a/index.php +++ b/index.php @@ -177,31 +177,6 @@
    -
    -
    -
    -
    -

    Recent Queries

    -
    - -
    - - - - - - -
    TimeDomainSource Ip
    -
    -
    - -
    - -
    - -
    -
    - ' + data.recent_queries[query].time + ' ' + data.recent_queries[query].domain + ' ' + data.recent_queries[query].ip + ' '); - } - $('#recent-queries .overlay').remove(); - }); - } From dd2b72627f051e9caa6e28088dfc2328391d97e2 Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Sat, 13 Feb 2016 12:22:43 -0600 Subject: [PATCH 21/21] Removed whitelist/blacklist links. Fixed merge error --- header.html | 4 ++++ queries.php | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/header.html b/header.html index 3d18992a..fb0a99b0 100644 --- a/header.html +++ b/header.html @@ -119,17 +119,21 @@ + +
  • diff --git a/queries.php b/queries.php index 301c4182..9a47c9af 100644 --- a/queries.php +++ b/queries.php @@ -44,7 +44,7 @@ +