Cosmetics admin-access page
[tomato.git] / release / src / router / www / status-webmon.asp
blob0cc665b151a45e21437c4e182d0e331011b32922
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 <= 50) E('mc50').style.display = 'none';
336 if (maxLimit <= 100) E('mc100').style.display = 'none';
337 if (maxLimit <= 200) E('mc200').style.display = 'none';
338 if (maxLimit <= 500) E('mc500').style.display = 'none';
339 if (maxLimit <= 1000) E('mc1000').style.display = 'none';
340 if (maxLimit <= 2000) E('mc2000').style.display = 'none';
341 if (maxLimit <= 5000) E('mc5000').style.display = 'none';
344 if (nvram.log_wmdmax == '0') E('webmon-domains').style.display = 'none';
345 if (nvram.log_wmsmax == '0') E('webmon-searches').style.display = 'none';
347 dg.setup();
348 sg.setup();
350 maxCount = fixInt(cookie.get('webmon-maxcount'), 0, maxLimit, 50);
351 showMaxCount();
353 </script>
355 </head>
356 <body onload='init()'>
357 <form id='_fom' action='javascript:{}'>
358 <table id='container' cellspacing=0>
359 <tr><td colspan=2 id='header'>
360 <div class='title'>Tomato</div>
361 <div class='version'>Version <% version(); %></div>
362 </td></tr>
363 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
364 <td id='content'>
365 <div id='ident'><% ident(); %></div>
367 <!-- / / / -->
369 <div id='webmon' style='display:none'>
370 <div id='webmon-domains'>
371 <div class='section-title'>Recently Visited Web Sites</div>
372 <div class='section'>
373 <table id='dom-grid' class='tomato-grid' style="float:left" cellspacing=1></table>
374 &raquo; <a href="webmon_recent_domains?_http_id=<% nv(http_id) %>">Download</a>
375 <div style="float:right;text-align:right;margin-right:5px" id="clear1">
376 &raquo; <a href="javascript:clearLog(1)">Clear</a>
377 </div>
378 </div>
379 </div>
381 <div id='webmon-searches'>
382 <div class='section-title'>Recent Web Searches</div>
383 <div class='section'>
384 <table id='srh-grid' class='tomato-grid' style="float:left" cellspacing=1></table>
385 &raquo; <a href="webmon_recent_searches?_http_id=<% nv(http_id) %>">Download</a>
386 <div style="float:right;text-align:right;margin-right:5px" id="clear2">
387 &raquo; <a href="javascript:clearLog(2)">Clear</a>
388 </div>
389 </div>
390 </div>
392 <div id='webmon-controls'>
393 <div id='webmon-mc'>
394 Show up to&nbsp;
395 <a href='javascript:switchMaxCount(10);' id='mc10'>10,</a>
396 <a href='javascript:switchMaxCount(50);' id='mc50'>50,</a>
397 <a href='javascript:switchMaxCount(100);' id='mc100'>100,</a>
398 <a href='javascript:switchMaxCount(200);' id='mc200'>200,</a>
399 <a href='javascript:switchMaxCount(500);' id='mc500'>500,</a>
400 <a href='javascript:switchMaxCount(1000);' id='mc1000'>1000,</a>
401 <a href='javascript:switchMaxCount(2000);' id='mc2000'>2000,</a>
402 <a href='javascript:switchMaxCount(5000);' id='mc5000'>5000,</a>
403 <a href='javascript:switchMaxCount(0);' id='mc0'>All</a>&nbsp;
404 <small>available entries</small>
405 </div>
406 &raquo; <a href="admin-log.asp">Web Monitor Configuration</a>
407 <br><br>
408 <script type='text/javascript'>genStdRefresh(1,3,'ref.toggle()');</script>
409 </div>
410 </div>
412 <div id='wm-disabled'>
413 <b>Web Monitoring disabled.</b>
414 <br><br>
415 <a href="admin-log.asp">Enable &raquo;</a>
416 <br><br>
417 </div>
419 <script type='text/javascript'>earlyInit();</script>
421 <!-- / / / -->
423 </td></tr>
424 <tr><td id='footer' colspan=2>&nbsp;</td></tr>
425 </table>
426 </form>
427 </body>
428 </html>