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']];
30 var hostnamecache = [];
39 return (byt / 125).toFixed(2) + ' <small>kbit/s</small><br>(' + (byt / 1024).toFixed(2) + ' <small>KB/s</small>)';
44 showTab('speed-tab-' + ifname);
47 function showSelectedOption(prefix, prev, now)
51 elem.removeClass(prefix + prev, 'selected'); // safe if prev doesn't exist
52 if ((e = E(prefix + now)) != null) {
53 elem.addClass(e, 'selected');
60 if (drawLast == drawMode) return;
61 showSelectedOption('draw', drawLast, drawMode);
65 function switchDraw(n)
67 if ((!svgReady) || (updating)) return;
71 cookie.set(cprefix + 'draw', drawMode);
76 E('drawcolor').innerHTML = colors[drawColor][0] + ' »';
77 E('rx-name').style.borderBottom = '2px dashed ' + colors[drawColor][1 + colorX];
78 E('tx-name').style.borderBottom = '2px dashed ' + colors[drawColor][1 + (colorX ^ 1)];
81 function switchColor(rev)
83 if ((!svgReady) || (updating)) return;
85 else drawColor = (drawColor + 1) % colors.length;
88 cookie.set(cprefix + 'color', drawColor + ',' + colorX);
93 if (scaleMode == scaleLast) return;
94 showSelectedOption('scale', scaleLast, scaleMode);
95 scaleLast = scaleMode;
98 function switchScale(n)
102 showTab('speed-tab-' + ifname);
103 cookie.set(cprefix + 'scale', scaleMode);
108 if (avgMode == avgLast) return;
109 showSelectedOption('avg', avgLast, avgMode);
113 function switchAvg(n)
115 if ((!svgReady) || (updating)) return;
119 cookie.set(cprefix + 'avg', avgMode);
122 function tabSelect(name)
124 if (!updating) showTab(name);
127 function showTab(name)
135 ifname = name.replace('speed-tab-', '');
136 cookie.set(cprefix + 'tab', ifname, 14);
139 h = speed_history[ifname];
142 E('rx-current').innerHTML = xpsb(h.rx[h.rx.length - 1] / updateDiv);
143 E('rx-avg').innerHTML = xpsb(h.rx_avg);
144 E('rx-max').innerHTML = xpsb(h.rx_max);
146 E('tx-current').innerHTML = xpsb(h.tx[h.tx.length - 1] / updateDiv);
147 E('tx-avg').innerHTML = xpsb(h.tx_avg);
148 E('tx-max').innerHTML = xpsb(h.tx_max);
150 E('rx-total').innerHTML = scaleSize(h.rx_total);
151 E('tx-total').innerHTML = scaleSize(h.tx_total);
154 max = scaleMode ? MAX(h.rx_max, h.tx_max) : xx_max
155 if (max > 12500) max = Math.round((max + 12499) / 12500) * 12500;
157 updateSVG(h.rx, h.tx, max, drawMode,
158 colors[drawColor][1 + colorX], colors[drawColor][1 + (colorX ^ 1)],
159 updateInt, updateMaxL, updateDiv, avgMode, clock);
176 if (!speed_history) {
180 for (var i in speed_history) {
181 var h = speed_history[i];
182 if ((typeof(h.rx) == 'undefined') || (typeof(h.tx) == 'undefined')) {
183 delete speed_history[i];
188 h.rx_total = h.rx_max = 0;
189 h.tx_total = h.tx_max = 0;
190 for (j = (h.rx.length - updateMaxL); j < h.rx.length; ++j) {
192 if (t > h.rx_max) h.rx_max = t;
195 if (t > h.tx_max) h.tx_max = t;
198 h.rx_avg = h.rx_total / updateMaxL;
199 h.tx_avg = h.tx_total / updateMaxL;
203 h.rx_max /= updateDiv;
204 h.tx_max /= updateDiv;
205 h.rx_avg /= updateDiv;
206 h.tx_avg /= updateDiv;
208 if (h.rx_max > xx_max) xx_max = h.rx_max;
209 if (h.tx_max > xx_max) xx_max = h.tx_max;
212 if (hostnamecache[i] != null) {
213 t = hostnamecache[i] + ' <small>(' + i + ')</small>';
215 else if (wl_ifidx(i) >= 0) {
217 // else if (i == nvram.wl_ifname) {
219 t = 'WL <small>(' + i + ')</small>';
221 else if ((nvram.wan_proto == 'pptp') || (nvram.wan_proto == 'pppoe') || (nvram.wan_proto == 'l2tp')) {
222 if (nvram.wan_iface == i) t = 'WAN <small>(' + i + ')</small>';
223 else if (nvram.wan_ifname == i && nvram.wan_proto != 'pppoe') t = 'MAN <small>(' + i + ')</small>';
225 else if (nvram.wan_proto != 'disabled') {
226 if (nvram.wan_ifname == i) t = 'WAN <small>(' + i + ')</small>';
228 tabs.push(['speed-tab-' + i, t]);
233 if (a[1] < b[1]) return -1;
234 if (a[1] > b[1]) return 1;
239 if (tabs.length == old.length) {
240 for (i = tabs.length - 1; i >= 0; --i)
241 if (tabs[i][0] != old[i][0]) break;
247 E('tab-area').innerHTML = _tabCreate.apply(this, tabs);
249 if (((name = cookie.get(cprefix + 'tab')) != null) && ((speed_history[name] != undefined))) {
250 showTab('speed-tab-' + name);
253 if (tabs.length) showTab(tabs[0][0]);
261 E('graph').style.visibility = 'visible';
262 E('bwm-controls').style.visibility = 'visible';
267 function initCommon(defAvg, defDrawMode, defDrawColor)
269 drawMode = fixInt(cookie.get(cprefix + 'draw'), 0, 1, defDrawMode);
272 if (nvram['rstats_colors'] != null)
273 var c = nvram.rstats_colors.split(',');
274 else if (nvram['cstats_colors'] != null)
275 var c = nvram.cstats_colors.split(',');
276 while (c.length >= 3) {
277 c[0] = escapeHTML(c[0]);
278 colors.push(c.splice(0, 3));
281 c = (cookie.get(cprefix + 'color') || '').split(',');
283 drawColor = fixInt(c[0], 0, colors.length - 1, defDrawColor);
284 colorX = fixInt(c[1], 0, 1, 0);
287 drawColor = defDrawColor;
291 scaleMode = fixInt(cookie.get(cprefix + 'scale'), 0, 1, 0);
294 avgMode = fixInt(cookie.get(cprefix + 'avg'), 1, 10, defAvg);
298 if ((nvram.wan_proto == 'disabled') || (nvram.wan_proto == 'wet')) {
299 nvram.wan_ifname = '';
304 E('refresh-spinner').style.visibility = 'hidden';
307 function populateCache() {
310 if (nvram['dhcpd_static'] != null ) {
311 s = nvram.dhcpd_static.split('>');
312 for (var i = 0; i < s.length; ++i) {
313 var t = s[i].split('<');
316 hostnamecache[t[1]] = t[2].split(' ').splice(0,1);
322 if (nvram['bwm_client'] != null ) {
323 s = nvram.bwm_client.split('>');
324 for (var i = 0; i < s.length; ++i) {
325 var t = s[i].split('<');
328 hostnamecache[t[0]] = t[1].split(' ').splice(0,1);
335 // if (dhcpd_lease != null ) {
337 if (typeof(dhcpd_lease) != 'undefined') {
338 for (var j=0; i<dhcpd_lease.length; ++j) {
339 s = dhcpd_lease[j].split('>');
340 for (var i = 0; i < s.length; ++i) {
341 var t = s[i].split('<');
344 hostnamecache[t[1]] = t[0].split(' ').splice(0,1);
350 for (var i = 0 ; i <= MAX_BRIDGE_ID ; i++) {
351 var j = (i == 0) ? '' : i.toString();
352 if (nvram['lan' + j + '_ipaddr'] != null)
353 if (nvram['lan' + j + '_netmask'] != null)
354 if (nvram['lan' + j + '_ipaddr'] != '')
355 if (nvram['lan' + j + '_netmask'] != '') {
356 hostnamecache[getNetworkAddress(nvram['lan' + j + '_ipaddr'], nvram['lan' + j + '_netmask'])] = 'LAN' + j;