1 function progressbar(q, v, m)
3 var pg = document.querySelector(q),
5 mn = parseInt(m) || 100,
6 pc = Math.floor((100 / mn) * vn);
9 pg.firstElementChild.style.width = pc + '%';
10 pg.setAttribute('title', '%s / %s (%d%%)'.format(v, m, pc));
14 function renderBox(title, active, childs) {
15 childs = childs || [];
16 childs.unshift(L.itemlist(E('span'), [].slice.call(arguments, 3)));
18 return E('div', { class: 'ifacebox' }, [
19 E('div', { class: 'ifacebox-head center ' + (active ? 'active' : '') },
21 E('div', { class: 'ifacebox-body left' }, childs)
25 function renderBadge(icon, title) {
26 return E('span', { class: 'ifacebadge' }, [
27 E('img', { src: icon, title: title || '' }),
28 L.itemlist(E('span'), [].slice.call(arguments, 2))
32 L.poll(5, L.location(), { status: 1 },
35 var us = document.getElementById('upstream_status_table');
37 while (us.lastElementChild)
38 us.removeChild(us.lastElementChild);
40 var wan_list = info.wan || [];
42 for (var i = 0; i < wan_list.length; i++) {
43 var ifc = wan_list[i];
45 us.appendChild(renderBox(
47 (ifc.ifname && ifc.proto != 'none'),
48 [ E('div', {}, renderBadge(
49 L.resource('icons/%s.png').format((ifc && ifc.type) ? ifc.type : 'ethernet_disabled'), null,
50 _('Device'), ifc ? (ifc.name || ifc.ifname || '-') : '-',
51 _('MAC-Address'), (ifc && ifc.ether) ? ifc.mac : null)) ],
52 _('Protocol'), ifc.i18n || E('em', _('Not connected')),
53 _('Address'), (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
54 _('Netmask'), (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
55 _('Gateway'), (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0',
56 _('DNS') + ' 1', (ifc.dns) ? ifc.dns[0] : null,
57 _('DNS') + ' 2', (ifc.dns) ? ifc.dns[1] : null,
58 _('DNS') + ' 3', (ifc.dns) ? ifc.dns[2] : null,
59 _('DNS') + ' 4', (ifc.dns) ? ifc.dns[3] : null,
60 _('DNS') + ' 5', (ifc.dns) ? ifc.dns[4] : null,
61 _('Expires'), (ifc.expires > -1) ? '%t'.format(ifc.expires) : null,
62 _('Connected'), (ifc.uptime > 0) ? '%t'.format(ifc.uptime) : null));
65 var wan6_list = info.wan6 || [];
67 for (var i = 0; i < wan6_list.length; i++) {
68 var ifc6 = wan6_list[i];
70 us.appendChild(renderBox(
72 (ifc6.ifname && ifc6.proto != 'none'),
73 [ E('div', {}, renderBadge(
74 L.resource('icons/%s.png').format(ifc6.type || 'ethernet_disabled'), null,
75 _('Device'), ifc6 ? (ifc6.name || ifc6.ifname || '-') : '-',
76 _('MAC-Address'), (ifc6 && ifc6.ether) ? ifc6.mac : null)) ],
77 _('Protocol'), ifc6.i18n ? (ifc6.i18n + (ifc6.proto === 'dhcp' && ifc6.ip6prefix ? '-PD' : '')) : E('em', _('Not connected')),
78 _('Prefix Delegated'), ifc6.ip6prefix,
79 _('Address'), (ifc6.ip6prefix) ? (ifc6.ip6addr || null) : (ifc6.ip6addr || '::'),
80 _('Gateway'), (ifc6.gw6addr) ? ifc6.gw6addr : '::',
81 _('DNS') + ' 1', (ifc6.dns) ? ifc6.dns[0] : null,
82 _('DNS') + ' 2', (ifc6.dns) ? ifc6.dns[1] : null,
83 _('DNS') + ' 3', (ifc6.dns) ? ifc6.dns[2] : null,
84 _('DNS') + ' 4', (ifc6.dns) ? ifc6.dns[3] : null,
85 _('DNS') + ' 5', (ifc6.dns) ? ifc6.dns[4] : null,
86 _('Connected'), (ifc6.uptime > 0) ? '%t'.format(ifc6.uptime) : null));
89 var ds = document.getElementById('dsl_status_table');
91 while (ds.lastElementChild)
92 ds.removeChild(ds.lastElementChild);
94 ds.appendChild(renderBox(
96 (info.dsl.line_state === 'UP'), [ ],
97 _('Line State'), '%s [0x%x]'.format(info.dsl.line_state, info.dsl.line_state_detail),
98 _('Line Mode'), info.dsl.line_mode_s || '-',
99 _('Line Uptime'), info.dsl.line_uptime_s || '-',
100 _('Annex'), info.dsl.annex_s || '-',
101 _('Profile'), info.dsl.profile_s || '-',
102 _('Data Rate'), '%s/s / %s/s'.format(info.dsl.data_rate_down_s, info.dsl.data_rate_up_s),
103 _('Max. Attainable Data Rate (ATTNDR)'), '%s/s / %s/s'.format(info.dsl.max_data_rate_down_s, info.dsl.max_data_rate_up_s),
104 _('Latency'), '%s / %s'.format(info.dsl.latency_num_down, info.dsl.latency_num_up),
105 _('Line Attenuation (LATN)'), '%.1f dB / %.1f dB'.format(info.dsl.line_attenuation_down, info.dsl.line_attenuation_up),
106 _('Signal Attenuation (SATN)'), '%.1f dB / %.1f dB'.format(info.dsl.signal_attenuation_down, info.dsl.signal_attenuation_up),
107 _('Noise Margin (SNR)'), '%.1f dB / %.1f dB'.format(info.dsl.noise_margin_down, info.dsl.noise_margin_up),
108 _('Aggregate Transmit Power(ACTATP)'), '%.1f dB / %.1f dB'.format(info.dsl.actatp_down, info.dsl.actatp_up),
109 _('Forward Error Correction Seconds (FECS)'), '%d / %d'.format(info.dsl.errors_fec_near, info.dsl.errors_fec_far),
110 _('Errored seconds (ES)'), '%d / %d'.format(info.dsl.errors_es_near, info.dsl.errors_es_far),
111 _('Severely Errored Seconds (SES)'), '%d / %d'.format(info.dsl.errors_ses_near, info.dsl.errors_ses_far),
112 _('Loss of Signal Seconds (LOSS)'), '%d / %d'.format(info.dsl.errors_loss_near, info.dsl.errors_loss_far),
113 _('Unavailable Seconds (UAS)'), '%d / %d'.format(info.dsl.errors_uas_near, info.dsl.errors_uas_far),
114 _('Header Error Code Errors (HEC)'), '%d / %d'.format(info.dsl.errors_hec_near, info.dsl.errors_hec_far),
115 _('Non Pre-emtive CRC errors (CRC_P)'), '%d / %d'.format(info.dsl.errors_crc_p_near, info.dsl.errors_crc_p_far),
116 _('Pre-emtive CRC errors (CRCP_P)'), '%d / %d'.format(info.dsl.errors_crcp_p_near, info.dsl.errors_crcp_p_far),
117 _('ATU-C System Vendor ID'), info.dsl.atuc_vendor_id,
118 _('Power Management Mode'), info.dsl.power_mode_s));
121 var ws = document.getElementById('wifi_status_table');
124 while (ws.lastElementChild)
125 ws.removeChild(ws.lastElementChild);
127 for (var didx = 0; didx < info.wifinets.length; didx++)
129 var dev = info.wifinets[didx];
130 var net0 = (dev.networks && dev.networks[0]) ? dev.networks[0] : {};
133 for (var nidx = 0; nidx < dev.networks.length; nidx++)
135 var net = dev.networks[nidx];
136 var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel && !net.disabled);
140 icon = L.resource('icons/signal-none.png');
141 else if (net.quality <= 0)
142 icon = L.resource('icons/signal-0.png');
143 else if (net.quality < 25)
144 icon = L.resource('icons/signal-0-25.png');
145 else if (net.quality < 50)
146 icon = L.resource('icons/signal-25-50.png');
147 else if (net.quality < 75)
148 icon = L.resource('icons/signal-50-75.png');
150 icon = L.resource('icons/signal-75-100.png');
152 vifs.push(renderBadge(
154 '%s: %d dBm / %s: %d%%'.format(_('Signal'), net.signal, _('Quality'), net.quality),
155 _('SSID'), E('a', { href: net.link }, [ net.ssid || '?' ]),
157 _('BSSID'), is_assoc ? (net.bssid || '-') : null,
158 _('Encryption'), is_assoc ? net.encryption : null,
159 _('Associations'), is_assoc ? (net.num_assoc || '-') : null,
160 null, is_assoc ? null : E('em', net.disabled ? _('Wireless is disabled') : _('Wireless is not associated'))));
163 ws.appendChild(renderBox(
164 dev.device, dev.up || net0.up,
166 _('Type'), dev.name.replace(/^Generic | Wireless Controller .+$/g, ''),
167 _('Channel'), net0.channel ? '%d (%.3f %s)'.format(net0.channel, net0.frequency, _('GHz')) : '-',
168 _('Bitrate'), net0.bitrate ? '%d %s'.format(net0.bitrate, _('Mbit/s')) : '-'));
171 if (!ws.lastElementChild)
172 ws.appendChild(E('em', _('No information available')));
177 if (e = document.getElementById('localtime'))
178 e.innerHTML = info.localtime;
180 if (e = document.getElementById('uptime'))
181 e.innerHTML = String.format('%t', info.uptime);
183 if (e = document.getElementById('loadavg'))
184 e.innerHTML = String.format(
185 '%.02f, %.02f, %.02f',
186 info.loadavg[0] / 65535.0,
187 info.loadavg[1] / 65535.0,
188 info.loadavg[2] / 65535.0
191 progressbar('#memtotal',
192 ((info.memory.free + info.memory.buffered) / 1024) + ' ' + _('kB'),
193 (info.memory.total / 1024) + ' ' + _('kB'));
195 progressbar('#memfree',
196 (info.memory.free / 1024) + ' ' + _('kB'),
197 (info.memory.total / 1024) + ' ' + _('kB'));
199 progressbar('#membuff',
200 (info.memory.buffered / 1024) + ' ' + _('kB'),
201 (info.memory.total / 1024) + ' ' + _('kB'));
203 progressbar('#swaptotal',
204 (info.swap.free / 1024) + ' ' + _('kB'),
205 (info.swap.total / 1024) + ' ' + _('kB'));
207 progressbar('#swapfree',
208 (info.swap.free / 1024) + ' ' + _('kB'),
209 (info.swap.total / 1024) + ' ' + _('kB'));
211 progressbar('#conns',
212 info.conncount, info.connmax);