Merge branch 'tomato-RT' into Toastman-RT
[tomato.git] / release / src / router / www / status-webmon.asp
blob01a81768f26c383830a4d511662c0e3b8d734df7
1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN'>
2 <!--
3 Tomato GUI
5 For use with Tomato Firmware only.
6 No part of this file may be used without permission.
7 -->
8 <html>
9 <head>
10 <meta http-equiv='content-type' content='text/html;charset=utf-8'>
11 <meta name='robots' content='noindex,nofollow'>
12 <title>[<% ident(); %>] Status: Web Usage</title>
13 <link rel='stylesheet' type='text/css' href='tomato.css'>
14 <link rel='stylesheet' type='text/css' href='color.css'>
15 <script type='text/javascript' src='tomato.js'></script>
17 <!-- / / / -->
19 <style type='text/css'>
21 #webmon-controls {
22 text-align: right;
23 float: right;
24 margin-right: 5px;
26 #webmon-controls .selected {
27 padding: 0 0px 0 4px;
28 font-weight: bold;
29 text-decoration: underline;
32 </style>
34 <script type='text/javascript' src='debug.js'></script>
36 <script type='text/javascript'>
38 // <% nvram("log_wm,log_wmdmax,log_wmsmax"); %>
40 list = [];
41 wm_domains = [];
42 wm_searches = [];
44 var maxLimit = 0;
45 var maxCount = 50;
46 var lastMaxCount = -1;
48 var queue = [];
49 var xob = null;
50 var cache = [];
51 var new_cache = [];
52 var lock = 0;
54 function clearLog(clear)
56 if (xob) return;
58 xob = new XmlHttp();
59 xob.onCompleted = function(text, xml) {
60 xob = null;
61 E('clear' + clear).innerHTML = '&raquo; <a href="javascript:clearLog(' + clear + ')">Clear</a>';
62 if (!ref.running) ref.once = 1;
63 ref.start();
65 xob.onError = function(ex) {
66 xob = null;
69 xob.post('webmon.cgi', 'clear=' + clear);
70 E('clear' + clear).innerHTML = 'Please wait... <img src="spin.gif" style="vertical-align:top">';
73 function resolve()
75 if ((queue.length == 0) || (xob)) return;
77 xob = new XmlHttp();
78 xob.onCompleted = function(text, xml) {
79 eval(text);
80 for (var i = 0; i < resolve_data.length; ++i) {
81 var r = resolve_data[i];
82 if (r[1] == '') r[1] = r[0];
83 cache[r[0]] = r[1];
84 if (lock == 0) {
85 dg.setName(r[0], r[1]);
86 sg.setName(r[0], r[1]);
89 xob = null;
91 xob.onError = function(ex) {
92 xob = null;
95 xob.post('resolve.cgi', 'ip=' + queue.splice(0, 20).join(','));
98 var ref = new TomatoRefresh('update.cgi', '', 0, 'status_webmon');
100 ref.refresh = function(text)
102 ++lock;
104 try {
105 eval(text);
107 catch (ex) {
108 wm_domains = [];
109 wm_searches = [];
112 new_cache = [];
113 dg.populate();
114 sg.populate();
115 cache = new_cache;
116 new_cache = null;
118 --lock;
121 function showSelectedOption(prev, curr)
123 var e;
125 elem.removeClass('mc' + prev, 'selected'); // safe if prev doesn't exist
126 if ((e = E('mc' + curr)) != null) {
127 elem.addClass(e, 'selected');
128 e.blur();
132 function showMaxCount()
134 if (maxCount == lastMaxCount) return;
135 showSelectedOption(lastMaxCount, maxCount);
136 lastMaxCount = maxCount;
137 ref.postData = 'exec=webmon&arg0=' + maxCount;
140 function switchMaxCount(c)
142 maxCount = c;
143 showMaxCount();
144 if (!ref.running) ref.once = 1;
145 ref.start();
146 cookie.set('webmon-maxcount', maxCount);
149 function WMGrid() { return this; }
150 WMGrid.prototype = new TomatoGrid;
152 WMGrid.prototype.resolveAll = function()
154 var i, ip, row, q;
156 q = [];
157 queue = [];
158 for (i = 1; i < this.tb.rows.length; ++i) {
159 row = this.tb.rows[i];
160 ip = row.getRowData().ip;
161 if (ip.indexOf('<') == -1) {
162 if (!q[ip]) {
163 q[ip] = 1;
164 queue.push(ip);
166 row.style.cursor = 'wait';
169 q = null;
170 resolve();
173 WMGrid.prototype.onClick = function(cell)
175 if ((cell.cellIndex || 0) == 2 /* url */) return;
177 var row = PR(cell);
178 var ip = row.getRowData().ip;
179 if (this.lastClicked != row) {
180 this.lastClicked = row;
181 queue = [];
182 if (ip.indexOf('<') == -1) {
183 queue.push(ip);
184 row.style.cursor = 'wait';
185 resolve();
188 else {
189 this.resolveAll();
193 WMGrid.prototype.setName = function(ip, name)
195 var i, row, data;
197 for (i = this.tb.rows.length - 1; i > 0; --i) {
198 row = this.tb.rows[i];
199 data = row.getRowData();
200 if (data.ip == ip) {
201 data[1] = name + ((ip.indexOf(':') != -1) ? '<br>' : ' ') + '<small>(' + ip + ')</small>';
202 row.setRowData(data);
203 row.cells[1].innerHTML = data[1];
204 row.style.cursor = 'default';
209 WMGrid.prototype.populateData = function(data, url)
211 var a, e, i;
212 var maxl = 45;
213 var cursor;
215 list = [];
216 this.lastClicked = null;
217 this.removeAllData();
218 for (i = 0; i < list.length; ++i) {
219 list[i].time = 0;
220 list[i].ip = '';
221 list[i].value = '';
224 for (i = data.length - 1; i >= 0; --i) {
225 a = data[i];
226 e = {
227 time: a[0],
228 ip: a[1],
229 value: a[2] + ''
231 list.push(e);
234 var dt = new Date();
235 for (i = list.length - 1; i >= 0; --i) {
236 e = list[i];
237 /* IPV6-BEGIN */
238 a = CompressIPv6Address(e.ip);
239 if (a != null) e.ip = a;
240 /* IPV6-END */
241 if (cache[e.ip] != null) {
242 new_cache[e.ip] = cache[e.ip];
243 e.ip = cache[e.ip] + ((e.ip.indexOf(':') != -1) ? '<br>' : ' ') + '<small>(' + e.ip + ')</small>';
244 cursor = 'default';
246 else cursor = null;
247 if (url != 0) {
248 e.value = '<a href="http://' + e.value + '" target="_new">' +
249 (e.value.length > maxl + 3 ? e.value.substr(0, maxl) + '...' : e.value) + '</a>';
251 else {
252 e.value = e.value.replace(/\+/g, ' ');
253 if (e.value.length > maxl + 3)
254 e.value = e.value.substr(0, maxl) + '...';
256 dt.setTime(e.time * 1000);
257 var row = this.insert(-1, e, [dt.toDateString() + ', ' + dt.toLocaleTimeString(),
258 e.ip, e.value], false);
259 if (cursor) row.style.cursor = cursor;
262 list = [];
263 this.resort();
264 this.recolor();
267 WMGrid.prototype.sortCompare = function(a, b)
269 var col = this.sortColumn;
270 var ra = a.getRowData();
271 var rb = b.getRowData();
272 var r;
274 switch (col) {
275 case 0:
276 r = -cmpInt(ra.time, rb.time);
277 break;
278 case 1:
279 var aip = fixIP(ra.ip);
280 var bip = fixIP(rb.ip);
281 if ((aip != null) && (bip != null)) {
282 r = aton(aip) - aton(bip);
283 break;
285 // fall
286 default:
287 r = cmpText(a.cells[col].innerHTML, b.cells[col].innerHTML);
289 return this.sortAscending ? r : -r;
292 var dg = new WMGrid();
294 dg.setup = function() {
295 this.init('dom-grid', 'sort');
296 this.headerSet(['Last Access Time', 'IP Address', 'Domain Name']);
297 this.sort(0);
300 dg.populate = function() {
301 this.populateData(wm_domains, 1);
304 var sg = new WMGrid();
306 sg.setup = function() {
307 this.init('srh-grid', 'sort');
308 this.headerSet(['Search Time', 'IP Address', 'Search Criteria']);
309 this.sort(0);
312 sg.populate = function() {
313 this.populateData(wm_searches, 0);
316 function init()
318 ref.initPage();
320 if (!ref.running) ref.once = 1;
321 ref.start();
324 function earlyInit()
326 if (nvram.log_wm == '1' && (nvram.log_wmdmax != '0' || nvram.log_wmsmax != '0')) {
327 E('webmon').style.display = '';
328 E('wm-disabled').style.display = 'none';
330 maxLimit = nvram.log_wmdmax * 1;
331 if (nvram.log_wmsmax * 1 > maxLimit) maxLimit = nvram.log_wmsmax * 1;
332 if (maxLimit <= 10)
333 E('webmon-mc').style.display = 'none';
334 else {
335 if (maxLimit <= 20) E('mc20').style.display = 'none';
336 if (maxLimit <= 50) E('mc50').style.display = 'none';
337 if (maxLimit <= 100) E('mc100').style.display = 'none';
338 if (maxLimit <= 200) E('mc200').style.display = 'none';
339 if (maxLimit <= 500) E('mc500').style.display = 'none';
340 if (maxLimit <= 1000) E('mc1000').style.display = 'none';
341 if (maxLimit <= 2000) E('mc2000').style.display = 'none';
342 if (maxLimit <= 5000) E('mc5000').style.display = 'none';
345 if (nvram.log_wmdmax == '0') E('webmon-domains').style.display = 'none';
346 if (nvram.log_wmsmax == '0') E('webmon-searches').style.display = 'none';
348 dg.setup();
349 sg.setup();
351 maxCount = fixInt(cookie.get('webmon-maxcount'), 0, maxLimit, 50);
352 showMaxCount();
354 </script>
356 </head>
357 <body onload='init()'>
358 <form id='_fom' action='javascript:{}'>
359 <table id='container' cellspacing=0>
360 <tr><td colspan=2 id='header'>
361 <div class='title'>Tomato</div>
362 <div class='version'>Version <% version(); %></div>
363 </td></tr>
364 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
365 <td id='content'>
366 <div id='ident'><% ident(); %></div>
368 <!-- / / / -->
370 <div id='webmon' style='display:none'>
371 <div id='webmon-domains'>
372 <div class='section-title'>Recently Visited Web Sites</div>
373 <div class='section'>
374 <table id='dom-grid' class='tomato-grid' style="float:left" cellspacing=1></table>
375 &raquo; <a href="webmon_recent_domains?_http_id=<% nv(http_id) %>">Download</a>
376 <div style="float:right;text-align:right;margin-right:5px" id="clear1">
377 &raquo; <a href="javascript:clearLog(1)">Clear</a>
378 </div>
379 </div>
380 </div>
382 <div id='webmon-searches'>
383 <div class='section-title'>Recent Web Searches</div>
384 <div class='section'>
385 <table id='srh-grid' class='tomato-grid' style="float:left" cellspacing=1></table>
386 &raquo; <a href="webmon_recent_searches?_http_id=<% nv(http_id) %>">Download</a>
387 <div style="float:right;text-align:right;margin-right:5px" id="clear2">
388 &raquo; <a href="javascript:clearLog(2)">Clear</a>
389 </div>
390 </div>
391 </div>
393 <div id='webmon-controls'>
394 <div id='webmon-mc'>
395 Show up to&nbsp;
396 <a href='javascript:switchMaxCount(10);' id='mc10'>10,</a>
397 <a href='javascript:switchMaxCount(20);' id='mc20'>20,</a>
398 <a href='javascript:switchMaxCount(50);' id='mc50'>50,</a>
399 <a href='javascript:switchMaxCount(100);' id='mc100'>100,</a>
400 <a href='javascript:switchMaxCount(200);' id='mc200'>200,</a>
401 <a href='javascript:switchMaxCount(500);' id='mc500'>500,</a>
402 <a href='javascript:switchMaxCount(1000);' id='mc1000'>1000,</a>
403 <a href='javascript:switchMaxCount(2000);' id='mc2000'>2000,</a>
404 <a href='javascript:switchMaxCount(5000);' id='mc5000'>5000,</a>
405 <a href='javascript:switchMaxCount(0);' id='mc0'>All</a>&nbsp;
406 <small>available entries</small>
407 </div>
408 &raquo; <a href="admin-log.asp">Web Monitor Configuration</a>
409 <br><br>
411 <script type='text/javascript'>genStdRefresh(1,0,'ref.toggle()');</script>
413 </div>
414 </div>
416 <div id='wm-disabled'>
417 <b>Web Monitoring disabled.</b>
418 <br><br>
419 <a href="admin-log.asp">Enable &raquo;</a>
420 <br><br>
421 </div>
423 <script type='text/javascript'>earlyInit();</script>
425 <!-- / / / -->
427 </td></tr>
428 <tr><td id='footer' colspan=2>&nbsp;</td></tr>
429 </table>
430 </form>
431 </body>
432 </html>