1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML
4.0//EN'
>
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.
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'
>
21 <script type='text/javascript' src='tomato.js'
></script>
25 <style type='text/css'
>
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"); %>
46 // <% ipt_bandwidth("monthly"); %>
52 if (typeof(monthly_history
) == 'undefined') {
60 var filteripe_before
= [];
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
];
74 w
.document
.writeln([t
[0], t
[1] + 1, h
[1], h
[2], h
[3]].join(','));
76 w
.document
.writeln('</pre>');
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']);
98 var subnetslisted
= [];
100 if (monthly_history
.length
> 0) {
102 for (i
= 0; i
< monthly_history
.length
; ++i
) {
104 b
= monthly_history
[i
];
106 if (E('_f_ignorezeroes').checked
)
107 if ((b
[2] < 1) || (b
[3] < 1))
110 if (E('_f_begin_date').value
.toString() != '0') {
111 if (b
[0] < E('_f_begin_date').value
)
115 if (E('_f_end_date').value
.toString() != '0') {
116 if (b
[0] > E('_f_end_date').value
)
120 if (filteripe
.length
>0) {
122 for (var x
= 0; x
< filteripe
.length
; ++x
) {
123 if (b
[1] == filteripe
[x
]){
128 if (fskip
== 1) continue;
131 if (filterip
.length
>0) {
133 for (var x
= 0; x
< filterip
.length
; ++x
) {
134 if (b
[1] == filterip
[x
]){
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) {
149 subnetslisted
.push(b
[1]);
152 hostslisted
.push(b
[1]);
157 if (hostslisted
.length
> 0) {
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);
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>';
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
);
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') : '')
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];
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];
241 dg
.dataToView = function(data
) {
245 dg
.sortCompare = function(a
, b
) {
246 var col
= this.sortColumn
;
247 var da
= a
.getRowData();
248 var db
= b
.getRowData();
253 r
= cmpText(da
[col
], db
[col
]);
258 r
= cmpFloat(parseFloat(da
[col
].replace(",","")), parseFloat(db
[col
].replace(",","")));
261 return this.sortAscending
? r
: -r
;
264 function init_filter_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) {
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');
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]);
300 if (nvram
.cstats_enable
!= '1') return;
308 if ((c
= '<% cgi_get("ipt_filterip"); %>') != '') {
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);
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) {
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");
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);
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() {
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(',') : '';
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(',') : '';
398 if (filteripe_before
!= filteripe
) {
399 cookie
.set('ipt_addr_hidden', (filteripe
.length
> 0) ? filteripe
.join(',') : '', 1);
400 filteripe_before
= filteripe
;
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
;
435 <body onload='init()'
>
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>
442 <tr id='body'
><td id='navi'
><script type='text/javascript'
>navi()</script></td>
444 <div id='ident'
><%
ident(); %></div>
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>
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'
>
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
);
470 <div style=
"float:right;text-align:right">
471 » <a href=
"javascript:genData()">Data
</a>
473 » <a href=
"admin-iptraffic.asp">Configure
</a>
479 <script type='text/javascript'
>checkCstats();</script>
484 <tr><td id='footer' colspan=
2>
485 <input type='button' value='Refresh' onclick='reloadPage()'
>