Latest updates from Teaman-IPTraffic
[tomato.git] / release / src / router / www / ipt-daily.asp
blob4195044ca44e70d8bb16e976e8983453ce14428d
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 dateFormat = -1;
61 var scale = -1;
64 function genData() {
65 var w, i, h, t;
67 w = window.open('', 'tomato_ipt_data_d');
68 w.document.writeln('<pre>');
69 for (i = 0; i < daily_history.length; ++i) {
70 h = daily_history[i];
71 t = getYMD(h[0]);
72 w.document.writeln([t[0], t[1] + 1, t[2], h[1], h[2], h[3]].join(','));
74 w.document.writeln('</pre>');
75 w.document.close();
78 function getYMD(n) {
79 // [y,m,d]
80 return [(((n >> 16) & 0xFF) + 1900), ((n >>> 8) & 0xFF), (n & 0xFF)];
83 var dg = new TomatoGrid();
85 dg.setup = function() {
86 this.init('daily-grid', 'sort');
87 this.headerSet(['Date', 'Host', 'Download', 'Upload', 'Total']);
90 function redraw() {
91 var i, b, d;
92 var fskip;
93 var tx = 0;
94 var rx = 0;
95 var hostslisted = [];
96 var subnetslisted = [];
98 if (daily_history.length > 0) {
99 dg.removeAllData();
100 for (i = 0; i < daily_history.length; ++i) {
101 fskip=0;
102 b = daily_history[i];
104 if (E('_f_ignorezeroes').checked)
105 if ((b[2] < 1) || (b[3] < 1))
106 continue;
108 if (E('_f_begin_date').value.toString() != '0') {
109 if (b[0] < E('_f_begin_date').value)
110 continue;
113 if (E('_f_end_date').value.toString() != '0') {
114 if (b[0] > E('_f_end_date').value)
115 continue;
118 if (filteripe.length>0) {
119 fskip = 0;
120 for (var x = 0; x < filteripe.length; ++x) {
121 if (b[1] == filteripe[x]){
122 fskip=1;
123 break;
126 if (fskip == 1) continue;
129 if (filterip.length>0) {
130 fskip = 1;
131 for (var x = 0; x < filterip.length; ++x) {
132 if (b[1] == filterip[x]){
133 fskip=0;
134 break;
137 if (fskip == 1) continue;
140 if ((b[1] == getNetworkAddress(nvram.lan_ipaddr,nvram.lan_netmask)) ||
141 (b[1] == getNetworkAddress(nvram.lan1_ipaddr,nvram.lan1_netmask)) ||
142 (b[1] == getNetworkAddress(nvram.lan2_ipaddr,nvram.lan2_netmask)) ||
143 (b[1] == getNetworkAddress(nvram.lan3_ipaddr,nvram.lan3_netmask))) {
144 if(E('_f_subnet').checked == 0) {
145 continue;
146 } else {
147 subnetslisted.push(b[1]);
149 } else {
150 hostslisted.push(b[1]);
151 rx += b[2];
152 tx += b[3];
155 if (hostslisted.length > 0) {
156 hostslisted.sort();
157 for (var j = 1; j < hostslisted.length; j++ ) {
158 if (hostslisted[j] === hostslisted[j - 1]) {
159 hostslisted.splice(j--, 1);
164 if (subnetslisted.length > 0) {
165 subnetslisted.sort();
166 for (var j = 1; j < subnetslisted.length; j++ ) {
167 if (subnetslisted[j] === subnetslisted[j - 1]) {
168 subnetslisted.splice(j--, 1);
173 var h = b[1];
174 if (E('_f_hostnames').checked) {
175 if(hostnamecache[b[1]] != null) {
176 h = hostnamecache[b[1]] + ((b[1].indexOf(':') != -1) ? '<br>' : ' ') + '<small>(' + b[1] + ')</small>';
179 if (E('_f_shortcuts').checked) {
180 h = h + '<br><small>';
181 h = h + '<a href="javascript:viewQosDetail(' + i + ')" title="View QoS Details">[qosdetails]</a>';
182 h = h + '<a href="javascript:viewQosCTrates(' + i + ')" title="View transfer rates per connection">[qosrates]</a>';
183 h = h + '<a href="javascript:viewIptDetail(' + i + ')" title="View real-time IP Traffic for this address">[iptraf]</a>';
184 h = h + '<a href="javascript:addExcludeList(' + i + ')" title="Filter out this address">[hide]</a>';
185 h = h + '</small>';
187 var ymd = getYMD(b[0]);
188 d = [ymdText(ymd[0], ymd[1], ymd[2]), h, rescale(b[2]), rescale(b[3]), rescale(b[2]+b[3])];
189 dg.insertData(-1, d);
192 dg.resort();
193 dg.recolor();
194 dg.footerSet([
195 'Total',
196 ('<small><i>(' +
197 (((hostslisted.length > 0) || (subnetslisted.length > 0)) ?
198 ((hostslisted.length > 0) ? (hostslisted.length + ' hosts') : '') +
199 (((hostslisted.length > 0) && (subnetslisted.length > 0)) ? ', ' : '') +
200 ((subnetslisted.length > 0) ? (subnetslisted.length + ' subnets') : '')
201 : 'no data') +
202 ')</i></small>'),
203 rescale(rx),
204 rescale(tx),
205 rescale(rx+tx)]);
209 function popupWindow(v) {
210 window.open(v, '', 'width=1000,height=600,toolbar=no,menubar=no,scrollbars=yes,resizable=yes');
213 function viewQosDetail(n) {
214 cookie.set('qos_filterip', [daily_history[n][1]], 1);
215 popupWindow('qos-detailed.asp');
218 function viewQosCTrates(n) {
219 cookie.set('qos_filterip', [daily_history[n][1]], 1);
220 popupWindow('qos-ctrate.asp');
223 function viewIptDetail(n) {
224 cookie.set('ipt_filterip', [daily_history[n][1]], 1);
225 popupWindow('ipt-details.asp');
228 function addExcludeList(n) {
229 if (E('_f_filter_ipe').value.length<6) {
230 E('_f_filter_ipe').value = daily_history[n][1];
231 } else {
232 if (E('_f_filter_ipe').value.indexOf(daily_history[n][1]) < 0) {
233 E('_f_filter_ipe').value = E('_f_filter_ipe').value + ',' + daily_history[n][1];
236 dofilter();
239 dg.dataToView = function(data) {
240 return(data);
243 function init_filter_dates() {
244 var dates = [];
245 if (daily_history.length > 0) {
246 for (var i = 0; i < daily_history.length; ++i) {
247 dates.push('0x' + daily_history[i][0].toString(16));
249 if (dates.length > 0) {
250 dates.sort();
251 for (var j = 1; j < dates.length; j++ ) {
252 if (dates[j] === dates[j - 1]) {
253 dates.splice(j--, 1);
258 var b = E('_f_begin_date');
259 var e = E('_f_end_date');
260 var d = new Date();
261 for (var i = 0; i < dates.length; ++i) {
262 var ymd = getYMD(dates[i]);
263 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()) ));
264 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()) ));
268 function update_filter_dates(b) {
269 for (var i = 0; i < b.options.length; ++i) {
270 if(b.options[i].value.toString() != '0') {
271 var ymd = getYMD(b.options[i].value);
272 b.options[i].text = ymdText(ymd[0], ymd[1], ymd[2]);
277 function init() {
279 if (nvram.cstats_enable != '1') return;
281 var c;
283 init_filter_dates();
285 populateCache();
287 if ((c = cookie.get('ipt_filterip')) != null) {
288 cookie.set('ipt_filterip', '', 0);
289 if (c.length>6) {
290 E('_f_begin_date').value = 0;
291 E('_f_end_date').value = 0;
292 E('_f_filter_ip').value = c;
293 filterip = c.split(',');
297 dateFormat = fixInt(cookie.get('ipt_history_dafm'), 0, 3, 0);
298 E('_f_dafm').value = dateFormat;
300 scale = fixInt(cookie.get('ipt_history_scale'), 0, 2, 0);
301 E('_f_scale').value = scale;
303 E('_f_subnet').checked = (((c = cookie.get('ipt_history_subnet')) != null) && (c == '1'));
305 E('_f_hostnames').checked = (((c = cookie.get('ipt_history_hostnames')) != null) && (c == '1'));
307 E('_f_shortcuts').checked = (((c = cookie.get('ipt_history_shortcuts')) != null) && (c == '1'));
309 E('_f_ignorezeroes').checked = (((c = cookie.get('ipt_history_ignorezeroes')) != null) && (c == '1'));
311 if (((c = cookie.get('ipt_history_options_vis')) != null) && (c == '1')) {
312 toggleVisibility("options");
315 dg.setup();
317 redraw();
320 function toggleVisibility(whichone) {
321 if(E('sesdiv' + whichone).style.display=='') {
322 E('sesdiv' + whichone).style.display='none';
323 E('sesdiv' + whichone + 'showhide').innerHTML='(Click here to show)';
324 cookie.set('ipt_history_' + whichone + '_vis', 0);
325 } else {
326 E('sesdiv' + whichone).style.display='';
327 E('sesdiv' + whichone + 'showhide').innerHTML='(Click here to hide)';
328 cookie.set('ipt_history_' + whichone + '_vis', 1);
332 function dofilter() {
333 if (E('_f_filter_ip').value.length>6) {
334 filterip = E('_f_filter_ip').value.split(',');
335 } else {
336 filterip = [];
339 if (E('_f_filter_ipe').value.length>6) {
340 filteripe = E('_f_filter_ipe').value.split(',');
341 } else {
342 filteripe = [];
345 redraw();
348 function verifyFields(focused, quiet) {
349 dateFormat = E('_f_dafm').value * 1;
350 cookie.set('ipt_history_dafm', E('_f_dafm').value, 31);
352 scale = E('_f_scale').value * 1;
353 cookie.set('ipt_history_scale', E('_f_scale').value, 2);
355 cookie.set('ipt_history_subnet', (E('_f_subnet').checked ? '1' : '0'), 1);
357 cookie.set('ipt_history_hostnames', (E('_f_hostnames').checked ? '1' : '0'), 1);
359 cookie.set('ipt_history_shortcuts', (E('_f_shortcuts').checked ? '1' : '0'), 1);
361 cookie.set('ipt_history_ignorezeroes', (E('_f_ignorezeroes').checked ? '1' : '0'), 1);
363 update_filter_dates(E('_f_begin_date'));
364 update_filter_dates(E('_f_end_date'));
366 if ((E('_f_begin_date').value > E('_f_end_date').value) && ( E('_f_end_date').value != '0')) {
367 var tmp = E('_f_begin_date').value;
368 E('_f_begin_date').value = E('_f_end_date').value;
369 E('_f_end_date').value = tmp;
372 dofilter();
373 return 1;
375 </script>
376 </head>
377 <body onload='init()'>
378 <form>
379 <table id='container' cellspacing=0>
380 <tr><td colspan=2 id='header'>
381 <div class='title'>Tomato</div>
382 <div class='version'>Version <% version(); %></div>
383 </td></tr>
384 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
385 <td id='content'>
386 <div id='ident'><% ident(); %></div>
388 <!-- / / / -->
390 <div class='section-title'>IP Traffic Daily History</div>
391 <div class='section'>
392 <table id='daily-grid' class='tomato-grid' cellspacing=0 style='height:auto'></table>
393 </div>
395 <div class='section-title'>Options <small><i><a href='javascript:toggleVisibility("options");'><span id='sesdivoptionsshowhide'>(Click here to show)</span></a></i></small></div>
396 <div class='section' id='sesdivoptions' style='display:none'>
397 <script type='text/javascript'>
398 var c;
399 c = [];
400 c.push({ title: 'List only these IPs', name: 'f_filter_ip', size: 50, maxlen: 255, type: 'text', suffix: ' <small>(Comma separated list)</small>' });
401 c.push({ title: 'Exclude these IPs', name: 'f_filter_ipe', size: 50, maxlen: 255, type: 'text', suffix: ' <small>(Comma separated list)</small>' });
402 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']] } ] } );
403 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']] });
404 c.push({ title: 'Scale', name: 'f_scale', type: 'select', options: [['0', 'KB'], ['1', 'MB'], ['2', 'GB']] });
405 c.push({ title: 'Show subnet totals', name: 'f_subnet', type: 'checkbox', suffix: ' <small>(Not considered when calculating total traffic on the last line)</small>' });
406 c.push({ title: 'Hide IPs without traffic', name: 'f_ignorezeroes', type: 'checkbox' });
407 c.push({ title: 'Show known hostnames', name: 'f_hostnames', type: 'checkbox' });
408 c.push({ title: 'Show shortcuts', name: 'f_shortcuts', type: 'checkbox' });
409 createFieldTable('',c);
410 </script>
411 <div style="float:right;text-align:right">
412 &raquo; <a href="javascript:genData()">Data</a>
413 <br>
414 &raquo; <a href="admin-iptraffic.asp">Configure</a>
415 </div>
416 </div>
418 <script type='text/javascript'>checkCstats();</script>
420 <!-- / / / -->
422 </td></tr>
423 <tr><td id='footer' colspan=2>
424 <input type='button' value='Refresh' onclick='reloadPage()'>
425 </td></tr>
426 </table>
427 </form>
428 </body>
429 </html>