3 Copyright (C) 2006-2010 Jonathan Zarate
4 http://www.polarcloud.com/tomato/
6 For use with Tomato Firmware only.
7 No part of this file may be used without permission.
27 ['Green & Blue', '#118811', '#6495ed'], ['Blue & Orange', '#003EBA', '#FF9000'],
28 ['Blue & Red', '#003EDD', '#CC4040'], ['Blue', '#22f', '#225'], ['Gray', '#000', '#999'],
29 ['Red & Black', '#d00', '#000']];
38 return (byt / 125).toFixed(2) + ' <small>kbit/s</small><br>(' + (byt / 1024).toFixed(2) + ' <small>KB/s</small>)';
43 showTab('speed-tab-' + ifname);
46 function showSelectedOption(prefix, prev, now)
50 elem.removeClass(prefix + prev, 'selected'); // safe if prev doesn't exist
51 if ((e = E(prefix + now)) != null) {
52 elem.addClass(e, 'selected');
59 if (drawLast == drawMode) return;
60 showSelectedOption('draw', drawLast, drawMode);
64 function switchDraw(n)
66 if ((!svgReady) || (updating)) return;
70 cookie.set(cprefix + 'draw', drawMode);
75 E('drawcolor').innerHTML = colors[drawColor][0] + ' »';
76 E('rx-name').style.borderBottom = '2px dashed ' + colors[drawColor][1 + colorX];
77 E('tx-name').style.borderBottom = '2px dashed ' + colors[drawColor][1 + (colorX ^ 1)];
80 function switchColor(rev)
82 if ((!svgReady) || (updating)) return;
84 else drawColor = (drawColor + 1) % colors.length;
87 cookie.set(cprefix + 'color', drawColor + ',' + colorX);
92 if (scaleMode == scaleLast) return;
93 showSelectedOption('scale', scaleLast, scaleMode);
94 scaleLast = scaleMode;
97 function switchScale(n)
101 showTab('speed-tab-' + ifname);
102 cookie.set(cprefix + 'scale', scaleMode);
107 if (avgMode == avgLast) return;
108 showSelectedOption('avg', avgLast, avgMode);
112 function switchAvg(n)
114 if ((!svgReady) || (updating)) return;
118 cookie.set(cprefix + 'avg', avgMode);
121 function tabSelect(name)
123 if (!updating) showTab(name);
126 function showTab(name)
134 ifname = name.replace('speed-tab-', '');
135 cookie.set(cprefix + 'tab', ifname, 14);
138 h = speed_history[ifname];
141 E('rx-current').innerHTML = xpsb(h.rx[h.rx.length - 1] / updateDiv);
142 E('rx-avg').innerHTML = xpsb(h.rx_avg);
143 E('rx-max').innerHTML = xpsb(h.rx_max);
145 E('tx-current').innerHTML = xpsb(h.tx[h.tx.length - 1] / updateDiv);
146 E('tx-avg').innerHTML = xpsb(h.tx_avg);
147 E('tx-max').innerHTML = xpsb(h.tx_max);
149 E('rx-total').innerHTML = scaleSize(h.rx_total);
150 E('tx-total').innerHTML = scaleSize(h.tx_total);
153 max = scaleMode ? MAX(h.rx_max, h.tx_max) : xx_max
154 if (max > 12500) max = Math.round((max + 12499) / 12500) * 12500;
156 updateSVG(h.rx, h.tx, max, drawMode,
157 colors[drawColor][1 + colorX], colors[drawColor][1 + (colorX ^ 1)],
158 updateInt, updateMaxL, updateDiv, avgMode, clock);
175 if (!speed_history) {
179 for (var i in speed_history) {
180 var h = speed_history[i];
181 if ((typeof(h.rx) == 'undefined') || (typeof(h.tx) == 'undefined')) {
182 delete speed_history[i];
185 if ((h.rx_total == 0) && (h.tx_total == 0) && (h.up == 0)) {
186 delete speed_history[i];
190 if (typeof(h.hide) != 'undefined') {
191 if (h.hide == 1) continue;
195 h.rx_total = h.rx_max = 0;
196 h.tx_total = h.tx_max = 0;
197 for (j = (h.rx.length - updateMaxL); j < h.rx.length; ++j) {
199 if (t > h.rx_max) h.rx_max = t;
202 if (t > h.tx_max) h.tx_max = t;
205 h.rx_avg = h.rx_total / updateMaxL;
206 h.tx_avg = h.tx_total / updateMaxL;
210 h.rx_max /= updateDiv;
211 h.tx_max /= updateDiv;
212 h.rx_avg /= updateDiv;
213 h.tx_avg /= updateDiv;
215 if (h.rx_max > xx_max) xx_max = h.rx_max;
216 if (h.tx_max > xx_max) xx_max = h.tx_max;
218 t = i; // by default, show only the IP address (or IF name)
219 if ((typeof(hostnamecache) != 'undefined') && (hostnamecache[i] != null)) {
220 if (nvram['cstats_labels'] != null ) {
221 if (nvram['cstats_labels'] == '1') { // if known, show only the hostname
222 t = hostnamecache[i];
224 if (nvram['cstats_labels'] == '0') { // show hostname and IP
225 t = hostnamecache[i] + ' <small>(' + i + ')</small>';
229 else if (wl_ifidx(i) >= 0) {
231 // else if (i == nvram.wl_ifname) {
233 t = 'WL <small>(' + i + ')</small>';
237 t = 'Lim. OUT <small>(' + i + ')</small>';
241 t = 'Lim. IN <small>(' + i + ')</small>';
245 t = 'Mon. OUT <small>(' + i + ')</small>';
249 t = 'Mon. IN <small>(' + i + ')</small>';
252 else if ((nvram.wan_proto == 'pptp') || (nvram.wan_proto == 'pppoe') || (nvram.wan_proto == 'l2tp')) {
253 if (nvram.wan_iface == i) t = 'WAN <small>(' + i + ')</small>';
254 else if (nvram.wan_ifname == i && nvram.wan_proto != 'pppoe') t = 'MAN <small>(' + i + ')</small>';
256 else if (nvram.wan_proto != 'disabled') {
257 if (nvram.wan_ifname == i) t = 'WAN <small>(' + i + ')</small>';
259 tabs.push(['speed-tab-' + i, t]);
264 if (a[1] < b[1]) return -1;
265 if (a[1] > b[1]) return 1;
270 if (tabs.length == old.length) {
271 for (i = tabs.length - 1; i >= 0; --i)
272 if (tabs[i][0] != old[i][0]) break;
278 E('tab-area').innerHTML = _tabCreate.apply(this, tabs);
280 if (((name = cookie.get(cprefix + 'tab')) != null) && ((speed_history[name] != undefined))) {
281 showTab('speed-tab-' + name);
284 if (tabs.length) showTab(tabs[0][0]);
292 E('graph').style.visibility = 'visible';
293 E('bwm-controls').style.visibility = 'visible';
298 function initCommon(defAvg, defDrawMode, defDrawColor)
300 drawMode = fixInt(cookie.get(cprefix + 'draw'), 0, 1, defDrawMode);
303 if (nvram['rstats_colors'] != null)
304 var c = nvram.rstats_colors.split(',');
305 else if (nvram['cstats_colors'] != null)
306 var c = nvram.cstats_colors.split(',');
307 while (c.length >= 3) {
308 c[0] = escapeHTML(c[0]);
309 colors.push(c.splice(0, 3));
312 c = (cookie.get(cprefix + 'color') || '').split(',');
314 drawColor = fixInt(c[0], 0, colors.length - 1, defDrawColor);
315 colorX = fixInt(c[1], 0, 1, 0);
318 drawColor = defDrawColor;
322 scaleMode = fixInt(cookie.get(cprefix + 'scale'), 0, 1, 0);
325 avgMode = fixInt(cookie.get(cprefix + 'avg'), 1, 10, defAvg);
329 if ((nvram.wan_proto == 'disabled') || (nvram.wan_proto == 'wet')) {
330 nvram.wan_ifname = '';
335 E('refresh-spinner').style.visibility = 'hidden';
338 function populateCache() {
341 if (nvram['dhcpd_static'] != null ) {
342 s = nvram.dhcpd_static.split('>');
343 for (var i = 0; i < s.length; ++i) {
344 var t = s[i].split('<');
345 if ((t.length == 3) || (t.length == 4)) {
347 hostnamecache[t[1]] = t[2].split(' ').splice(0,1);
352 if (typeof(dhcpd_lease) != 'undefined') {
353 for (var j=0; j<dhcpd_lease.length; ++j) {
354 if (dhcpd_lease[j][0] != '') {
355 hostnamecache[dhcpd_lease[j][1]] = dhcpd_lease[j][0].split(' ').splice(0,1);
360 for (var i = 0 ; i <= MAX_BRIDGE_ID ; i++) {
361 var j = (i == 0) ? '' : i.toString();
362 if (nvram['lan' + j + '_ipaddr'] != null)
363 if (nvram['lan' + j + '_netmask'] != null)
364 if (nvram['lan' + j + '_ipaddr'] != '')
365 if (nvram['lan' + j + '_netmask'] != '') {
366 hostnamecache[getNetworkAddress(nvram['lan' + j + '_ipaddr'], nvram['lan' + j + '_netmask'])] = 'LAN' + j;