Merge branch 'Tomato-RAF' into tomato-shibby
[tomato.git] / release / src / router / www / status-data.jsx
blob1c0130e7c5ff876e4bf7c8a90c3167f68fd84c11
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.cpumhz = sysinfo.cpuclk+'MHz';
30         stats.systemtype = sysinfo.systemtype;
31         stats.cpuload = ((sysinfo.loads[0] / 65536.0).toFixed(2) + '<small> / </small> ' +
32                 (sysinfo.loads[1] / 65536.0).toFixed(2) + '<small> / </small>' +
33                 (sysinfo.loads[2] / 65536.0).toFixed(2));
34         stats.uptime = sysinfo.uptime_s;
36         a = sysinfo.totalram;
37         b = sysinfo.totalfreeram;
38         stats.memory = scaleSize(a) + ' / ' + scaleSize(b) + ' <small>(' + (b / a * 100.0).toFixed(2) + '%)</small>';
39         if (sysinfo.totalswap > 0) {
40                 a = sysinfo.totalswap;
41                 b = sysinfo.freeswap;
42                 stats.swap = scaleSize(a) + ' / ' + scaleSize(b) + ' <small>(' + (b / a * 100.0).toFixed(2) + '%)</small>';
43         } else
44                 stats.swap = '';
46         stats.time = '<% time(); %>';
47         stats.wanup = '<% wanup(); %>' == '1';
48         stats.wanuptime = '<% link_uptime(); %>';
49         stats.wanlease = '<% dhcpc_time(); %>';
51         //<% dns(); %>
52         stats.dns = dns.join(', ');
54         stats.wanip = nvram.wan_ipaddr;
55         stats.wannetmask = nvram.wan_netmask;
56         stats.wangateway = nvram.wan_gateway_get;
57         if (stats.wangateway == '0.0.0.0' || stats.wangateway == '')
58                 stats.wangateway = nvram.wan_gateway;
60         switch (nvram.wan_proto) {
61         case 'pptp':
62         case 'l2tp':
63                 if (stats.wanup) {
64                         stats.wanip = nvram.ppp_get_ip;
65                         if (nvram.pptp_dhcp == '1') {
66                                 if (nvram.wan_ipaddr != '' && nvram.wan_ipaddr != '0.0.0.0' && nvram.wan_ipaddr != stats.wanip)
67                                         stats.wanip += '&nbsp;&nbsp;<small>(DHCP: ' + nvram.wan_ipaddr + ')</small>';
68                                 if (nvram.wan_gateway != '' && nvram.wan_gateway != '0.0.0.0' && nvram.wan_gateway != stats.wangateway)
69                                         stats.wangateway += '&nbsp;&nbsp;<small>(DHCP: ' + nvram.wan_gateway + ')</small>';
70                         }
71                         if (stats.wannetmask == '0.0.0.0')
72                                 stats.wannetmask = '255.255.255.255';
73                 }
74                 else {
75                         if (nvram.wan_proto == 'pptp')
76                                 stats.wangateway = nvram.pptp_server_ip;
77                 }
78                 break;
79         default:
80                 if (!stats.wanup) {
81                         stats.wanip = '0.0.0.0';
82                         stats.wannetmask = '0.0.0.0';
83                         stats.wangateway = '0.0.0.0';
84                 }
85         }
87 /* IPV6-BEGIN */
88         stats.ip6_wan = ((typeof(sysinfo.ip6_wan) != 'undefined') ? sysinfo.ip6_wan : '') + '';
89         stats.ip6_lan = ((typeof(sysinfo.ip6_lan) != 'undefined') ? sysinfo.ip6_lan : '') + ''
90         stats.ip6_lan_ll = ((typeof(sysinfo.ip6_lan_ll) != 'undefined') ? sysinfo.ip6_lan_ll : '') + ''
91 /* IPV6-END */
93         stats.wanstatus = '<% wanstatus(); %>';
94         if (stats.wanstatus != 'Connected') stats.wanstatus = '<b>' + stats.wanstatus + '</b>';
96         stats.channel = [];
97         stats.interference = [];
98         stats.qual = [];
100         for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
101                 u = wl_unit(uidx);
103                 a = i = wlstats[uidx].channel * 1;
104                 if (i < 0) i = -i;
105                 stats.channel.push('<a href="tools-survey.asp">' + ((i) ? i + '' : 'Auto') +
106                         ((wlstats[uidx].mhz) ? ' - ' + (wlstats[uidx].mhz / 1000.0).toFixed(3) + ' <small>GHz</small>' : '') + '</a>' +
107                         ((a < 0) ? ' <small>(scanning...)</small>' : ''));
108                 stats.interference.push((wlstats[uidx].intf >= 0) ? ((wlstats[uidx].intf) ? 'Severe' : 'Acceptable') : '');
110                 a = wlstats[uidx].nbw * 1;
111                 wlstats[uidx].nbw = (a > 0) ? (a + ' <small>MHz</small>') : 'Auto';
113                 if (wlstats[uidx].radio) {
114                         a = wlstats[uidx].rate * 1;
115                         if (a > 0)
116                                 wlstats[uidx].rate = Math.floor(a / 2) + ((a & 1) ? '.5' : '') + ' <small>Mbps</small>';
117                         else
118                                 wlstats[uidx].rate = '-';
120                         if (wlstats[uidx].client) {
121                                 if (wlstats[uidx].rssi == 0) a = 0;
122                                         else a = MAX(wlstats[uidx].rssi - wlstats[uidx].noise, 0);
123                                 stats.qual.push(a + ' <img src="bar' + MIN(MAX(Math.floor(a / 10), 1), 6) + '.gif">');
124                         }
125                         else {
126                                 stats.qual.push('');
127                         }
128                         wlstats[uidx].noise += ' <small>dBm</small>';
129                         wlstats[uidx].rssi += ' <small>dBm</small>';
130                 }
131                 else {
132                         wlstats[uidx].rate = '';
133                         wlstats[uidx].noise = '';
134                         wlstats[uidx].rssi = '';
135                         stats.qual.push('');
136                 }
137         }
138 } while (0);