From 5d68c72477ec6b790699840f5472cd4a5f3339b1 Mon Sep 17 00:00:00 2001 From: Brice Johnson Date: Wed, 10 Feb 2016 23:18:11 -0600 Subject: [PATCH] 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');