Improved readability of labels on IPTraffic graphics
[tomato.git] / release / src / router / www / ipt-realtime.asp
blob899a04824b54abbdce524b60dadee8427f336226
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 For use with Tomato Firmware only.
8 No part of this file may be used without permission.
9 -->
10 <html>
11 <head>
12 <meta http-equiv='content-type' content='text/html;charset=utf-8'>
13 <meta name='robots' content='noindex,nofollow'>
14 <title>[<% ident(); %>] Bandwidth: Real-Time Client Monitor</title>
15 <link rel='stylesheet' type='text/css' href='tomato.css'>
16 <% css(); %>
17 <script type='text/javascript' src='tomato.js'></script>
19 <!-- / / / -->
21 <style type='text/css'>
22 #txt {
23 width: 550px;
24 white-space: nowrap;
26 #bwm-controls {
27 text-align: right;
28 margin-right: 5px;
29 margin-top: 5px;
30 float: right;
31 visibility: hidden;
33 ul.tabs a,
34 #tabs a {
35 width: 140px;
36 height: 12px;
37 font-size: 9px;
38 font-weight:bold;
40 </style>
42 <script type='text/javascript' src='debug.js'></script>
44 <script type='text/javascript' src='wireless.jsx?_http_id=<% nv(http_id); %>'></script>
45 <script type='text/javascript' src='bwm-common.js'></script>
46 <script type='text/javascript' src='interfaces.js'></script>
48 <script type='text/javascript'>
49 // <% nvram("wan_ifname,lan_ifname,wl_ifname,wan_proto,wan_iface,web_svg,cstats_colors,dhcpd_static,lan_ipaddr,lan_netmask,lan1_ipaddr,lan1_netmask,lan2_ipaddr,lan2_netmask,lan3_ipaddr,lan3_netmask,cstats_labels"); %>
51 // <% devlist(); %>
53 var cprefix = 'ipt_r';
54 var updateInt = 2;
55 var updateDiv = updateInt;
56 var updateMaxL = 300;
57 var updateReTotal = 1;
58 var prev = [];
59 var debugTime = 0;
60 var avgMode = 0;
61 var wdog = null;
62 var wdogWarn = null;
64 var ipt_addr_shown = [];
65 var ipt_addr_hidden = [];
67 hostnamecache = [];
69 var ref = new TomatoRefresh('update.cgi', 'exec=iptmon', updateInt);
71 ref.stop = function() {
72 this.timer.start(1000);
75 ref.refresh = function(text) {
76 var c, i, h, n, j, k, l;
78 watchdogReset();
80 ++updating;
81 try {
82 iptmon = null;
83 eval(text);
85 n = (new Date()).getTime();
86 if (this.timeExpect) {
87 if (debugTime) E('dtime').innerHTML = (this.timeExpect - n) + ' ' + ((this.timeExpect + 1000*updateInt) - n);
88 this.timeExpect += 1000*updateInt;
89 this.refreshTime = MAX(this.timeExpect - n, 500);
91 else {
92 this.timeExpect = n + 1000*updateInt;
95 for (i in iptmon) {
96 c = iptmon[i];
97 if ((p = prev[i]) != null) {
98 h = speed_history[i];
100 h.rx.splice(0, 1);
101 h.rx.push((c.rx < p.rx) ? (c.rx + (0xFFFFFFFF - p.rx)) : (c.rx - p.rx));
103 h.tx.splice(0, 1);
104 h.tx.push((c.tx < p.tx) ? (c.tx + (0xFFFFFFFF - p.tx)) : (c.tx - p.tx));
106 else if (!speed_history[i]) {
107 speed_history[i] = {};
108 h = speed_history[i];
109 h.rx = [];
110 h.tx = [];
111 for (j = 300; j > 0; --j) {
112 h.rx.push(0);
113 h.tx.push(0);
115 h.count = 0;
116 h.hide = 0;
118 prev[i] = c;
120 if ((ipt_addr_hidden.find(i) == -1) && (ipt_addr_shown.find(i) == -1) && (i.trim() != '')) {
121 ipt_addr_shown.push(i);
122 var option=document.createElement("option");
123 option.value=i;
124 if (hostnamecache[i] != null) {
125 option.text = hostnamecache[i] + ' (' + i + ')';
126 } else {
127 option.text=i;
129 E('_f_ipt_addr_shown').add(option,null);
132 if (ipt_addr_hidden.find(i) != -1) {
133 speed_history[i].hide = 1;
134 } else {
135 speed_history[i].hide = 0;
138 verifyFields(null,1);
141 loadData();
143 catch (ex) {
144 /* REMOVE-BEGIN
145 // alert('ex=' + ex);
146 REMOVE-END */
148 --updating;
151 function watchdog() {
152 watchdogReset();
153 ref.stop();
154 wdogWarn.style.display = '';
157 function watchdogReset() {
158 if (wdog) clearTimeout(wdog)
159 wdog = setTimeout(watchdog, 5000*updateInt);
160 wdogWarn.style.display = 'none';
163 function init() {
164 populateCache();
166 speed_history = [];
168 initCommon(2, 1, 1);
170 wdogWarn = E('warnwd');
171 watchdogReset();
173 var c;
174 if ((c = cookie.get('ipt_addr_hidden')) != null) {
175 c = c.split(',');
176 for (var i = 0; i < c.length; ++i) {
177 if (c[i].trim() != '') {
178 ipt_addr_hidden.push(c[i]);
179 var option=document.createElement("option");
180 option.value=c[i];
181 if (hostnamecache[c[i]] != null) {
182 option.text = hostnamecache[c[i]] + ' (' + c[i] + ')';
183 } else {
184 option.text = c[i];
186 E('_f_ipt_addr_hidden').add(option,null);
191 verifyFields(null,1);
193 var theRules = document.styleSheets[2].cssRules;
194 switch (nvram['cstats_labels']) {
195 case '1': // show hostnames only
196 theRules[theRules.length-1].style.cssText = 'width: 140px; font-weight:bold;';
197 /* REMOVE-BEGIN */
198 // document.styleSheets[2].deleteRule(theRules.length - 1);
199 /* REMOVE-END */
200 break;
201 case '2': // show IPs only
202 theRules[theRules.length-1].style.cssText = 'width: 140px; font-weight:bold;';
203 break;
204 case '0': // show hostnames + IPs
205 default:
206 /* REMOVE-BEGIN */
207 // theRules[theRules.length-1].style.cssText = 'width: 140px; height: 12px; font-size: 9px;';
208 /* REMOVE-END */
209 break;
212 ref.start();
215 function verifyFields(focused, quiet) {
216 var changed_addr_hidden = 0;
217 if (focused != null) {
218 if (focused.id == '_f_ipt_addr_shown') {
219 ipt_addr_shown.remove(focused.options[focused.selectedIndex].value);
220 ipt_addr_hidden.push(focused.options[focused.selectedIndex].value);
221 var option=document.createElement("option");
222 option.text=focused.options[focused.selectedIndex].text;
223 option.value=focused.options[focused.selectedIndex].value;
224 E('_f_ipt_addr_shown').remove(focused.selectedIndex);
225 E('_f_ipt_addr_shown').selectedIndex=0;
226 E('_f_ipt_addr_hidden').add(option,null);
227 changed_addr_hidden = 1;
230 if (focused.id == '_f_ipt_addr_hidden') {
231 ipt_addr_hidden.remove(focused.options[focused.selectedIndex].value);
232 ipt_addr_shown.push(focused.options[focused.selectedIndex].value);
233 var option=document.createElement("option");
234 option.text=focused.options[focused.selectedIndex].text;
235 option.value=focused.options[focused.selectedIndex].value;
236 E('_f_ipt_addr_hidden').remove(focused.selectedIndex);
237 E('_f_ipt_addr_hidden').selectedIndex=0;
238 E('_f_ipt_addr_shown').add(option,null);
239 changed_addr_hidden = 1;
241 if (changed_addr_hidden == 1) {
242 cookie.set('ipt_addr_hidden', ipt_addr_hidden.join(','), 1);
246 if (E('_f_ipt_addr_hidden').length < 2) {
247 E('_f_ipt_addr_hidden').disabled = 1;
248 } else {
249 E('_f_ipt_addr_hidden').disabled = 0;
252 if (E('_f_ipt_addr_shown').length < 2) {
253 E('_f_ipt_addr_shown').disabled = 1;
254 } else {
255 E('_f_ipt_addr_shown').disabled = 0;
258 return 1;
260 </script>
262 </head>
263 <body onload='init()'>
264 <form>
265 <table id='container' cellspacing=0>
266 <tr><td colspan=2 id='header'>
267 <div class='title'>Tomato</div>
268 <div class='version'>Version <% version(); %></div>
269 </td></tr>
270 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
271 <td id='content'>
272 <div id='ident'><% ident(); %></div>
274 <!-- / / / -->
275 <div id='cstats'>
276 <div id='tab-area'></div>
278 <script type='text/javascript'>
279 if (nvram.web_svg != '0') {
280 // without a div, Opera 9 moves svgdoc several pixels outside of <embed> (?)
281 W("<div style='border-top:1px solid #f0f0f0;border-bottom:1px solid #f0f0f0;visibility:hidden;padding:0;margin:0' id='graph'><embed src='bwm-graph.svg?<% version(); %>' style='width:760px;height:300px;margin:0;padding:0' type='image/svg+xml' pluginspage='http://www.adobe.com/svg/viewer/install/'></embed></div>");
283 </script>
285 <div id='bwm-controls'>
286 <small>(<script type='text/javascript'>W(5*updateInt);</script> minute window, <script type='text/javascript'>W(updateInt);</script> second interval)</small><br>
287 <br>
288 Avg:&nbsp;
289 <a href='javascript:switchAvg(1)' id='avg1'>Off</a>,
290 <a href='javascript:switchAvg(2)' id='avg2'>2x</a>,
291 <a href='javascript:switchAvg(4)' id='avg4'>4x</a>,
292 <a href='javascript:switchAvg(6)' id='avg6'>6x</a>,
293 <a href='javascript:switchAvg(8)' id='avg8'>8x</a><br>
294 Max:&nbsp;
295 <a href='javascript:switchScale(0)' id='scale0'>Uniform</a>,
296 <a href='javascript:switchScale(1)' id='scale1'>Per Address</a><br>
297 Display:&nbsp;
298 <a href='javascript:switchDraw(0)' id='draw0'>Solid</a>,
299 <a href='javascript:switchDraw(1)' id='draw1'>Line</a><br>
300 Color:&nbsp; <a href='javascript:switchColor()' id='drawcolor'>-</a><br>
301 <small><a href='javascript:switchColor(1)' id='drawrev'>[reverse]</a></small><br>
303 <br><br>
304 &nbsp; &raquo; <a href="admin-iptraffic.asp">Configure</a>
305 </div>
307 <br><br>
308 <table border=0 cellspacing=2 id='txt'>
309 <tr>
310 <td width='8%' align='right' valign='top'><b style='border-bottom:blue 1px solid' id='rx-name'>RX</b></td>
311 <td width='15%' align='right' valign='top'><span id='rx-current'></span></td>
312 <td width='8%' align='right' valign='top'><b>Avg</b></td>
313 <td width='15%' align='right' valign='top' id='rx-avg'></td>
314 <td width='8%' align='right' valign='top'><b>Peak</b></td>
315 <td width='15%' align='right' valign='top' id='rx-max'></td>
316 <td width='8%' align='right' valign='top'><b>Total</b></td>
317 <td width='14%' align='right' valign='top' id='rx-total'></td>
318 <td>&nbsp;</td>
319 </tr>
320 <tr>
321 <td width='8%' align='right' valign='top'><b style='border-bottom:blue 1px solid' id='tx-name'>TX</b></td>
322 <td width='15%' align='right' valign='top'><span id='tx-current'></span></td>
323 <td width='8%' align='right' valign='top'><b>Avg</b></td>
324 <td width='15%' align='right' valign='top' id='tx-avg'></td>
325 <td width='8%' align='right' valign='top'><b>Peak</b></td>
326 <td width='15%' align='right' valign='top' id='tx-max'></td>
327 <td width='8%' align='right' valign='top'><b>Total</b></td>
328 <td width='14%' align='right' valign='top' id='tx-total'></td>
329 <td>&nbsp;</td>
330 </tr>
331 </table>
333 <!-- / / / -->
335 <br>
337 <div>
338 <script type='text/javascript'>
339 createFieldTable('', [
340 { title: 'IPs currently on graphic', name: 'f_ipt_addr_shown', type: 'select', options: [[0,'Select']], suffix: ' <small>(Click/select a device from this list to hide it)</small>' },
341 { title: 'Hidden addresses', name: 'f_ipt_addr_hidden', type: 'select', options: [[0,'Select']], suffix: ' <small>(Click/select to show it again)</small>' }
343 </script>
344 </div>
346 </div>
347 <br>
349 <!-- / / / -->
351 </td></tr>
352 <tr><td id='footer' colspan=2>
353 <span id='warnwd' style='display:none'>Warning: 10 second timeout, restarting...&nbsp;</span>
354 <span id='dtime'></span>
355 <img src='spin.gif' id='refresh-spinner' onclick='javascript:debugTime=1'>
357 </td></tr>
358 </table>
359 </form>
360 </body>
361 </html>