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.ipaddr) ? ifc.ipaddr : '0.0.0.0',
56 _('Netmask'), (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
57 _('Gateway'), (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0',
58 _('DNS') + ' 1', (ifc.dns) ? ifc.dns[0] : null,
59 _('DNS') + ' 2', (ifc.dns) ? ifc.dns[1] : null,
60 _('DNS') + ' 3', (ifc.dns) ? ifc.dns[2] : null,
61 _('DNS') + ' 4', (ifc.dns) ? ifc.dns[3] : null,
62 _('DNS') + ' 5', (ifc.dns) ? ifc.dns[4] : null,
63 _('Expires'), (ifc.expires > -1) ? '%t'.format(ifc.expires) : null,
64 _('Connected'), (ifc.uptime > 0) ? '%t'.format(ifc.uptime) : null));
67 var wan6_list = info.wan6 || [];
69 for (var i = 0; i < wan6_list.length; i++) {
70 var ifc6 = wan6_list[i];
72 us.appendChild(renderBox(
74 (ifc6.ifname && ifc6.proto != 'none'),
75 [ E('div', {}, renderBadge(
76 L.resource('icons/%s.png').format(ifc6.type || 'ethernet_disabled'), null,
77 _('Device'), ifc6 ? (ifc6.name || ifc6.ifname || '-') : '-',
78 _('MAC-Address'), (ifc6 && ifc6.ether) ? ifc6.mac : null)) ],
79 _('Protocol'), ifc6.i18n ? (ifc6.i18n + (ifc6.proto === 'dhcp' && ifc6.ip6prefix ? '-PD' : '')) : E('em', _('Not connected')),
80 _('Prefix Delegated'), ifc6.ip6prefix,
81 _('Address'), (ifc6.ip6prefix) ? (ifc6.ip6addr || null) : (ifc6.ip6addr || '::'),
82 _('Gateway'), (ifc6.gw6addr) ? ifc6.gw6addr : '::',
83 _('DNS') + ' 1', (ifc6.dns) ? ifc6.dns[0] : null,
84 _('DNS') + ' 2', (ifc6.dns) ? ifc6.dns[1] : null,
85 _('DNS') + ' 3', (ifc6.dns) ? ifc6.dns[2] : null,
86 _('DNS') + ' 4', (ifc6.dns) ? ifc6.dns[3] : null,
87 _('DNS') + ' 5', (ifc6.dns) ? ifc6.dns[4] : null,
88 _('Connected'), (ifc6.uptime > 0) ? '%t'.format(ifc6.uptime) : null));
91 var ds = document.getElementById('dsl_status_table');
93 while (ds.lastElementChild)
94 ds.removeChild(ds.lastElementChild);
96 ds.appendChild(renderBox(
98 (info.dsl.line_state === 'UP'), [ ],
99 _('Line State'), '%s [0x%x]'.format(info.dsl.line_state, info.dsl.line_state_detail),
100 _('Line Mode'), info.dsl.line_mode_s || '-',
101 _('Line Uptime'), info.dsl.line_uptime_s || '-',
102 _('Annex'), info.dsl.annex_s || '-',
103 _('Profile'), info.dsl.profile_s || '-',
104 _('Data Rate'), '%s/s / %s/s'.format(info.dsl.data_rate_down_s, info.dsl.data_rate_up_s),
105 _('Max. Attainable Data Rate (ATTNDR)'), '%s/s / %s/s'.format(info.dsl.max_data_rate_down_s, info.dsl.max_data_rate_up_s),
106 _('Latency'), '%s / %s'.format(info.dsl.latency_num_down, info.dsl.latency_num_up),
107 _('Line Attenuation (LATN)'), '%.1f dB / %.1f dB'.format(info.dsl.line_attenuation_down, info.dsl.line_attenuation_up),
108 _('Signal Attenuation (SATN)'), '%.1f dB / %.1f dB'.format(info.dsl.signal_attenuation_down, info.dsl.signal_attenuation_up),
109 _('Noise Margin (SNR)'), '%.1f dB / %.1f dB'.format(info.dsl.noise_margin_down, info.dsl.noise_margin_up),
110 _('Aggregate Transmit Power(ACTATP)'), '%.1f dB / %.1f dB'.format(info.dsl.actatp_down, info.dsl.actatp_up),
111 _('Forward Error Correction Seconds (FECS)'), '%d / %d'.format(info.dsl.errors_fec_near, info.dsl.errors_fec_far),
112 _('Errored seconds (ES)'), '%d / %d'.format(info.dsl.errors_es_near, info.dsl.errors_es_far),
113 _('Severely Errored Seconds (SES)'), '%d / %d'.format(info.dsl.errors_ses_near, info.dsl.errors_ses_far),
114 _('Loss of Signal Seconds (LOSS)'), '%d / %d'.format(info.dsl.errors_loss_near, info.dsl.errors_loss_far),
115 _('Unavailable Seconds (UAS)'), '%d / %d'.format(info.dsl.errors_uas_near, info.dsl.errors_uas_far),
116 _('Header Error Code Errors (HEC)'), '%d / %d'.format(info.dsl.errors_hec_near, info.dsl.errors_hec_far),
117 _('Non Pre-emtive CRC errors (CRC_P)'), '%d / %d'.format(info.dsl.errors_crc_p_near, info.dsl.errors_crc_p_far),
118 _('Pre-emtive CRC errors (CRCP_P)'), '%d / %d'.format(info.dsl.errors_crcp_p_near, info.dsl.errors_crcp_p_far),
119 _('ATU-C System Vendor ID'), info.dsl.atuc_vendor_id,
120 _('Power Management Mode'), info.dsl.power_mode_s));
123 var ws = document.getElementById('wifi_status_table');
126 while (ws.lastElementChild)
127 ws.removeChild(ws.lastElementChild);
129 for (var didx = 0; didx < info.wifinets.length; didx++)
131 var dev = info.wifinets[didx];
132 var net0 = (dev.networks && dev.networks[0]) ? dev.networks[0] : {};
135 for (var nidx = 0; nidx < dev.networks.length; nidx++)
137 var net = dev.networks[nidx];
138 var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel && !net.disabled);
142 icon = L.resource('icons/signal-none.png');
143 else if (net.quality <= 0)
144 icon = L.resource('icons/signal-0.png');
145 else if (net.quality < 25)
146 icon = L.resource('icons/signal-0-25.png');
147 else if (net.quality < 50)
148 icon = L.resource('icons/signal-25-50.png');
149 else if (net.quality < 75)
150 icon = L.resource('icons/signal-50-75.png');
152 icon = L.resource('icons/signal-75-100.png');
154 vifs.push(renderBadge(
156 '%s: %d dBm / %s: %d%%'.format(_('Signal'), net.signal, _('Quality'), net.quality),
157 _('SSID'), E('a', { href: net.link }, [ net.ssid || '?' ]),
159 _('BSSID'), is_assoc ? (net.bssid || '-') : null,
160 _('Encryption'), is_assoc ? net.encryption : null,
161 _('Associations'), is_assoc ? (net.num_assoc || '-') : null,
162 null, is_assoc ? null : E('em', net.disabled ? _('Wireless is disabled') : _('Wireless is not associated'))));
165 ws.appendChild(renderBox(
166 dev.device, dev.up || net0.up,
168 _('Type'), dev.name.replace(/^Generic | Wireless Controller .+$/g, ''),
169 _('Channel'), net0.channel ? '%d (%.3f %s)'.format(net0.channel, net0.frequency, _('GHz')) : '-',
170 _('Bitrate'), net0.bitrate ? '%d %s'.format(net0.bitrate, _('Mbit/s')) : '-'));
173 if (!ws.lastElementChild)
174 ws.appendChild(E('em', _('No information available')));
179 if (e = document.getElementById('localtime'))
180 e.innerHTML = info.localtime;
182 if (e = document.getElementById('uptime'))
183 e.innerHTML = String.format('%t', info.uptime);
185 if (e = document.getElementById('loadavg'))
186 e.innerHTML = String.format(
187 '%.02f, %.02f, %.02f',
188 info.loadavg[0] / 65535.0,
189 info.loadavg[1] / 65535.0,
190 info.loadavg[2] / 65535.0
193 progressbar('#memtotal',
194 info.memory.free + info.memory.buffered,
198 progressbar('#memfree',
203 progressbar('#membuff',
204 info.memory.buffered,
208 progressbar('#swaptotal',
213 progressbar('#swapfree',
218 progressbar('#conns',
219 info.conncount, info.connmax, false);