1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML
4.0//EN'
>
4 Copyright (C) 2006-2010 Jonathan Zarate
5 http://www.polarcloud.com/tomato/
7 For use with Tomato Firmware only.
8 No part of this file may be used without permission.
12 <meta http-equiv='content-type' content='text/html;charset=utf-
8'
>
13 <meta name='robots' content='noindex,nofollow'
>
14 <title>[<%
ident(); %>] IP Traffic: View Graphs
</title>
15 <link rel='stylesheet' type='text/css' href='tomato.css'
>
17 <script type='text/javascript' src='tomato.js'
></script>
20 <script type='text/javascript' src='debug.js'
></script>
22 <style type='text/css'
>
41 border-top: 1px dashed
#bbb;
46 <script type='text/javascript'
>
47 // <% nvram('cstats_enable,lan_ipaddr,lan1_ipaddr,lan2_ipaddr,lan3_ipaddr,lan_netmask,lan1_netmask,lan2_netmask,lan3_netmask,dhcpd_static,web_svg'); %>
60 var abc
= ['', '', '', '', '', '', '', '', '', '', ''];
76 //var grid = new TomatoGrid();
81 var prevtimestamp
= new Date().getTime();
84 var avgiptraffic
= [];
85 var lastiptraffic
= iptraffic
;
91 function updateLabels() {
93 while ((i
< abc
.length
) && (i
< iptraffic
.length
)) {
94 abc
[i
] = iptraffic
[i
][0]; // IP address
103 // while ((i <= nfmarks.length) && (i <= iptraffic.length)) {
104 // while (i < nfmarks.length){
108 if (iptraffic
[i
] != null) {
109 nfmarks
[i
] = iptraffic
[i
][9] + iptraffic
[i
][10]; // TCP + UDP connections
120 location
.href
= 'ipt-details.asp?ipt_filterip=' + abc
[n
];
123 function showData() {
128 for (i
= 0; i
< 11; ++i
) {
129 if (!nfmarks
[i
]) nfmarks
[i
] = 0;
131 if (!irates
[i
]) irates
[i
] = 0;
133 if (!orates
[i
]) orates
[i
] = 0;
137 for (i
= 0; i
< 11; ++i
) {
139 E('ccnt' + i
).innerHTML
= (abc
[i
] != '') ? n
: '';
140 if (ct
> 0) p
= (n
/ ct
) * 100;
142 E('cpct' + i
).innerHTML
= (abc
[i
] != '') ? p
.toFixed(2) + '%' : '';
144 E('ccnt-total').innerHTML
= ct
;
146 for (i
= 0; i
< 11; ++i
) {
148 E('bcnt' + i
).innerHTML
= (abc
[i
] != '') ? (n
/ 125).toFixed(2) : '';
149 E('bcntx' + i
).innerHTML
= (abc
[i
] != '') ? (n
/ 1024).toFixed(2) : '';
150 if (rt
> 0) p
= (n
/ rt
) * 100;
152 E('bpct' + i
).innerHTML
= (abc
[i
] != '') ? p
.toFixed(2) + '%' : '';
154 E('bcnt-total').innerHTML
= (rt
/ 125).toFixed(2);
155 E('bcntx-total').innerHTML
= (rt
/ 1024).toFixed(2);
157 for (i
= 0; i
< 11; ++i
) {
159 E('obcnt' + i
).innerHTML
= (abc
[i
] != '') ? (n
/ 125).toFixed(2) : '';
160 E('obcntx' + i
).innerHTML
= (abc
[i
] != '') ? (n
/ 1024).toFixed(2) : '';
161 if (ort
> 0) p
= (n
/ ort
) * 100;
163 E('obpct' + i
).innerHTML
= (abc
[i
] != '') ? p
.toFixed(2) + '%' : '';
165 E('obcnt-total').innerHTML
= (ort
/ 125).toFixed(2);
166 E('obcntx-total').innerHTML
= (ort
/ 1024).toFixed(2);
169 function getArrayPosByElement(haystack
, needle
, index
) {
170 for (var i
= 0; i
< haystack
.length
; ++i
) {
171 if (haystack
[i
][index
] == needle
) {
178 var ref
= new TomatoRefresh('update.cgi', 'exec=iptraffic', 2, 'ipt_graphs');
180 ref
.refresh = function(text
) {
185 thistimestamp
= new Date().getTime();
201 difftimestamp
= thistimestamp
- prevtimestamp
;
202 prevtimestamp
= thistimestamp
;
204 for (i
= 0; i
< iptraffic
.length
; ++i
) {
207 j
= getArrayPosByElement(avgiptraffic
, b
[0], 0);
209 j
= avgiptraffic
.length
;
210 avgiptraffic
[j
] = [ b
[0], 0, 0, 0, 0, 0, 0, 0, 0, b
[9], b
[10] ];
213 k
= getArrayPosByElement(lastiptraffic
, b
[0], 0);
215 k
= lastiptraffic
.length
;
216 lastiptraffic
[k
] = b
;
219 for (l
= 1; l
<= 8; ++l
) {
220 avgiptraffic
[j
][l
] = ((b
[l
] - lastiptraffic
[k
][l
]) / difftimestamp
* 1000);
221 lastiptraffic
[k
][l
] = b
[l
];
224 avgiptraffic
[j
][9] = b
[9];
225 avgiptraffic
[j
][10] = b
[10];
226 lastiptraffic
[k
][9] = b
[9];
227 lastiptraffic
[k
][10] = b
[10];
237 if (iptraffic
[i
] != null) {
238 nfmarks
[i
] = avgiptraffic
[i
][9] + avgiptraffic
[i
][10]; // TCP + UDP connections
239 irates
[i
] = avgiptraffic
[i
][1]; // RX bytes
240 orates
[i
] = avgiptraffic
[i
][2]; // TX bytes
251 updateCD(nfmarks
, abc
);
252 updateBD(irates
, abc
);
253 updateOB(orates
, abc
);
257 function checkSVG() {
261 for (i
= 2; i
>= 0; --i
) {
263 d
= e
.getSVGDocument();
264 if (d
.defaultView
) w
= d
.defaultView
;
265 else w
= e
.getWindow();
267 if (i
== 0) updateCD
= w
.updateSVG
;
268 if (i
== 1) updateBD
= w
.updateSVG
;
269 if (i
== 2) updateOB
= w
.updateSVG
;
277 updateCD(nfmarks
, abc
);
278 updateBD(irates
, abc
);
279 updateOB(orates
, abc
);
281 else if (--svgReady
> -5) {
282 setTimeout(checkSVG
, 500);
289 ref
.initPage(2000, 3);
290 if (!ref
.running
) ref
.once
= 1;
295 <body onload='init()'
>
296 <form id='_fom' action='javascript:{}'
>
297 <table id='container' cellspacing=
0>
298 <tr><td colspan=
2 id='header'
>
299 <div class='title'
>Tomato
</div>
300 <div class='version'
>Version <%
version(); %></div>
302 <tr id='body'
><td id='navi'
><script type='text/javascript'
>navi()</script></td>
304 <div id='ident'
><%
ident(); %></div>
308 <div class=
"section-title">Connections Distribution (TCP/UDP)
</div>
309 <div class=
"section">
310 <table border=
0 width=
"100%"><tr><td>
311 <table style=
"width:250px">
312 <script type='text/javascript'
>
313 for (i
= 0; i
< 11; ++i
) {
314 W('<tr style="cursor:pointer" onclick="mClick(' + i
+ ')">' +
315 '<td class="color" style="background:#' + colors
[i
] + '" onclick="mClick(' + i
+ ')"> </td>' +
316 '<td class="title" style="width:45px"><a href="ipt-details.asp?ipt_filterip=' + abc
[i
] + '">' + abc
[i
] + '</a></td>' +
317 '<td id="ccnt' + i
+ '" class="count" style="width:90px"></td>' +
318 '<td id="cpct' + i
+ '" class="pct"></td></tr>');
321 <tr><td> </td><td class=
"total">Total
</a></td><td id=
"ccnt-total" class=
"total count"></td><td class=
"total pct">100%
</td></tr>
323 </td><td style=
"margin-right:150px">
324 <script type='text/javascript'
>
325 if (nvram
.web_svg
!= '0') {
326 W('<embed src="ipt-graph.svg?n=0&v=<% version(); %>" style="width:310px;height:310px;margin:0;padding:0" id="svg0" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/"></embed>');
335 <div class=
"section-title">Bandwidth Distribution (Inbound)
</div>
336 <div class=
"section">
337 <table border=
0 width=
"100%"><tr><td>
338 <table style=
"width:250px">
339 <tr><td class='color'
style=
"height:1em"></td><td class='title'
style=
"width:45px"> </td><td class='thead count'
>kbit/s
</td><td class='thead count'
>KB/s
</td><td class='pct'
> </td></tr>
340 <script type='text/javascript'
>
341 for (i
= 0; i
< 11; ++i
) {
342 W('<tr style="cursor:pointer" onclick="mClick(' + i
+ ')">' +
343 '<td class="color" style="background:#' + colors
[i
] + '" onclick="mClick(' + i
+ ')"> </td>' +
344 '<td class="title" style="width:45px"><a href="ipt-details.asp?ipt_filterip=' + abc
[i
] + '">' + abc
[i
] + '</a></td>' +
345 '<td id="bcnt' + i
+ '" class="count" style="width:60px"></td>' +
346 '<td id="bcntx' + i
+ '" class="count" style="width:50px"></td>' +
347 '<td id="bpct' + i
+ '" class="pct"></td></tr>');
350 <tr><td> </td><td class=
"total">Total
</a></td><td id=
"bcnt-total" class=
"total count"></td><td id=
"bcntx-total" class=
"total count"></td><td class=
"total pct">100%
</td></tr>
352 </td><td style=
"margin-right:150px">
353 <script type='text/javascript'
>
354 if (nvram
.web_svg
!= '0') {
355 W('<embed src="ipt-graph.svg?n=1&v=<% version(); %>" style="width:310px;height:310px;margin:0;padding:0" id="svg1" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/"></embed>');
364 <div class=
"section-title">Bandwidth Distribution (Outbound)
</div>
365 <div class=
"section">
366 <table border=
0 width=
"100%"><tr><td>
367 <table style=
"width:250px">
368 <tr><td class='color'
style=
"height:1em"></td><td class='title'
style=
"width:45px"> </td><td class='thead count'
>kbit/s
</td><td class='thead count'
>KB/s
</td><td class='pct'
> </td></tr>
369 <script type='text/javascript'
>
370 for (i
= 0; i
< 11; ++i
) {
371 W('<tr style="cursor:pointer" onclick="mClick(' + i
+ ')">' +
372 '<td class="color" style="background:#' + colors
[i
] + '" onclick="mClick(' + i
+ ')"> </td>' +
373 '<td class="title" style="width:45px"><a href="ipt-details.asp?ipt_filterip=' + abc
[i
] + '">' + abc
[i
] + '</a></td>' +
374 '<td id="obcnt' + i
+ '" class="count" style="width:60px"></td>' +
375 '<td id="obcntx' + i
+ '" class="count" style="width:50px"></td>' +
376 '<td id="obpct' + i
+ '" class="pct"></td></tr>');
379 <tr><td> </td><td class=
"total">Total
</a></td><td id=
"obcnt-total" class=
"total count"></td><td id=
"obcntx-total" class=
"total count"></td><td class=
"total pct">100%
</td></tr>
381 </td><td style=
"margin-right:150px">
382 <script type='text/javascript'
>
383 if (nvram
.web_svg
!= '0') {
384 W('<embed src="ipt-graph.svg?n=2&v=<% version(); %>" style="width:310px;height:310px;margin:0;padding:0" id="svg2" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/"></embed>');
393 <script type='text/javascript'
>
394 if (nvram
.cstats_enable
!= '1') {
395 W('<div class="note-disabled"><b>IP Traffic monitoring disabled.</b> <a href="admin-iptraffic.asp">Enable »</a></div>');
402 <tr><td id='footer' colspan=
2>
403 <script type='text/javascript'
>genStdRefresh(1,1,'ref.toggle()');</script>