cosmetics
[tomato.git] / release / src / router / www / qos-ctrate.asp
blobd36820ca21f6925cd4b90b3e9467f7b6f24ed4ba
1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN'>
2 <!--
3 Tomato GUI
4 Copyright (C) 2006-2010 Jonathan Zarate
5 http://www.polarcloud.com/tomato/
7 Filtering/Extensions on this QoS/Transfer Rates page
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.
13 -->
14 <html>
15 <head>
16 <meta http-equiv='content-type' content='text/html;charset=utf-8'>
17 <meta name='robots' content='noindex,nofollow'>
18 <title>[<% ident(); %>] QoS: View Per-Connection Transfer Rates</title>
19 <link rel='stylesheet' type='text/css' href='tomato.css'>
20 <% css(); %>
21 <script type='text/javascript' src='tomato.js'></script>
23 <!-- / / / -->
25 <style type='text/css'>
26 #grid .co6 {
27 text-align: right;
29 #grid .co7 {
30 text-align: right;
32 </style>
34 <script type='text/javascript' src='debug.js'></script>
35 <script type='text/javascript' src='protocols.js'></script>
36 <script type='text/javascript' src='interfaces.js'></script>
38 <script type='text/javascript'>
39 // <% nvram('lan_ipaddr,lan1_ipaddr,lan2_ipaddr,lan3_ipaddr,lan_netmask,lan1_netmask,lan2_netmask,lan3_netmask,t_hidelr'); %>
40 var filterip = [];
41 var filteripe = [];
43 readDelay = fixInt('<% cgi_get("delay"); %>', 2, 30, 2);
45 var queue = [];
46 var xob = null;
47 var cache = [];
48 var lock = 0;
50 function resolve()
52 if ((queue.length == 0) || (xob)) return;
54 xob = new XmlHttp();
55 xob.onCompleted = function(text, xml) {
56 eval(text);
57 for (var i = 0; i < resolve_data.length; ++i) {
58 var r = resolve_data[i];
59 if (r[1] == '') r[1] = r[0];
60 cache[r[0]] = r[1];
61 if (lock == 0) grid.setName(r[0], r[1]);
63 if (queue.length == 0) {
64 if ((lock == 0) && (resolveCB) && (grid.sortColumn == 4)) grid.resort();
66 else setTimeout(resolve, 500);
67 xob = null;
69 xob.onError = function(ex) {
70 xob = null;
73 xob.post('resolve.cgi', 'ip=' + queue.splice(0, 20).join(','));
76 var resolveCB = 0;
77 var bcastCB = 0;
78 var mcastCB = 0;
80 function resolveChanged()
82 var b;
84 b = E('_f_autoresolve').checked ? 1 : 0;
85 if (b != resolveCB) {
86 resolveCB = b;
87 cookie.set('qos_ctr_resolve', b);
89 if (b) grid.resolveAll();
92 var thres = 0;
94 function thresChanged()
96 var a, b;
98 b = E('_f_excludebythreshold').checked ? fixInt('<% cgi_get("thres"); %>', 100, 10000000, 100) : 0;
99 if (b != thres) {
100 thres = b;
101 cookie.set('qos_ctr_thres', b);
102 ref.postData = 'exec=ctrate&arg0=' + readDelay + '&arg1=' + thres;
103 if (!ref.running) ref.once = 1;
104 E('loading').style.visibility = '';
105 ref.start();
109 var grid = new TomatoGrid();
111 grid.dataToView = function(data) {
112 var s, v = [];
113 for (var col = 0; col < data.length; ++col) {
114 switch (col) {
115 case 5:
116 case 6:
117 s = (data[col] / (readDelay * 1024)).toFixed(1);
118 break;
119 default:
120 s = data[col];
121 break;
123 v.push('' + s);
125 return v;
128 grid.sortCompare = function(a, b) {
129 var obj = TGO(a);
130 var col = obj.sortColumn;
131 var da = a.getRowData();
132 var db = b.getRowData();
133 var r;
135 switch (col) {
136 case 2:
137 case 4:
138 case 5:
139 case 6:
140 r = cmpInt(da[col], db[col]);
141 break;
142 case 1:
143 case 3:
144 var a = fixIP(da[col]);
145 var b = fixIP(db[col]);
146 if ((a != null) && (b != null)) {
147 r = aton(a) - aton(b);
148 break;
150 default:
151 r = cmpText(da[col], db[col]);
152 break;
154 return obj.sortAscending ? r : -r;
157 grid.onClick = function(cell) {
158 var row = PR(cell);
159 var ip = row.getRowData()[3];
160 if (this.lastClicked != row) {
161 this.lastClicked = row;
162 if (ip.indexOf('<') == -1) {
163 queue.push(ip);
164 row.style.cursor = 'wait';
165 resolve();
168 else {
169 this.resolveAll();
173 grid.resolveAll = function()
175 var i, ip, row, q, cols, j;
177 q = [];
178 cols = [1, 3];
179 for (i = 1; i < this.tb.rows.length; ++i) {
180 row = this.tb.rows[i];
181 for (j = cols.length-1; j >= 0; j--) {
182 ip = row.getRowData()[cols[j]];
183 if (ip.indexOf('<') == -1) {
184 if (!q[ip]) {
185 q[ip] = 1;
186 queue.push(ip);
188 row.style.cursor = 'wait';
192 q = null;
193 resolve();
196 grid.setName = function(ip, name) {
197 var i, row, data, cols, j;
199 cols = [1, 3];
200 for (i = this.tb.rows.length - 1; i > 0; --i) {
201 row = this.tb.rows[i];
202 data = row.getRowData();
203 for (j = cols.length-1; j >= 0; j--) {
204 if (data[cols[j]] == ip) {
205 data[cols[j]] = name + ((ip.indexOf(':') != -1) ? '<br>' : ' ') + '<small>(' + ip + ')</small>';
206 row.setRowData(data);
207 row.cells[cols[j]].innerHTML = data[cols[j]];
208 row.style.cursor = 'default';
214 grid.setup = function() {
215 this.init('grid', 'sort');
216 this.headerSet(['Proto', 'Source', 'S Port', 'Destination', 'D Port', 'UL Rate', 'DL Rate']);
219 var ref = new TomatoRefresh('update.cgi', '', 0, 'qos_ctrate');
221 var numconntotal = 0;
222 var numconnshown = 0;
224 ref.refresh = function(text)
226 var i, b, d, cols, j;
228 ++lock;
230 numconntotal = 0;
231 numconnshown = 0;
233 try {
234 ctrate = [];
235 eval(text);
237 catch (ex) {
238 ctrate = [];
241 grid.lastClicked = null;
242 grid.removeAllData();
244 var c = [];
245 var q = [];
246 var cursor;
247 var ip;
249 var fskip;
251 cols = [1, 2];
253 for (i = 0; i < ctrate.length; ++i) {
254 fskip=0;
255 numconntotal++;
256 b = ctrate[i];
258 if (E('_f_excludegw').checked) {
259 if ((b[1] == nvram.lan_ipaddr) || (b[2] == nvram.lan_ipaddr) ||
260 (b[1] == nvram.lan1_ipaddr) || (b[2] == nvram.lan1_ipaddr) ||
261 (b[1] == nvram.lan2_ipaddr) || (b[2] == nvram.lan2_ipaddr) ||
262 (b[1] == nvram.lan3_ipaddr) || (b[2] == nvram.lan3_ipaddr) ||
263 (b[1] == '127.0.0.1') || (b[2] == '127.0.0.1') ) {
264 continue;
268 if (E('_f_excludebcast').checked) {
269 if ((b[2] == getBroadcastAddress(getNetworkAddress(nvram.lan_ipaddr,nvram.lan_netmask),nvram.lan_netmask)) ||
270 (b[2] == getBroadcastAddress(getNetworkAddress(nvram.lan1_ipaddr,nvram.lan1_netmask),nvram.lan1_netmask)) ||
271 (b[2] == getBroadcastAddress(getNetworkAddress(nvram.lan2_ipaddr,nvram.lan2_netmask),nvram.lan2_netmask)) ||
272 (b[2] == getBroadcastAddress(getNetworkAddress(nvram.lan3_ipaddr,nvram.lan3_netmask),nvram.lan3_netmask)) ||
273 (b[2] == '255.255.255.255') || (b[2] == '0.0.0.0') ) {
274 continue;
278 if (E('_f_excludemcast').checked) {
279 var mmin = 3758096384; // aton('224.0.0.0') == 3758096384
280 var mmax = 4026531839; // aton('239.255.255.255') == 4026531839
281 if (((aton(b[1]) >= mmin) && (aton(b[1]) <= mmax)) ||
282 ((aton(b[2]) >= mmin) && (aton(b[2]) <= mmax))) {
283 continue;
287 if (filteripe.length>0) {
288 fskip = 0;
289 for (x = 0; x < filteripe.length; ++x) {
290 if ((b[1] == filteripe[x]) || (b[2] == filteripe[x])) {
291 fskip=1;
292 break;
295 if (fskip == 1) continue;
298 if (filterip.length>0) {
299 fskip = 1;
300 for (x = 0; x < filterip.length; ++x) {
301 if ((b[1] == filterip[x]) || (b[2] == filterip[x])) {
302 fskip=0;
303 break;
306 if (fskip == 1) continue;
309 for (j = cols.length-1; j >= 0; j--) {
310 ip = b[cols[j]];
311 if (cache[ip] != null) {
312 c[ip] = cache[ip];
313 b[cols[j]] = cache[ip] + ((ip.indexOf(':') != -1) ? '<br>' : ' ') + '<small>(' + ip + ')</small>';
314 cursor = 'default';
316 else {
317 if (resolveCB) {
318 if (!q[ip]) {
319 q[ip] = 1;
320 queue.push(ip);
322 cursor = 'wait';
324 else cursor = null;
328 numconnshown++;
329 d = [protocols[b[0]] || b[0], b[1], b[3], b[2], b[4], b[5], b[6]];
330 var row = grid.insertData(-1, d);
331 if (cursor) row.style.cursor = cursor;
333 cache = c;
334 c = null;
335 q = null;
337 grid.resort();
338 setTimeout(function() { E('loading').style.visibility = 'hidden'; }, 100);
340 --lock;
342 if (resolveCB) resolve();
344 if (numconnshown != numconntotal)
345 E('numtotalconn').innerHTML='<small><i>(showing ' + numconnshown + ' out of ' + numconntotal + ' connections)</i></small>';
346 else
347 E('numtotalconn').innerHTML='<small><i>(' + numconntotal + ' connections)</i></small>';
350 function init()
352 var c;
354 if (((c = cookie.get('qos_ctr_resolve')) != null) && (c == '1')) {
355 E('_f_autoresolve').checked = resolveCB = 1;
358 if (((c = cookie.get('qos_ctr_bcast')) != null) && (c == '1')) {
359 E('_f_excludebcast').checked = bcastCB = 1;
362 if (((c = cookie.get('qos_ctr_mcast')) != null) && (c == '1')) {
363 E('_f_excludemcast').checked = mcastCB = 1;
366 if (((c = cookie.get('qos_ctr_filters')) != null) && (c == '1')) {
367 E('sesdivfilters').style.display='';
370 if ((thres = cookie.get('qos_ctr_thres')) == null || isNaN(thres *= 1)) {
371 thres = 0;
374 E('_f_excludebythreshold').checked = (thres != 0);
375 grid.setup();
376 ref.postData = 'exec=ctrate&arg0=' + readDelay + '&arg1=' + thres;
377 ref.initPage(250);
379 if (!ref.running) ref.once = 1;
380 ref.start();
383 function dofilter() {
384 if (E('_f_filter_ip').value.length>6) {
385 filterip = E('_f_filter_ip').value.split(',');
386 } else {
387 filterip = [];
390 if (E('_f_filter_ipe').value.length>6) {
391 filteripe = E('_f_filter_ipe').value.split(',');
392 } else {
393 filteripe = [];
396 if (!ref.running)
397 ref.start();
400 function toggleFiltersVisibility(){
401 if(E('sesdivfilters').style.display=='') {
402 E('sesdivfilters').style.display='none';
403 cookie.set('qos_ctr_filters', 0);
404 } else {
405 E('sesdivfilters').style.display='';
406 cookie.set('qos_ctr_filters', 1);
410 function verifyFields(focused, quiet)
412 var b;
414 b = E('_f_excludebcast').checked ? 1 : 0;
415 if (b != bcastCB) {
416 bcastCB = b;
417 cookie.set('qos_ctr_bcast', b);
420 b = E('_f_excludemcast').checked ? 1 : 0;
421 if (b != mcastCB) {
422 mcastCB = b;
423 cookie.set('qos_ctr_mcast', b);
426 thresChanged();
427 resolveChanged();
428 dofilter();
429 return 1;
431 </script>
433 </head>
434 <body onload='init()'>
435 <form id='_fom' action='javascript:{}'>
436 <table id='container' cellspacing=0>
437 <tr><td colspan=2 id='header'>
438 <div class='title'>Tomato</div>
439 <div class='version'>Version <% version(); %></div>
440 </td></tr>
441 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
442 <td id='content'>
443 <div id='ident'><% ident(); %></div>
446 <!-- / / / -->
449 <div class='section-title' id='stitle' onclick='document.location="qos-graphs.asp"' style='cursor:pointer'>Transfer Rates: <span id='numtotalconn'></span></div>
450 <div class='section'>
451 <table id='grid' class='tomato-grid' style="float:left" cellspacing=1></table>
453 <div id='loading'><br><b>Loading...</b></div>
454 </div>
457 <!-- / / / -->
460 <div class='section-title'>Filters: <small><i><a href='javascript:toggleFiltersVisibility();'>(Toggle Visibility)</a></i></small></div>
461 <div class='section' id='sesdivfilters' style='display:none'>
462 <script type='text/javascript'>
463 var c;
464 c = [];
465 c.push({ title: 'Only these IPs', name: 'f_filter_ip', size: 50, maxlen: 255, type: 'text', suffix: ' <small>(Comma separated list)</small>' });
466 c.push({ title: 'Exclude these IPs', name: 'f_filter_ipe', size: 50, maxlen: 255, type: 'text', suffix: ' <small>(Comma separated list)</small>' });
467 c.push({ title: 'Exclude gateway traffic', name: 'f_excludegw', type: 'checkbox', value: ((nvram.t_hidelr) == '1' ? 1 : 0) });
468 c.push({ title: 'Exclude broadcasts', name: 'f_excludebcast', type: 'checkbox' });
469 c.push({ title: 'Exclude multicast', name: 'f_excludemcast', type: 'checkbox' });
470 c.push({ title: 'Ignore inactive connections', name: 'f_excludebythreshold', type: 'checkbox' });
471 c.push({ title: 'Auto resolve addresses', name: 'f_autoresolve', type: 'checkbox' });
472 createFieldTable('',c);
473 </script>
474 </div>
476 <!-- / / / -->
479 </td></tr>
480 <tr><td id='footer' colspan=2>
481 <script type='text/javascript'>genStdRefresh(1,1,'ref.toggle()');</script>
482 </td></tr>
483 </table>
484 </form>
485 </body>
486 </html>