forked from yaosj2k/dnsforwarder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StatisticTemplate.html
executable file
·474 lines (400 loc) · 10.7 KB
/
StatisticTemplate.html
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<!DOCTYPE html>
<html>
<head>
<!-- INSERT HERE -->
<!-- FORMAT:
<script type="text/javascript">
var StartUpTime = %d;
var LastStatistic = %d;
var InfoArray = [
{ Domain : "www.google.com",
Total : 2,
RaF : 1,
Hosts : 1,
Cache : 1,
UDP : 1,
TCP : 1,
BlockedMsg : 1
},
{ Domain : "www.google.com.hk",
Total : 1,
RaF : 2,
Hosts : 2,
Cache : 2,
UDP : 2,
TCP : 2,
BlockedMsg : 5
}
];
var Sum = { Total : 2,
RaF : 1,
Hosts : 1,
Cache : 1,
UDP : 1,
TCP : 1,
BlockedMsg : 1
};
</script>
-->
<script type="text/javascript">
var ST = new Date(StartUpTime * 1000);
var LT = new Date(LastStatistic * 1000);
</script>
<title>Domain Statistic</title>
<base target="_blank" />
<style type="text/css">
body {
margin-right: 0px;
margin-left: 0px;
}
.clearboth {
float: left;
clear: both;
width: 100%;
}
.mainmargin {
margin-left: 10px;
}
.topmargin {
margin-top: 10px;
}
h1 {
display: block;
color: #4078C0;
}
.top_menu li {
float: left;
color: #777777;
display: block;
width: 100px;
padding: 10px 0 10px 0;
text-align: center;
vertical-align: middle;
cursor: pointer;
}
.top_menu li:hover:not(.active) {
color: #333333;
}
.top_menu li.active {
background-color: #E7E7E7;
color: #555555;
}
.top_menu ul {
overflow: hidden;
list-style-type: none;
margin: 10px 0 10px 0;
padding: 0;
background-color: #F8F8F8;
width: 100%;
}
table {
border-collapse: collapse;
border: 1px solid #E7E7E7;
margin-bottom: 10px;
}
.displaynone{
display: none;
}
th {
padding: 5px;
font-weight: bold;
}
th a {
color: #4078C0;
}
tr {
border-bottom: 1px solid #E7E7E7;
}
td {
padding: 5px;
}
</style>
</head>
<body>
<h1 class="mainmargin clearboth">Domain Statistics</h1>
<div class="top_menu clearboth">
<ul>
<li data-model="Overview" class="menu_item active">Overview</li>
<li data-model="3-level" class="menu_item">3-level</li>
<li data-model="Details" class="menu_item">Details</li>
</ul>
<script type="text/javascript">
function MenuSwitching()
{
var model = this.getAttribute("data-model");
var li_a = document.getElementsByClassName("menu_item");
for( var i = 0; i < li_a.length; ++i )
{
li_a[i].classList.remove("active");
}
this.classList.add("active");
var allframes = document.getElementsByClassName("mainframe");
for( var i = 0; i < allframes.length; ++i )
{
if( allframes[i].getAttribute("data-model") != model )
{
allframes[i].classList.add("displaynone");
} else {
allframes[i].classList.remove("displaynone");
}
}
}
var li_a = document.getElementsByClassName("menu_item");
for( var i = 0; i < li_a.length; ++i )
{
li_a[i].addEventListener("click", MenuSwitching);
}
</script>
</div>
<div data-model="Overview" class="mainframe mainmargin clearboth">
<p class="mainmargin clearboth" style="margin: 0px;">
Program startup time : <script type="text/javascript">document.write(ST.toString());</script><br />
Last statistic : <script type="text/javascript">document.write(LT.toString());</script><br />
Elapsed time : <script type="text/javascript">document.write((LastStatistic - StartUpTime) + "s");</script><br />
<br />
Requests per minute : <script type="text/javascript">document.write((Sum.Total / (LastStatistic - StartUpTime)) * 60);</script><br />
<script type="text/javascript">
if( (Sum.UDP + Sum.TCP + Sum.Cache) > 0 )
{
document.write("Cache utilization : " + ((Sum.Cache / (Sum.UDP + Sum.TCP + Sum.Cache)) * 100) + "%<br />");
}
</script>
</p>
</div>
<div data-model="3-level" class="mainframe mainmargin clearboth displaynone">
<script type="text/javascript">
function FindDotPosition(domain, n)
{
domain = "." + domain;
var p = 0;
while( (n--) > 0 )
{
p = domain.lastIndexOf(".");
if( p < 0 )
{
return -1;
}
domain = domain.substr(0, p);
}
return p;
}
function GetLevel1OfADomian(domain)
{
return domain.substr(FindDotPosition(domain, 1));
}
function GetLevel2OfADomian(domain)
{
var p = FindDotPosition(domain, 2);
if( p < 0 )
{
return undefined;
} else {
return domain.substr(p);
}
}
function GetLevel3OfADomian(domain)
{
var p = FindDotPosition(domain, 3);
if( p < 0 )
{
return undefined;
} else {
return domain.substr(p);
}
}
</script>
<table>
<tr>
<th>Top Level Domain</th>
<th>Count</th>
</tr>
<tbody>
<script type="text/javascript">
var l1 = [];
for( var i = 0; i < InfoArray.length; ++i )
{
var d = GetLevel1OfADomian(InfoArray[i].Domain);
if( d in l1 )
{
l1[d] += InfoArray[i].Total;
} else {
l1[d] = InfoArray[i].Total;
}
}
for( var k in l1 )
{
var tmphtml = "";
tmphtml += "<tr>";
tmphtml += ("<td>" + k + "</td>");
tmphtml += ("<td>" + l1[k] + "</td>");
tmphtml += "</tr>";
document.write(tmphtml);
}
</script>
</tbody>
</table>
<table>
<tr>
<th>Second Level Domain</th>
<th>Count</th>
</tr>
<tbody>
<script type="text/javascript">
var l1 = [];
for( var i = 0; i < InfoArray.length; ++i )
{
var d = GetLevel2OfADomian(InfoArray[i].Domain);
if( d == undefined )
{
continue;
}
if( d in l1 )
{
l1[d] += InfoArray[i].Total;
} else {
l1[d] = InfoArray[i].Total;
}
}
for( var k in l1 )
{
var tmphtml = "";
tmphtml += "<tr>";
tmphtml += ("<td>" + k + "</td>");
tmphtml += ("<td>" + l1[k] + "</td>");
tmphtml += "</tr>";
document.write(tmphtml);
}
</script>
</tbody>
</table>
<table>
<tr>
<th>Third Level Domain</th>
<th>Count</th>
</tr>
<tbody>
<script type="text/javascript">
var l1 = [];
for( var i = 0; i < InfoArray.length; ++i )
{
var d = GetLevel3OfADomian(InfoArray[i].Domain);
if( d == undefined )
{
continue;
}
if( d in l1 )
{
l1[d] += InfoArray[i].Total;
} else {
l1[d] = InfoArray[i].Total;
}
}
for( var k in l1 )
{
var tmphtml = "";
tmphtml += "<tr>";
tmphtml += ("<td>" + k + "</td>");
tmphtml += ("<td>" + l1[k] + "</td>");
tmphtml += "</tr>";
document.write(tmphtml);
}
</script>
</tbody>
</table>
</div>
<div data-model="Details" class="mainframe mainmargin clearboth displaynone">
<script type="text/javascript">
function GetParameter(name)
{
var Pattern = new RegExp("[\\?&]" + name + "=[a-z0-9]+");
var PatternE = Pattern.exec(window.location.href);
if( PatternE != null )
{
return PatternE.toString().split("=")[1];
} else {
return "total";
}
}
function InfoSortDomain(i1, i2)
{
return i1.Domain.localeCompare(i2.Domain);
}
function InfoSortTotal(i1, i2)
{
return i2.Total - i1.Total;
}
function InfoSortRaF(i1, i2)
{
return i2.RaF - i1.RaF;
}
function InfoSortHosts(i1, i2)
{
return i2.Hosts - i1.Hosts;
}
function InfoSortCache(i1, i2)
{
return i2.Cache - i1.Cache;
}
function InfoSortUDP(i1, i2)
{
return i2.UDP - i1.UDP;
}
function InfoSortTCP(i1, i2)
{
return i2.TCP - i1.TCP;
}
function InfoSortBlockedMsg(i1, i2)
{
return i2.BlockedMsg - i1.BlockedMsg;
}
function ReSort(sortfunc)
{
InfoArray.sort(sortfunc);
var tb = document.getElementById("details_tbody");
var tmphtml = "";
for( var i = 0; i < InfoArray.length; ++i )
{
tmphtml += "<tr>";
tmphtml += ("<td><a href=http://" + InfoArray[i].Domain + ">" + InfoArray[i].Domain + "</a></td>");
tmphtml += ("<td>" + InfoArray[i].Total + "</td>");
tmphtml += ("<td>" + InfoArray[i].RaF + "</td>");
tmphtml += ("<td>" + InfoArray[i].Hosts + "</td>");
tmphtml += ("<td>" + InfoArray[i].Cache + "</td>");
tmphtml += ("<td>" + InfoArray[i].UDP + "</td>");
tmphtml += ("<td>" + InfoArray[i].TCP + "</td>");
tmphtml += ("<td>" + InfoArray[i].BlockedMsg + "</td>");
tmphtml += "</tr>";
}
tb.innerHTML = tmphtml;
}
</script>
<table>
<tr>
<th><a href="javascript:ReSort(InfoSortDomain);" target="_self">Domain</a></th>
<th><a href="javascript:ReSort(InfoSortTotal);" target="_self">Total</a></th>
<th><a href="javascript:ReSort(InfoSortRaF);" target="_self">Refused&Failed</a></th>
<th><a href="javascript:ReSort(InfoSortHosts);" target="_self">Hosts</a></th>
<th><a href="javascript:ReSort(InfoSortCache);" target="_self">Cache</a></th>
<th><a href="javascript:ReSort(InfoSortUDP);" target="_self">UDP</a></th>
<th><a href="javascript:ReSort(InfoSortTCP);" target="_self">TCP</a></th>
<th><a href="javascript:ReSort(InfoSortBlockedMsg);" target="_self">BlockedMsg</a></th>
</tr>
<tbody id="details_tbody">
<script type="text/javascript">
ReSort(InfoSortTotal);
</script>
</tbody>
<tr>
<td>Sum : <script type="text/javascript">document.write(InfoArray.length);</script></td> <!-- Domain -->
<td><script type="text/javascript">document.write(Sum.Total);</script></td> <!-- Total -->
<td><script type="text/javascript">document.write(Sum.RaF);</script></td> <!-- Refused&Failed -->
<td><script type="text/javascript">document.write(Sum.Hosts);</script></td> <!-- Hosts -->
<td><script type="text/javascript">document.write(Sum.Cache);</script></td> <!-- Cache -->
<td><script type="text/javascript">document.write(Sum.UDP);</script></td> <!-- UDP -->
<td><script type="text/javascript">document.write(Sum.TCP);</script></td> <!-- TCP -->
<td><script type="text/javascript">document.write(Sum.BlockedMsg);</script></td> <!-- BlockedMsg -->
</tr>
</table>
</div>
</body>
</html>