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: Daily 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("daily"); %>
52 if (typeof(daily_history
) == 'undefined') {
60 var filteripe_before
= [];
69 w
= window
.open('', 'tomato_ipt_data_d');
70 w
.document
.writeln('<pre>');
71 for (i
= 0; i
< daily_history
.length
; ++i
) {
74 w
.document
.writeln([t
[0], t
[1] + 1, t
[2], 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('daily-grid', 'sort');
89 this.headerSet(['Date', 'Host', 'Download', 'Upload', 'Total']);
98 var subnetslisted
= [];
100 if (daily_history
.length
> 0) {
102 for (i
= 0; i
< daily_history
.length
; ++i
) {
104 b
= daily_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
= [ymdText(ymd
[0], ymd
[1], ymd
[2]), 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', [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];
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];
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
= cmpIP(da
[col
], db
[col
]);
255 r
= cmpText(da
[col
], db
[col
]);
260 r
= cmpFloat(da
[col
].replace(/,/g,""), db[col].replace(/,/g
,""));
263 return this.sortAscending
? r
: -r
;
266 function init_filter_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) {
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');
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]);
302 if (nvram
.cstats_enable
!= '1') return;
310 if ((c
= '<% cgi_get("ipt_filterip"); %>') != '') {
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);
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) {
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");
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);
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() {
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(',') : '';
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(',') : '';
400 if (filteripe_before
!= filteripe
) {
401 cookie
.set('ipt_addr_hidden', (filteripe
.length
> 0) ? filteripe
.join(',') : '', 1);
402 filteripe_before
= filteripe
;
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
;
437 <body onload='init()'
>
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>
444 <tr id='body'
><td id='navi'
><script type='text/javascript'
>navi()</script></td>
446 <div id='ident'
><%
ident(); %></div>
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>
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'
>
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
);
472 <div style=
"float:right;text-align:right">
473 » <a href=
"javascript:genData()">Data
</a>
475 » <a href=
"admin-iptraffic.asp">Configure
</a>
481 <script type='text/javascript'
>checkCstats();</script>
486 <tr><td id='footer' colspan=
2>
487 <input type='button' value='Refresh' onclick='reloadPage()'
>