New routers supported
[tomato.git] / release / src / router / www / status-data.jsx
blob98036f18d5d0995ac2f4136aebb7bcdb4a8a4122
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 */
10 //<% nvram("ppp_get_ip,pptp_server_ip,router_name,wan_ipaddr_buf,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,wl_closed,t_model_name,t_features,pptp_dhcp,dhcp1_start,dhcp1_num,dhcpd1_startip,dhcpd1_endip,dhcp2_start,dhcp2_num,dhcpd2_startip,dhcpd2_endip,dhcp3_start,dhcp3_num,dhcpd3_startip,dhcpd3_endip,lan1_proto,lan1_ipaddr,lan1_netmask,lan2_proto,lan2_ipaddr,lan2_netmask,lan3_proto,lan3_ipaddr,lan3_netmask,lan_ifname,lan1_ifname,lan2_ifname,lan3_ifname,lan_ifnames,lan1_ifnames,lan2_ifnames,lan3_ifnames,wan_ifnames,tomatoanon_enable,tomatoanon_answer,lan_desc"); %>
11 //<% uptime(); %>
12 //<% sysinfo(); %>
13 //<% wlstats(1); %>
15 stats = { };
17 do {
18         var a, b, i;
19         var xifs = ['wan', 'lan', 'lan1', 'lan2', 'lan3'];
21         stats.anon_enable = nvram.tomatoanon_enable;
22         stats.anon_answer = nvram.tomatoanon_answer;
24         stats.lan_desc = nvram.lan_desc;
26         if (typeof(last_wan_proto) == 'undefined') {
27                 last_wan_proto = nvram.wan_proto;
28         }
29         else if (last_wan_proto != nvram.wan_proto) {
30                 reloadPage();
31         }
32         stats.flashsize = sysinfo.flashsize+'MB';
33         stats.cpumhz = sysinfo.cpuclk+'MHz';
34         stats.systemtype = sysinfo.systemtype;
35         stats.cpuload = ((sysinfo.loads[0] / 65536.0).toFixed(2) + '<small> / </small> ' +
36                 (sysinfo.loads[1] / 65536.0).toFixed(2) + '<small> / </small>' +
37                 (sysinfo.loads[2] / 65536.0).toFixed(2));
38         stats.uptime = sysinfo.uptime_s;
40         a = sysinfo.totalram;
41         b = sysinfo.totalfreeram;
42         stats.memory = scaleSize(a) + ' / ' + scaleSize(b) + ' <small>(' + (b / a * 100.0).toFixed(2) + '%)</small>';
43         if (sysinfo.totalswap > 0) {
44                 a = sysinfo.totalswap;
45                 b = sysinfo.freeswap;
46                 stats.swap = scaleSize(a) + ' / ' + scaleSize(b) + ' <small>(' + (b / a * 100.0).toFixed(2) + '%)</small>';
47         } else
48                 stats.swap = '';
50         stats.time = '<% time(); %>';
51         stats.wanup = '<% wanup(); %>' == '1';
52         stats.wanprebuf = nvram.wan_ipaddr_buf;
53         stats.wanuptime = '<% link_uptime(); %>';
54         stats.wanlease = '<% dhcpc_time(); %>';
56         //<% dns(); %>
57         stats.dns = dns.join(', ');
59         stats.wanip = nvram.wan_ipaddr;
60         stats.wannetmask = nvram.wan_netmask;
61         stats.wangateway = nvram.wan_gateway_get;
62         if (stats.wangateway == '0.0.0.0' || stats.wangateway == '')
63                 stats.wangateway = nvram.wan_gateway;
65         switch (nvram.wan_proto) {
66         case 'pptp':
67         case 'l2tp':
68                 if (stats.wanup) {
69                         stats.wanip = nvram.ppp_get_ip;
70                         if (nvram.pptp_dhcp == '1') {
71                                 if (nvram.wan_ipaddr != '' && nvram.wan_ipaddr != '0.0.0.0' && nvram.wan_ipaddr != stats.wanip)
72                                         stats.wanip += '&nbsp;&nbsp;<small>(DHCP: ' + nvram.wan_ipaddr + ')</small>';
73                                 if (nvram.wan_gateway != '' && nvram.wan_gateway != '0.0.0.0' && nvram.wan_gateway != stats.wangateway)
74                                         stats.wangateway += '&nbsp;&nbsp;<small>(DHCP: ' + nvram.wan_gateway + ')</small>';
75                         }
76                         if (stats.wannetmask == '0.0.0.0')
77                                 stats.wannetmask = '255.255.255.255';
78                 }
79                 else {
80                         if (nvram.wan_proto == 'pptp')
81                                 stats.wangateway = nvram.pptp_server_ip;
82                 }
83                 break;
84         default:
85                 if (!stats.wanup) {
86                         stats.wanip = '0.0.0.0';
87                         stats.wannetmask = '0.0.0.0';
88                         stats.wangateway = '0.0.0.0';
89                 }
90         }
92 /* IPV6-BEGIN */
93         stats.ip6_wan = ((typeof(sysinfo.ip6_wan) != 'undefined') ? sysinfo.ip6_wan : '') + '';
94         stats.ip6_lan = ((typeof(sysinfo.ip6_lan) != 'undefined') ? sysinfo.ip6_lan : '') + ''
95         stats.ip6_lan_ll = ((typeof(sysinfo.ip6_lan_ll) != 'undefined') ? sysinfo.ip6_lan_ll : '') + ''
96 /* IPV6-END */
98         stats.wanstatus = '<% wanstatus(); %>';
99         if (stats.wanstatus != 'Connected') stats.wanstatus = '<b>' + stats.wanstatus + '</b>';
101         stats.channel = [];
102         stats.interference = [];
103         stats.qual = [];
105         for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
106                 u = wl_unit(uidx);
108                 a = i = wlstats[uidx].channel * 1;
109                 if (i < 0) i = -i;
110                 stats.channel.push('<a href="tools-survey.asp">' + ((i) ? i + '' : 'Auto') +
111                         ((wlstats[uidx].mhz) ? ' - ' + (wlstats[uidx].mhz / 1000.0).toFixed(3) + ' <small>GHz</small>' : '') + '</a>' +
112                         ((a < 0) ? ' <small>(scanning...)</small>' : ''));
113                 stats.interference.push((wlstats[uidx].intf >= 0) ? ((wlstats[uidx].intf) ? 'Severe' : 'Acceptable') : '');
115                 a = wlstats[uidx].nbw * 1;
116                 wlstats[uidx].nbw = (a > 0) ? (a + ' <small>MHz</small>') : 'Auto';
118                 if (wlstats[uidx].radio) {
119                         a = wlstats[uidx].rate * 1;
120                         if (a > 0)
121                                 wlstats[uidx].rate = Math.floor(a / 2) + ((a & 1) ? '.5' : '') + ' <small>Mbps</small>';
122                         else
123                                 wlstats[uidx].rate = '-';
125                         if (wlstats[uidx].client) {
126                                 if (wlstats[uidx].rssi == 0) a = 0;
127                                         else a = MAX(wlstats[uidx].rssi - wlstats[uidx].noise, 0);
128                                 stats.qual.push(a + ' <img src="bar' + MIN(MAX(Math.floor(a / 10), 1), 6) + '.gif">');
129                         }
130                         else {
131                                 stats.qual.push('');
132                         }
133                         wlstats[uidx].noise += ' <small>dBm</small>';
134                         wlstats[uidx].rssi += ' <small>dBm</small>';
135                 }
136                 else {
137                         wlstats[uidx].rate = '';
138                         wlstats[uidx].noise = '';
139                         wlstats[uidx].rssi = '';
140                         stats.qual.push('');
141                 }
143                 if (wl_ifaces[uidx][6] != 1) {
144                         wlstats[uidx].ifstatus = '<b>Down</b>';
145                 } else {
146                         wlstats[uidx].ifstatus = 'Up';
147                         for (i = 0; i < xifs.length ; ++i) {
148                                 if ((nvram[xifs[i] + '_ifnames']).indexOf(wl_ifaces[uidx][0]) >= 0) {
149                                         wlstats[uidx].ifstatus = wlstats[uidx].ifstatus + ' (' + xifs[i].toUpperCase() + ')';
150                                         break;
151                                 }
152                         }
153                 }
154         }
155 } while (0);