UI cleanup, phase 2 (partially cosmetic)
[tomato.git] / release / src-rt-6.x.4708 / router / www / ipt-daily.asp
blobf85d6b83aaebb7f1c9e2777801d26dd0af71e6a8
1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN'>
2 <!--
3 Tomato GUI
4 Copyright (C) 2006-2010 Jonathan Zarate
5 http://www.polarcloud.com/tomato/
7 IP Traffic enhancements
8 Copyright (C) 2011 Augusto Bott
9 http://code.google.com/p/tomato-sdhc-vlan/
11 For use with Tomato Firmware only.
12 No part of this file may be used without permission.
13 -->
14 <html>
15 <head>
16 <meta http-equiv='content-type' content='text/html;charset=utf-8'>
17 <meta name='robots' content='noindex,nofollow'>
18 <title>[<% ident(); %>] IP Traffic: Daily History</title>
19 <link rel='stylesheet' type='text/css' href='tomato.css'>
20 <% css(); %>
21 <script type='text/javascript' src='tomato.js'></script>
23 <!-- / / / -->
25 <style type='text/css'>
26 #daily-grid .co3,
27 #daily-grid .co4,
28 #daily-grid .co5 {
29 text-align: right;
31 </style>
33 <!-- / / / -->
35 <script type='text/javascript' src='debug.js'></script>
36 <script type='text/javascript' src='bwm-hist.js'></script>
37 <script type='text/javascript' src='bwm-common.js'></script>
38 <script type='text/javascript' src='interfaces.js'></script>
40 <script type='text/javascript'>
41 // <% nvram("wan_ifname,lan_ifname,wl_ifname,wan_proto,wan_iface,web_svg,cstats_enable,cstats_colors,dhcpd_static,lan_ipaddr,lan_netmask,lan1_ipaddr,lan1_netmask,lan2_ipaddr,lan2_netmask,lan3_ipaddr,lan3_netmask"); %>
43 // <% devlist(); %>
45 try {
46 // <% ipt_bandwidth("daily"); %>
48 catch (ex) {
49 daily_history = [];
51 cstats_busy = 0;
52 if (typeof(daily_history) == 'undefined') {
53 daily_history = [];
54 cstats_busy = 1;
58 var filterip = [];
59 var filteripe = [];
60 var filteripe_before = [];
61 var dateFormat = -1;
62 var scale = -1;
64 hostnamecache = [];
66 function genData() {
67 var w, i, h, t;
69 w = window.open('', 'tomato_ipt_data_d');
70 w.document.writeln('<pre>');
71 for (i = 0; i < daily_history.length; ++i) {
72 h = daily_history[i];
73 t = getYMD(h[0]);
74 w.document.writeln([t[0], t[1] + 1, t[2], h[1], h[2], h[3]].join(','));
76 w.document.writeln('</pre>');
77 w.document.close();
80 function getYMD(n) {
81 // [y,m,d]
82 return [(((n >> 16) & 0xFF) + 1900), ((n >>> 8) & 0xFF), (n & 0xFF)];
85 var dg = new TomatoGrid();
87 dg.setup = function() {
88 this.init('daily-grid', 'sort');
89 this.headerSet(['Date', 'Host', 'Download', 'Upload', 'Total']);
92 function redraw() {
93 var i, b, d;
94 var fskip;
95 var tx = 0;
96 var rx = 0;
97 var hostslisted = [];
98 var subnetslisted = [];
100 if (daily_history.length > 0) {
101 dg.removeAllData();
102 for (i = 0; i < daily_history.length; ++i) {
103 fskip=0;
104 b = daily_history[i];
106 if (E('_f_ignorezeroes').checked)
107 if ((b[2] < 1) || (b[3] < 1))
108 continue;
110 if (E('_f_begin_date').value.toString() != '0') {
111 if (b[0] < E('_f_begin_date').value)
112 continue;
115 if (E('_f_end_date').value.toString() != '0') {
116 if (b[0] > E('_f_end_date').value)
117 continue;
120 if (filteripe.length>0) {
121 fskip = 0;
122 for (var x = 0; x < filteripe.length; ++x) {
123 if (b[1] == filteripe[x]){
124 fskip=1;
125 break;
128 if (fskip == 1) continue;
131 if (filterip.length>0) {
132 fskip = 1;
133 for (var x = 0; x < filterip.length; ++x) {
134 if (b[1] == filterip[x]){
135 fskip=0;
136 break;
139 if (fskip == 1) continue;
142 if ((b[1] == getNetworkAddress(nvram.lan_ipaddr,nvram.lan_netmask)) ||
143 (b[1] == getNetworkAddress(nvram.lan1_ipaddr,nvram.lan1_netmask)) ||
144 (b[1] == getNetworkAddress(nvram.lan2_ipaddr,nvram.lan2_netmask)) ||
145 (b[1] == getNetworkAddress(nvram.lan3_ipaddr,nvram.lan3_netmask))) {
146 if(E('_f_subnet').checked == 0) {
147 continue;
148 } else {
149 subnetslisted.push(b[1]);
151 } else {
152 hostslisted.push(b[1]);
153 rx += b[2];
154 tx += b[3];
157 if (hostslisted.length > 0) {
158 hostslisted.sort();
159 for (var j = 1; j < hostslisted.length; j++ ) {
160 if (hostslisted[j] === hostslisted[j - 1]) {
161 hostslisted.splice(j--, 1);
166 if (subnetslisted.length > 0) {
167 subnetslisted.sort();
168 for (var j = 1; j < subnetslisted.length; j++ ) {
169 if (subnetslisted[j] === subnetslisted[j - 1]) {
170 subnetslisted.splice(j--, 1);
175 var h = b[1];
176 if (E('_f_hostnames').checked) {
177 if(hostnamecache[b[1]] != null) {
178 h = hostnamecache[b[1]] + ((b[1].indexOf(':') != -1) ? '<br>' : ' ') + '<small>(' + b[1] + ')</small>';
181 if (E('_f_shortcuts').checked) {
182 h = h + '<br><small>';
183 h = h + '<a href="javascript:viewQosDetail(' + i + ')" title="View QoS Details">[qosdetails]</a>';
184 h = h + '<a href="javascript:viewQosCTrates(' + i + ')" title="View transfer rates per connection">[qosrates]</a>';
185 h = h + '<a href="javascript:viewIptDetail(' + i + ')" title="View real-time IP Traffic for this address">[iptraf]</a>';
186 h = h + '<a href="javascript:addExcludeList(' + i + ')" title="Filter out this address">[hide]</a>';
187 h = h + '</small>';
189 var ymd = getYMD(b[0]);
190 d = [ymdText(ymd[0], ymd[1], ymd[2]), h, rescale(b[2]), rescale(b[3]), rescale(b[2]+b[3])];
191 dg.insertData(-1, d);
194 dg.resort();
195 dg.recolor();
196 dg.footerSet([
197 'Total',
198 ('<small><i>(' +
199 (((hostslisted.length > 0) || (subnetslisted.length > 0)) ?
200 ((hostslisted.length > 0) ? (hostslisted.length + ' hosts') : '') +
201 (((hostslisted.length > 0) && (subnetslisted.length > 0)) ? ', ' : '') +
202 ((subnetslisted.length > 0) ? (subnetslisted.length + ' subnets') : '')
203 : 'no data') +
204 ')</i></small>'),
205 rescale(rx),
206 rescale(tx),
207 rescale(rx+tx)]);
211 function popupWindow(v) {
212 window.open(v, '', 'width=1000,height=600,toolbar=no,menubar=no,scrollbars=yes,resizable=yes');
215 function viewQosDetail(n) {
216 cookie.set('qos_filterip', [daily_history[n][1]], 1);
217 popupWindow('qos-detailed.asp');
220 function viewQosCTrates(n) {
221 cookie.set('qos_filterip', [daily_history[n][1]], 1);
222 popupWindow('qos-ctrate.asp');
225 function viewIptDetail(n) {
226 cookie.set('ipt_filterip', [daily_history[n][1]], 1);
227 popupWindow('ipt-details.asp');
230 function addExcludeList(n) {
231 if (E('_f_filter_ipe').value.length<6) {
232 E('_f_filter_ipe').value = daily_history[n][1];
233 } else {
234 if (E('_f_filter_ipe').value.indexOf(daily_history[n][1]) < 0) {
235 E('_f_filter_ipe').value = E('_f_filter_ipe').value + ',' + daily_history[n][1];
238 dofilter();
241 dg.dataToView = function(data) {
242 return(data);
245 dg.sortCompare = function(a, b) {
246 var col = this.sortColumn;
247 var da = a.getRowData();
248 var db = b.getRowData();
249 var r = 0;
250 switch (col) {
251 case 0: // Date
252 case 1: // Hostname
253 r = cmpIP(da[col], db[col]);
254 if (r == 0)
255 r = cmpText(da[col], db[col]);
256 break;
257 case 2: // Download
258 case 3: // Upload
259 case 4: // Total
260 r = cmpFloat(da[col].replace(/,/g,""), db[col].replace(/,/g,""));
261 break;
263 return this.sortAscending ? r : -r;
266 function init_filter_dates() {
267 var dates = [];
268 if (daily_history.length > 0) {
269 for (var i = 0; i < daily_history.length; ++i) {
270 dates.push('0x' + daily_history[i][0].toString(16));
272 if (dates.length > 0) {
273 dates.sort();
274 for (var j = 1; j < dates.length; j++ ) {
275 if (dates[j] === dates[j - 1]) {
276 dates.splice(j--, 1);
281 var b = E('_f_begin_date');
282 var e = E('_f_end_date');
283 var d = new Date();
284 for (var i = 0; i < dates.length; ++i) {
285 var ymd = getYMD(dates[i]);
286 b.options[i+1] = new Option(ymdText(ymd[0], ymd[1], ymd[2]), dates[i], false, ((ymd[0]==d.getFullYear()) && (ymd[1]==d.getMonth()) && (ymd[2]==d.getDate()) ));
287 e.options[i+1] = new Option(ymdText(ymd[0], ymd[1], ymd[2]), dates[i], false, ((ymd[0]==d.getFullYear()) && (ymd[1]==d.getMonth()) && (ymd[2]==d.getDate()) ));
291 function update_filter_dates(b) {
292 for (var i = 0; i < b.options.length; ++i) {
293 if(b.options[i].value.toString() != '0') {
294 var ymd = getYMD(b.options[i].value);
295 b.options[i].text = ymdText(ymd[0], ymd[1], ymd[2]);
300 function init() {
302 if (nvram.cstats_enable != '1') return;
304 var c;
306 init_filter_dates();
308 populateCache();
310 if ((c = '<% cgi_get("ipt_filterip"); %>') != '') {
311 if (c.length>6) {
312 E('_f_begin_date').value = 0;
313 E('_f_end_date').value = 0;
314 E('_f_filter_ip').value = c;
315 filterip = c.split(',');
319 if ((c = cookie.get('ipt_filterip')) != null) {
320 cookie.set('ipt_filterip', '', 0);
321 if (c.length>6) {
322 E('_f_begin_date').value = 0;
323 E('_f_end_date').value = 0;
324 E('_f_filter_ip').value = E('_f_filter_ip').value + ((E('_f_filter_ip').value.length > 0) ? ',' : '') + c;
325 filterip.push(c.split(','));
329 if ((c = cookie.get('ipt_addr_hidden')) != null) {
330 if (c.length>6) {
331 E('_f_filter_ipe').value = c;
332 filteripe = c.split(',');
336 filteripe_before = filteripe;
338 dateFormat = fixInt(cookie.get('ipt_history_dafm'), 0, 3, 0);
339 E('_f_dafm').value = dateFormat;
341 scale = fixInt(cookie.get('ipt_history_scale'), 0, 2, 0);
342 E('_f_scale').value = scale;
344 E('_f_subnet').checked = (((c = cookie.get('ipt_history_subnet')) != null) && (c == '1'));
346 E('_f_hostnames').checked = (((c = cookie.get('ipt_history_hostnames')) != null) && (c == '1'));
348 E('_f_shortcuts').checked = (((c = cookie.get('ipt_history_shortcuts')) != null) && (c == '1'));
350 E('_f_ignorezeroes').checked = (((c = cookie.get('ipt_history_ignorezeroes')) != null) && (c == '1'));
352 if (((c = cookie.get('ipt_history_options_vis')) != null) && (c == '1')) {
353 toggleVisibility("options");
356 dg.setup();
358 redraw();
361 function toggleVisibility(whichone) {
362 if(E('sesdiv' + whichone).style.display=='') {
363 E('sesdiv' + whichone).style.display='none';
364 E('sesdiv' + whichone + 'showhide').innerHTML='(Click here to show)';
365 cookie.set('ipt_history_' + whichone + '_vis', 0);
366 } else {
367 E('sesdiv' + whichone).style.display='';
368 E('sesdiv' + whichone + 'showhide').innerHTML='(Click here to hide)';
369 cookie.set('ipt_history_' + whichone + '_vis', 1);
373 function dofilter() {
374 var i;
376 if (E('_f_filter_ip').value.length>0) {
377 filterip = E('_f_filter_ip').value.split(',');
378 for (i = 0; i < filterip.length; ++i) {
379 if ((filterip[i] = fixIP(filterip[i])) == null) {
380 filterip.splice(i,1);
383 E('_f_filter_ip').value = (filterip.length > 0) ? filterip.join(',') : '';
384 } else {
385 filterip = [];
388 if (E('_f_filter_ipe').value.length>0) {
389 filteripe = E('_f_filter_ipe').value.split(',');
390 for (i = 0; i < filteripe.length; ++i) {
391 if ((filteripe[i] = fixIP(filteripe[i])) == null) {
392 filteripe.splice(i,1);
395 E('_f_filter_ipe').value = (filteripe.length > 0) ? filteripe.join(',') : '';
396 } else {
397 filteripe = [];
400 if (filteripe_before != filteripe) {
401 cookie.set('ipt_addr_hidden', (filteripe.length > 0) ? filteripe.join(',') : '', 1);
402 filteripe_before = filteripe;
405 redraw();
408 function verifyFields(focused, quiet) {
409 dateFormat = E('_f_dafm').value * 1;
410 cookie.set('ipt_history_dafm', E('_f_dafm').value, 31);
412 scale = E('_f_scale').value * 1;
413 cookie.set('ipt_history_scale', E('_f_scale').value, 2);
415 cookie.set('ipt_history_subnet', (E('_f_subnet').checked ? '1' : '0'), 1);
417 cookie.set('ipt_history_hostnames', (E('_f_hostnames').checked ? '1' : '0'), 1);
419 cookie.set('ipt_history_shortcuts', (E('_f_shortcuts').checked ? '1' : '0'), 1);
421 cookie.set('ipt_history_ignorezeroes', (E('_f_ignorezeroes').checked ? '1' : '0'), 1);
423 update_filter_dates(E('_f_begin_date'));
424 update_filter_dates(E('_f_end_date'));
426 if ((E('_f_begin_date').value > E('_f_end_date').value) && ( E('_f_end_date').value != '0')) {
427 var tmp = E('_f_begin_date').value;
428 E('_f_begin_date').value = E('_f_end_date').value;
429 E('_f_end_date').value = tmp;
432 dofilter();
433 return 1;
435 </script>
436 </head>
437 <body onload='init()'>
438 <form>
439 <table id='container' cellspacing=0>
440 <tr><td colspan=2 id='header'>
441 <div class='title'>Tomato</div>
442 <div class='version'>Version <% version(); %></div>
443 </td></tr>
444 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
445 <td id='content'>
446 <div id='ident'><% ident(); %></div>
448 <!-- / / / -->
450 <div id='cstats'>
451 <div class='section-title'>IP Traffic Daily History</div>
452 <div class='section'>
453 <table id='daily-grid' class='tomato-grid' cellspacing=0 style='height:auto'></table>
454 </div>
456 <div class='section-title'>Options <small><i><a href='javascript:toggleVisibility("options");'><span id='sesdivoptionsshowhide'>(Click here to show)</span></a></i></small></div>
457 <div class='section' id='sesdivoptions' style='display:none'>
458 <script type='text/javascript'>
459 var c;
460 c = [];
461 c.push({ title: 'List only these IPs', name: 'f_filter_ip', size: 50, maxlen: 255, type: 'text', suffix: ' <small>(comma separated list)</small>' });
462 c.push({ title: 'Exclude these IPs', name: 'f_filter_ipe', size: 50, maxlen: 255, type: 'text', suffix: ' <small>(comma separated list)</small>' });
463 c.push({ title: 'Date Range', multi: [ { name: 'f_begin_date', type: 'select', options: [['0', 'Any']], suffix: ' - ' }, { name: 'f_end_date', type: 'select', options: [['0', 'Any']] } ] } );
464 c.push({ title: 'Date Format', name: 'f_dafm', type: 'select', options: [['0', 'yyyy-mm-dd'], ['1', 'mm-dd-yyyy'], ['2', 'mmm dd, yyyy'], ['3', 'dd.mm.yyyy']] });
465 c.push({ title: 'Scale', name: 'f_scale', type: 'select', options: [['0', 'KB'], ['1', 'MB'], ['2', 'GB']] });
466 c.push({ title: 'Show subnet totals', name: 'f_subnet', type: 'checkbox', suffix: ' <small>(Not considered when calculating total traffic on the last line)</small>' });
467 c.push({ title: 'Hide IPs without traffic', name: 'f_ignorezeroes', type: 'checkbox' });
468 c.push({ title: 'Show known hostnames', name: 'f_hostnames', type: 'checkbox' });
469 c.push({ title: 'Show shortcuts', name: 'f_shortcuts', type: 'checkbox' });
470 createFieldTable('',c);
471 </script>
472 <div style="float:right;text-align:right">
473 &raquo; <a href="javascript:genData()">Data</a>
474 <br>
475 &raquo; <a href="admin-iptraffic.asp">Configure</a>
476 </div>
477 </div>
478 </div>
479 <br>
481 <script type='text/javascript'>checkCstats();</script>
483 <!-- / / / -->
485 </td></tr>
486 <tr><td id='footer' colspan=2>
487 <input type='button' value='Refresh' onclick='reloadPage()'>
488 </td></tr>
489 </table>
490 </form>
491 </body>
492 </html>