forked from pi-hole/web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
388 lines (363 loc) · 13.9 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<?php
require "header.html";
?>
<!-- JS Warning -->
<div>
<link rel="stylesheet" type="text/css" href="css/js-warn.css">
<input type="checkbox" id="js-hide" />
<div class="js-warn" id="js-warn-exit"><h1>Javascript Is Disabled</h1><p>Javascript seems to be disabled. This will break some site features.</p>
<p>To enable Javascript click <a href="http://www.enable-javascript.com/" target="_blank">here</a></p><label for="js-hide">Close</label></div>
<script>var jswarn = document.getElementById("js-warn-exit"); jswarn.parentNode.removeChild(jswarn);</script>
</div>
<!-- /JS Warning -->
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-aqua">
<div class="inner">
<h3 class="statistic" id="ads_blocked_today">---</h3>
<p>Ads Blocked Today</p>
</div>
<div class="icon">
<i class="ion ion-android-hand"></i>
</div>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-green">
<div class="inner">
<h3 class="statistic" id="dns_queries_today">---</h3>
<p>DNS Queries Today</p>
</div>
<div class="icon">
<i class="ion ion-earth"></i>
</div>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-yellow">
<div class="inner">
<h3 class="statistic" id="ads_percentage_today">---</h3>
<p>Of Today's Traffic Is Ads</p>
</div>
<div class="icon">
<i class="ion ion-pie-graph"></i>
</div>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-red">
<div class="inner">
<h3 class="statistic" id="domains_being_blocked"><sup style="font-size: 30px">---</sup></h3>
<p>Domains Being Blocked</p>
</div>
<div class="icon">
<i class="ion ion-ios-list"></i>
</div>
</div>
</div>
<!-- ./col -->
</div>
<div class="row">
<div class="col-md-12">
<div class="box" id="queries-over-time">
<div class="box-header with-border">
<h3 class="box-title">Queries over time</h3>
</div>
<div class="box-body">
<div class="chart">
<canvas id="queryOverTimeChart" style="height: 247px; width: 466px;" width="932" height="494"></canvas>
</div>
</div>
<div class="overlay">
<i class="fa fa-refresh fa-spin"></i>
</div>
<!-- /.box-body -->
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="box" id="query-types">
<div class="box-header with-border">
<h3 class="box-title">Query Types</h3>
</div>
<div class="box-body">
<div class="chart">
<canvas id="queryTypeChart" style="height: 247px; width: 466px;" width="932" height="494"></canvas>
</div>
</div>
<div class="overlay">
<i class="fa fa-refresh fa-spin"></i>
</div>
<!-- /.box-body -->
</div>
</div>
<div class="col-md-6">
<div class="box" id="forward-destinations">
<div class="box-header with-border">
<h3 class="box-title">Forward Destinations</h3>
</div>
<div class="box-body">
<div class="chart">
<canvas id="forwardDestinationChart" style="height: 247px; width: 466px;" width="932" height="494"></canvas>
</div>
</div>
<div class="overlay">
<i class="fa fa-refresh fa-spin"></i>
</div>
<!-- /.box-body -->
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="box" id="domain-frequency">
<div class="box-header with-border">
<h3 class="box-title">Top Domains</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table class="table table-bordered">
<tbody><tr>
<th>Domain</th>
<th>Hits</th>
<th>Frequency</th>
</tr>
</tbody></table>
</div>
<div class="overlay">
<i class="fa fa-refresh fa-spin"></i>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<!-- /.col -->
<div class="col-md-4">
<div class="box" id="ad-frequency">
<div class="box-header with-border">
<h3 class="box-title">Top Advertisers</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table class="table table-bordered">
<tbody>
<tr>
<th>Domain</th>
<th>Hits</th>
<th>Frequency</th>
</tr>
</tbody>
</table>
</div>
<div class="overlay">
<i class="fa fa-refresh fa-spin"></i>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<!-- /.col -->
<div class="col-md-4">
<div class="box" id="client-frequency">
<div class="box-header with-border">
<h3 class="box-title">Top Clients</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table class="table table-bordered">
<tbody><tr>
<th>Client</th>
<th>Requests</th>
<th>Frequency</th>
</tr>
</tbody></table>
</div>
<div class="overlay">
<i class="fa fa-refresh fa-spin"></i>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
<?php
require "footer.php";
?>
<script type="text/javascript">
$(document).ready(function() {
// Pull in data via AJAX
updateSummaryData();
updateQueriesOverTime();
updateQueryTypes();
updateTopClientsChart();
updateForwardDestinations();
updateTopLists();
// Create charts
var chartData = {
labels: [],
datasets: [
{
label: "All Queries",
fillColor: "rgba(220,220,220,0.5)",
strokeColor: "rgba(0, 166, 90,.8)",
pointColor: "rgba(0, 166, 90,.8)"
},
{
label: "Ad Queries",
fillColor: "rgba(0,192,239,0.5)",
strokeColor: "rgba(0,192,239,1)",
pointColor: "rgba(0,192,239,1)"
}
]
};
var isMobile = {
Windows: function() {
return /IEMobile/i.test(navigator.userAgent);
},
Android: function() {
return /Android/i.test(navigator.userAgent);
},
BlackBerry: function() {
return /BlackBerry/i.test(navigator.userAgent);
},
iOS: function() {
return /iPhone|iPad|iPod/i.test(navigator.userAgent);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
}
};
var animate = false;
var ctx = document.getElementById("queryOverTimeChart").getContext("2d");
timeLineChart = new Chart(ctx).Line(chartData,
{
pointDot : false,
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>",
animation : animate
}
);
ctx = document.getElementById("queryTypeChart").getContext("2d");
queryTypeChart = new Chart(ctx).Doughnut([],
{
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].strokeColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>",
animation : animate
}
);
ctx = document.getElementById("forwardDestinationChart").getContext("2d");
forwardDestinationChart = new Chart(ctx).Doughnut([],
{
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].strokeColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>",
animation : animate
}
);
});
// Functions to oupdate data in page
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");
}
if ($("h3#dns_queries_today").text() != data.dns_queries_today) {
$("h3#dns_queries_today").addClass("glow");
}
if ($("h3#ads_percentage_today").text() != data.ads_percentage_today) {
$("h3#ads_percentage_today").addClass("glow");
}
window.setTimeout(function(){
$("h3#ads_blocked_today").text(data.ads_blocked_today);
$("h3#dns_queries_today").text(data.dns_queries_today);
$("h3#domains_being_blocked").text(data.domains_being_blocked);
$("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() {
$.getJSON("api.php?overTimeData", function(data) {
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();
//$('#queries-over-time').append(timeLineChart.generateLegend());
});
}
function updateTopClientsChart() {
$.getJSON("api.php?summaryRaw&getQuerySources", function(data) {
var clienttable = $('#client-frequency').find('tbody:last');
for (domain in data.top_sources) {
clienttable.append('<tr> <td>' + domain +
'</td> <td>' + data.top_sources[domain] + '</td> <td> <div class="progress progress-sm"> <div class="progress-bar progress-bar-blue" style="width: ' +
data.top_sources[domain] / data.dns_queries_today * 100 + '%"></div> </div> </td> </tr> ');
}
$('#client-frequency .overlay').remove();
});
}
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.substr(6,key.length - 7)
});
});
$('#query-types .overlay').remove();
//$('#query-types').append(queryTypeChart.generateLegend());
});
}
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();
//$('#forward-destinations').append(forwardDestinationChart.generateLegend());
});
}
function updateTopLists() {
$.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('<tr> <td>' + domain +
'</td> <td>' + data.top_queries[domain] + '</td> <td> <div class="progress progress-sm"> <div class="progress-bar progress-bar-green" style="width: ' +
data.top_queries[domain] / data.dns_queries_today * 100 + '%"></div> </div> </td> </tr> ');
}
for (domain in data.top_ads) {
adtable.append('<tr> <td>' + domain +
'</td> <td>' + data.top_ads[domain] + '</td> <td> <div class="progress progress-sm"> <div class="progress-bar progress-bar-yellow" style="width: ' +
data.top_ads[domain] / data.ads_blocked_today * 100 + '%"></div> </div> </td> </tr> ');
}
$('#domain-frequency .overlay').remove();
$('#ad-frequency .overlay').remove();
});
}
</script>