Merge remote-tracking branch 'origin/tomato-shibby' into tomato-null
[tomato/tomato-cn.git] / release / src / router / www / status-data.jsx
blobcb5253bb8f49999b13124f3208f610d39892fa69
1 /*
2         Tomato GUI
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.
8 */
11 //<% nvram("ppp_get_ip,pptp_server_ip,router_name,wan_domain,wan_gateway,wan_gateway_get,wan_get_domain,wan_hostname,wan_hwaddr,wan_ipaddr,wan_netmask,wan_proto,wan_run_mtu,et0macaddr,lan_proto,lan_ipaddr,dhcp_start,dhcp_num,dhcpd_startip,dhcpd_endip,lan_netmask,wl_security_mode,wl_crypto,wl_mode,wl_wds_enable,wl_hwaddr,wl_net_mode,wl_radio,wl_channel,lan_gateway,wl_ssid,t_model_name,t_features,pptp_dhcp"); %>
14 //<% uptime(); %>
15 //<% sysinfo(); %>
16 //<% wlstats(); %>
18 stats = { };
20 do {
21         var a, b, i;
23         if (typeof(last_wan_proto) == 'undefined') {
24                 last_wan_proto = nvram.wan_proto;
25         }
26         else if (last_wan_proto != nvram.wan_proto) {
27                 reloadPage();
28         }
29         stats.flashsize = sysinfo.flashsize+'MB';
30         stats.cpumhz = sysinfo.cpuclk+'MHz';
31         stats.systemtype = sysinfo.systemtype;
32         stats.cpuload = ((sysinfo.loads[0] / 65536.0).toFixed(2) + '<small> / </small> ' +
33                 (sysinfo.loads[1] / 65536.0).toFixed(2) + '<small> / </small>' +
34                 (sysinfo.loads[2] / 65536.0).toFixed(2));
35         stats.freqcpu = nvram.clkfreq;
36         stats.uptime = sysinfo.uptime_s;
38         a = sysinfo.totalram;
39         b = sysinfo.totalfreeram;
40         stats.memory = scaleSize(a) + ' / ' + scaleSize(b) + ' <small>(' + (b / a * 100.0).toFixed(2) + '%)</small>';
41         if (sysinfo.totalswap > 0) {
42                 a = sysinfo.totalswap;
43                 b = sysinfo.freeswap;
44                 stats.swap = scaleSize(a) + ' / ' + scaleSize(b) + ' <small>(' + (b / a * 100.0).toFixed(2) + '%)</small>';
45         } else
46                 stats.swap = '';
48         stats.time = '<% time(); %>';
49         stats.wanup = '<% wanup(); %>' == '1';
50         stats.wanprebuf = nvram.wan_ipaddr_buf;
51         stats.wanuptime = '<% link_uptime(); %>';
52         stats.wanlease = '<% dhcpc_time(); %>';
54         //<% dns(); %>
55         stats.dns = dns.join(', ');
57         stats.wanip = nvram.wan_ipaddr;
58         stats.wannetmask = nvram.wan_netmask;
59         stats.wangateway = nvram.wan_gateway_get;
60         if (stats.wangateway == '0.0.0.0' || stats.wangateway == '')
61                 stats.wangateway = nvram.wan_gateway;
63         switch (nvram.wan_proto) {
64         case 'pptp':
65         case 'l2tp':
66                 if (stats.wanup) {
67                         stats.wanip = nvram.ppp_get_ip;
68                         if (nvram.pptp_dhcp == '1') {
69                                 if (nvram.wan_ipaddr != '' && nvram.wan_ipaddr != '0.0.0.0' && nvram.wan_ipaddr != stats.wanip)
70                                         stats.wanip += '&nbsp;&nbsp;<small>(DHCP: ' + nvram.wan_ipaddr + ')</small>';
71                                 if (nvram.wan_gateway != '' && nvram.wan_gateway != '0.0.0.0' && nvram.wan_gateway != stats.wangateway)
72                                         stats.wangateway += '&nbsp;&nbsp;<small>(DHCP: ' + nvram.wan_gateway + ')</small>';
73                         }
74                         if (stats.wannetmask == '0.0.0.0')
75                                 stats.wannetmask = '255.255.255.255';
76                 }
77                 else {
78                         if (nvram.wan_proto == 'pptp')
79                                 stats.wangateway = nvram.pptp_server_ip;
80                 }
81                 break;
82         default:
83                 if (!stats.wanup) {
84                         stats.wanip = '0.0.0.0';
85                         stats.wannetmask = '0.0.0.0';
86                         stats.wangateway = '0.0.0.0';
87                 }
88         }
90 /* IPV6-BEGIN */
91         stats.ip6_wan = ((typeof(sysinfo.ip6_wan) != 'undefined') ? sysinfo.ip6_wan : '') + '';
92         stats.ip6_lan = ((typeof(sysinfo.ip6_lan) != 'undefined') ? sysinfo.ip6_lan : '') + ''
93         stats.ip6_lan_ll = ((typeof(sysinfo.ip6_lan_ll) != 'undefined') ? sysinfo.ip6_lan_ll : '') + ''
94 /* IPV6-END */
96         stats.wanstatus = '<% wanstatus(); %>';
97         if (stats.wanstatus != 'Connected') stats.wanstatus = '<b>' + stats.wanstatus + '</b>';
99         stats.channel = [];
100         stats.interference = [];
101         stats.qual = [];
103         for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
104                 u = wl_unit(uidx);
106                 a = i = wlstats[uidx].channel * 1;
107                 if (i < 0) i = -i;
108                 stats.channel.push('<a href="tools-survey.asp">' + ((i) ? i + '' : 'Auto') +
109                         ((wlstats[uidx].mhz) ? ' - ' + (wlstats[uidx].mhz / 1000.0).toFixed(3) + ' <small>GHz</small>' : '') + '</a>' +
110                         ((a < 0) ? ' <small>(scanning...)</small>' : ''));
111                 stats.interference.push((wlstats[uidx].intf >= 0) ? ((wlstats[uidx].intf) ? 'Severe' : 'Acceptable') : '');
113                 a = wlstats[uidx].nbw * 1;
114                 wlstats[uidx].nbw = (a > 0) ? (a + ' <small>MHz</small>') : 'Auto';
116                 if (wlstats[uidx].radio) {
117                         a = wlstats[uidx].rate * 1;
118                         if (a > 0)
119                                 wlstats[uidx].rate = Math.floor(a / 2) + ((a & 1) ? '.5' : '') + ' <small>Mbps</small>';
120                         else
121                                 wlstats[uidx].rate = '-';
123                         if (wlstats[uidx].client) {
124                                 if (wlstats[uidx].rssi == 0) a = 0;
125                                         else a = MAX(wlstats[uidx].rssi - wlstats[uidx].noise, 0);
126                                 stats.qual.push(a + ' <img src="bar' + MIN(MAX(Math.floor(a / 10), 1), 6) + '.gif">');
127                         }
128                         else {
129                                 stats.qual.push('');
130                         }
131                         wlstats[uidx].noise += ' <small>dBm</small>';
132                         wlstats[uidx].rssi += ' <small>dBm</small>';
133                 }
134                 else {
135                         wlstats[uidx].rate = '';
136                         wlstats[uidx].noise = '';
137                         wlstats[uidx].rssi = '';
138                         stats.qual.push('');
139                 }
140         }
141 } while (0);