forked from Jackysi/advancedtomato-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status-webmon.asp
397 lines (344 loc) · 9.93 KB
/
status-webmon.asp
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
<!--
Tomato GUI
Copyright (C) 2006-2010 Jonathan Zarate
http://www.polarcloud.com/tomato/
For use with Tomato Firmware only.
No part of this file may be used without permission.
--><title>Web Usage</title>
<content><style type="text/css">
#webmon-controls {
text-align: right;
float: right;
margin-right: 5px;
}
#webmon-controls .selected {
padding: 0 0px 0 4px;
font-weight: 500;
text-decoration: underline;
}
.tomato-refresh {
float: left;
margin: 0 0 0 -7px;
}
</style>
<script type="text/javascript">
// <% nvram("at_update,tomatoanon_answer,log_wm,log_wmdmax,log_wmsmax"); %>
list = [];
wm_domains = [];
wm_searches = [];
var maxLimit = 0;
var maxCount = 50;
var lastMaxCount = -1;
var queue = [];
var xob = null;
var cache = [];
var new_cache = [];
var lock = 0;
function clearLog(clear)
{
if (xob) return;
xob = new XmlHttp();
xob.onCompleted = function(text, xml) {
xob = null;
E('clear' + clear).innerHTML = '<a class="btn btn-primary btn-small" href="javascript:clearLog(' + clear + ')">Clear Log <i class="icon-cancel"></i></a>';
if (!ref.running) ref.once = 1;
ref.start();
}
xob.onError = function(ex) {
xob = null;
}
xob.post('/webmon.cgi', 'clear=' + clear);
E('clear' + clear).innerHTML = 'Please wait... <div class="spinner"></div>';
}
function resolve()
{
if ((queue.length == 0) || (xob)) return;
xob = new XmlHttp();
xob.onCompleted = function(text, xml) {
eval(text);
for (var i = 0; i < resolve_data.length; ++i) {
var r = resolve_data[i];
if (r[1] == '') r[1] = r[0];
cache[r[0]] = r[1];
if (lock == 0) {
dg.setName(r[0], r[1]);
sg.setName(r[0], r[1]);
}
}
xob = null;
}
xob.onError = function(ex) {
xob = null;
}
xob.post('/resolve.cgi', 'ip=' + queue.splice(0, 20).join(','));
}
var ref = new TomatoRefresh('/update.cgi', '', 0, 'status_webmon_refresh');
ref.refresh = function(text)
{
++lock;
try {
eval(text);
}
catch (ex) {
wm_domains = [];
wm_searches = [];
}
new_cache = [];
dg.populate();
sg.populate();
cache = new_cache;
new_cache = null;
--lock;
}
function showSelectedOption(prev, curr)
{
var e;
elem.removeClass('mc' + prev, 'selected'); // safe if prev doesn't exist
if ((e = E('mc' + curr)) != null) {
elem.addClass(e, 'selected');
e.blur();
}
}
function showMaxCount()
{
if (maxCount == lastMaxCount) return;
showSelectedOption(lastMaxCount, maxCount);
lastMaxCount = maxCount;
ref.postData = 'exec=webmon&arg0=' + maxCount;
}
function switchMaxCount(c)
{
maxCount = c;
showMaxCount();
if (!ref.running) ref.once = 1;
ref.start();
cookie.set('webmon-maxcount', maxCount);
}
function WMGrid() { return this; }
WMGrid.prototype = new TomatoGrid;
WMGrid.prototype.resolveAll = function()
{
var i, ip, row, q;
q = [];
queue = [];
for (i = 1; i < this.tb.rows.length; ++i) {
row = this.tb.rows[i];
ip = row.getRowData().ip;
if (ip.indexOf('<') == -1) {
if (!q[ip]) {
q[ip] = 1;
queue.push(ip);
}
row.style.cursor = 'wait';
}
}
q = null;
resolve();
}
WMGrid.prototype.onClick = function(cell)
{
if ((cell.cellIndex || 0) == 2 /* url */) return;
var row = PR(cell);
var ip = row.getRowData().ip;
if (this.lastClicked != row) {
this.lastClicked = row;
queue = [];
if (ip.indexOf('<') == -1) {
queue.push(ip);
row.style.cursor = 'wait';
resolve();
}
}
else {
this.resolveAll();
}
}
WMGrid.prototype.setName = function(ip, name)
{
var i, row, data;
for (i = this.tb.rows.length - 1; i > 0; --i) {
row = this.tb.rows[i];
data = row.getRowData();
if (data.ip == ip) {
data[1] = name + ((ip.indexOf(':') != -1) ? '<br>' : ' ') + '<small>(' + ip + ')</small>';
row.setRowData(data);
row.cells[1].innerHTML = data[1];
row.style.cursor = 'default';
}
}
}
WMGrid.prototype.populateData = function(data, url)
{
var a, e, i;
var maxl = 45;
var cursor;
list = [];
this.lastClicked = null;
this.removeAllData();
for (i = 0; i < list.length; ++i) {
list[i].time = 0;
list[i].ip = '';
list[i].value = '';
}
for (i = data.length - 1; i >= 0; --i) {
a = data[i];
e = {
time: a[0],
ip: a[1],
value: a[2] + ''
};
list.push(e);
}
var dt = new Date();
for (i = list.length - 1; i >= 0; --i) {
e = list[i];
/* IPV6-BEGIN */
a = CompressIPv6Address(e.ip);
if (a != null) e.ip = a;
/* IPV6-END */
if (cache[e.ip] != null) {
new_cache[e.ip] = cache[e.ip];
e.ip = cache[e.ip] + ((e.ip.indexOf(':') != -1) ? '<br>' : ' ') + '<small>(' + e.ip + ')</small>';
cursor = 'default';
}
else cursor = null;
if (url != 0) {
e.value = '<a href="http://' + e.value + '" target="_new">' +
(e.value.length > maxl + 3 ? e.value.substr(0, maxl) + '...' : e.value) + '</a>';
}
else {
e.value = e.value.replace(/\+/g, ' ');
if (e.value.length > maxl + 3)
e.value = e.value.substr(0, maxl) + '...';
}
dt.setTime(e.time * 1000);
var row = this.insert(-1, e, [dt.toDateString() + ', ' + dt.toLocaleTimeString(),
e.ip, e.value], false);
if (cursor) row.style.cursor = cursor;
}
list = [];
this.resort();
this.recolor();
}
WMGrid.prototype.sortCompare = function(a, b)
{
var col = this.sortColumn;
var ra = a.getRowData();
var rb = b.getRowData();
var r;
switch (col) {
case 0:
r = -cmpInt(ra.time, rb.time);
break;
case 1:
var aip = fixIP(ra.ip);
var bip = fixIP(rb.ip);
if ((aip != null) && (bip != null)) {
r = aton(aip) - aton(bip);
break;
}
// fall
default:
r = cmpText(a.cells[col].innerHTML, b.cells[col].innerHTML);
}
return this.sortAscending ? r : -r;
}
var dg = new WMGrid();
dg.setup = function() {
this.init('dom-grid', 'sort');
this.headerSet(['Last Access Time', 'IP Address', 'Domain Name']);
this.sort(0);
}
dg.populate = function() {
this.populateData(wm_domains, 1);
}
var sg = new WMGrid();
sg.setup = function() {
this.init('srh-grid', 'sort');
this.headerSet(['Search Time', 'IP Address', 'Search Criteria']);
this.sort(0);
}
sg.populate = function() {
this.populateData(wm_searches, 0);
}
function earlyInit() {
$('#webmon-controls').before(genStdRefresh(1,1,'ref.toggle()'));
ref.initPage(3000,3);
if (nvram.log_wm == '1' && (nvram.log_wmdmax != '0' || nvram.log_wmsmax != '0')) {
E('webmon').style.display = '';
E('wm-disabled').style.display = 'none';
maxLimit = nvram.log_wmdmax * 1;
if (nvram.log_wmsmax * 1 > maxLimit) maxLimit = nvram.log_wmsmax * 1;
if (maxLimit <= 10)
E('webmon-mc').style.display = 'none';
else {
if (maxLimit <= 20) E('mc20').style.display = 'none';
if (maxLimit <= 50) E('mc50').style.display = 'none';
if (maxLimit <= 100) E('mc100').style.display = 'none';
if (maxLimit <= 200) E('mc200').style.display = 'none';
if (maxLimit <= 500) E('mc500').style.display = 'none';
if (maxLimit <= 1000) E('mc1000').style.display = 'none';
if (maxLimit <= 2000) E('mc2000').style.display = 'none';
if (maxLimit <= 5000) E('mc5000').style.display = 'none';
}
if (nvram.log_wmdmax == '0') E('webmon-domains').style.display = 'none';
if (nvram.log_wmsmax == '0') E('webmon-searches').style.display = 'none';
}
dg.setup();
sg.setup();
maxCount = fixInt(cookie.get('webmon-maxcount'), 0, maxLimit, 50);
showMaxCount();
if (!ref.running) ref.once = 1;
ref.start();
}
</script>
<div class="row" id="webmon" style="display:none">
<div class="col-lg-12">
<div id="webmon-domains" class="box">
<div class="heading">Recently Visited Web Sites</div>
<div class="content">
<table id="dom-grid" class="line-table"></table>
<br /><div id="clear1">
<a class="btn btn-primary btn-small" href="javascript:clearLog(1)">Clear Log <i class="icon-cancel"></i></a>
<a class="btn btn-small" href="webmon_recent_domains?_http_id=<% nv(http_id) %>">Download <i class="icon-download"></i></a>
</div>
</div>
</div>
</div>
<div class="col-lg-12">
<div id="webmon-searches" class="box">
<div class="heading">Recent Web Searches</div>
<div class="content">
<table id="srh-grid" class="line-table"></table>
<br /><div id="clear2">
<a class="btn btn-primary btn-small" href="javascript:clearLog(2)">Clear Log <i class="icon-cancel"></i></a>
<a class="btn btn-small" href="webmon_recent_searches?_http_id=<% nv(http_id) %>">Download <i class="icon-download"></i></a>
</div>
</div>
</div>
</div>
<div id="webmon-controls">
<div id="webmon-mc">
Show up to
<a href="javascript:switchMaxCount(10);" id="mc10">10,</a>
<a href="javascript:switchMaxCount(20);" id="mc20">20,</a>
<a href="javascript:switchMaxCount(50);" id="mc50">50,</a>
<a href="javascript:switchMaxCount(100);" id="mc100">100,</a>
<a href="javascript:switchMaxCount(200);" id="mc200">200,</a>
<a href="javascript:switchMaxCount(500);" id="mc500">500,</a>
<a href="javascript:switchMaxCount(1000);" id="mc1000">1000,</a>
<a href="javascript:switchMaxCount(2000);" id="mc2000">2000,</a>
<a href="javascript:switchMaxCount(5000);" id="mc5000">5000,</a>
<a href="javascript:switchMaxCount(0);" id="mc0">All</a>
<small>available entries</small>
</div>
» <a class="ajaxload" href="admin-log.asp">Web Monitor Configuration</a>
<br><br>
</div>
</div>
<div id="wm-disabled" class="alert alert-info icon">
<h5>Web Monitoring disabled</h5>
Please <a class="ajaxload" href="/#admin-log.asp">enable</a> web monitoring in order to view information on this page.
</div>
<script type="text/javascript">earlyInit();</script>
</content>