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();
252 r
= cmpText(da
[col
], db
[col
]);
255 r
= cmpIP(da
[col
], db
[col
]);
257 r
= cmpText(da
[col
], db
[col
]);
262 r
= cmpFloat(da
[col
].replace(/,/g,""), db[col].replace(/,/g
,""));
265 return this.sortAscending
? r
: -r
;
268 function init_filter_dates() {
270 if (monthly_history
.length
> 0) {
271 for (var i
= 0; i
< monthly_history
.length
; ++i
) {
272 dates
.push('0x' + monthly_history
[i
][0].toString(16));
274 if (dates
.length
> 0) {
276 for (var j
= 1; j
< dates
.length
; j
++ ) {
277 if (dates
[j
] === dates
[j
- 1]) {
278 dates
.splice(j
--, 1);
283 var b
= E('_f_begin_date');
284 var e
= E('_f_end_date');
286 for (var i
= 0; i
< dates
.length
; ++i
) {
287 var ymd
= getYMD(dates
[i
]);
288 b
.options
[i
+1] = new Option(ymText(ymd
[0], ymd
[1]), dates
[i
], false, ((ymd
[0]==d
.getFullYear()) && (ymd
[1]==d
.getMonth()) ) );
289 e
.options
[i
+1] = new Option(ymText(ymd
[0], ymd
[1]), dates
[i
], false, ((ymd
[0]==d
.getFullYear()) && (ymd
[1]==d
.getMonth()) ) );
293 function update_filter_dates(b
) {
294 for (var i
= 0; i
< b
.options
.length
; ++i
) {
295 if(b
.options
[i
].value
.toString() != '0') {
296 var ymd
= getYMD(b
.options
[i
].value
);
297 b
.options
[i
].text
= ymText(ymd
[0], ymd
[1]);
304 if (nvram
.cstats_enable
!= '1') return;
312 if ((c
= '<% cgi_get("ipt_filterip"); %>') != '') {
314 E('_f_begin_date').value
= 0;
315 E('_f_end_date').value
= 0;
316 E('_f_filter_ip').value
= c
;
317 filterip
= c
.split(',');
321 if ((c
= cookie
.get('ipt_filterip')) != null) {
322 cookie
.set('ipt_filterip', '', 0);
324 E('_f_begin_date').value
= 0;
325 E('_f_end_date').value
= 0;
326 E('_f_filter_ip').value
= E('_f_filter_ip').value
+ ((E('_f_filter_ip').value
.length
> 0) ? ',' : '') + c
;
327 filterip
.push(c
.split(','));
331 if ((c
= cookie
.get('ipt_addr_hidden')) != null) {
333 E('_f_filter_ipe').value
= c
;
334 filteripe
= c
.split(',');
338 filteripe_before
= filteripe
;
340 dateFormat
= fixInt(cookie
.get('ipt_history_dafm'), 0, 3, 0);
341 E('_f_dafm').value
= dateFormat
;
343 scale
= fixInt(cookie
.get('ipt_history_scale'), 0, 2, 0);
344 E('_f_scale').value
= scale
;
346 E('_f_subnet').checked
= (((c
= cookie
.get('ipt_history_subnet')) != null) && (c
== '1'));
348 E('_f_hostnames').checked
= (((c
= cookie
.get('ipt_history_hostnames')) != null) && (c
== '1'));
350 E('_f_shortcuts').checked
= (((c
= cookie
.get('ipt_history_shortcuts')) != null) && (c
== '1'));
352 E('_f_ignorezeroes').checked
= (((c
= cookie
.get('ipt_history_ignorezeroes')) != null) && (c
== '1'));
354 if (((c
= cookie
.get('ipt_history_options_vis')) != null) && (c
== '1')) {
355 toggleVisibility("options");
363 function toggleVisibility(whichone
) {
364 if(E('sesdiv' + whichone
).style
.display
=='') {
365 E('sesdiv' + whichone
).style
.display
='none';
366 E('sesdiv' + whichone
+ 'showhide').innerHTML
='(Click here to show)';
367 cookie
.set('ipt_history_' + whichone
+ '_vis', 0);
369 E('sesdiv' + whichone
).style
.display
='';
370 E('sesdiv' + whichone
+ 'showhide').innerHTML
='(Click here to hide)';
371 cookie
.set('ipt_history_' + whichone
+ '_vis', 1);
375 function dofilter() {
378 if (E('_f_filter_ip').value
.length
>0) {
379 filterip
= E('_f_filter_ip').value
.split(',');
380 for (i
= 0; i
< filterip
.length
; ++i
) {
381 if ((filterip
[i
] = fixIP(filterip
[i
])) == null) {
382 filterip
.splice(i
,1);
385 E('_f_filter_ip').value
= (filterip
.length
> 0) ? filterip
.join(',') : '';
390 if (E('_f_filter_ipe').value
.length
>0) {
391 filteripe
= E('_f_filter_ipe').value
.split(',');
392 for (i
= 0; i
< filteripe
.length
; ++i
) {
393 if ((filteripe
[i
] = fixIP(filteripe
[i
])) == null) {
394 filteripe
.splice(i
,1);
397 E('_f_filter_ipe').value
= (filteripe
.length
> 0) ? filteripe
.join(',') : '';
402 if (filteripe_before
!= filteripe
) {
403 cookie
.set('ipt_addr_hidden', (filteripe
.length
> 0) ? filteripe
.join(',') : '', 1);
404 filteripe_before
= filteripe
;
410 function verifyFields(focused
, quiet
) {
411 dateFormat
= E('_f_dafm').value
* 1;
412 cookie
.set('ipt_history_dafm', E('_f_dafm').value
, 31);
414 scale
= E('_f_scale').value
* 1;
415 cookie
.set('ipt_history_scale', E('_f_scale').value
, 2);
417 // cookie.set('ipt_history_subnet', (E('_f_subnet').checked ? '1' : '0'), 1);
419 cookie
.set('ipt_history_hostnames', (E('_f_hostnames').checked
? '1' : '0'), 1);
421 cookie
.set('ipt_history_shortcuts', (E('_f_shortcuts').checked
? '1' : '0'), 1);
423 cookie
.set('ipt_history_ignorezeroes', (E('_f_ignorezeroes').checked
? '1' : '0'), 1);
425 update_filter_dates(E('_f_begin_date'));
426 update_filter_dates(E('_f_end_date'));
428 if ((E('_f_begin_date').value
> E('_f_end_date').value
) && ( E('_f_end_date').value
!= '0')) {
429 var tmp
= E('_f_begin_date').value
;
430 E('_f_begin_date').value
= E('_f_end_date').value
;
431 E('_f_end_date').value
= tmp
;
439 <body onload='init()'
>
441 <table id='container' cellspacing=
0>
442 <tr><td colspan=
2 id='header'
>
443 <div class='title'
>Tomato
</div>
444 <div class='version'
>Version <%
version(); %></div>
446 <tr id='body'
><td id='navi'
><script type='text/javascript'
>navi()</script></td>
448 <div id='ident'
><%
ident(); %></div>
453 <div class='section-title'
>IP Traffic Monthly History
</div>
454 <div class='section'
>
455 <table id='monthly-grid' class='tomato-grid' cellspacing=
0 style='height:auto'
></table>
458 <div class='section-title'
>Options
<small><i><a href='javascript:toggleVisibility(
"options");'
><span id='sesdivoptionsshowhide'
>(Click here to show)
</span></a></i></small></div>
459 <div class='section' id='sesdivoptions' style='display:none'
>
460 <script type='text/javascript'
>
463 c
.push({ title
: 'List only these IPs', name
: 'f_filter_ip', size
: 50, maxlen
: 255, type
: 'text', suffix
: ' <small>(comma separated list)</small>' });
464 c
.push({ title
: 'Exclude these IPs', name
: 'f_filter_ipe', size
: 50, maxlen
: 255, type
: 'text', suffix
: ' <small>(comma separated list)</small>' });
465 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']] } ] } );
466 c
.push({ title
: 'Date Format', name
: 'f_dafm', type
: 'select', options
: [['0', 'yyyy-mm'], ['1', 'mm-yyyy'], ['2', 'mmm, yyyy'], ['3', 'mm.yyyy']] });
467 c
.push({ title
: 'Scale', name
: 'f_scale', type
: 'select', options
: [['0', 'KB'], ['1', 'MB'], ['2', 'GB']] });
468 c
.push({ title
: 'Show subnet totals', name
: 'f_subnet', type
: 'checkbox', suffix
: ' <small>(Not considered when calculating total traffic on the last line)</small>' });
469 c
.push({ title
: 'Hide IPs without traffic', name
: 'f_ignorezeroes', type
: 'checkbox' });
470 c
.push({ title
: 'Show known hostnames', name
: 'f_hostnames', type
: 'checkbox' });
471 c
.push({ title
: 'Show shortcuts', name
: 'f_shortcuts', type
: 'checkbox' });
472 createFieldTable('',c
);
474 <div style=
"float:right;text-align:right">
475 » <a href=
"javascript:genData()">Data
</a>
477 » <a href=
"admin-iptraffic.asp">Configure
</a>
483 <script type='text/javascript'
>checkCstats();</script>
488 <tr><td id='footer' colspan=
2>
489 <input type='button' value='Refresh' onclick='reloadPage()'
>