1 function progressbar(query, value, max, byte)
3 var pg = document.querySelector(query),
4 vn = parseInt(value) || 0,
5 mn = parseInt(max) || 100,
6 fv = byte ? String.format('%1024.2mB', value) : value,
7 fm = byte ? String.format('%1024.2mB', max) : max,
8 pc = Math.floor((100 / mn) * vn);
11 pg.firstElementChild.style.width = pc + '%';
12 pg.setAttribute('title', '%s / %s (%d%%)'.format(fv, fm, pc));
16 function renderBox(title, active, childs) {
17 childs = childs || [];
18 childs.unshift(L.itemlist(E('span'), [].slice.call(arguments, 3)));
20 return E('div', { class: 'ifacebox' }, [
21 E('div', { class: 'ifacebox-head center ' + (active ? 'active' : '') },
23 E('div', { class: 'ifacebox-body left' }, childs)
27 function renderBadge(icon, title) {
28 return E('span', { class: 'ifacebadge' }, [
29 E('img', { src: icon, title: title || '' }),
30 L.itemlist(E('span'), [].slice.call(arguments, 2))
34 L.poll(5, L.location(), { status: 1 },
37 var us = document.getElementById('upstream_status_table');
39 while (us.lastElementChild)
40 us.removeChild(us.lastElementChild);
42 var wan_list = info.wan || [];
44 for (var i = 0; i < wan_list.length; i++) {
45 var ifc = wan_list[i];
47 us.appendChild(renderBox(
49 (ifc.ifname && ifc.proto != 'none'),
50 [ E('div', {}, renderBadge(
51 L.resource('icons/%s.png').format((ifc && ifc.type) ? ifc.type : 'ethernet_disabled'), null,
52 _('Device'), ifc ? (ifc.name || ifc.ifname || '-') : '-',
53 _('MAC-Address'), (ifc && ifc.ether) ? ifc.mac : null)) ],
54 _('Protocol'), ifc.i18n || E('em', _('Not connected')),
55 _('Address'), (ifc.ipaddrs) ? ifc.ipaddrs[0] : null,
56 _('Address'), (ifc.ipaddrs) ? ifc.ipaddrs[1] : null,
57 _('Address'), (ifc.ipaddrs) ? ifc.ipaddrs[2] : null,
58 _('Address'), (ifc.ipaddrs) ? ifc.ipaddrs[3] : null,
59 _('Address'), (ifc.ipaddrs) ? ifc.ipaddrs[4] : null,
60 _('Address'), (ifc.ipaddrs) ? ifc.ipaddrs[5] : null,
61 _('Address'), (ifc.ipaddrs) ? ifc.ipaddrs[6] : null,
62 _('Address'), (ifc.ipaddrs) ? ifc.ipaddrs[7] : null,
63 _('Address'), (ifc.ipaddrs) ? ifc.ipaddrs[8] : null,
64 _('Address'), (ifc.ipaddrs) ? ifc.ipaddrs[9] : null,
65 _('Gateway'), (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0',
66 _('DNS') + ' 1', (ifc.dns) ? ifc.dns[0] : null,
67 _('DNS') + ' 2', (ifc.dns) ? ifc.dns[1] : null,
68 _('DNS') + ' 3', (ifc.dns) ? ifc.dns[2] : null,
69 _('DNS') + ' 4', (ifc.dns) ? ifc.dns[3] : null,
70 _('DNS') + ' 5', (ifc.dns) ? ifc.dns[4] : null,
71 _('Expires'), (ifc.expires > -1) ? '%t'.format(ifc.expires) : null,
72 _('Connected'), (ifc.uptime > 0) ? '%t'.format(ifc.uptime) : null));
75 var wan6_list = info.wan6 || [];
77 for (var i = 0; i < wan6_list.length; i++) {
78 var ifc6 = wan6_list[i];
80 us.appendChild(renderBox(
82 (ifc6.ifname && ifc6.proto != 'none'),
83 [ E('div', {}, renderBadge(
84 L.resource('icons/%s.png').format(ifc6.type || 'ethernet_disabled'), null,
85 _('Device'), ifc6 ? (ifc6.name || ifc6.ifname || '-') : '-',
86 _('MAC-Address'), (ifc6 && ifc6.ether) ? ifc6.mac : null)) ],
87 _('Protocol'), ifc6.i18n ? (ifc6.i18n + (ifc6.proto === 'dhcp' && ifc6.ip6prefix ? '-PD' : '')) : E('em', _('Not connected')),
88 _('Prefix Delegated'), ifc6.ip6prefix,
89 _('Address'), (ifc6.ip6addrs) ? ifc6.ip6addrs[0] : null,
90 _('Address'), (ifc6.ip6addrs) ? ifc6.ip6addrs[1] : null,
91 _('Address'), (ifc6.ip6addrs) ? ifc6.ip6addrs[2] : null,
92 _('Address'), (ifc6.ip6addrs) ? ifc6.ip6addrs[3] : null,
93 _('Address'), (ifc6.ip6addrs) ? ifc6.ip6addrs[4] : null,
94 _('Address'), (ifc6.ip6addrs) ? ifc6.ip6addrs[5] : null,
95 _('Address'), (ifc6.ip6addrs) ? ifc6.ip6addrs[6] : null,
96 _('Address'), (ifc6.ip6addrs) ? ifc6.ip6addrs[7] : null,
97 _('Address'), (ifc6.ip6addrs) ? ifc6.ip6addrs[8] : null,
98 _('Address'), (ifc6.ip6addrs) ? ifc6.ip6addrs[9] : null,
99 _('Gateway'), (ifc6.gw6addr) ? ifc6.gw6addr : '::',
100 _('DNS') + ' 1', (ifc6.dns) ? ifc6.dns[0] : null,
101 _('DNS') + ' 2', (ifc6.dns) ? ifc6.dns[1] : null,
102 _('DNS') + ' 3', (ifc6.dns) ? ifc6.dns[2] : null,
103 _('DNS') + ' 4', (ifc6.dns) ? ifc6.dns[3] : null,
104 _('DNS') + ' 5', (ifc6.dns) ? ifc6.dns[4] : null,
105 _('Connected'), (ifc6.uptime > 0) ? '%t'.format(ifc6.uptime) : null));
108 var ds = document.getElementById('dsl_status_table');
110 while (ds.lastElementChild)
111 ds.removeChild(ds.lastElementChild);
113 ds.appendChild(renderBox(
115 (info.dsl.line_state === 'UP'), [ ],
116 _('Line State'), '%s [0x%x]'.format(info.dsl.line_state, info.dsl.line_state_detail),
117 _('Line Mode'), info.dsl.line_mode_s || '-',
118 _('Line Uptime'), info.dsl.line_uptime_s || '-',
119 _('Annex'), info.dsl.annex_s || '-',
120 _('Profile'), info.dsl.profile_s || '-',
121 _('Data Rate'), '%s/s / %s/s'.format(info.dsl.data_rate_down_s, info.dsl.data_rate_up_s),
122 _('Max. Attainable Data Rate (ATTNDR)'), '%s/s / %s/s'.format(info.dsl.max_data_rate_down_s, info.dsl.max_data_rate_up_s),
123 _('Latency'), '%s / %s'.format(info.dsl.latency_num_down, info.dsl.latency_num_up),
124 _('Line Attenuation (LATN)'), '%.1f dB / %.1f dB'.format(info.dsl.line_attenuation_down, info.dsl.line_attenuation_up),
125 _('Signal Attenuation (SATN)'), '%.1f dB / %.1f dB'.format(info.dsl.signal_attenuation_down, info.dsl.signal_attenuation_up),
126 _('Noise Margin (SNR)'), '%.1f dB / %.1f dB'.format(info.dsl.noise_margin_down, info.dsl.noise_margin_up),
127 _('Aggregate Transmit Power(ACTATP)'), '%.1f dB / %.1f dB'.format(info.dsl.actatp_down, info.dsl.actatp_up),
128 _('Forward Error Correction Seconds (FECS)'), '%d / %d'.format(info.dsl.errors_fecs_near, info.dsl.errors_fecs_far),
129 _('Errored seconds (ES)'), '%d / %d'.format(info.dsl.errors_es_near, info.dsl.errors_es_far),
130 _('Severely Errored Seconds (SES)'), '%d / %d'.format(info.dsl.errors_ses_near, info.dsl.errors_ses_far),
131 _('Loss of Signal Seconds (LOSS)'), '%d / %d'.format(info.dsl.errors_loss_near, info.dsl.errors_loss_far),
132 _('Unavailable Seconds (UAS)'), '%d / %d'.format(info.dsl.errors_uas_near, info.dsl.errors_uas_far),
133 _('Header Error Code Errors (HEC)'), '%d / %d'.format(info.dsl.errors_hec_near, info.dsl.errors_hec_far),
134 _('Non Pre-emtive CRC errors (CRC_P)'), '%d / %d'.format(info.dsl.errors_crc_p_near, info.dsl.errors_crc_p_far),
135 _('Pre-emtive CRC errors (CRCP_P)'), '%d / %d'.format(info.dsl.errors_crcp_p_near, info.dsl.errors_crcp_p_far),
136 _('ATU-C System Vendor ID'), info.dsl.atuc_vendor_id,
137 _('Power Management Mode'), info.dsl.power_mode_s));
140 var ws = document.getElementById('wifi_status_table');
143 while (ws.lastElementChild)
144 ws.removeChild(ws.lastElementChild);
146 for (var didx = 0; didx < info.wifinets.length; didx++)
148 var dev = info.wifinets[didx];
149 var net0 = (dev.networks && dev.networks[0]) ? dev.networks[0] : {};
152 for (var nidx = 0; nidx < dev.networks.length; nidx++)
154 var net = dev.networks[nidx];
155 var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel && !net.disabled);
159 icon = L.resource('icons/signal-none.png');
160 else if (net.quality <= 0)
161 icon = L.resource('icons/signal-0.png');
162 else if (net.quality < 25)
163 icon = L.resource('icons/signal-0-25.png');
164 else if (net.quality < 50)
165 icon = L.resource('icons/signal-25-50.png');
166 else if (net.quality < 75)
167 icon = L.resource('icons/signal-50-75.png');
169 icon = L.resource('icons/signal-75-100.png');
171 vifs.push(renderBadge(
173 '%s: %d dBm / %s: %d%%'.format(_('Signal'), net.signal, _('Quality'), net.quality),
174 _('SSID'), E('a', { href: net.link }, [ net.ssid || '?' ]),
176 _('BSSID'), is_assoc ? (net.bssid || '-') : null,
177 _('Encryption'), is_assoc ? net.encryption : null,
178 _('Associations'), is_assoc ? (net.num_assoc || '-') : null,
179 null, is_assoc ? null : E('em', net.disabled ? _('Wireless is disabled') : _('Wireless is not associated'))));
182 ws.appendChild(renderBox(
183 dev.device, dev.up || net0.up,
185 _('Type'), dev.name.replace(/^Generic | Wireless Controller .+$/g, ''),
186 _('Channel'), net0.channel ? '%d (%.3f %s)'.format(net0.channel, net0.frequency, _('GHz')) : '-',
187 _('Bitrate'), net0.bitrate ? '%d %s'.format(net0.bitrate, _('Mbit/s')) : '-'));
190 if (!ws.lastElementChild)
191 ws.appendChild(E('em', _('No information available')));
196 if (e = document.getElementById('localtime'))
197 e.innerHTML = info.localtime;
199 if (e = document.getElementById('uptime'))
200 e.innerHTML = String.format('%t', info.uptime);
202 if (e = document.getElementById('loadavg'))
203 e.innerHTML = String.format(
204 '%.02f, %.02f, %.02f',
205 info.loadavg[0] / 65535.0,
206 info.loadavg[1] / 65535.0,
207 info.loadavg[2] / 65535.0
210 progressbar('#memtotal',
211 info.memory.free + info.memory.buffered,
215 progressbar('#memfree',
220 progressbar('#membuff',
221 info.memory.buffered,
225 progressbar('#swaptotal',
230 progressbar('#swapfree',
235 progressbar('#conns',
236 info.conncount, info.connmax, false);