Fix nvram size for router with more than 32kB of nvram.
[tomato.git] / release / src / router / www / ipt-monthly.asp
blobf63de72ee87acb6735ae3f08e995bb2169eafa76
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: Monthly 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 #monthly-grid .co3,
27 #monthly-grid .co4,
28 #monthly-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("monthly"); %>
48 catch (ex) {
49 monthly_history = [];
51 cstats_busy = 0;
52 if (typeof(monthly_history) == 'undefined') {
53 monthly_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 < monthly_history.length; ++i) {
72 h = monthly_history[i];
73 t = getYMD(h[0]);
74 w.document.writeln([t[0], t[1] + 1, 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('monthly-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 (monthly_history.length > 0) {
101 dg.removeAllData();
102 for (i = 0; i < monthly_history.length; ++i) {
103 fskip=0;
104 b = monthly_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 = [ymText(ymd[0], ymd[1]), 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', [monthly_history[n][1]], 1);
217 popupWindow('qos-detailed.asp');
220 function viewQosCTrates(n) {
221 cookie.set('qos_filterip', [monthly_history[n][1]], 1);
222 popupWindow('qos-ctrate.asp');
225 function viewIptDetail(n) {
226 cookie.set('ipt_filterip', [monthly_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 = monthly_history[n][1];
233 } else {
234 if (E('_f_filter_ipe').value.indexOf(monthly_history[n][1]) < 0) {
235 E('_f_filter_ipe').value = E('_f_filter_ipe').value + ',' + monthly_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 = cmpText(da[col], db[col]);
254 break;
255 case 2: // Download
256 case 3: // Upload
257 case 4: // Total
258 r = cmpFloat(parseFloat(da[col].replace(",","")), parseFloat(db[col].replace(",","")));
259 break;
261 return this.sortAscending ? r : -r;
264 function init_filter_dates() {
265 var dates = [];
266 if (monthly_history.length > 0) {
267 for (var i = 0; i < monthly_history.length; ++i) {
268 dates.push('0x' + monthly_history[i][0].toString(16));
270 if (dates.length > 0) {
271 dates.sort();
272 for (var j = 1; j < dates.length; j++ ) {
273 if (dates[j] === dates[j - 1]) {
274 dates.splice(j--, 1);
279 var b = E('_f_begin_date');
280 var e = E('_f_end_date');
281 var d = new Date();
282 for (var i = 0; i < dates.length; ++i) {
283 var ymd = getYMD(dates[i]);
284 b.options[i+1] = new Option(ymText(ymd[0], ymd[1]), dates[i], false, ((ymd[0]==d.getFullYear()) && (ymd[1]==d.getMonth()) ) );
285 e.options[i+1] = new Option(ymText(ymd[0], ymd[1]), dates[i], false, ((ymd[0]==d.getFullYear()) && (ymd[1]==d.getMonth()) ) );
289 function update_filter_dates(b) {
290 for (var i = 0; i < b.options.length; ++i) {
291 if(b.options[i].value.toString() != '0') {
292 var ymd = getYMD(b.options[i].value);
293 b.options[i].text = ymText(ymd[0], ymd[1]);
298 function init() {
300 if (nvram.cstats_enable != '1') return;
302 var c;
304 init_filter_dates();
306 populateCache();
308 if ((c = '<% cgi_get("ipt_filterip"); %>') != '') {
309 if (c.length>6) {
310 E('_f_begin_date').value = 0;
311 E('_f_end_date').value = 0;
312 E('_f_filter_ip').value = c;
313 filterip = c.split(',');
317 if ((c = cookie.get('ipt_filterip')) != null) {
318 cookie.set('ipt_filterip', '', 0);
319 if (c.length>6) {
320 E('_f_begin_date').value = 0;
321 E('_f_end_date').value = 0;
322 E('_f_filter_ip').value = E('_f_filter_ip').value + ((E('_f_filter_ip').value.length > 0) ? ',' : '') + c;
323 filterip.push(c.split(','));
327 if ((c = cookie.get('ipt_addr_hidden')) != null) {
328 if (c.length>6) {
329 E('_f_filter_ipe').value = c;
330 filteripe = c.split(',');
334 filteripe_before = filteripe;
336 dateFormat = fixInt(cookie.get('ipt_history_dafm'), 0, 3, 0);
337 E('_f_dafm').value = dateFormat;
339 scale = fixInt(cookie.get('ipt_history_scale'), 0, 2, 0);
340 E('_f_scale').value = scale;
342 E('_f_subnet').checked = (((c = cookie.get('ipt_history_subnet')) != null) && (c == '1'));
344 E('_f_hostnames').checked = (((c = cookie.get('ipt_history_hostnames')) != null) && (c == '1'));
346 E('_f_shortcuts').checked = (((c = cookie.get('ipt_history_shortcuts')) != null) && (c == '1'));
348 E('_f_ignorezeroes').checked = (((c = cookie.get('ipt_history_ignorezeroes')) != null) && (c == '1'));
350 if (((c = cookie.get('ipt_history_options_vis')) != null) && (c == '1')) {
351 toggleVisibility("options");
354 dg.setup();
356 redraw();
359 function toggleVisibility(whichone) {
360 if(E('sesdiv' + whichone).style.display=='') {
361 E('sesdiv' + whichone).style.display='none';
362 E('sesdiv' + whichone + 'showhide').innerHTML='(Click here to show)';
363 cookie.set('ipt_history_' + whichone + '_vis', 0);
364 } else {
365 E('sesdiv' + whichone).style.display='';
366 E('sesdiv' + whichone + 'showhide').innerHTML='(Click here to hide)';
367 cookie.set('ipt_history_' + whichone + '_vis', 1);
371 function dofilter() {
372 var i;
374 if (E('_f_filter_ip').value.length>0) {
375 filterip = E('_f_filter_ip').value.split(',');
376 for (i = 0; i < filterip.length; ++i) {
377 if ((filterip[i] = fixIP(filterip[i])) == null) {
378 filterip.splice(i,1);
381 E('_f_filter_ip').value = (filterip.length > 0) ? filterip.join(',') : '';
382 } else {
383 filterip = [];
386 if (E('_f_filter_ipe').value.length>0) {
387 filteripe = E('_f_filter_ipe').value.split(',');
388 for (i = 0; i < filteripe.length; ++i) {
389 if ((filteripe[i] = fixIP(filteripe[i])) == null) {
390 filteripe.splice(i,1);
393 E('_f_filter_ipe').value = (filteripe.length > 0) ? filteripe.join(',') : '';
394 } else {
395 filteripe = [];
398 if (filteripe_before != filteripe) {
399 cookie.set('ipt_addr_hidden', (filteripe.length > 0) ? filteripe.join(',') : '', 1);
400 filteripe_before = filteripe;
403 redraw();
406 function verifyFields(focused, quiet) {
407 dateFormat = E('_f_dafm').value * 1;
408 cookie.set('ipt_history_dafm', E('_f_dafm').value, 31);
410 scale = E('_f_scale').value * 1;
411 cookie.set('ipt_history_scale', E('_f_scale').value, 2);
413 // cookie.set('ipt_history_subnet', (E('_f_subnet').checked ? '1' : '0'), 1);
415 cookie.set('ipt_history_hostnames', (E('_f_hostnames').checked ? '1' : '0'), 1);
417 cookie.set('ipt_history_shortcuts', (E('_f_shortcuts').checked ? '1' : '0'), 1);
419 cookie.set('ipt_history_ignorezeroes', (E('_f_ignorezeroes').checked ? '1' : '0'), 1);
421 update_filter_dates(E('_f_begin_date'));
422 update_filter_dates(E('_f_end_date'));
424 if ((E('_f_begin_date').value > E('_f_end_date').value) && ( E('_f_end_date').value != '0')) {
425 var tmp = E('_f_begin_date').value;
426 E('_f_begin_date').value = E('_f_end_date').value;
427 E('_f_end_date').value = tmp;
430 dofilter();
431 return 1;
433 </script>
434 </head>
435 <body onload='init()'>
436 <form>
437 <table id='container' cellspacing=0>
438 <tr><td colspan=2 id='header'>
439 <div class='title'>Tomato</div>
440 <div class='version'>Version <% version(); %></div>
441 </td></tr>
442 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
443 <td id='content'>
444 <div id='ident'><% ident(); %></div>
446 <!-- / / / -->
448 <div id='cstats'>
449 <div class='section-title'>IP Traffic Monthly History</div>
450 <div class='section'>
451 <table id='monthly-grid' class='tomato-grid' cellspacing=0 style='height:auto'></table>
452 </div>
454 <div class='section-title'>Options <small><i><a href='javascript:toggleVisibility("options");'><span id='sesdivoptionsshowhide'>(Click here to show)</span></a></i></small></div>
455 <div class='section' id='sesdivoptions' style='display:none'>
456 <script type='text/javascript'>
457 var c;
458 c = [];
459 c.push({ title: 'List only these IPs', name: 'f_filter_ip', size: 50, maxlen: 255, type: 'text', suffix: ' <small>(Comma separated list)</small>' });
460 c.push({ title: 'Exclude these IPs', name: 'f_filter_ipe', size: 50, maxlen: 255, type: 'text', suffix: ' <small>(Comma separated list)</small>' });
461 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']] } ] } );
462 c.push({ title: 'Date Format', name: 'f_dafm', type: 'select', options: [['0', 'yyyy-mm'], ['1', 'mm-yyyy'], ['2', 'mmm, yyyy'], ['3', 'mm.yyyy']] });
463 c.push({ title: 'Scale', name: 'f_scale', type: 'select', options: [['0', 'KB'], ['1', 'MB'], ['2', 'GB']] });
464 c.push({ title: 'Show subnet totals', name: 'f_subnet', type: 'checkbox', suffix: ' <small>(Not considered when calculating total traffic on the last line)</small>' });
465 c.push({ title: 'Hide IPs without traffic', name: 'f_ignorezeroes', type: 'checkbox' });
466 c.push({ title: 'Show known hostnames', name: 'f_hostnames', type: 'checkbox' });
467 c.push({ title: 'Show shortcuts', name: 'f_shortcuts', type: 'checkbox' });
468 createFieldTable('',c);
469 </script>
470 <div style="float:right;text-align:right">
471 &raquo; <a href="javascript:genData()">Data</a>
472 <br>
473 &raquo; <a href="admin-iptraffic.asp">Configure</a>
474 </div>
475 </div>
476 </div>
477 <br>
479 <script type='text/javascript'>checkCstats();</script>
481 <!-- / / / -->
483 </td></tr>
484 <tr><td id='footer' colspan=2>
485 <input type='button' value='Refresh' onclick='reloadPage()'>
486 </td></tr>
487 </table>
488 </form>
489 </body>
490 </html>