luci-mod-network: fix creating joining wireless networks
[project/luci.git] / modules / luci-mod-network / htdocs / luci-static / resources / view / network / wireless.js
1 'use strict';
2 'require view';
3 'require dom';
4 'require poll';
5 'require fs';
6 'require ui';
7 'require rpc';
8 'require uci';
9 'require form';
10 'require network';
11 'require firewall';
12 'require tools.widgets as widgets';
13
14 var isReadonlyView = !L.hasViewPermission();
15
16 function count_changes(section_id) {
17 var changes = ui.changes.changes, n = 0;
18
19 if (!L.isObject(changes))
20 return n;
21
22 if (Array.isArray(changes.wireless))
23 for (var i = 0; i < changes.wireless.length; i++)
24 n += (changes.wireless[i][1] == section_id);
25
26 return n;
27 }
28
29 function render_radio_badge(radioDev) {
30 return E('span', { 'class': 'ifacebadge' }, [
31 E('img', { 'src': L.resource('icons/wifi%s.png').format(radioDev.isUp() ? '' : '_disabled') }),
32 ' ',
33 radioDev.getName()
34 ]);
35 }
36
37 function render_signal_badge(signalPercent, signalValue, noiseValue, wrap, mode) {
38 var icon, title, value;
39
40 if (signalPercent < 0)
41 icon = L.resource('icons/signal-none.png');
42 else if (signalPercent == 0)
43 icon = L.resource('icons/signal-0.png');
44 else if (signalPercent < 25)
45 icon = L.resource('icons/signal-0-25.png');
46 else if (signalPercent < 50)
47 icon = L.resource('icons/signal-25-50.png');
48 else if (signalPercent < 75)
49 icon = L.resource('icons/signal-50-75.png');
50 else
51 icon = L.resource('icons/signal-75-100.png');
52
53 if (signalValue != null && signalValue != 0) {
54 if (noiseValue != null && noiseValue != 0) {
55 value = '%d/%d\xa0%s'.format(signalValue, noiseValue, _('dBm'));
56 title = '%s: %d %s / %s: %d %s / %s %d'.format(
57 _('Signal'), signalValue, _('dBm'),
58 _('Noise'), noiseValue, _('dBm'),
59 _('SNR'), signalValue - noiseValue);
60 }
61 else {
62 value = '%d\xa0%s'.format(signalValue, _('dBm'));
63 title = '%s: %d %s'.format(_('Signal'), signalValue, _('dBm'));
64 }
65 }
66 else if (signalPercent > -1) {
67 switch (mode) {
68 case 'ap':
69 title = _('No client associated');
70 break;
71
72 case 'sta':
73 case 'adhoc':
74 case 'mesh':
75 title = _('Not associated');
76 break;
77
78 default:
79 title = _('No RX signal');
80 }
81
82 if (noiseValue != null && noiseValue != 0) {
83 value = '---/%d\x0a%s'.format(noiseValue, _('dBm'));
84 title = '%s / %s: %d %s'.format(title, _('Noise'), noiseValue, _('dBm'));
85 }
86 else {
87 value = '---\xa0%s'.format(_('dBm'));
88 }
89 }
90 else {
91 value = E('em', {}, E('small', {}, [ _('disabled') ]));
92 title = _('Interface is disabled');
93 }
94
95 return E('div', {
96 'class': wrap ? 'center' : 'ifacebadge',
97 'title': title,
98 'data-signal': signalValue,
99 'data-noise': noiseValue
100 }, [
101 E('img', { 'src': icon }),
102 E('span', {}, [
103 wrap ? E('br') : ' ',
104 value
105 ])
106 ]);
107 }
108
109 function render_network_badge(radioNet) {
110 return render_signal_badge(
111 radioNet.isUp() ? radioNet.getSignalPercent() : -1,
112 radioNet.getSignal(), radioNet.getNoise(), false, radioNet.getMode());
113 }
114
115 function render_radio_status(radioDev, wifiNets) {
116 var name = radioDev.getI18n().replace(/ Wireless Controller .+$/, ''),
117 node = E('div', [ E('big', {}, E('strong', {}, name)), E('div') ]),
118 channel, frequency, bitrate;
119
120 for (var i = 0; i < wifiNets.length; i++) {
121 channel = channel || wifiNets[i].getChannel();
122 frequency = frequency || wifiNets[i].getFrequency();
123 bitrate = bitrate || wifiNets[i].getBitRate();
124 }
125
126 if (radioDev.isUp())
127 L.itemlist(node.lastElementChild, [
128 _('Channel'), '%s (%s %s)'.format(channel || '?', frequency || '?', _('GHz')),
129 _('Bitrate'), '%s %s'.format(bitrate || '?', _('Mbit/s'))
130 ], ' | ');
131 else
132 node.lastElementChild.appendChild(E('em', _('Device is not active')));
133
134 return node;
135 }
136
137 function render_network_status(radioNet) {
138 var mode = radioNet.getActiveMode(),
139 bssid = radioNet.getActiveBSSID(),
140 channel = radioNet.getChannel(),
141 disabled = (radioNet.get('disabled') == '1' || uci.get('wireless', radioNet.getWifiDeviceName(), 'disabled') == '1'),
142 is_assoc = (bssid && bssid != '00:00:00:00:00:00' && channel && mode != 'Unknown' && !disabled),
143 is_mesh = (radioNet.getMode() == 'mesh'),
144 changecount = count_changes(radioNet.getName()),
145 status_text = null;
146
147 if (changecount)
148 status_text = E('a', {
149 href: '#',
150 click: L.bind(ui.changes.displayChanges, ui.changes)
151 }, _('Interface has %d pending changes').format(changecount));
152 else if (!is_assoc)
153 status_text = E('em', disabled ? _('Wireless is disabled') : _('Wireless is not associated'));
154
155 return L.itemlist(E('div'), [
156 is_mesh ? _('Mesh ID') : _('SSID'), (is_mesh ? radioNet.getMeshID() : radioNet.getSSID()) || '?',
157 _('Mode'), mode,
158 _('BSSID'), (!changecount && is_assoc) ? bssid : null,
159 _('Encryption'), (!changecount && is_assoc) ? radioNet.getActiveEncryption() || _('None') : null,
160 null, status_text
161 ], [ ' | ', E('br') ]);
162 }
163
164 function render_modal_status(node, radioNet) {
165 var mode = radioNet.getActiveMode(),
166 noise = radioNet.getNoise(),
167 bssid = radioNet.getActiveBSSID(),
168 channel = radioNet.getChannel(),
169 disabled = (radioNet.get('disabled') == '1'),
170 is_assoc = (bssid && bssid != '00:00:00:00:00:00' && channel && mode != 'Unknown' && !disabled);
171
172 if (node == null)
173 node = E('span', { 'class': 'ifacebadge large', 'data-network': radioNet.getName() }, [ E('small'), E('span') ]);
174
175 dom.content(node.firstElementChild, render_signal_badge(
176 disabled ? -1 : radioNet.getSignalPercent(),
177 radioNet.getSignal(), noise, true, radioNet.getMode()));
178
179 L.itemlist(node.lastElementChild, [
180 _('Mode'), mode,
181 _('SSID'), radioNet.getSSID() || '?',
182 _('BSSID'), is_assoc ? bssid : null,
183 _('Encryption'), is_assoc ? radioNet.getActiveEncryption() || _('None') : null,
184 _('Channel'), is_assoc ? '%d (%.3f %s)'.format(radioNet.getChannel(), radioNet.getFrequency() || 0, _('GHz')) : null,
185 _('Tx-Power'), is_assoc ? '%d %s'.format(radioNet.getTXPower(), _('dBm')) : null,
186 _('Signal'), is_assoc ? '%d %s'.format(radioNet.getSignal(), _('dBm')) : null,
187 _('Noise'), (is_assoc && noise != null) ? '%d %s'.format(noise, _('dBm')) : null,
188 _('Bitrate'), is_assoc ? '%.1f %s'.format(radioNet.getBitRate() || 0, _('Mbit/s')) : null,
189 _('Country'), is_assoc ? radioNet.getCountryCode() : null
190 ], [ ' | ', E('br'), E('br'), E('br'), E('br'), E('br'), ' | ', E('br'), ' | ' ]);
191
192 if (!is_assoc)
193 dom.append(node.lastElementChild, E('em', disabled ? _('Wireless is disabled') : _('Wireless is not associated')));
194
195 return node;
196 }
197
198 function format_wifirate(rate) {
199 var s = '%.1f\xa0%s, %d\xa0%s'.format(rate.rate / 1000, _('Mbit/s'), rate.mhz, _('MHz')),
200 ht = rate.ht, vht = rate.vht,
201 mhz = rate.mhz, nss = rate.nss,
202 mcs = rate.mcs, sgi = rate.short_gi,
203 he = rate.he, he_gi = rate.he_gi,
204 he_dcm = rate.he_dcm;
205
206 if (ht || vht) {
207 if (vht) s += ', VHT-MCS\xa0%d'.format(mcs);
208 if (nss) s += ', VHT-NSS\xa0%d'.format(nss);
209 if (ht) s += ', MCS\xa0%s'.format(mcs);
210 if (sgi) s += ', ' + _('Short GI').replace(/ /g, '\xa0');
211 }
212
213 if (he) {
214 s += ', HE-MCS\xa0%d'.format(mcs);
215 if (nss) s += ', HE-NSS\xa0%d'.format(nss);
216 if (he_gi) s += ', HE-GI\xa0%d'.format(he_gi);
217 if (he_dcm) s += ', HE-DCM\xa0%d'.format(he_dcm);
218 }
219
220 return s;
221 }
222
223 function radio_restart(id, ev) {
224 var row = document.querySelector('.cbi-section-table-row[data-sid="%s"]'.format(id)),
225 dsc = row.querySelector('[data-name="_stat"] > div'),
226 btn = row.querySelector('.cbi-section-actions button');
227
228 btn.blur();
229 btn.classList.add('spinning');
230 btn.disabled = true;
231
232 dsc.setAttribute('restart', '');
233 dom.content(dsc, E('em', _('Device is restarting…')));
234 }
235
236 function network_updown(id, map, ev) {
237 var radio = uci.get('wireless', id, 'device'),
238 disabled = (uci.get('wireless', id, 'disabled') == '1') ||
239 (uci.get('wireless', radio, 'disabled') == '1');
240
241 if (disabled) {
242 uci.unset('wireless', id, 'disabled');
243 uci.unset('wireless', radio, 'disabled');
244 }
245 else {
246 uci.set('wireless', id, 'disabled', '1');
247
248 var all_networks_disabled = true,
249 wifi_ifaces = uci.sections('wireless', 'wifi-iface');
250
251 for (var i = 0; i < wifi_ifaces.length; i++) {
252 if (wifi_ifaces[i].device == radio && wifi_ifaces[i].disabled != '1') {
253 all_networks_disabled = false;
254 break;
255 }
256 }
257
258 if (all_networks_disabled)
259 uci.set('wireless', radio, 'disabled', '1');
260 }
261
262 return map.save().then(function() {
263 ui.changes.apply()
264 });
265 }
266
267 function next_free_sid(offset) {
268 var sid = 'wifinet' + offset;
269
270 while (uci.get('wireless', sid))
271 sid = 'wifinet' + (++offset);
272
273 return sid;
274 }
275
276 function add_dependency_permutations(o, deps) {
277 var res = null;
278
279 for (var key in deps) {
280 if (!deps.hasOwnProperty(key) || !Array.isArray(deps[key]))
281 continue;
282
283 var list = deps[key],
284 tmp = [];
285
286 for (var j = 0; j < list.length; j++) {
287 for (var k = 0; k < (res ? res.length : 1); k++) {
288 var item = (res ? Object.assign({}, res[k]) : {});
289 item[key] = list[j];
290 tmp.push(item);
291 }
292 }
293
294 res = tmp;
295 }
296
297 for (var i = 0; i < (res ? res.length : 0); i++)
298 o.depends(res[i]);
299 }
300
301 var CBIWifiFrequencyValue = form.Value.extend({
302 callFrequencyList: rpc.declare({
303 object: 'iwinfo',
304 method: 'freqlist',
305 params: [ 'device' ],
306 expect: { results: [] }
307 }),
308
309 load: function(section_id) {
310 return Promise.all([
311 network.getWifiDevice(section_id),
312 this.callFrequencyList(section_id)
313 ]).then(L.bind(function(data) {
314 this.channels = {
315 '2g': L.hasSystemFeature('hostapd', 'acs') ? [ 'auto', 'auto', true ] : [],
316 '5g': L.hasSystemFeature('hostapd', 'acs') ? [ 'auto', 'auto', true ] : [],
317 '6g': [],
318 '60g': []
319 };
320
321 for (var i = 0; i < data[1].length; i++) {
322 var band;
323
324 if (data[1][i].mhz >= 2412 && data[1][i].mhz <= 2484)
325 band = '2g';
326 else if (data[1][i].mhz >= 5160 && data[1][i].mhz <= 5885)
327 band = '5g';
328 else if (data[1][i].mhz >= 5925 && data[1][i].mhz <= 7125)
329 band = '6g';
330 else if (data[1][i].mhz >= 58320 && data[1][i].mhz <= 69120)
331 band = '60g';
332 else
333 continue;
334
335 this.channels[band].push(
336 data[1][i].channel,
337 '%d (%d Mhz)'.format(data[1][i].channel, data[1][i].mhz),
338 !data[1][i].restricted
339 );
340 }
341
342 var hwmodelist = L.toArray(data[0] ? data[0].getHWModes() : null)
343 .reduce(function(o, v) { o[v] = true; return o }, {});
344
345 this.modes = [
346 '', 'Legacy', true,
347 'n', 'N', hwmodelist.n,
348 'ac', 'AC', hwmodelist.ac,
349 'ax', 'AX', hwmodelist.ax
350 ];
351
352 var htmodelist = L.toArray(data[0] ? data[0].getHTModes() : null)
353 .reduce(function(o, v) { o[v] = true; return o }, {});
354
355 this.htmodes = {
356 '': [ '', '-', true ],
357 'n': [
358 'HT20', '20 MHz', htmodelist.HT20,
359 'HT40', '40 MHz', htmodelist.HT40
360 ],
361 'ac': [
362 'VHT20', '20 MHz', htmodelist.VHT20,
363 'VHT40', '40 MHz', htmodelist.VHT40,
364 'VHT80', '80 MHz', htmodelist.VHT80,
365 'VHT160', '160 MHz', htmodelist.VHT160
366 ],
367 'ax': [
368 'HE20', '20 MHz', htmodelist.HE20,
369 'HE40', '40 MHz', htmodelist.HE40,
370 'HE80', '80 MHz', htmodelist.HE80,
371 'HE160', '160 MHz', htmodelist.HE160
372 ]
373 };
374
375 this.bands = {
376 '': [
377 '2g', '2.4 GHz', this.channels['2g'].length > 3,
378 '5g', '5 GHz', this.channels['5g'].length > 3,
379 '60g', '60 GHz', this.channels['60g'].length > 0
380 ],
381 'n': [
382 '2g', '2.4 GHz', this.channels['2g'].length > 3,
383 '5g', '5 GHz', this.channels['5g'].length > 3
384 ],
385 'ac': [
386 '5g', '5 GHz', true
387 ],
388 'ax': [
389 '2g', '2.4 GHz', this.channels['2g'].length > 3,
390 '5g', '5 GHz', this.channels['5g'].length > 3
391 ]
392 };
393 }, this));
394 },
395
396 setValues: function(sel, vals) {
397 if (sel.vals)
398 sel.vals.selected = sel.selectedIndex;
399
400 while (sel.options[0])
401 sel.remove(0);
402
403 for (var i = 0; vals && i < vals.length; i += 3)
404 if (vals[i+2])
405 sel.add(E('option', { value: vals[i+0] }, [ vals[i+1] ]));
406
407 if (vals && !isNaN(vals.selected))
408 sel.selectedIndex = vals.selected;
409
410 sel.parentNode.style.display = (sel.options.length <= 1) ? 'none' : '';
411 sel.vals = vals;
412 },
413
414 toggleWifiMode: function(elem) {
415 this.toggleWifiHTMode(elem);
416 this.toggleWifiBand(elem);
417 },
418
419 toggleWifiHTMode: function(elem) {
420 var mode = elem.querySelector('.mode');
421 var bwdt = elem.querySelector('.htmode');
422
423 this.setValues(bwdt, this.htmodes[mode.value]);
424 },
425
426 toggleWifiBand: function(elem) {
427 var mode = elem.querySelector('.mode');
428 var band = elem.querySelector('.band');
429
430 this.setValues(band, this.bands[mode.value]);
431 this.toggleWifiChannel(elem);
432
433 this.map.checkDepends();
434 },
435
436 toggleWifiChannel: function(elem) {
437 var band = elem.querySelector('.band');
438 var chan = elem.querySelector('.channel');
439
440 this.setValues(chan, this.channels[band.value]);
441 },
442
443 setInitialValues: function(section_id, elem) {
444 var mode = elem.querySelector('.mode'),
445 band = elem.querySelector('.band'),
446 chan = elem.querySelector('.channel'),
447 bwdt = elem.querySelector('.htmode'),
448 htval = uci.get('wireless', section_id, 'htmode'),
449 hwval = uci.get('wireless', section_id, 'hwmode'),
450 chval = uci.get('wireless', section_id, 'channel'),
451 bandval = uci.get('wireless', section_id, 'band');
452
453 this.setValues(mode, this.modes);
454
455 if (/HE20|HE40|HE80|HE160/.test(htval))
456 mode.value = 'ax';
457 else if (/VHT20|VHT40|VHT80|VHT160/.test(htval))
458 mode.value = 'ac';
459 else if (/HT20|HT40/.test(htval))
460 mode.value = 'n';
461 else
462 mode.value = '';
463
464 this.toggleWifiMode(elem);
465
466 if (hwval != null) {
467 this.useBandOption = false;
468
469 if (/a/.test(hwval))
470 band.value = '5g';
471 else
472 band.value = '2g';
473 }
474 else {
475 this.useBandOption = true;
476
477 band.value = bandval;
478 }
479
480 this.toggleWifiBand(elem);
481
482 bwdt.value = htval;
483 chan.value = chval || chan.options[0].value;
484
485 return elem;
486 },
487
488 renderWidget: function(section_id, option_index, cfgvalue) {
489 var elem = E('div');
490
491 dom.content(elem, [
492 E('label', { 'style': 'float:left; margin-right:3px' }, [
493 _('Mode'), E('br'),
494 E('select', {
495 'class': 'mode',
496 'style': 'width:auto',
497 'change': L.bind(this.toggleWifiMode, this, elem),
498 'disabled': (this.disabled != null) ? this.disabled : this.map.readonly
499 })
500 ]),
501 E('label', { 'style': 'float:left; margin-right:3px' }, [
502 _('Band'), E('br'),
503 E('select', {
504 'class': 'band',
505 'style': 'width:auto',
506 'change': L.bind(this.toggleWifiBand, this, elem),
507 'disabled': (this.disabled != null) ? this.disabled : this.map.readonly
508 })
509 ]),
510 E('label', { 'style': 'float:left; margin-right:3px' }, [
511 _('Channel'), E('br'),
512 E('select', {
513 'class': 'channel',
514 'style': 'width:auto',
515 'change': L.bind(this.map.checkDepends, this.map),
516 'disabled': (this.disabled != null) ? this.disabled : this.map.readonly
517 })
518 ]),
519 E('label', { 'style': 'float:left; margin-right:3px' }, [
520 _('Width'), E('br'),
521 E('select', {
522 'class': 'htmode',
523 'style': 'width:auto',
524 'change': L.bind(this.map.checkDepends, this.map),
525 'disabled': (this.disabled != null) ? this.disabled : this.map.readonly
526 })
527 ]),
528 E('br', { 'style': 'clear:left' })
529 ]);
530
531 return this.setInitialValues(section_id, elem);
532 },
533
534 cfgvalue: function(section_id) {
535 return [
536 uci.get('wireless', section_id, 'htmode'),
537 uci.get('wireless', section_id, 'hwmode') || uci.get('wireless', section_id, 'band'),
538 uci.get('wireless', section_id, 'channel')
539 ];
540 },
541
542 formvalue: function(section_id) {
543 var node = this.map.findElement('data-field', this.cbid(section_id));
544
545 return [
546 node.querySelector('.htmode').value,
547 node.querySelector('.band').value,
548 node.querySelector('.channel').value
549 ];
550 },
551
552 write: function(section_id, value) {
553 uci.set('wireless', section_id, 'htmode', value[0] || null);
554
555 if (this.useBandOption)
556 uci.set('wireless', section_id, 'band', value[1]);
557 else
558 uci.set('wireless', section_id, 'hwmode', (value[1] == '2g') ? '11g' : '11a');
559
560 uci.set('wireless', section_id, 'channel', value[2]);
561 }
562 });
563
564 var CBIWifiTxPowerValue = form.ListValue.extend({
565 callTxPowerList: rpc.declare({
566 object: 'iwinfo',
567 method: 'txpowerlist',
568 params: [ 'device' ],
569 expect: { results: [] }
570 }),
571
572 load: function(section_id) {
573 return this.callTxPowerList(section_id).then(L.bind(function(pwrlist) {
574 this.powerval = this.wifiNetwork ? this.wifiNetwork.getTXPower() : null;
575 this.poweroff = this.wifiNetwork ? this.wifiNetwork.getTXPowerOffset() : null;
576
577 this.value('', _('driver default'));
578
579 for (var i = 0; i < pwrlist.length; i++)
580 this.value(pwrlist[i].dbm, '%d dBm (%d mW)'.format(pwrlist[i].dbm, pwrlist[i].mw));
581
582 return form.ListValue.prototype.load.apply(this, [section_id]);
583 }, this));
584 },
585
586 renderWidget: function(section_id, option_index, cfgvalue) {
587 var widget = form.ListValue.prototype.renderWidget.apply(this, [section_id, option_index, cfgvalue]);
588 widget.firstElementChild.style.width = 'auto';
589
590 dom.append(widget, E('span', [
591 ' - ', _('Current power'), ': ',
592 E('span', [ this.powerval != null ? '%d dBm'.format(this.powerval) : E('em', _('unknown')) ]),
593 this.poweroff ? ' + %d dB offset = %s dBm'.format(this.poweroff, this.powerval != null ? this.powerval + this.poweroff : '?') : ''
594 ]));
595
596 return widget;
597 }
598 });
599
600 var CBIWifiCountryValue = form.Value.extend({
601 callCountryList: rpc.declare({
602 object: 'iwinfo',
603 method: 'countrylist',
604 params: [ 'device' ],
605 expect: { results: [] }
606 }),
607
608 load: function(section_id) {
609 return this.callCountryList(section_id).then(L.bind(function(countrylist) {
610 if (Array.isArray(countrylist) && countrylist.length > 0) {
611 this.value('', _('driver default'));
612
613 for (var i = 0; i < countrylist.length; i++)
614 this.value(countrylist[i].iso3166, '%s - %s'.format(countrylist[i].iso3166, countrylist[i].country));
615 }
616
617 return form.Value.prototype.load.apply(this, [section_id]);
618 }, this));
619 },
620
621 validate: function(section_id, formvalue) {
622 if (formvalue != null && formvalue != '' && !/^[A-Z0-9][A-Z0-9]$/.test(formvalue))
623 return _('Use ISO/IEC 3166 alpha2 country codes.');
624
625 return true;
626 },
627
628 renderWidget: function(section_id, option_index, cfgvalue) {
629 var typeClass = (this.keylist && this.keylist.length) ? form.ListValue : form.Value;
630 return typeClass.prototype.renderWidget.apply(this, [section_id, option_index, cfgvalue]);
631 }
632 });
633
634 return view.extend({
635 poll_status: function(map, data) {
636 var rows = map.querySelectorAll('.cbi-section-table-row[data-sid]');
637
638 for (var i = 0; i < rows.length; i++) {
639 var section_id = rows[i].getAttribute('data-sid'),
640 radioDev = data[1].filter(function(d) { return d.getName() == section_id })[0],
641 radioNet = data[2].filter(function(n) { return n.getName() == section_id })[0],
642 badge = rows[i].querySelector('[data-name="_badge"] > div'),
643 stat = rows[i].querySelector('[data-name="_stat"]'),
644 btns = rows[i].querySelectorAll('.cbi-section-actions button'),
645 busy = btns[0].classList.contains('spinning') || btns[1].classList.contains('spinning') || btns[2].classList.contains('spinning');
646
647 if (radioDev) {
648 dom.content(badge, render_radio_badge(radioDev));
649 dom.content(stat, render_radio_status(radioDev, data[2].filter(function(n) { return n.getWifiDeviceName() == radioDev.getName() })));
650 }
651 else {
652 dom.content(badge, render_network_badge(radioNet));
653 dom.content(stat, render_network_status(radioNet));
654 }
655
656 if (stat.hasAttribute('restart'))
657 dom.content(stat, E('em', _('Device is restarting…')));
658
659 btns[0].disabled = isReadonlyView || busy;
660 btns[1].disabled = (isReadonlyView && radioDev) || busy;
661 btns[2].disabled = isReadonlyView || busy;
662 }
663
664 var table = document.querySelector('#wifi_assoclist_table'),
665 hosts = data[0],
666 trows = [];
667
668 for (var i = 0; i < data[3].length; i++) {
669 var bss = data[3][i],
670 name = hosts.getHostnameByMACAddr(bss.mac),
671 ipv4 = hosts.getIPAddrByMACAddr(bss.mac),
672 ipv6 = hosts.getIP6AddrByMACAddr(bss.mac);
673
674 var hint;
675
676 if (name && ipv4 && ipv6)
677 hint = '%s <span class="hide-xs">(%s, %s)</span>'.format(name, ipv4, ipv6);
678 else if (name && (ipv4 || ipv6))
679 hint = '%s <span class="hide-xs">(%s)</span>'.format(name, ipv4 || ipv6);
680 else
681 hint = name || ipv4 || ipv6 || '?';
682
683 var row = [
684 E('span', {
685 'class': 'ifacebadge',
686 'data-ifname': bss.network.getIfname(),
687 'data-ssid': bss.network.getSSID()
688 }, [
689 E('img', {
690 'src': L.resource('icons/wifi%s.png').format(bss.network.isUp() ? '' : '_disabled'),
691 'title': bss.radio.getI18n()
692 }),
693 E('span', [
694 ' %s '.format(bss.network.getShortName()),
695 E('small', '(%s)'.format(bss.network.getIfname()))
696 ])
697 ]),
698 bss.mac,
699 hint,
700 render_signal_badge(Math.min((bss.signal + 110) / 70 * 100, 100), bss.signal, bss.noise),
701 E('span', {}, [
702 E('span', format_wifirate(bss.rx)),
703 E('br'),
704 E('span', format_wifirate(bss.tx))
705 ])
706 ];
707
708 if (bss.network.isClientDisconnectSupported()) {
709 if (table.firstElementChild.childNodes.length < 6)
710 table.firstElementChild.appendChild(E('th', { 'class': 'th cbi-section-actions'}));
711
712 row.push(E('button', {
713 'class': 'cbi-button cbi-button-remove',
714 'click': L.bind(function(net, mac, ev) {
715 dom.parent(ev.currentTarget, '.tr').style.opacity = 0.5;
716 ev.currentTarget.classList.add('spinning');
717 ev.currentTarget.disabled = true;
718 ev.currentTarget.blur();
719
720 net.disconnectClient(mac, true, 5, 60000);
721 }, this, bss.network, bss.mac),
722 'disabled': isReadonlyView || null
723 }, [ _('Disconnect') ]));
724 }
725 else {
726 row.push('-');
727 }
728
729 trows.push(row);
730 }
731
732 cbi_update_table(table, trows, E('em', _('No information available')));
733
734 var stat = document.querySelector('.cbi-modal [data-name="_wifistat_modal"] .ifacebadge.large');
735
736 if (stat)
737 render_modal_status(stat, data[2].filter(function(n) { return n.getName() == stat.getAttribute('data-network') })[0]);
738
739 return network.flushCache();
740 },
741
742 load: function() {
743 return Promise.all([
744 uci.changes(),
745 uci.load('wireless')
746 ]);
747 },
748
749 checkAnonymousSections: function() {
750 var wifiIfaces = uci.sections('wireless', 'wifi-iface');
751
752 for (var i = 0; i < wifiIfaces.length; i++)
753 if (wifiIfaces[i]['.anonymous'])
754 return true;
755
756 return false;
757 },
758
759 callUciRename: rpc.declare({
760 object: 'uci',
761 method: 'rename',
762 params: [ 'config', 'section', 'name' ]
763 }),
764
765 render: function() {
766 if (this.checkAnonymousSections())
767 return this.renderMigration();
768 else
769 return this.renderOverview();
770 },
771
772 handleMigration: function(ev) {
773 var wifiIfaces = uci.sections('wireless', 'wifi-iface'),
774 id_offset = 0,
775 tasks = [];
776
777 for (var i = 0; i < wifiIfaces.length; i++) {
778 if (!wifiIfaces[i]['.anonymous'])
779 continue;
780
781 var new_name = next_free_sid(id_offset);
782
783 tasks.push(this.callUciRename('wireless', wifiIfaces[i]['.name'], new_name));
784 id_offset = +new_name.substring(7) + 1;
785 }
786
787 return Promise.all(tasks)
788 .then(L.bind(ui.changes.init, ui.changes))
789 .then(L.bind(ui.changes.apply, ui.changes));
790 },
791
792 renderMigration: function() {
793 ui.showModal(_('Wireless configuration migration'), [
794 E('p', _('The existing wireless configuration needs to be changed for LuCI to function properly.')),
795 E('p', _('Upon pressing "Continue", anonymous "wifi-iface" sections will be assigned with a name in the form <em>wifinet#</em> and the network will be restarted to apply the updated configuration.')),
796 E('div', { 'class': 'right' },
797 E('button', {
798 'class': 'btn cbi-button-action important',
799 'click': ui.createHandlerFn(this, 'handleMigration')
800 }, _('Continue')))
801 ]);
802 },
803
804 renderOverview: function() {
805 var m, s, o;
806
807 m = new form.Map('wireless');
808 m.chain('network');
809 m.chain('firewall');
810
811 s = m.section(form.GridSection, 'wifi-device', _('Wireless Overview'));
812 s.anonymous = true;
813 s.addremove = false;
814
815 s.load = function() {
816 return network.getWifiDevices().then(L.bind(function(radios) {
817 this.radios = radios.sort(function(a, b) {
818 return a.getName() > b.getName();
819 });
820
821 var tasks = [];
822
823 for (var i = 0; i < radios.length; i++)
824 tasks.push(radios[i].getWifiNetworks());
825
826 return Promise.all(tasks);
827 }, this)).then(L.bind(function(data) {
828 this.wifis = [];
829
830 for (var i = 0; i < data.length; i++)
831 this.wifis.push.apply(this.wifis, data[i]);
832 }, this));
833 };
834
835 s.cfgsections = function() {
836 var rv = [];
837
838 for (var i = 0; i < this.radios.length; i++) {
839 rv.push(this.radios[i].getName());
840
841 for (var j = 0; j < this.wifis.length; j++)
842 if (this.wifis[j].getWifiDeviceName() == this.radios[i].getName())
843 rv.push(this.wifis[j].getName());
844 }
845
846 return rv;
847 };
848
849 s.modaltitle = function(section_id) {
850 var radioNet = this.wifis.filter(function(w) { return w.getName() == section_id})[0];
851 return radioNet ? radioNet.getI18n() : _('Edit wireless network');
852 };
853
854 s.lookupRadioOrNetwork = function(section_id) {
855 var radioDev = this.radios.filter(function(r) { return r.getName() == section_id })[0];
856 if (radioDev)
857 return radioDev;
858
859 var radioNet = this.wifis.filter(function(w) { return w.getName() == section_id })[0];
860 if (radioNet)
861 return radioNet;
862
863 return null;
864 };
865
866 s.renderRowActions = function(section_id) {
867 var inst = this.lookupRadioOrNetwork(section_id), btns;
868
869 if (inst.getWifiNetworks) {
870 btns = [
871 E('button', {
872 'class': 'cbi-button cbi-button-neutral',
873 'title': _('Restart radio interface'),
874 'click': ui.createHandlerFn(this, radio_restart, section_id)
875 }, _('Restart')),
876 E('button', {
877 'class': 'cbi-button cbi-button-action important',
878 'title': _('Find and join network'),
879 'click': ui.createHandlerFn(this, 'handleScan', inst)
880 }, _('Scan')),
881 E('button', {
882 'class': 'cbi-button cbi-button-add',
883 'title': _('Provide new network'),
884 'click': ui.createHandlerFn(this, 'handleAdd', inst)
885 }, _('Add'))
886 ];
887 }
888 else {
889 var isDisabled = (inst.get('disabled') == '1' ||
890 uci.get('wireless', inst.getWifiDeviceName(), 'disabled') == '1');
891
892 btns = [
893 E('button', {
894 'class': 'cbi-button cbi-button-neutral enable-disable',
895 'title': isDisabled ? _('Enable this network') : _('Disable this network'),
896 'click': ui.createHandlerFn(this, network_updown, section_id, this.map)
897 }, isDisabled ? _('Enable') : _('Disable')),
898 E('button', {
899 'class': 'cbi-button cbi-button-action important',
900 'title': _('Edit this network'),
901 'click': ui.createHandlerFn(this, 'renderMoreOptionsModal', section_id)
902 }, _('Edit')),
903 E('button', {
904 'class': 'cbi-button cbi-button-negative remove',
905 'title': _('Delete this network'),
906 'click': ui.createHandlerFn(this, 'handleRemove', section_id)
907 }, _('Remove'))
908 ];
909 }
910
911 return E('td', { 'class': 'td middle cbi-section-actions' }, E('div', btns));
912 };
913
914 s.addModalOptions = function(s) {
915 return network.getWifiNetwork(s.section).then(function(radioNet) {
916 var hwtype = uci.get('wireless', radioNet.getWifiDeviceName(), 'type');
917 var o, ss;
918
919 o = s.option(form.SectionValue, '_device', form.NamedSection, radioNet.getWifiDeviceName(), 'wifi-device', _('Device Configuration'));
920 o.modalonly = true;
921
922 ss = o.subsection;
923 ss.tab('general', _('General Setup'));
924 ss.tab('advanced', _('Advanced Settings'));
925
926 var isDisabled = (radioNet.get('disabled') == '1' ||
927 uci.get('wireless', radioNet.getWifiDeviceName(), 'disabled') == 1);
928
929 o = ss.taboption('general', form.DummyValue, '_wifistat_modal', _('Status'));
930 o.cfgvalue = L.bind(function(radioNet) {
931 return render_modal_status(null, radioNet);
932 }, this, radioNet);
933 o.write = function() {};
934
935 o = ss.taboption('general', form.Button, '_toggle', isDisabled ? _('Wireless network is disabled') : _('Wireless network is enabled'));
936 o.inputstyle = isDisabled ? 'apply' : 'reset';
937 o.inputtitle = isDisabled ? _('Enable') : _('Disable');
938 o.onclick = ui.createHandlerFn(s, network_updown, s.section, s.map);
939
940 o = ss.taboption('general', CBIWifiFrequencyValue, '_freq', '<br />' + _('Operating frequency'));
941 o.ucisection = s.section;
942
943 if (hwtype == 'mac80211') {
944 o = ss.taboption('general', form.Flag, 'legacy_rates', _('Allow legacy 802.11b rates'), _('Legacy or badly behaving devices may require legacy 802.11b rates to interoperate. Airtime efficiency may be significantly reduced where these are used. It is recommended to not allow 802.11b rates where possible.'));
945 o.depends({'_freq': '2g', '!contains': true});
946
947 o = ss.taboption('general', CBIWifiTxPowerValue, 'txpower', _('Maximum transmit power'), _('Specifies the maximum transmit power the wireless radio may use. Depending on regulatory requirements and wireless usage, the actual transmit power may be reduced by the driver.'));
948 o.wifiNetwork = radioNet;
949
950 o = ss.taboption('advanced', CBIWifiCountryValue, 'country', _('Country Code'));
951 o.wifiNetwork = radioNet;
952
953 o = ss.taboption('advanced', form.ListValue, 'cell_density', _('Coverage cell density'), _('Configures data rates based on the coverage cell density. Normal configures basic rates to 6, 12, 24 Mbps if legacy 802.11b rates are not used else to 5.5, 11 Mbps. High configures basic rates to 12, 24 Mbps if legacy 802.11b rates are not used else to the 11 Mbps rate. Very High configures 24 Mbps as the basic rate. Supported rates lower than the minimum basic rate are not offered.'));
954 o.value('0', _('Disabled'));
955 o.value('1', _('Normal'));
956 o.value('2', _('High'));
957 o.value('3', _('Very High'));
958
959 o = ss.taboption('advanced', form.Value, 'distance', _('Distance Optimization'), _('Distance to farthest network member in meters.'));
960 o.datatype = 'or(range(0,114750),"auto")';
961 o.placeholder = 'auto';
962
963 o = ss.taboption('advanced', form.Value, 'frag', _('Fragmentation Threshold'));
964 o.datatype = 'min(256)';
965 o.placeholder = _('off');
966
967 o = ss.taboption('advanced', form.Value, 'rts', _('RTS/CTS Threshold'));
968 o.datatype = 'uinteger';
969 o.placeholder = _('off');
970
971 o = ss.taboption('advanced', form.Flag, 'noscan', _('Force 40MHz mode'), _('Always use 40MHz channels even if the secondary channel overlaps. Using this option does not comply with IEEE 802.11n-2009!'));
972 o.rmempty = true;
973
974 o = ss.taboption('advanced', form.Value, 'beacon_int', _('Beacon Interval'));
975 o.datatype = 'range(15,65535)';
976 o.placeholder = 100;
977 o.rmempty = true;
978 }
979
980
981 o = s.option(form.SectionValue, '_device', form.NamedSection, radioNet.getName(), 'wifi-iface', _('Interface Configuration'));
982 o.modalonly = true;
983
984 ss = o.subsection;
985 ss.tab('general', _('General Setup'));
986 ss.tab('encryption', _('Wireless Security'));
987 ss.tab('macfilter', _('MAC-Filter'));
988 ss.tab('advanced', _('Advanced Settings'));
989
990 o = ss.taboption('general', form.ListValue, 'mode', _('Mode'));
991 o.value('ap', _('Access Point'));
992 o.value('sta', _('Client'));
993 o.value('adhoc', _('Ad-Hoc'));
994
995 o = ss.taboption('general', form.Value, 'mesh_id', _('Mesh Id'));
996 o.depends('mode', 'mesh');
997
998 o = ss.taboption('advanced', form.Flag, 'mesh_fwding', _('Forward mesh peer traffic'));
999 o.rmempty = false;
1000 o.default = '1';
1001 o.depends('mode', 'mesh');
1002
1003 o = ss.taboption('advanced', form.Value, 'mesh_rssi_threshold', _('RSSI threshold for joining'), _('0 = not using RSSI threshold, 1 = do not change driver default'));
1004 o.rmempty = false;
1005 o.default = '0';
1006 o.datatype = 'range(-255,1)';
1007 o.depends('mode', 'mesh');
1008
1009 o = ss.taboption('general', form.Value, 'ssid', _('<abbr title="Extended Service Set Identifier">ESSID</abbr>'));
1010 o.datatype = 'maxlength(32)';
1011 o.depends('mode', 'ap');
1012 o.depends('mode', 'sta');
1013 o.depends('mode', 'adhoc');
1014 o.depends('mode', 'ahdemo');
1015 o.depends('mode', 'monitor');
1016 o.depends('mode', 'ap-wds');
1017 o.depends('mode', 'sta-wds');
1018 o.depends('mode', 'wds');
1019
1020 o = ss.taboption('general', form.Value, 'bssid', _('<abbr title="Basic Service Set Identifier">BSSID</abbr>'));
1021 o.datatype = 'macaddr';
1022
1023 o = ss.taboption('general', widgets.NetworkSelect, 'network', _('Network'), _('Choose the network(s) you want to attach to this wireless interface or fill out the <em>custom</em> field to define a new network.'));
1024 o.rmempty = true;
1025 o.multiple = true;
1026 o.novirtual = true;
1027 o.write = function(section_id, value) {
1028 return network.getDevice(section_id).then(L.bind(function(dev) {
1029 var old_networks = dev.getNetworks().reduce(function(o, v) { o[v.getName()] = v; return o }, {}),
1030 new_networks = {},
1031 values = L.toArray(value),
1032 tasks = [];
1033
1034 for (var i = 0; i < values.length; i++) {
1035 new_networks[values[i]] = true;
1036
1037 if (old_networks[values[i]])
1038 continue;
1039
1040 tasks.push(network.getNetwork(values[i]).then(L.bind(function(name, net) {
1041 return net || network.addNetwork(name, { proto: 'none' });
1042 }, this, values[i])).then(L.bind(function(dev, net) {
1043 if (net) {
1044 if (!net.isEmpty()) {
1045 var target_dev = net.getDevice();
1046
1047 /* Resolve parent interface of vlan */
1048 while (target_dev && target_dev.getType() == 'vlan')
1049 target_dev = target_dev.getParent();
1050
1051 if (!target_dev || target_dev.getType() != 'bridge')
1052 net.set('type', 'bridge');
1053 }
1054
1055 net.addDevice(dev);
1056 }
1057 }, this, dev)));
1058 }
1059
1060 for (var name in old_networks)
1061 if (!new_networks[name])
1062 tasks.push(network.getNetwork(name).then(L.bind(function(dev, net) {
1063 if (net)
1064 net.deleteDevice(dev);
1065 }, this, dev)));
1066
1067 return Promise.all(tasks);
1068 }, this));
1069 };
1070
1071 if (hwtype == 'mac80211') {
1072 var mode = ss.children[0],
1073 bssid = ss.children[5],
1074 encr;
1075
1076 mode.value('mesh', '802.11s');
1077 mode.value('ahdemo', _('Pseudo Ad-Hoc (ahdemo)'));
1078 mode.value('monitor', _('Monitor'));
1079
1080 bssid.depends('mode', 'adhoc');
1081 bssid.depends('mode', 'sta');
1082 bssid.depends('mode', 'sta-wds');
1083
1084 o = ss.taboption('macfilter', form.ListValue, 'macfilter', _('MAC Address Filter'));
1085 o.depends('mode', 'ap');
1086 o.depends('mode', 'ap-wds');
1087 o.value('', _('disable'));
1088 o.value('allow', _('Allow listed only'));
1089 o.value('deny', _('Allow all except listed'));
1090
1091 o = ss.taboption('macfilter', form.DynamicList, 'maclist', _('MAC-List'));
1092 o.datatype = 'macaddr';
1093 o.retain = true;
1094 o.depends('macfilter', 'allow');
1095 o.depends('macfilter', 'deny');
1096 o.load = function(section_id) {
1097 return network.getHostHints().then(L.bind(function(hints) {
1098 hints.getMACHints().map(L.bind(function(hint) {
1099 this.value(hint[0], hint[1] ? '%s (%s)'.format(hint[0], hint[1]) : hint[0]);
1100 }, this));
1101
1102 return form.DynamicList.prototype.load.apply(this, [section_id]);
1103 }, this));
1104 };
1105
1106 mode.value('ap-wds', '%s (%s)'.format(_('Access Point'), _('WDS')));
1107 mode.value('sta-wds', '%s (%s)'.format(_('Client'), _('WDS')));
1108
1109 mode.write = function(section_id, value) {
1110 switch (value) {
1111 case 'ap-wds':
1112 uci.set('wireless', section_id, 'mode', 'ap');
1113 uci.set('wireless', section_id, 'wds', '1');
1114 break;
1115
1116 case 'sta-wds':
1117 uci.set('wireless', section_id, 'mode', 'sta');
1118 uci.set('wireless', section_id, 'wds', '1');
1119 break;
1120
1121 default:
1122 uci.set('wireless', section_id, 'mode', value);
1123 uci.unset('wireless', section_id, 'wds');
1124 break;
1125 }
1126 };
1127
1128 mode.cfgvalue = function(section_id) {
1129 var mode = uci.get('wireless', section_id, 'mode'),
1130 wds = uci.get('wireless', section_id, 'wds');
1131
1132 if (mode == 'ap' && wds)
1133 return 'ap-wds';
1134 else if (mode == 'sta' && wds)
1135 return 'sta-wds';
1136
1137 return mode;
1138 };
1139
1140 o = ss.taboption('general', form.Flag, 'hidden', _('Hide <abbr title="Extended Service Set Identifier">ESSID</abbr>'), _('Where the ESSID is hidden, clients may fail to roam and airtime efficiency may be significantly reduced.'));
1141 o.depends('mode', 'ap');
1142 o.depends('mode', 'ap-wds');
1143
1144 o = ss.taboption('general', form.Flag, 'wmm', _('WMM Mode'), _('Where Wi-Fi Multimedia (WMM) Mode QoS is disabled, clients may be limited to 802.11a/802.11g rates.'));
1145 o.depends('mode', 'ap');
1146 o.depends('mode', 'ap-wds');
1147 o.default = o.enabled;
1148
1149 o = ss.taboption('advanced', form.Flag, 'isolate', _('Isolate Clients'), _('Prevents client-to-client communication'));
1150 o.depends('mode', 'ap');
1151 o.depends('mode', 'ap-wds');
1152
1153 o = ss.taboption('advanced', form.Value, 'ifname', _('Interface name'), _('Override default interface name'));
1154 o.optional = true;
1155 o.placeholder = radioNet.getIfname();
1156 if (/^radio\d+\.network/.test(o.placeholder))
1157 o.placeholder = '';
1158
1159 o = ss.taboption('advanced', form.Flag, 'short_preamble', _('Short Preamble'));
1160 o.default = o.enabled;
1161
1162 o = ss.taboption('advanced', form.Value, 'dtim_period', _('DTIM Interval'), _('Delivery Traffic Indication Message Interval'));
1163 o.optional = true;
1164 o.placeholder = 2;
1165 o.datatype = 'range(1,255)';
1166
1167 o = ss.taboption('advanced', form.Value, 'wpa_group_rekey', _('Time interval for rekeying GTK'), _('sec'));
1168 o.optional = true;
1169 o.placeholder = 600;
1170 o.datatype = 'uinteger';
1171
1172 o = ss.taboption('advanced', form.Flag , 'skip_inactivity_poll', _('Disable Inactivity Polling'));
1173 o.optional = true;
1174 o.datatype = 'uinteger';
1175
1176 o = ss.taboption('advanced', form.Value, 'max_inactivity', _('Station inactivity limit'), _('sec'));
1177 o.optional = true;
1178 o.placeholder = 300;
1179 o.datatype = 'uinteger';
1180
1181 o = ss.taboption('advanced', form.Value, 'max_listen_interval', _('Maximum allowed Listen Interval'));
1182 o.optional = true;
1183 o.placeholder = 65535;
1184 o.datatype = 'uinteger';
1185
1186 o = ss.taboption('advanced', form.Flag, 'disassoc_low_ack', _('Disassociate On Low Acknowledgement'), _('Allow AP mode to disconnect STAs based on low ACK condition'));
1187 o.default = o.enabled;
1188 }
1189
1190
1191 encr = o = ss.taboption('encryption', form.ListValue, 'encryption', _('Encryption'));
1192 o.depends('mode', 'ap');
1193 o.depends('mode', 'sta');
1194 o.depends('mode', 'adhoc');
1195 o.depends('mode', 'ahdemo');
1196 o.depends('mode', 'ap-wds');
1197 o.depends('mode', 'sta-wds');
1198 o.depends('mode', 'mesh');
1199
1200 o.cfgvalue = function(section_id) {
1201 var v = String(uci.get('wireless', section_id, 'encryption'));
1202 if (v == 'wep')
1203 return 'wep-open';
1204 else if (v.match(/\+/))
1205 return v.replace(/\+.+$/, '');
1206 return v;
1207 };
1208
1209 o.write = function(section_id, value) {
1210 var e = this.section.children.filter(function(o) { return o.option == 'encryption' })[0].formvalue(section_id),
1211 co = this.section.children.filter(function(o) { return o.option == 'cipher' })[0], c = co.formvalue(section_id);
1212
1213 if (value == 'wpa' || value == 'wpa2' || value == 'wpa3' || value == 'wpa3-mixed')
1214 uci.unset('wireless', section_id, 'key');
1215
1216 if (co.isActive(section_id) && e && (c == 'tkip' || c == 'ccmp' || c == 'tkip+ccmp'))
1217 e += '+' + c;
1218
1219 uci.set('wireless', section_id, 'encryption', e);
1220 };
1221
1222 o = ss.taboption('encryption', form.ListValue, 'cipher', _('Cipher'));
1223 o.depends('encryption', 'wpa');
1224 o.depends('encryption', 'wpa2');
1225 o.depends('encryption', 'wpa3');
1226 o.depends('encryption', 'wpa3-mixed');
1227 o.depends('encryption', 'psk');
1228 o.depends('encryption', 'psk2');
1229 o.depends('encryption', 'wpa-mixed');
1230 o.depends('encryption', 'psk-mixed');
1231 o.value('auto', _('auto'));
1232 o.value('ccmp', _('Force CCMP (AES)'));
1233 o.value('tkip', _('Force TKIP'));
1234 o.value('tkip+ccmp', _('Force TKIP and CCMP (AES)'));
1235 o.write = ss.children.filter(function(o) { return o.option == 'encryption' })[0].write;
1236
1237 o.cfgvalue = function(section_id) {
1238 var v = String(uci.get('wireless', section_id, 'encryption'));
1239 if (v.match(/\+/)) {
1240 v = v.replace(/^[^+]+\+/, '');
1241 if (v == 'aes')
1242 v = 'ccmp';
1243 else if (v == 'tkip+aes' || v == 'aes+tkip' || v == 'ccmp+tkip')
1244 v = 'tkip+ccmp';
1245 }
1246 return v;
1247 };
1248
1249
1250 var crypto_modes = [];
1251
1252 if (hwtype == 'mac80211') {
1253 var has_supplicant = L.hasSystemFeature('wpasupplicant'),
1254 has_hostapd = L.hasSystemFeature('hostapd');
1255
1256 // Probe EAP support
1257 var has_ap_eap = L.hasSystemFeature('hostapd', 'eap'),
1258 has_sta_eap = L.hasSystemFeature('wpasupplicant', 'eap');
1259
1260 // Probe SAE support
1261 var has_ap_sae = L.hasSystemFeature('hostapd', 'sae'),
1262 has_sta_sae = L.hasSystemFeature('wpasupplicant', 'sae');
1263
1264 // Probe OWE support
1265 var has_ap_owe = L.hasSystemFeature('hostapd', 'owe'),
1266 has_sta_owe = L.hasSystemFeature('wpasupplicant', 'owe');
1267
1268 // Probe Suite-B support
1269 var has_ap_eap192 = L.hasSystemFeature('hostapd', 'suiteb192'),
1270 has_sta_eap192 = L.hasSystemFeature('wpasupplicant', 'suiteb192');
1271
1272 // Probe WEP support
1273 var has_ap_wep = L.hasSystemFeature('hostapd', 'wep'),
1274 has_sta_wep = L.hasSystemFeature('wpasupplicant', 'wep');
1275
1276 if (has_hostapd || has_supplicant) {
1277 crypto_modes.push(['psk2', 'WPA2-PSK', 35]);
1278 crypto_modes.push(['psk-mixed', 'WPA-PSK/WPA2-PSK Mixed Mode', 22]);
1279 crypto_modes.push(['psk', 'WPA-PSK', 21]);
1280 }
1281 else {
1282 encr.description = _('WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP and ad-hoc mode) to be installed.');
1283 }
1284
1285 if (has_ap_sae || has_sta_sae) {
1286 crypto_modes.push(['sae', 'WPA3-SAE', 31]);
1287 crypto_modes.push(['sae-mixed', 'WPA2-PSK/WPA3-SAE Mixed Mode', 30]);
1288 }
1289
1290 if (has_ap_wep || has_sta_wep) {
1291 crypto_modes.push(['wep-open', _('WEP Open System'), 11]);
1292 crypto_modes.push(['wep-shared', _('WEP Shared Key'), 10]);
1293 }
1294
1295 if (has_ap_eap || has_sta_eap) {
1296 if (has_ap_eap192 || has_sta_eap192) {
1297 crypto_modes.push(['wpa3', 'WPA3-EAP', 33]);
1298 crypto_modes.push(['wpa3-mixed', 'WPA2-EAP/WPA3-EAP Mixed Mode', 32]);
1299 }
1300
1301 crypto_modes.push(['wpa2', 'WPA2-EAP', 34]);
1302 crypto_modes.push(['wpa', 'WPA-EAP', 20]);
1303 }
1304
1305 if (has_ap_owe || has_sta_owe) {
1306 crypto_modes.push(['owe', 'OWE', 1]);
1307 }
1308
1309 encr.crypto_support = {
1310 'ap': {
1311 'wep-open': has_ap_wep || _('Requires hostapd with WEP support'),
1312 'wep-shared': has_ap_wep || _('Requires hostapd with WEP support'),
1313 'psk': has_hostapd || _('Requires hostapd'),
1314 'psk2': has_hostapd || _('Requires hostapd'),
1315 'psk-mixed': has_hostapd || _('Requires hostapd'),
1316 'sae': has_ap_sae || _('Requires hostapd with SAE support'),
1317 'sae-mixed': has_ap_sae || _('Requires hostapd with SAE support'),
1318 'wpa': has_ap_eap || _('Requires hostapd with EAP support'),
1319 'wpa2': has_ap_eap || _('Requires hostapd with EAP support'),
1320 'wpa3': has_ap_eap192 || _('Requires hostapd with EAP Suite-B support'),
1321 'wpa3-mixed': has_ap_eap192 || _('Requires hostapd with EAP Suite-B support'),
1322 'owe': has_ap_owe || _('Requires hostapd with OWE support')
1323 },
1324 'sta': {
1325 'wep-open': has_sta_wep || _('Requires wpa-supplicant with WEP support'),
1326 'wep-shared': has_sta_wep || _('Requires wpa-supplicant with WEP support'),
1327 'psk': has_supplicant || _('Requires wpa-supplicant'),
1328 'psk2': has_supplicant || _('Requires wpa-supplicant'),
1329 'psk-mixed': has_supplicant || _('Requires wpa-supplicant'),
1330 'sae': has_sta_sae || _('Requires wpa-supplicant with SAE support'),
1331 'sae-mixed': has_sta_sae || _('Requires wpa-supplicant with SAE support'),
1332 'wpa': has_sta_eap || _('Requires wpa-supplicant with EAP support'),
1333 'wpa2': has_sta_eap || _('Requires wpa-supplicant with EAP support'),
1334 'wpa3': has_sta_eap192 || _('Requires wpa-supplicant with EAP Suite-B support'),
1335 'wpa3-mixed': has_sta_eap192 || _('Requires wpa-supplicant with EAP Suite-B support'),
1336 'owe': has_sta_owe || _('Requires wpa-supplicant with OWE support')
1337 },
1338 'adhoc': {
1339 'wep-open': true,
1340 'wep-shared': true,
1341 'psk': has_supplicant || _('Requires wpa-supplicant'),
1342 'psk2': has_supplicant || _('Requires wpa-supplicant'),
1343 'psk-mixed': has_supplicant || _('Requires wpa-supplicant'),
1344 },
1345 'mesh': {
1346 'sae': has_sta_sae || _('Requires wpa-supplicant with SAE support')
1347 },
1348 'ahdemo': {
1349 'wep-open': true,
1350 'wep-shared': true
1351 },
1352 'wds': {
1353 'wep-open': true,
1354 'wep-shared': true
1355 }
1356 };
1357
1358 encr.crypto_support['ap-wds'] = encr.crypto_support['ap'];
1359 encr.crypto_support['sta-wds'] = encr.crypto_support['sta'];
1360
1361 encr.validate = function(section_id, value) {
1362 var modeopt = this.section.children.filter(function(o) { return o.option == 'mode' })[0],
1363 modeval = modeopt.formvalue(section_id),
1364 modetitle = modeopt.vallist[modeopt.keylist.indexOf(modeval)],
1365 enctitle = this.vallist[this.keylist.indexOf(value)];
1366
1367 if (value == 'none')
1368 return true;
1369
1370 if (!L.isObject(this.crypto_support[modeval]) || !this.crypto_support[modeval].hasOwnProperty(value))
1371 return _('The selected %s mode is incompatible with %s encryption').format(modetitle, enctitle);
1372
1373 return this.crypto_support[modeval][value];
1374 };
1375 }
1376 else if (hwtype == 'broadcom') {
1377 crypto_modes.push(['psk2', 'WPA2-PSK', 33]);
1378 crypto_modes.push(['psk+psk2', 'WPA-PSK/WPA2-PSK Mixed Mode', 22]);
1379 crypto_modes.push(['psk', 'WPA-PSK', 21]);
1380 crypto_modes.push(['wep-open', _('WEP Open System'), 11]);
1381 crypto_modes.push(['wep-shared', _('WEP Shared Key'), 10]);
1382 }
1383
1384 crypto_modes.push(['none', _('No Encryption'), 0]);
1385
1386 crypto_modes.sort(function(a, b) { return b[2] - a[2] });
1387
1388 for (var i = 0; i < crypto_modes.length; i++) {
1389 var security_level = (crypto_modes[i][2] >= 30) ? _('strong security')
1390 : (crypto_modes[i][2] >= 20) ? _('medium security')
1391 : (crypto_modes[i][2] >= 10) ? _('weak security') : _('open network');
1392
1393 encr.value(crypto_modes[i][0], '%s (%s)'.format(crypto_modes[i][1], security_level));
1394 }
1395
1396
1397 o = ss.taboption('encryption', form.Value, 'auth_server', _('Radius-Authentication-Server'));
1398 add_dependency_permutations(o, { mode: ['ap', 'ap-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1399 o.rmempty = true;
1400 o.datatype = 'host(0)';
1401
1402 o = ss.taboption('encryption', form.Value, 'auth_port', _('Radius-Authentication-Port'), _('Default %d').format(1812));
1403 add_dependency_permutations(o, { mode: ['ap', 'ap-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1404 o.rmempty = true;
1405 o.datatype = 'port';
1406
1407 o = ss.taboption('encryption', form.Value, 'auth_secret', _('Radius-Authentication-Secret'));
1408 add_dependency_permutations(o, { mode: ['ap', 'ap-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1409 o.rmempty = true;
1410 o.password = true;
1411
1412 o = ss.taboption('encryption', form.Value, 'acct_server', _('Radius-Accounting-Server'));
1413 add_dependency_permutations(o, { mode: ['ap', 'ap-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1414 o.rmempty = true;
1415 o.datatype = 'host(0)';
1416
1417 o = ss.taboption('encryption', form.Value, 'acct_port', _('Radius-Accounting-Port'), _('Default %d').format(1813));
1418 add_dependency_permutations(o, { mode: ['ap', 'ap-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1419 o.rmempty = true;
1420 o.datatype = 'port';
1421
1422 o = ss.taboption('encryption', form.Value, 'acct_secret', _('Radius-Accounting-Secret'));
1423 add_dependency_permutations(o, { mode: ['ap', 'ap-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1424 o.rmempty = true;
1425 o.password = true;
1426
1427 o = ss.taboption('encryption', form.Value, 'dae_client', _('DAE-Client'));
1428 add_dependency_permutations(o, { mode: ['ap', 'ap-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1429 o.rmempty = true;
1430 o.datatype = 'host(0)';
1431
1432 o = ss.taboption('encryption', form.Value, 'dae_port', _('DAE-Port'), _('Default %d').format(3799));
1433 add_dependency_permutations(o, { mode: ['ap', 'ap-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1434 o.rmempty = true;
1435 o.datatype = 'port';
1436
1437 o = ss.taboption('encryption', form.Value, 'dae_secret', _('DAE-Secret'));
1438 add_dependency_permutations(o, { mode: ['ap', 'ap-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1439 o.rmempty = true;
1440 o.password = true;
1441
1442
1443 o = ss.taboption('encryption', form.Value, '_wpa_key', _('Key'));
1444 o.depends('encryption', 'psk');
1445 o.depends('encryption', 'psk2');
1446 o.depends('encryption', 'psk+psk2');
1447 o.depends('encryption', 'psk-mixed');
1448 o.depends('encryption', 'sae');
1449 o.depends('encryption', 'sae-mixed');
1450 o.datatype = 'wpakey';
1451 o.rmempty = true;
1452 o.password = true;
1453
1454 o.cfgvalue = function(section_id) {
1455 var key = uci.get('wireless', section_id, 'key');
1456 return /^[1234]$/.test(key) ? null : key;
1457 };
1458
1459 o.write = function(section_id, value) {
1460 uci.set('wireless', section_id, 'key', value);
1461 uci.unset('wireless', section_id, 'key1');
1462 uci.unset('wireless', section_id, 'key2');
1463 uci.unset('wireless', section_id, 'key3');
1464 uci.unset('wireless', section_id, 'key4');
1465 };
1466
1467
1468 o = ss.taboption('encryption', form.ListValue, '_wep_key', _('Used Key Slot'));
1469 o.depends('encryption', 'wep-open');
1470 o.depends('encryption', 'wep-shared');
1471 o.value('1', _('Key #%d').format(1));
1472 o.value('2', _('Key #%d').format(2));
1473 o.value('3', _('Key #%d').format(3));
1474 o.value('4', _('Key #%d').format(4));
1475
1476 o.cfgvalue = function(section_id) {
1477 var slot = +uci.get('wireless', section_id, 'key');
1478 return (slot >= 1 && slot <= 4) ? String(slot) : '';
1479 };
1480
1481 o.write = function(section_id, value) {
1482 uci.set('wireless', section_id, 'key', value);
1483 };
1484
1485 for (var slot = 1; slot <= 4; slot++) {
1486 o = ss.taboption('encryption', form.Value, 'key%d'.format(slot), _('Key #%d').format(slot));
1487 o.depends('encryption', 'wep-open');
1488 o.depends('encryption', 'wep-shared');
1489 o.datatype = 'wepkey';
1490 o.rmempty = true;
1491 o.password = true;
1492
1493 o.write = function(section_id, value) {
1494 if (value != null && (value.length == 5 || value.length == 13))
1495 value = 's:%s'.format(value);
1496 uci.set('wireless', section_id, this.option, value);
1497 };
1498 }
1499
1500
1501 if (hwtype == 'mac80211') {
1502 // Probe 802.11r support (and EAP support as a proxy for Openwrt)
1503 var has_80211r = L.hasSystemFeature('hostapd', '11r') || L.hasSystemFeature('hostapd', 'eap');
1504
1505 o = ss.taboption('encryption', form.Flag, 'ieee80211r', _('802.11r Fast Transition'), _('Enables fast roaming among access points that belong to the same Mobility Domain'));
1506 add_dependency_permutations(o, { mode: ['ap', 'ap-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1507 if (has_80211r)
1508 add_dependency_permutations(o, { mode: ['ap', 'ap-wds'], encryption: ['psk', 'psk2', 'psk-mixed', 'sae', 'sae-mixed'] });
1509 o.rmempty = true;
1510
1511 o = ss.taboption('encryption', form.Value, 'nasid', _('NAS ID'), _('Used for two different purposes: RADIUS NAS ID and 802.11r R0KH-ID. Not needed with normal WPA(2)-PSK.'));
1512 add_dependency_permutations(o, { mode: ['ap', 'ap-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1513 o.depends({ ieee80211r: '1' });
1514 o.rmempty = true;
1515
1516 o = ss.taboption('encryption', form.Value, 'mobility_domain', _('Mobility Domain'), _('4-character hexadecimal ID'));
1517 o.depends({ ieee80211r: '1' });
1518 o.placeholder = '4f57';
1519 o.datatype = 'and(hexstring,length(4))';
1520 o.rmempty = true;
1521
1522 o = ss.taboption('encryption', form.Value, 'reassociation_deadline', _('Reassociation Deadline'), _('time units (TUs / 1.024 ms) [1000-65535]'));
1523 o.depends({ ieee80211r: '1' });
1524 o.placeholder = '1000';
1525 o.datatype = 'range(1000,65535)';
1526 o.rmempty = true;
1527
1528 o = ss.taboption('encryption', form.ListValue, 'ft_over_ds', _('FT protocol'));
1529 o.depends({ ieee80211r: '1' });
1530 o.value('1', _('FT over DS'));
1531 o.value('0', _('FT over the Air'));
1532 o.rmempty = true;
1533
1534 o = ss.taboption('encryption', form.Flag, 'ft_psk_generate_local', _('Generate PMK locally'), _('When using a PSK, the PMK can be automatically generated. When enabled, the R0/R1 key options below are not applied. Disable this to use the R0 and R1 key options.'));
1535 o.depends({ ieee80211r: '1' });
1536 o.default = o.enabled;
1537 o.rmempty = false;
1538
1539 o = ss.taboption('encryption', form.Value, 'r0_key_lifetime', _('R0 Key Lifetime'), _('minutes'));
1540 o.depends({ ieee80211r: '1' });
1541 o.placeholder = '10000';
1542 o.datatype = 'uinteger';
1543 o.rmempty = true;
1544
1545 o = ss.taboption('encryption', form.Value, 'r1_key_holder', _('R1 Key Holder'), _('6-octet identifier as a hex string - no colons'));
1546 o.depends({ ieee80211r: '1' });
1547 o.placeholder = '00004f577274';
1548 o.datatype = 'and(hexstring,length(12))';
1549 o.rmempty = true;
1550
1551 o = ss.taboption('encryption', form.Flag, 'pmk_r1_push', _('PMK R1 Push'));
1552 o.depends({ ieee80211r: '1' });
1553 o.placeholder = '0';
1554 o.rmempty = true;
1555
1556 o = ss.taboption('encryption', form.DynamicList, 'r0kh', _('External R0 Key Holder List'), _('List of R0KHs in the same Mobility Domain. <br />Format: MAC-address,NAS-Identifier,128-bit key as hex string. <br />This list is used to map R0KH-ID (NAS Identifier) to a destination MAC address when requesting PMK-R1 key from the R0KH that the STA used during the Initial Mobility Domain Association.'));
1557 o.depends({ ieee80211r: '1' });
1558 o.rmempty = true;
1559
1560 o = ss.taboption('encryption', form.DynamicList, 'r1kh', _('External R1 Key Holder List'), _ ('List of R1KHs in the same Mobility Domain. <br />Format: MAC-address,R1KH-ID as 6 octets with colons,128-bit key as hex string. <br />This list is used to map R1KH-ID to a destination MAC address when sending PMK-R1 key from the R0KH. This is also the list of authorized R1KHs in the MD that can request PMK-R1 keys.'));
1561 o.depends({ ieee80211r: '1' });
1562 o.rmempty = true;
1563 // End of 802.11r options
1564
1565 o = ss.taboption('encryption', form.ListValue, 'eap_type', _('EAP-Method'));
1566 o.value('tls', 'TLS');
1567 o.value('ttls', 'TTLS');
1568 o.value('peap', 'PEAP');
1569 o.value('fast', 'FAST');
1570 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1571
1572 o = ss.taboption('encryption', form.Flag, 'ca_cert_usesystem', _('Use system certificates'), _("Validate server certificate using built-in system CA bundle,<br />requires the \"ca-bundle\" package"));
1573 o.enabled = '1';
1574 o.disabled = '0';
1575 o.default = o.disabled;
1576 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1577 o.validate = function(section_id, value) {
1578 if (value == '1' && !L.hasSystemFeature('cabundle')) {
1579 return _("This option cannot be used because the ca-bundle package is not installed.");
1580 }
1581 return true;
1582 };
1583
1584 o = ss.taboption('encryption', form.FileUpload, 'ca_cert', _('Path to CA-Certificate'));
1585 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], ca_cert_usesystem: ['0'] });
1586
1587 o = ss.taboption('encryption', form.Value, 'subject_match', _('Certificate constraint (Subject)'), _("Certificate constraint substring - e.g. /CN=wifi.mycompany.com<br />See `logread -f` during handshake for actual values"));
1588 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1589
1590 o = ss.taboption('encryption', form.DynamicList, 'altsubject_match', _('Certificate constraint (SAN)'), _("Certificate constraint(s) via Subject Alternate Name values<br />(supported attributes: EMAIL, DNS, URI) - e.g. DNS:wifi.mycompany.com"));
1591 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1592
1593 o = ss.taboption('encryption', form.DynamicList, 'domain_match', _('Certificate constraint (Domain)'), _("Certificate constraint(s) against DNS SAN values (if available)<br />or Subject CN (exact match)"));
1594 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1595
1596 o = ss.taboption('encryption', form.DynamicList, 'domain_suffix_match', _('Certificate constraint (Wildcard)'), _("Certificate constraint(s) against DNS SAN values (if available)<br />or Subject CN (suffix match)"));
1597 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1598
1599 o = ss.taboption('encryption', form.FileUpload, 'client_cert', _('Path to Client-Certificate'));
1600 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], eap_type: ['tls'] });
1601
1602 o = ss.taboption('encryption', form.FileUpload, 'priv_key', _('Path to Private Key'));
1603 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], eap_type: ['tls'] });
1604
1605 o = ss.taboption('encryption', form.Value, 'priv_key_pwd', _('Password of Private Key'));
1606 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], eap_type: ['tls'] });
1607 o.password = true;
1608
1609 o = ss.taboption('encryption', form.ListValue, 'auth', _('Authentication'));
1610 o.value('PAP', 'PAP');
1611 o.value('CHAP', 'CHAP');
1612 o.value('MSCHAP', 'MSCHAP');
1613 o.value('MSCHAPV2', 'MSCHAPv2');
1614 o.value('EAP-GTC', 'EAP-GTC');
1615 o.value('EAP-MD5', 'EAP-MD5');
1616 o.value('EAP-MSCHAPV2', 'EAP-MSCHAPv2');
1617 o.value('EAP-TLS', 'EAP-TLS');
1618 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], eap_type: ['fast', 'peap', 'ttls'] });
1619
1620 o.validate = function(section_id, value) {
1621 var eo = this.section.children.filter(function(o) { return o.option == 'eap_type' })[0],
1622 ev = eo.formvalue(section_id);
1623
1624 if (ev != 'ttls' && (value == 'PAP' || value == 'CHAP' || value == 'MSCHAP' || value == 'MSCHAPV2'))
1625 return _('This authentication type is not applicable to the selected EAP method.');
1626
1627 return true;
1628 };
1629
1630 o = ss.taboption('encryption', form.Flag, 'ca_cert2_usesystem', _('Use system certificates for inner-tunnel'), _("Validate server certificate using built-in system CA bundle,<br />requires the \"ca-bundle\" package"));
1631 o.enabled = '1';
1632 o.disabled = '0';
1633 o.default = o.disabled;
1634 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], auth: ['EAP-TLS'] });
1635 o.validate = function(section_id, value) {
1636 if (value == '1' && !L.hasSystemFeature('cabundle')) {
1637 return _("This option cannot be used because the ca-bundle package is not installed.");
1638 }
1639 return true;
1640 };
1641
1642 o = ss.taboption('encryption', form.FileUpload, 'ca_cert2', _('Path to inner CA-Certificate'));
1643 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], auth: ['EAP-TLS'], ca_cert2_usesystem: ['0'] });
1644
1645 o = ss.taboption('encryption', form.Value, 'subject_match2', _('Inner certificate constraint (Subject)'), _("Certificate constraint substring - e.g. /CN=wifi.mycompany.com<br />See `logread -f` during handshake for actual values"));
1646 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], auth: ['EAP-TLS'] });
1647
1648 o = ss.taboption('encryption', form.DynamicList, 'altsubject_match2', _('Inner certificate constraint (SAN)'), _("Certificate constraint(s) via Subject Alternate Name values<br />(supported attributes: EMAIL, DNS, URI) - e.g. DNS:wifi.mycompany.com"));
1649 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], auth: ['EAP-TLS'] });
1650
1651 o = ss.taboption('encryption', form.DynamicList, 'domain_match2', _('Inner certificate constraint (Domain)'), _("Certificate constraint(s) against DNS SAN values (if available)<br />or Subject CN (exact match)"));
1652 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], auth: ['EAP-TLS'] });
1653
1654 o = ss.taboption('encryption', form.DynamicList, 'domain_suffix_match2', _('Inner certificate constraint (Wildcard)'), _("Certificate constraint(s) against DNS SAN values (if available)<br />or Subject CN (suffix match)"));
1655 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], auth: ['EAP-TLS'] });
1656
1657 o = ss.taboption('encryption', form.FileUpload, 'client_cert2', _('Path to inner Client-Certificate'));
1658 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], auth: ['EAP-TLS'] });
1659
1660 o = ss.taboption('encryption', form.FileUpload, 'priv_key2', _('Path to inner Private Key'));
1661 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], auth: ['EAP-TLS'] });
1662
1663 o = ss.taboption('encryption', form.Value, 'priv_key2_pwd', _('Password of inner Private Key'));
1664 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], auth: ['EAP-TLS'] });
1665 o.password = true;
1666
1667 o = ss.taboption('encryption', form.Value, 'identity', _('Identity'));
1668 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], eap_type: ['fast', 'peap', 'tls', 'ttls'] });
1669
1670 o = ss.taboption('encryption', form.Value, 'anonymous_identity', _('Anonymous Identity'));
1671 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], eap_type: ['fast', 'peap', 'tls', 'ttls'] });
1672
1673 o = ss.taboption('encryption', form.Value, 'password', _('Password'));
1674 add_dependency_permutations(o, { mode: ['sta', 'sta-wds'], encryption: ['wpa', 'wpa2', 'wpa3', 'wpa3-mixed'], eap_type: ['fast', 'peap', 'ttls'] });
1675 o.password = true;
1676
1677
1678 if (hwtype == 'mac80211') {
1679 // ieee802.11w options
1680 o = ss.taboption('encryption', form.ListValue, 'ieee80211w', _('802.11w Management Frame Protection'), _("Note: Some wireless drivers do not fully support 802.11w. E.g. mwlwifi may have problems"));
1681 o.value('0', _('Disabled'));
1682 o.value('1', _('Optional'));
1683 o.value('2', _('Required'));
1684 add_dependency_permutations(o, { mode: ['ap', 'ap-wds', 'sta', 'sta-wds'], encryption: ['owe', 'psk2', 'psk-mixed', 'sae', 'sae-mixed', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1685
1686 o.defaults = {
1687 '2': [{ encryption: 'sae' }, { encryption: 'owe' }, { encryption: 'wpa3' }, { encryption: 'wpa3-mixed' }],
1688 '1': [{ encryption: 'sae-mixed'}],
1689 '0': []
1690 };
1691
1692 o.write = function(section_id, value) {
1693 if (value != this.default)
1694 return form.ListValue.prototype.write.call(this, section_id, value);
1695 else
1696 return form.ListValue.prototype.remove.call(this, section_id);
1697 };
1698
1699 o = ss.taboption('encryption', form.Value, 'ieee80211w_max_timeout', _('802.11w maximum timeout'), _('802.11w Association SA Query maximum timeout'));
1700 o.depends('ieee80211w', '1');
1701 o.depends('ieee80211w', '2');
1702 o.datatype = 'uinteger';
1703 o.placeholder = '1000';
1704 o.rmempty = true;
1705
1706 o = ss.taboption('encryption', form.Value, 'ieee80211w_retry_timeout', _('802.11w retry timeout'), _('802.11w Association SA Query retry timeout'));
1707 o.depends('ieee80211w', '1');
1708 o.depends('ieee80211w', '2');
1709 o.datatype = 'uinteger';
1710 o.placeholder = '201';
1711 o.rmempty = true;
1712
1713 o = ss.taboption('encryption', form.Flag, 'wpa_disable_eapol_key_retries', _('Enable key reinstallation (KRACK) countermeasures'), _('Complicates key reinstallation attacks on the client side by disabling retransmission of EAPOL-Key frames that are used to install keys. This workaround might cause interoperability issues and reduced robustness of key negotiation especially in environments with heavy traffic load.'));
1714 add_dependency_permutations(o, { mode: ['ap', 'ap-wds'], encryption: ['psk2', 'psk-mixed', 'sae', 'sae-mixed', 'wpa2', 'wpa3', 'wpa3-mixed'] });
1715
1716 if (L.hasSystemFeature('hostapd', 'wps') && L.hasSystemFeature('wpasupplicant')) {
1717 o = ss.taboption('encryption', form.Flag, 'wps_pushbutton', _('Enable WPS pushbutton, requires WPA(2)-PSK/WPA3-SAE'))
1718 o.enabled = '1';
1719 o.disabled = '0';
1720 o.default = o.disabled;
1721 o.depends('encryption', 'psk');
1722 o.depends('encryption', 'psk2');
1723 o.depends('encryption', 'psk-mixed');
1724 o.depends('encryption', 'sae');
1725 o.depends('encryption', 'sae-mixed');
1726 }
1727 }
1728 }
1729 });
1730 };
1731
1732 s.handleRemove = function(section_id, ev) {
1733 document.querySelector('.cbi-section-table-row[data-sid="%s"]'.format(section_id)).style.opacity = 0.5;
1734 return form.TypedSection.prototype.handleRemove.apply(this, [section_id, ev]);
1735 };
1736
1737 s.handleScan = function(radioDev, ev) {
1738 var table = E('table', { 'class': 'table' }, [
1739 E('tr', { 'class': 'tr table-titles' }, [
1740 E('th', { 'class': 'th col-2 middle center' }, _('Signal')),
1741 E('th', { 'class': 'th col-4 middle left' }, _('SSID')),
1742 E('th', { 'class': 'th col-2 middle center hide-xs' }, _('Channel')),
1743 E('th', { 'class': 'th col-2 middle left hide-xs' }, _('Mode')),
1744 E('th', { 'class': 'th col-3 middle left hide-xs' }, _('BSSID')),
1745 E('th', { 'class': 'th col-3 middle left' }, _('Encryption')),
1746 E('th', { 'class': 'th cbi-section-actions right' }, ' '),
1747 ])
1748 ]);
1749
1750 var stop = E('button', {
1751 'class': 'btn',
1752 'click': L.bind(this.handleScanStartStop, this),
1753 'style': 'display:none',
1754 'data-state': 'stop'
1755 }, _('Stop refresh'));
1756
1757 cbi_update_table(table, [], E('em', { class: 'spinning' }, _('Starting wireless scan...')));
1758
1759 var md = ui.showModal(_('Join Network: Wireless Scan'), [
1760 table,
1761 E('div', { 'class': 'right' }, [
1762 stop,
1763 ' ',
1764 E('button', {
1765 'class': 'btn',
1766 'click': L.bind(this.handleScanAbort, this)
1767 }, _('Dismiss'))
1768 ])
1769 ]);
1770
1771 md.style.maxWidth = '90%';
1772 md.style.maxHeight = 'none';
1773
1774 this.pollFn = L.bind(this.handleScanRefresh, this, radioDev, {}, table, stop);
1775
1776 poll.add(this.pollFn);
1777 poll.start();
1778 };
1779
1780 s.handleScanRefresh = function(radioDev, scanCache, table, stop) {
1781 return radioDev.getScanList().then(L.bind(function(results) {
1782 var rows = [];
1783
1784 for (var i = 0; i < results.length; i++)
1785 scanCache[results[i].bssid] = results[i];
1786
1787 for (var k in scanCache)
1788 if (scanCache[k].stale)
1789 results.push(scanCache[k]);
1790
1791 results.sort(function(a, b) {
1792 var diff = (b.quality - a.quality) || (a.channel - b.channel);
1793
1794 if (diff)
1795 return diff;
1796
1797 if (a.ssid < b.ssid)
1798 return -1;
1799 else if (a.ssid > b.ssid)
1800 return 1;
1801
1802 if (a.bssid < b.bssid)
1803 return -1;
1804 else if (a.bssid > b.bssid)
1805 return 1;
1806 });
1807
1808 for (var i = 0; i < results.length; i++) {
1809 var res = results[i],
1810 qv = res.quality || 0,
1811 qm = res.quality_max || 0,
1812 q = (qv > 0 && qm > 0) ? Math.floor((100 / qm) * qv) : 0,
1813 s = res.stale ? 'opacity:0.5' : '';
1814
1815 rows.push([
1816 E('span', { 'style': s }, render_signal_badge(q, res.signal, res.noise)),
1817 E('span', { 'style': s }, (res.ssid != null) ? '%h'.format(res.ssid) : E('em', _('hidden'))),
1818 E('span', { 'style': s }, '%d'.format(res.channel)),
1819 E('span', { 'style': s }, '%h'.format(res.mode)),
1820 E('span', { 'style': s }, '%h'.format(res.bssid)),
1821 E('span', { 'style': s }, '%h'.format(network.formatWifiEncryption(res.encryption))),
1822 E('div', { 'class': 'right' }, E('button', {
1823 'class': 'cbi-button cbi-button-action important',
1824 'click': ui.createHandlerFn(this, 'handleJoin', radioDev, res)
1825 }, _('Join Network')))
1826 ]);
1827
1828 res.stale = true;
1829 }
1830
1831 cbi_update_table(table, rows);
1832
1833 stop.disabled = false;
1834 stop.style.display = '';
1835 stop.classList.remove('spinning');
1836 }, this));
1837 };
1838
1839 s.handleScanStartStop = function(ev) {
1840 var btn = ev.currentTarget;
1841
1842 if (btn.getAttribute('data-state') == 'stop') {
1843 poll.remove(this.pollFn);
1844 btn.firstChild.data = _('Start refresh');
1845 btn.setAttribute('data-state', 'start');
1846 }
1847 else {
1848 poll.add(this.pollFn);
1849 btn.firstChild.data = _('Stop refresh');
1850 btn.setAttribute('data-state', 'stop');
1851 btn.classList.add('spinning');
1852 btn.disabled = true;
1853 }
1854 };
1855
1856 s.handleScanAbort = function(ev) {
1857 var md = dom.parent(ev.target, 'div[aria-modal="true"]');
1858 if (md) {
1859 md.style.maxWidth = '';
1860 md.style.maxHeight = '';
1861 }
1862
1863 ui.hideModal();
1864 poll.remove(this.pollFn);
1865
1866 this.pollFn = null;
1867 };
1868
1869 s.handleJoinConfirm = function(radioDev, bss, form, ev) {
1870 var nameopt = L.toArray(form.lookupOption('name', '_new_'))[0],
1871 passopt = L.toArray(form.lookupOption('password', '_new_'))[0],
1872 ssidopt = L.toArray(form.lookupOption('ssid', '_new_'))[0],
1873 bssidopt = L.toArray(form.lookupOption('bssid', '_new_'))[0],
1874 zoneopt = L.toArray(form.lookupOption('zone', '_new_'))[0],
1875 replopt = L.toArray(form.lookupOption('replace', '_new_'))[0],
1876 nameval = (nameopt && nameopt.isValid('_new_')) ? nameopt.formvalue('_new_') : null,
1877 passval = (passopt && passopt.isValid('_new_')) ? passopt.formvalue('_new_') : null,
1878 ssidval = (ssidopt && ssidopt.isValid('_new_')) ? ssidopt.formvalue('_new_') : null,
1879 bssidval = (bssidopt && bssidopt.isValid('_new_')) ? bssidopt.formvalue('_new_') : null,
1880 zoneval = zoneopt ? zoneopt.formvalue('_new_') : null,
1881 enc = L.isObject(bss.encryption) ? bss.encryption : null,
1882 is_wep = (enc && Array.isArray(enc.wep)),
1883 is_psk = (enc && Array.isArray(enc.wpa) && L.toArray(enc.authentication).filter(function(a) { return a == 'psk' }).length > 0),
1884 is_sae = (enc && Array.isArray(enc.wpa) && L.toArray(enc.authentication).filter(function(a) { return a == 'sae' }).length > 0);
1885
1886 if (nameval == null || (passopt && passval == null))
1887 return;
1888
1889 var section_id = null;
1890
1891 return this.map.save(function() {
1892 var wifi_sections = uci.sections('wireless', 'wifi-iface');
1893
1894 if (replopt.formvalue('_new_') == '1') {
1895 for (var i = 0; i < wifi_sections.length; i++)
1896 if (wifi_sections[i].device == radioDev.getName())
1897 uci.remove('wireless', wifi_sections[i]['.name']);
1898 }
1899
1900 if (uci.get('wireless', radioDev.getName(), 'disabled') == '1') {
1901 for (var i = 0; i < wifi_sections.length; i++)
1902 if (wifi_sections[i].device == radioDev.getName())
1903 uci.set('wireless', wifi_sections[i]['.name'], 'disabled', '1');
1904
1905 uci.unset('wireless', radioDev.getName(), 'disabled');
1906 }
1907
1908 section_id = next_free_sid(wifi_sections.length);
1909
1910 uci.add('wireless', 'wifi-iface', section_id);
1911 uci.set('wireless', section_id, 'device', radioDev.getName());
1912 uci.set('wireless', section_id, 'mode', (bss.mode == 'Ad-Hoc') ? 'adhoc' : 'sta');
1913 uci.set('wireless', section_id, 'network', nameval);
1914
1915 if (bss.ssid != null) {
1916 uci.set('wireless', section_id, 'ssid', bss.ssid);
1917
1918 if (bssidval == '1')
1919 uci.set('wireless', section_id, 'bssid', bss.bssid);
1920 }
1921 else if (bss.bssid != null) {
1922 uci.set('wireless', section_id, 'bssid', bss.bssid);
1923 }
1924
1925 if (ssidval != null)
1926 uci.set('wireless', section_id, 'ssid', ssidval);
1927
1928 if (is_sae) {
1929 uci.set('wireless', section_id, 'encryption', 'sae');
1930 uci.set('wireless', section_id, 'key', passval);
1931 }
1932 else if (is_psk) {
1933 for (var i = enc.wpa.length - 1; i >= 0; i--) {
1934 if (enc.wpa[i] == 2) {
1935 uci.set('wireless', section_id, 'encryption', 'psk2');
1936 break;
1937 }
1938 else if (enc.wpa[i] == 1) {
1939 uci.set('wireless', section_id, 'encryption', 'psk');
1940 break;
1941 }
1942 }
1943
1944 uci.set('wireless', section_id, 'key', passval);
1945 }
1946 else if (is_wep) {
1947 uci.set('wireless', section_id, 'encryption', 'wep-open');
1948 uci.set('wireless', section_id, 'key', '1');
1949 uci.set('wireless', section_id, 'key1', passval);
1950 }
1951 else {
1952 uci.set('wireless', section_id, 'encryption', 'none');
1953 }
1954
1955 return network.addNetwork(nameval, { proto: 'dhcp' }).then(function(net) {
1956 firewall.deleteNetwork(net.getName());
1957
1958 var zonePromise = zoneval
1959 ? firewall.getZone(zoneval).then(function(zone) { return zone || firewall.addZone(zoneval) })
1960 : Promise.resolve();
1961
1962 return zonePromise.then(function(zone) {
1963 if (zone)
1964 zone.addNetwork(net.getName());
1965 });
1966 });
1967 }).then(L.bind(function() {
1968 ui.showModal(null, E('p', { 'class': 'spinning' }, [ _('Loading data…') ]));
1969
1970 return this.renderMoreOptionsModal(section_id);
1971 }, this));
1972 };
1973
1974 s.handleJoin = function(radioDev, bss, ev) {
1975 poll.remove(this.pollFn);
1976
1977 var m2 = new form.Map('wireless'),
1978 s2 = m2.section(form.NamedSection, '_new_'),
1979 enc = L.isObject(bss.encryption) ? bss.encryption : null,
1980 is_wep = (enc && Array.isArray(enc.wep)),
1981 is_psk = (enc && Array.isArray(enc.wpa) && L.toArray(enc.authentication).filter(function(a) { return a == 'psk' || a == 'sae' })),
1982 replace, passphrase, name, bssid, zone;
1983
1984 var nameUsed = function(name) {
1985 var s = uci.get('network', name);
1986 if (s != null && s['.type'] != 'interface')
1987 return true;
1988
1989 var net = (s != null) ? network.instantiateNetwork(name) : null;
1990 return (net != null && !net.isEmpty());
1991 };
1992
1993 s2.render = function() {
1994 return Promise.all([
1995 {},
1996 this.renderUCISection('_new_')
1997 ]).then(this.renderContents.bind(this));
1998 };
1999
2000 if (bss.ssid == null) {
2001 name = s2.option(form.Value, 'ssid', _('Network SSID'), _('The correct SSID must be manually specified when joining a hidden wireless network'));
2002 name.rmempty = false;
2003 };
2004
2005 replace = s2.option(form.Flag, 'replace', _('Replace wireless configuration'), _('Check this option to delete the existing networks from this radio.'));
2006
2007 name = s2.option(form.Value, 'name', _('Name of the new network'), _('The allowed characters are: <code>A-Z</code>, <code>a-z</code>, <code>0-9</code> and <code>_</code>'));
2008 name.datatype = 'uciname';
2009 name.default = 'wwan';
2010 name.rmempty = false;
2011 name.validate = function(section_id, value) {
2012 if (nameUsed(value))
2013 return _('The network name is already used');
2014
2015 return true;
2016 };
2017
2018 for (var i = 2; nameUsed(name.default); i++)
2019 name.default = 'wwan%d'.format(i);
2020
2021 if (is_wep || is_psk) {
2022 passphrase = s2.option(form.Value, 'password', is_wep ? _('WEP passphrase') : _('WPA passphrase'), _('Specify the secret encryption key here.'));
2023 passphrase.datatype = is_wep ? 'wepkey' : 'wpakey';
2024 passphrase.password = true;
2025 passphrase.rmempty = false;
2026 }
2027
2028 if (bss.ssid != null) {
2029 bssid = s2.option(form.Flag, 'bssid', _('Lock to BSSID'), _('Instead of joining any network with a matching SSID, only connect to the BSSID <code>%h</code>.').format(bss.bssid));
2030 bssid.default = '0';
2031 }
2032
2033 zone = s2.option(widgets.ZoneSelect, 'zone', _('Create / Assign firewall-zone'), _('Choose the firewall zone you want to assign to this interface. Select <em>unspecified</em> to remove the interface from the associated zone or fill out the <em>custom</em> field to define a new zone and attach the interface to it.'));
2034 zone.default = 'wan';
2035
2036 return m2.render().then(L.bind(function(nodes) {
2037 ui.showModal(_('Joining Network: %q').replace(/%q/, '"%h"'.format(bss.ssid)), [
2038 nodes,
2039 E('div', { 'class': 'right' }, [
2040 E('button', {
2041 'class': 'btn',
2042 'click': ui.hideModal
2043 }, _('Cancel')), ' ',
2044 E('button', {
2045 'class': 'cbi-button cbi-button-positive important',
2046 'click': ui.createHandlerFn(this, 'handleJoinConfirm', radioDev, bss, m2)
2047 }, _('Submit'))
2048 ])
2049 ], 'cbi-modal').querySelector('[id="%s"] input[class][type]'.format((passphrase || name).cbid('_new_'))).focus();
2050 }, this));
2051 };
2052
2053 s.handleAdd = function(radioDev, ev) {
2054 var section_id = next_free_sid(uci.sections('wireless', 'wifi-iface').length);
2055
2056 uci.unset('wireless', radioDev.getName(), 'disabled');
2057
2058 uci.add('wireless', 'wifi-iface', section_id);
2059 uci.set('wireless', section_id, 'device', radioDev.getName());
2060 uci.set('wireless', section_id, 'mode', 'ap');
2061 uci.set('wireless', section_id, 'ssid', 'OpenWrt');
2062 uci.set('wireless', section_id, 'encryption', 'none');
2063
2064 this.addedSection = section_id;
2065 return this.renderMoreOptionsModal(section_id);
2066 };
2067
2068 o = s.option(form.DummyValue, '_badge');
2069 o.modalonly = false;
2070 o.textvalue = function(section_id) {
2071 var inst = this.section.lookupRadioOrNetwork(section_id),
2072 node = E('div', { 'class': 'center' });
2073
2074 if (inst.getWifiNetworks)
2075 node.appendChild(render_radio_badge(inst));
2076 else
2077 node.appendChild(render_network_badge(inst));
2078
2079 return node;
2080 };
2081
2082 o = s.option(form.DummyValue, '_stat');
2083 o.modalonly = false;
2084 o.textvalue = function(section_id) {
2085 var inst = this.section.lookupRadioOrNetwork(section_id);
2086
2087 if (inst.getWifiNetworks)
2088 return render_radio_status(inst, this.section.wifis.filter(function(e) {
2089 return (e.getWifiDeviceName() == inst.getName());
2090 }));
2091 else
2092 return render_network_status(inst);
2093 };
2094
2095 return m.render().then(L.bind(function(m, nodes) {
2096 poll.add(L.bind(function() {
2097 var section_ids = m.children[0].cfgsections(),
2098 tasks = [ network.getHostHints(), network.getWifiDevices() ];
2099
2100 for (var i = 0; i < section_ids.length; i++) {
2101 var row = nodes.querySelector('.cbi-section-table-row[data-sid="%s"]'.format(section_ids[i])),
2102 dsc = row.querySelector('[data-name="_stat"] > div'),
2103 btns = row.querySelectorAll('.cbi-section-actions button');
2104
2105 if (dsc.getAttribute('restart') == '') {
2106 dsc.setAttribute('restart', '1');
2107 tasks.push(fs.exec('/sbin/wifi', ['up', section_ids[i]]).catch(function(e) {
2108 ui.addNotification(null, E('p', e.message));
2109 }));
2110 }
2111 else if (dsc.getAttribute('restart') == '1') {
2112 dsc.removeAttribute('restart');
2113 btns[0].classList.remove('spinning');
2114 btns[0].disabled = false;
2115 }
2116 }
2117
2118 return Promise.all(tasks)
2119 .then(L.bind(function(hosts_radios) {
2120 var tasks = [];
2121
2122 for (var i = 0; i < hosts_radios[1].length; i++)
2123 tasks.push(hosts_radios[1][i].getWifiNetworks());
2124
2125 return Promise.all(tasks).then(function(data) {
2126 hosts_radios[2] = [];
2127
2128 for (var i = 0; i < data.length; i++)
2129 hosts_radios[2].push.apply(hosts_radios[2], data[i]);
2130
2131 return hosts_radios;
2132 });
2133 }, network))
2134 .then(L.bind(function(hosts_radios_wifis) {
2135 var tasks = [];
2136
2137 for (var i = 0; i < hosts_radios_wifis[2].length; i++)
2138 tasks.push(hosts_radios_wifis[2][i].getAssocList());
2139
2140 return Promise.all(tasks).then(function(data) {
2141 hosts_radios_wifis[3] = [];
2142
2143 for (var i = 0; i < data.length; i++) {
2144 var wifiNetwork = hosts_radios_wifis[2][i],
2145 radioDev = hosts_radios_wifis[1].filter(function(d) { return d.getName() == wifiNetwork.getWifiDeviceName() })[0];
2146
2147 for (var j = 0; j < data[i].length; j++)
2148 hosts_radios_wifis[3].push(Object.assign({ radio: radioDev, network: wifiNetwork }, data[i][j]));
2149 }
2150
2151 return hosts_radios_wifis;
2152 });
2153 }, network))
2154 .then(L.bind(this.poll_status, this, nodes));
2155 }, this), 5);
2156
2157 var table = E('table', { 'class': 'table assoclist', 'id': 'wifi_assoclist_table' }, [
2158 E('tr', { 'class': 'tr table-titles' }, [
2159 E('th', { 'class': 'th nowrap' }, _('Network')),
2160 E('th', { 'class': 'th hide-xs' }, _('MAC address')),
2161 E('th', { 'class': 'th' }, _('Host')),
2162 E('th', { 'class': 'th' }, _('Signal / Noise')),
2163 E('th', { 'class': 'th' }, _('RX Rate / TX Rate'))
2164 ])
2165 ]);
2166
2167 cbi_update_table(table, [], E('em', { 'class': 'spinning' }, _('Collecting data...')))
2168
2169 return E([ nodes, E('h3', _('Associated Stations')), table ]);
2170 }, this, m));
2171 }
2172 });