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: Details
</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'
>
37 <script type='text/javascript' src='debug.js'
></script>
38 <script type='text/javascript' src='protocols.js'
></script>
39 <script type='text/javascript' src='bwm-hist.js'
></script>
40 <script type='text/javascript' src='bwm-common.js'
></script>
41 <script type='text/javascript' src='interfaces.js'
></script>
43 <script type='text/javascript'
>
44 // <% nvram('cstats_enable,lan_ipaddr,lan1_ipaddr,lan2_ipaddr,lan3_ipaddr,lan_netmask,lan1_netmask,lan2_netmask,lan3_netmask,dhcpd_static'); %>
58 if (typeof(iptraffic
) == 'undefined') {
63 var grid
= new TomatoGrid();
71 var prevtimestamp
= new Date().getTime();
74 var avgiptraffic
= [];
75 var lastiptraffic
= iptraffic
;
77 var ref
= new TomatoRefresh('update.cgi', '', 0, 'ipt_details');
78 ref
.refresh = function(text
) {
84 thistimestamp
= new Date().getTime();
94 difftimestamp
= thistimestamp
- prevtimestamp
;
95 prevtimestamp
= thistimestamp
;
97 for (i
= 0; i
< iptraffic
.length
; ++i
) {
100 j
= getArrayPosByElement(avgiptraffic
, b
[0], 0);
102 j
= avgiptraffic
.length
;
103 avgiptraffic
[j
] = [ b
[0], 0, 0, 0, 0, 0, 0, 0, 0, b
[9], b
[10] ];
106 k
= getArrayPosByElement(lastiptraffic
, b
[0], 0);
108 k
= lastiptraffic
.length
;
109 lastiptraffic
[k
] = b
;
112 for (l
= 1; l
<= 8; ++l
) {
113 avgiptraffic
[j
][l
] = ((b
[l
] - lastiptraffic
[k
][l
]) / difftimestamp
* 1000);
114 lastiptraffic
[k
][l
] = b
[l
];
117 avgiptraffic
[j
][9] = b
[9];
118 avgiptraffic
[j
][10] = b
[10];
119 lastiptraffic
[k
][9] = b
[9];
120 lastiptraffic
[k
][10] = b
[10];
123 setTimeout(function() { E('loading').style
.visibility
= 'hidden'; }, 100);
130 grid
.populate = function() {
131 if ((lock
) || (cstats_busy
)) return;
133 var hostslisted
= [];
149 grid
.removeAllData();
151 for (i
= 0; i
< avgiptraffic
.length
; ++i
) {
155 if(E('_f_onlyactive').checked
) {
156 if ((b
[2] < 10) && (b
[3] < 10))
160 if (filteripe
.length
>0) {
162 for (x
= 0; x
< filteripe
.length
; ++x
) {
163 if (b
[0] == filteripe
[x
]){
168 if (fskip
== 1) continue;
171 if (filterip
.length
>0) {
173 for (x
= 0; x
< filterip
.length
; ++x
) {
174 if (b
[0] == filterip
[x
]){
179 if (fskip
== 1) continue;
192 hostslisted
.push(b
[0]);
195 if (E('_f_hostnames').checked
) {
196 if(hostnamecache
[b
[0]] != null) {
197 h
= hostnamecache
[b
[0]] + ((b
[0].indexOf(':') != -1) ? '<br>' : ' ') + '<small>(' + b
[0] + ')</small>';
201 if (E('_f_shortcuts').checked
) {
202 h
= h
+ '<br><small>';
203 h
= h
+ '<a href="javascript:viewQosDetail(' + i
+ ')" title="View QoS Details">[qosdetails]</a>';
204 h
= h
+ '<a href="javascript:viewQosCTrates(' + i
+ ')" title="View transfer rates per connection">[qosrates]</a>';
205 h
= h
+ '<a href="javascript:viewIptHistory(' + i
+ ')" title="View IP Traffic History">[history]</a>';
206 h
= h
+ '<a href="javascript:addExcludeList(' + i
+ ')" title="Filter out this address">[hide]</a>';
211 rescale((b
[1]/1024).toFixed(2)).toString(),
212 rescale((b
[2]/1024).toFixed(2)).toString(),
213 b
[3].toFixed(0).toString(),
214 b
[4].toFixed(0).toString(),
215 b
[5].toFixed(0).toString(),
216 b
[6].toFixed(0).toString(),
217 b
[7].toFixed(0).toString(),
218 b
[8].toFixed(0).toString(),
222 grid
.insertData(-1, d
);
227 grid
.footerSet([ 'Total ' + ('<small><i>(' + ((hostslisted
.length
> 0) ? (hostslisted
.length
+ ' hosts') : 'no data') + ')</i></small>'),
228 rescale((rx
/1024).toFixed(2)).toString(),
229 rescale((tx
/1024).toFixed(2)).toString(),
230 tcpi
.toFixed(0).toString() + '/' + tcpo
.toFixed(0).toString(),
231 udpi
.toFixed(0).toString() + '/' + udpo
.toFixed(0).toString(),
232 icmpi
.toFixed(0).toString() + '/' + icmpo
.toFixed(0).toString(),
233 tcpconn
.toString(), udpconn
.toString() ]);
236 function popupWindow(v
) {
237 window
.open(v
, '', 'width=1000,height=600,toolbar=no,menubar=no,scrollbars=yes,resizable=yes');
240 function viewQosDetail(n
) {
241 cookie
.set('qos_filterip', [avgiptraffic
[n
][0]], 1);
242 popupWindow('qos-detailed.asp');
245 function viewQosCTrates(n
) {
246 cookie
.set('qos_filterip', [avgiptraffic
[n
][0]], 1);
247 popupWindow('qos-ctrate.asp');
250 function viewIptHistory(n
) {
251 cookie
.set('ipt_filterip', [avgiptraffic
[n
][0]], 1);
252 popupWindow('ipt-daily.asp');
255 function addExcludeList(n
) {
256 if (E('_f_filter_ipe').value
.length
<6) {
257 E('_f_filter_ipe').value
= avgiptraffic
[n
][0];
259 if (E('_f_filter_ipe').value
.indexOf(avgiptraffic
[n
][0]) < 0) {
260 E('_f_filter_ipe').value
= E('_f_filter_ipe').value
+ ',' + avgiptraffic
[n
][0];
266 grid
.dataToView = function(data
) {
267 return [data
[0].toString(),
270 data
[3] + '/' + data
[4],
271 data
[5] + '/' + data
[6],
272 data
[7] + '/' + data
[8],
274 data
[10].toString() ];
277 grid
.setup = function() {
278 this.init('grid', 'sort');
279 this.headerSet(['Host', 'Download (bytes/s)', 'Upload (bytes/s)', 'TCP IN/OUT (pkt/s)', 'UDP IN/OUT (pkt/s)', 'ICMP IN/OUT (pkt/s)', 'TCP Connections', 'UDP Connections']);
283 if ((c
= cookie
.get('ipt_filterip')) != null) {
284 cookie
.set('ipt_filterip', '', 0);
286 E('_f_filter_ip').value
= c
;
287 filterip
= c
.split(',');
291 if (((c
= cookie
.get('ipt_details_options_vis')) != null) && (c
== '1')) {
292 toggleVisibility("options");
294 scale
= fixInt(cookie
.get('ipt_details_scale'), 0, 2, 0);
296 E('_f_scale').value
= scale
;
298 E('_f_onlyactive').checked
= (((c
= cookie
.get('ipt_details_onlyactive')) != null) && (c
== '1'));
300 E('_f_hostnames').checked
= (((c
= cookie
.get('ipt_details_hostnames')) != null) && (c
== '1'));
302 E('_f_shortcuts').checked
= (((c
= cookie
.get('ipt_details_shortcuts')) != null) && (c
== '1'));
306 ref
.postData
= 'exec=iptraffic';
308 if (!ref
.running
) ref
.once
= 1;
312 function getArrayPosByElement(haystack
, needle
, index
) {
313 for (var i
= 0; i
< haystack
.length
; ++i
) {
314 if (haystack
[i
][index
] == needle
) {
321 function dofilter() {
322 if (E('_f_filter_ip').value
.length
>6) {
323 filterip
= E('_f_filter_ip').value
.split(',');
328 if (E('_f_filter_ipe').value
.length
>6) {
329 filteripe
= E('_f_filter_ipe').value
.split(',');
337 function verifyFields(focused
, quiet
) {
338 scale
= E('_f_scale').value
* 1;
339 cookie
.set('ipt_details_scale', E('_f_scale').value
, 2);
341 cookie
.set('ipt_details_onlyactive', (E('_f_onlyactive').checked
? '1' : '0'), 1);
343 cookie
.set('ipt_details_hostnames', (E('_f_hostnames').checked
? '1' : '0'), 1);
345 cookie
.set('ipt_details_shortcuts', (E('_f_shortcuts').checked
? '1' : '0'), 1);
351 function toggleVisibility(whichone
) {
352 if(E('sesdiv' + whichone
).style
.display
=='') {
353 E('sesdiv' + whichone
).style
.display
='none';
354 E('sesdiv' + whichone
+ 'showhide').innerHTML
='(Click here to show)';
355 cookie
.set('ipt_details_' + whichone
+ '_vis', 0);
357 E('sesdiv' + whichone
).style
.display
='';
358 E('sesdiv' + whichone
+ 'showhide').innerHTML
='(Click here to hide)';
359 cookie
.set('ipt_details_' + whichone
+ '_vis', 1);
366 <body onload='init()'
>
367 <form id='_fom' action='javascript:{}'
>
368 <table id='container' cellspacing=
0>
369 <tr><td colspan=
2 id='header'
>
370 <div class='title'
>Tomato
</div>
371 <div class='version'
>Version <%
version(); %></div>
373 <tr id='body'
><td id='navi'
><script type='text/javascript'
>navi()</script></td>
375 <div id='ident'
><%
ident(); %></div>
379 <div class='section-title'
>IP Traffic Details
</div>
380 <div class='section'
>
381 <table id='grid' class='tomato-grid'
style=
"float:left" cellspacing=
1></table>
383 <div id='loading'
><br><b>Loading...
</b></div>
388 <div class='section-title'
>Options
<small><i><a href='javascript:toggleVisibility(
"options");'
><span id='sesdivoptionsshowhide'
>(Click here to show)
</span></a></i></small></div>
389 <div class='section' id='sesdivoptions' style='display:none'
>
390 <script type='text/javascript'
>
393 c
.push({ title
: 'Only these IPs', name
: 'f_filter_ip', size
: 50, maxlen
: 255, type
: 'text', suffix
: ' <small>(Comma separated list)</small>' });
394 c
.push({ title
: 'Exclude these IPs', name
: 'f_filter_ipe', size
: 50, maxlen
: 255, type
: 'text', suffix
: ' <small>(Comma separated list)</small>' });
395 c
.push({ title
: 'Scale', name
: 'f_scale', type
: 'select', options
: [['0', 'KB'], ['1', 'MB'], ['2', 'GB']] });
396 c
.push({ title
: 'Ignore inactive hosts', name
: 'f_onlyactive', type
: 'checkbox' });
397 c
.push({ title
: 'Show hostnames', name
: 'f_hostnames', type
: 'checkbox' });
398 c
.push({ title
: 'Show shortcuts', name
: 'f_shortcuts', type
: 'checkbox' });
399 createFieldTable('',c
);
401 <div style=
"float:right;text-align:right">
402 » <a href=
"admin-iptraffic.asp">Configure
</a>
406 <script type='text/javascript'
>checkCstats();</script>
411 <tr><td id='footer' colspan=
2>
412 <script type='text/javascript'
>genStdRefresh(1,1,'ref.toggle()');</script>