summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-travelmate/htdocs/luci-static/resources/view/travelmate/stations.js
blob: d9976363003d152c598af0042233280188328554 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
'use strict';
'require view';
'require poll';
'require fs';
'require ui';
'require uci';
'require form';
'require network';
'require tools.widgets as widgets';

/*
	remove wireless and stale travelmate sections
*/
function handleRemove(sid) {
	var w_sections, t_sections, match, changes;

	uci.remove('wireless', sid);
	w_sections = uci.sections('wireless', 'wifi-iface');
	t_sections = uci.sections('travelmate', 'uplink');
	for (var i = 0; i < t_sections.length; i++) {
		match = false;
		for (var j = 0; j < w_sections.length; j++) {
			if (t_sections[i].device === w_sections[j].device && t_sections[i].ssid === w_sections[j].ssid && t_sections[i].bssid === w_sections[j].bssid) {
				match = true;
				break;
			}
		}
		if (match === false) {
			uci.remove('travelmate', t_sections[i]['.name']);
		}
	}
	uci.save();
}

/*
	add missing travelmate sections
*/
function handleSectionsAdd(iface) {
	var w_sections, t_sections, match, changes;

	w_sections = uci.sections('wireless', 'wifi-iface');
	t_sections = uci.sections('travelmate', 'uplink');
	for (var i = 0; i < w_sections.length; i++) {
		if (w_sections[i].mode !== 'sta' || w_sections[i].network !== iface) {
			continue;
		}
		match = false;
		for (var j = 0; j < t_sections.length; j++) {
			if (w_sections[i].device === t_sections[j].device && w_sections[i].ssid === t_sections[j].ssid && w_sections[i].bssid === t_sections[j].bssid) {
				match = true;
				break;
			}
		}
		if (match === false) {
			var sid = uci.add('travelmate', 'uplink');
			uci.set('travelmate', sid, 'enabled', '1');
			uci.set('travelmate', sid, 'device', w_sections[i].device);
			uci.set('travelmate', sid, 'ssid', w_sections[i].ssid);
			uci.set('travelmate', sid, 'bssid', w_sections[i].bssid);
			uci.set('travelmate', sid, 'con_start_expiry', '0');
			uci.set('travelmate', sid, 'con_end_expiry', '0');
		}
	}
}

/*
	update travelmate sections
*/
function handleSectionsVal(action, section_id, option, value) {
	var date, oldValue, w_device, w_ssid, w_bssid, t_sections;

	w_device   = uci.get('wireless', section_id, 'device');
	w_ssid     = uci.get('wireless', section_id, 'ssid');
	w_bssid    = uci.get('wireless', section_id, 'bssid');
	t_sections = uci.sections('travelmate', 'uplink');

	for (var i = 0; i < t_sections.length; i++) {
		if (t_sections[i].device === w_device && t_sections[i].ssid === w_ssid && t_sections[i].bssid === w_bssid) {
			if (action === 'get') {
				return t_sections[i][option];
			}
			else if (action === 'set') {
				if (option === 'enabled') {
					oldValue = t_sections[i][option];
					if (oldValue !== value && value === '0') {
						date = new Date(new Date().getTime() - new Date().getTimezoneOffset()*60*1000).toISOString().substr(0,19).replace(/-/g, '.').replace('T', '-');
						uci.set('travelmate', t_sections[i]['.name'], 'con_end', date);
					}
					else if (oldValue !== value && value === '1') {
						uci.unset('travelmate', t_sections[i]['.name'], 'con_end');
					}
				}
				return uci.set('travelmate', t_sections[i]['.name'], option, value);
			}
			else if (action === 'del') {
				return uci.unset('travelmate', t_sections[i]['.name'], option);
			}
		}
	}
}

/*
	update travelmate status
*/
function handleStatus() {
	poll.add(function() {
		L.resolveDefault(fs.stat('/var/run/travelmate.refresh'), null).then(function(res) {
			if (res) {
				L.resolveDefault(fs.read_direct('/var/run/travelmate.refresh'), null).then(function(res) {
					fs.remove('/var/run/travelmate.refresh');
					if (res && res === 'ui_reload') {
						location.reload();
					}
					else if (res && res === 'cfg_reload') {
						if (document.readyState === 'complete') {
							uci.unload('wireless');
							uci.unload('travelmate');
						}
						return Promise.all([
							uci.load('wireless'),
							uci.load('travelmate')
						]).then(function() {
							var item, value,
							container = document.querySelectorAll('.cbi-section-table-row[data-sid]');
							for (var i = 0; i < container.length; i++) {
								item  = container[i].querySelector('.cbi-value-field[data-title="Enabled"]');
								value = handleSectionsVal('get', container[i].getAttribute('data-sid'), 'enabled');
								item.textContent = (value == 0 ? 'No' : 'Yes');
							}
						});
					}
				});
			}
		});
		return L.resolveDefault(fs.stat('/tmp/trm_runtime.json'), null).then(function(res) {
			if (res) {
				L.resolveDefault(fs.read_direct('/tmp/trm_runtime.json'), null).then(function(res) {
					if (res) {
						var info = JSON.parse(res);
						if (info) {
							var t_device, t_ssid, t_bssid, oldUplinkView, newUplinkView,
							uplinkId      = info.data.station_id.trim().split('/'),
							oldUplinkView = document.getElementsByName('uplinkStation'),
							w_sections    = uci.sections('wireless', 'wifi-iface');

							t_device = uplinkId[0];
							t_bssid  = uplinkId[uplinkId.length-1];
							for (var i = 1; i < uplinkId.length-1; i++) {
								if (!t_ssid) {
									t_ssid = uplinkId[i];
								}
								else {
									t_ssid = t_ssid + '/' + uplinkId[i];
								}
							}
							if (t_ssid === '-') {
								if (oldUplinkView.length > 0) {
									oldUplinkView[0].removeAttribute('style');
									oldUplinkView[0].removeAttribute('name', 'uplinkStation');
								}
							}
							else {
								for (var i = 0; i < w_sections.length; i++) {
									newUplinkView = document.getElementById('cbi-wireless-' + w_sections[i]['.name']);
									if (t_device === w_sections[i].device && t_ssid === w_sections[i].ssid && t_bssid === (w_sections[i].bssid || '-')) {
										if (oldUplinkView.length === 0 && newUplinkView) {
											newUplinkView.setAttribute('name', 'uplinkStation');
											newUplinkView.setAttribute('style', 'text-align: left !important; color: #37c !important;font-weight: bold !important;');
										}
										else if (oldUplinkView.length > 0 && newUplinkView && oldUplinkView[0].getAttribute('id') !== newUplinkView.getAttribute('id')) {
											oldUplinkView[0].removeAttribute('style');
											oldUplinkView[0].removeAttribute('name', 'uplinkStation');
											newUplinkView.setAttribute('name', 'uplinkStation');
											newUplinkView.setAttribute('style', 'text-align: left !important; color: #37c !important;font-weight: bold !important;');
										}
									}
								}
							}
						}
					}
				});
			}
		});
	}, 1);
}

return view.extend({
	load: function() {
		return Promise.all([
			uci.load('wireless'),
			uci.load('travelmate')
		]);
	},

	render: function() {
		var m, s, o,
		iface = uci.get('travelmate', 'global', 'trm_iface') || 'trm_wwan';

		m = new form.Map('wireless');
		m.chain('travelmate');
		s = m.section(form.GridSection, 'wifi-iface', null, _('Overview of all configured uplinks for travelmate.<br /> \
			You can edit, remove or prioritize existing uplinks by drag \&#38; drop and scan for new ones. The currently used uplink is emphasized in blue.'));
		s.anonymous = true;
		s.sortable  = true;
		s.filter = function(section_id) {
			return (uci.get('wireless', section_id, 'network') == iface && uci.get('wireless', section_id, 'mode') == 'sta');
		};
		s.tab('wireless',  _('Wireless Settings'));
		s.tab('travelmate', _('Travelmate Settings'));
		s.renderRowActions = function(section_id) {
			var btns;
			btns = [
				E('button', {
					'class': 'btn cbi-button drag-handle center',
					'title': _('Drag to reorder'),
					'style': 'cursor:move',
					'disabled': this.map.readonly || null
				}, '☰'),
				E('button', {
					'class': 'cbi-button cbi-button-action important',
					'title': _('Edit this network'),
					'click': ui.createHandlerFn(this, 'renderMoreOptionsModal', section_id)
				}, _('Edit')),
				E('button', {
					'class': 'cbi-button cbi-button-negative remove',
					'title': _('Delete this network'),
					'click': ui.createHandlerFn(this, handleRemove, section_id)
				}, _('Del'))
			];
			return E('div', { 'class': 'td middle cbi-section-actions' }, E('div', btns));
		};

		o = s.taboption('travelmate', form.Flag, '_enabled', _('Enabled'));
		o.uciconfig = 'travelmate';
		o.ucisection = 'uplink';
		o.ucioption = 'enabled';
		o.rmempty = false;
		o.cfgvalue = function(section_id) {
			return handleSectionsVal('get', section_id, 'enabled');
		}
		o.write = function(section_id, value) {
			return handleSectionsVal('set', section_id, 'enabled', value);
		}

		o = s.taboption('wireless', form.Value, 'device', _('Device'));
		o.readonly = true;

		o = s.taboption('wireless', form.Value, 'ssid', _('SSID'));
		o.datatype = 'maxlength(32)';
		o.readonly = true;

		o = s.taboption('wireless', form.Value, 'bssid', _('BSSID'));
		o.datatype = 'macaddr';
		o.readonly = true;

		o = s.taboption('wireless', form.ListValue, 'encryption', _('Encryption'));
		o.value('sae', _('WPA3 Pers.'));
		o.value('sae-mixed', _('WPA2/WPA3 Pers. (CCMP)'));
		o.value('psk2', _('WPA2 Pers.'));
		o.value('psk2+ccmp', _('WPA2 Pers. (CCMP)'));
		o.value('psk2+tkip', _('WPA2 Pers. (TKIP)'));
		o.value('psk', _('WPA Pers.'));
		o.value('psk+ccmp', _('WPA Pers. (CCMP)'));
		o.value('psk+tkip', _('WPA Pers. (TKIP)'));
		o.value('psk-mixed+ccmp', _('WPA/WPA2 Pers. (CCMP)'));
		o.value('psk-mixed+tkip', _('WPA/WPA2 Pers. (TKIP)'));
		o.value('wpa3', _('WPA3 Ent.'));
		o.value('wpa3-mixed', _('WPA3/WPA2 Ent.'));
		o.value('wpa2+ccmp', _('WPA2 Ent. (CCMP)'));
		o.value('wpa2+tkip', _('WPA2 Ent. (TKIP)'));
		o.value('wpa+ccmp', _('WPA Ent. (CCMP)'));
		o.value('wpa+tkip', _('WPA Ent. (TKIP)'));
		o.value('wpa-mixed+ccmp', _('WPA/WPA2 Ent. (CCMP)'));
		o.value('wpa-mixed+tkip', _('WPA/WPA2 Ent. (TKIP)'));
		o.value('owe', _('OWE'));
		o.value('none', _('none'));
		o.default = 'none';
		o.textvalue = function(section_id) {
			var cfgvalue = this.map.data.get('wireless', section_id, 'encryption');
			switch (cfgvalue) {
				case 'sae':
					cfgvalue = 'WPA3 Pers. (SAE)';
					break;
				case 'sae-mixed':
					cfgvalue = 'WPA2/WPA3 Pers. (CCMP)';
					break;
				case 'psk2':
					cfgvalue = 'WPA2 Pers.';
					break;
				case 'psk2+ccmp':
					cfgvalue = 'WPA2 Pers. (CCMP)';
					break;
				case 'psk2+tkip':
					cfgvalue = 'WPA2 Ent. (TKIP)';
					break;
				case 'psk':
					cfgvalue = 'WPA Pers.';
					break;
				case 'psk-mixed+ccmp':
					cfgvalue = 'WPA/WPA2 Pers. (CCMP)';
					break;
				case 'psk-mixed+tkip':
					cfgvalue = 'WPA/WPA2 Pers. (TKIP)';
					break;
				case 'wpa3':
					cfgvalue = 'WPA3 Ent.';
					break;
				case 'wpa3-mixed':
					cfgvalue = 'WPA3/WPA2 Ent.';
					break;
				case 'wpa2+ccmp':
					cfgvalue = 'WPA2 Ent. (CCMP)';
					break;
				case 'wpa2+tkip':
					cfgvalue = 'WPA2 Ent. (TKIP)';
					break;
				case 'wpa+ccmp':
					cfgvalue = 'WPA Ent. (CCMP)';
					break;
				case 'wpa+tkip':
					cfgvalue = 'WPA Ent. (TKIP)';
					break;
				case 'wpa-mixed+ccmp':
					cfgvalue = 'WPA/WPA2 Ent. (CCMP)';
					break;
				case 'wpa-mixed+tkip':
					cfgvalue = 'WPA/WPA2 Ent. (TKIP)';
					break;
				case 'owe':
					cfgvalue = 'WPA3 OWE (CCMP)';
					break;
				case 'none':
					cfgvalue = 'none';
					break;
			}
			return cfgvalue;
		};
		handleStatus();

		/*
			modal wireless tab
		*/
		o = s.taboption('wireless', form.Value, 'key', _('Password'));
		o.datatype = 'wpakey';
		o.depends({ encryption: 'sae', '!contains': true });
		o.depends({ encryption: 'psk', '!contains': true });
		o.depends({ encryption: 'wpa', '!contains': true });
		o.modalonly = true;
		o.password = true;

		o = s.taboption('wireless', form.ListValue, 'eap_type', _('EAP-Method'));
		o.value('tls', _('TLS'));
		o.value('ttls', _('TTLS'));
		o.value('peap', _('PEAP'));
		o.value('fast', _('FAST'));
		o.default = 'peap';
		o.depends({ encryption: 'wpa', '!contains': true });
		o.modalonly = true;

		o = s.taboption('wireless', form.ListValue, 'auth', _('Authentication'));
		o.value('PAP', _('PAP'));
		o.value('CHAP', _('CHAP'));
		o.value('MSCHAP', _('MSCHAP'));
		o.value('MSCHAPV2', _('MSCHAPV2'));
		o.value('EAP-GTC', _('EAP-GTC'));
		o.value('EAP-MD5', _('EAP-MD5'));
		o.value('EAP-MSCHAPV2', _('EAP-MSCHAPV2'));
		o.value('EAP-TLS', _('EAP-TLS'));
		o.value('auth=PAP', _('auth=PAP'));
		o.value('auth=MSCHAPV2', _('auth=MSCHAPV2'));
		o.default = 'EAP-MSCHAPV2';
		o.depends({ encryption: 'wpa', '!contains': true });
		o.modalonly = true;

		o = s.taboption('wireless', form.Value, 'identify', _('Identify'));
		o.depends({ encryption: 'wpa', '!contains': true });
		o.modalonly = true;

		o = s.taboption('wireless', form.Value, 'ca_cert', _('Path to CA-Certificate'));
		o.depends({ eap_type: 'tls' });
		o.modalonly = true;
		o.rmempty = true;

		o = s.taboption('wireless', form.Value, 'client_cert', _('Path to Client-Certificate'));
		o.depends({ eap_type: 'tls' });
		o.modalonly = true;
		o.rmempty = true;

		o = s.taboption('wireless', form.Value, 'priv_key', _('Path to Private Key'));
		o.depends({ eap_type: 'tls' });
		o.modalonly = true;
		o.rmempty = true;

		o = s.taboption('wireless', form.Value, 'priv_key_pwd', _('Password of Private Key'));
		o.datatype = 'wpakey';
		o.depends({ eap_type: 'tls' });
		o.modalonly = true;
		o.password = true;
		o.rmempty = true;

		/*
			modal travelmate tab
		*/
		o = s.taboption('travelmate', form.Value, '_ssid', _('SSID'));
		o.modalonly = true;
		o.uciconfig = 'travelmate';
		o.ucisection = 'uplink';
		o.ucioption = 'ssid';
		o.rmempty = false;
		o.readonly = true;
		o.cfgvalue = function(section_id) {
			return handleSectionsVal('get', section_id, 'ssid');
		}

		o = s.taboption('travelmate', form.Value, '_bssid', _('BSSID'));
		o.modalonly = true;
		o.uciconfig = 'travelmate';
		o.ucisection = 'uplink';
		o.ucioption = 'bssid';
		o.rmempty = true;
		o.readonly = true;
		o.cfgvalue = function(section_id) {
			return handleSectionsVal('get', section_id, 'bssid');
		}

		o = s.taboption('travelmate', form.Value, '_con_start', _('Connection Start'));
		o.modalonly = true;
		o.uciconfig = 'travelmate';
		o.ucisection = 'uplink';
		o.ucioption = 'con_start';
		o.rmempty = true;
		o.readonly = true;
		o.cfgvalue = function(section_id) {
			return handleSectionsVal('get', section_id, 'con_start');
		}

		o = s.taboption('travelmate', form.Value, '_con_end', _('Connection End'));
		o.modalonly = true;
		o.uciconfig = 'travelmate';
		o.ucisection = 'uplink';
		o.ucioption = 'con_end';
		o.rmempty = true;
		o.readonly = true;
		o.cfgvalue = function(section_id) {
			return handleSectionsVal('get', section_id, 'con_end');
		}

		o = s.taboption('travelmate', form.Value, '_con_start_expiry', _('Connection Start Expiry'),
			_('Automatically disable the uplink after <em>n</em> minutes, e.g. for timed connections.<br /> \
			The default of \'0\' disables this feature.'));
		o.modalonly = true;
		o.uciconfig = 'travelmate';
		o.ucisection = 'uplink';
		o.ucioption = 'con_start_expiry';
		o.rmempty = false;
		o.placeholder = '0';
		o.default = '0';
		o.datatype = 'range(0,720)';
		o.cfgvalue = function(section_id) {
			return handleSectionsVal('get', section_id, 'con_start_expiry');
		}
		o.write = function(section_id, value) {
			return handleSectionsVal('set', section_id, 'con_start_expiry', value);
		}

		o = s.taboption('travelmate', form.Value, '_con_end_expiry', _('Connection End Expiry'),
			_('Automatically (re-)enable the uplink after <em>n</em> minutes, e.g. after failed login attempts.<br /> \
			The default of \'0\' disables this feature.'));
		o.modalonly = true;
		o.uciconfig = 'travelmate';
		o.ucisection = 'uplink';
		o.ucioption = 'con_end_expiry';
		o.rmempty = false;
		o.placeholder = '0';
		o.default = '0';
		o.datatype = 'range(0,720)';
		o.cfgvalue = function(section_id) {
			return handleSectionsVal('get', section_id, 'con_end_expiry');
		}
		o.write = function(section_id, value) {
			return handleSectionsVal('set', section_id, 'con_end_expiry', value);
		}

		o = s.taboption('travelmate', form.FileUpload, '_script', _('Auto Login Script'),
			_('External script reference which will be called for automated captive portal logins.'));
		o.root_directory = '/etc/travelmate';
		o.enable_remove = false;
		o.enable_upload = false;
		o.modalonly = true;
		o.uciconfig = 'travelmate';
		o.ucisection = 'uplink';
		o.ucioption = 'script';
		o.renderWidget = function(section_id, option_index, cfgvalue) {
			var browserEl = new ui.FileUpload((cfgvalue != null) ? cfgvalue : this.default, {
				id: this.cbid(section_id),
				name: this.cbid(section_id),
				show_hidden: this.show_hidden,
				enable_upload: this.enable_upload,
				enable_remove: this.enable_remove,
				root_directory: this.root_directory,
				disabled: (this.readonly != null) ? this.readonly : this.map.readonly
			});
			browserEl.renderListing = function(container, path, list) {
				return ui.FileUpload.prototype.renderListing.apply(this, [
					container, path,
					list.filter(function(entry) {
						return ((entry.type == 'directory') || (entry.type == 'file' && entry.name.match(/\.login$/)));
					})
				]);
			};
			return browserEl.render();
		};
		o.cfgvalue = function(section_id) {
			return handleSectionsVal('get', section_id, 'script');
		}
		o.write = function(section_id, value) {
			return handleSectionsVal('set', section_id, 'script', value);
		}
		o.remove =  function(section_id) {
			return handleSectionsVal('del', section_id, 'script');
		}

		o = s.taboption('travelmate', form.Value, '_args', _('Script Arguments'),
			_('Space separated list of additional arguments passed to the Auto Login Script, i.e. username and password'));
		o.modalonly = true;
		o.uciconfig = 'travelmate';
		o.ucisection = 'uplink';
		o.ucioption = 'script_args';
		o.rmempty = true;
		o.depends({ _script: '/etc/travelmate', '!contains': true });
		o.cfgvalue = function(section_id) {
			return handleSectionsVal('get', section_id, 'script_args');
		}
		o.write = function(section_id, value) {
			return handleSectionsVal('set', section_id, 'script_args', value);
		}
		o.remove =  function(section_id) {
			return handleSectionsVal('del', section_id, 'script_args');
		}

		/*
			scan buttons
		*/
		s = m.section(form.GridSection, 'wifi-device');
		s.anonymous = true;
		s.addremove = false;
		s.render = function() {
			return network.getWifiDevices().then(L.bind(function(radios) {
				var radio, ifname, btns = [];
				for (var i = 0; i < radios.length; i++) {
					radio  = radios[i].sid;
					if (radio) {
						btns.push(E('button', {
							'class': 'cbi-button cbi-button-apply',
							'id': radio,
							'click': ui.createHandlerFn(this, 'handleScan', radio)
						}, [ _('Scan on ' + radio + '...') ]),
						'\xa0')
					}
				}
				return E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, E('div', { 'class': 'left', 'style': 'padding-top:5px; padding-bottom:5px' }, btns));
			}, this))
		};

		/*
			modal 'scan' dialog
		*/
		s.handleScan = function(radio) {
			var table = E('div', { 'class': 'table' }, [
				E('div', { 'class': 'tr table-titles' }, [
					E('div', { 'class': 'th col-1 middle left' }, _('Strength')),
					E('div', { 'class': 'th col-1 middle left hide-xs' }, _('Channel')),
					E('div', { 'class': 'th col-2 middle left' }, _('SSID')),
					E('div', { 'class': 'th col-2 middle left' }, _('BSSID')),
					E('div', { 'class': 'th col-3 middle left' }, _('Encryption')),
					E('div', { 'class': 'th cbi-section-actions right' }, '\xa0')
				])
			]);
			cbi_update_table(table, [], E('em', { class: 'spinning' }, _('Starting wireless scan on \'' + radio + '\'...')));

			var md = ui.showModal(_('Wireless Scan'), [
				table,
				E('div', { 'class': 'right' }, [
					E('button', {
						'class': 'btn',
						'click': ui.hideModal
					}, _('Dismiss')),
					'\xa0',
					E('button', {
						'class': 'cbi-button cbi-button-positive important',
						'click': L.bind(this.handleScan, this, radio)
					}, _('Repeat Scan'))
				])
			]);

			md.style.maxWidth = '90%';
			md.style.maxHeight = 'none';

			return L.resolveDefault(fs.exec_direct('/etc/init.d/travelmate', [ 'scan', radio ]), null)
			.then(L.bind(function(res) {
				if (res) {
					var lines, strength, channel, encryption, tbl_encryption, bssid, ssid, tbl_ssid, rows = [];
					lines = res.trim().split('\n');
					for (var i = 0; i < lines.length; i++) {
						if (lines[i].match(/^\s+[0-9]/)) {
							encryption = lines[i].slice(80).trim();
							if (!encryption.includes('WEP')) {
								strength = lines[i].slice(4,7).trim();
								channel  = lines[i].slice(15,18).trim();
								bssid    = lines[i].slice(60,77).trim();
								ssid     = lines[i].slice(25,59).trim();
								if (ssid.startsWith('"')) {
									ssid = ssid.slice(1, ssid.length-1);
									tbl_ssid = ssid;
								}
								else {
									ssid = "hidden";
									tbl_ssid = "<em>hidden</em>";
								}
								switch (encryption) {
									case 'WPA3 PSK (SAE)':
										encryption = 'sae';
										tbl_encryption = 'WPA3 Pers. (SAE)';
										break;
									case 'mixed WPA2/WPA3 PSK/SAE (CCMP)':
										encryption = 'sae-mixed';
										tbl_encryption = 'WPA2/WPA3 Pers. (CCMP)';
										break;
									case 'WPA2 PSK (CCMP)':
										encryption = 'psk2+ccmp';
										tbl_encryption = 'WPA2 Pers. (CCMP)';
										break;
									case 'WPA2 PSK (TKIP)':
										encryption = 'psk2+tkip';
										tbl_encryption = 'WPA2 Pers. (TKIP)';
										break;
									case 'mixed WPA/WPA2 PSK (TKIP, CCMP)':
										encryption = 'psk-mixed+ccmp';
										tbl_encryption = 'WPA/WPA2 Pers. (CCMP)';
										break;
									case 'WPA PSK (CCMP)':
										encryption = 'psk2+ccmp';
										tbl_encryption = 'WPA Pers. (CCMP)';
										break;
									case 'WPA PSK (TKIP)':
										encryption = 'psk2+tkip';
										tbl_encryption = 'WPA Pers. (TKIP)';
										break;
									case 'WPA2 802.1X (CCMP)':
										encryption = 'wpa2+ccmp';
										tbl_encryption = 'WPA2 Ent. (CCMP)';
										break;
									case 'WPA3 OWE (CCMP)':
										encryption = 'owe';
										tbl_encryption = 'WPA3 OWE (CCMP)';
										break;
									case 'none':
										encryption = 'none';
										tbl_encryption = 'none';
										break;
								}
								rows.push([
									strength,
									channel,
									tbl_ssid,
									bssid,
									tbl_encryption,
									E('div', { 'class': 'right' }, E('button', {
										'class': 'cbi-button cbi-button-action',
										'click': ui.createHandlerFn(this, 'handleAdd', radio, iface, ssid, bssid, encryption)
									}, _('Add Uplink...')))
								]);
							}
						}
						else if (lines[i] === '::: No scan results') {
							rows.push([
								'No scan results'
							]);
						}
					}
				}
				else {
					rows.push([
						'No scan results'
					]);
				}
				cbi_update_table(table, rows);
			}, this));
		};

		/*
			modal 'add' dialog
		*/
		s.handleAdd = function(radio, iface, ssid, bssid, encryption, ev) {
			ui.hideModal;
			var m2, s2, o2;

			m2 = new form.Map('wireless'),
			s2 = m2.section(form.NamedSection, '_add_trm');

			s2.render = function() {
				return Promise.all([
					{},
					this.renderUCISection('_add_trm')
				]).then(this.renderContents.bind(this));
			};

			o2 = s2.option(form.Value, 'device', _('Device Name'));
			o2.default = radio;
			o2.readonly = true;

			o2 = s2.option(form.Value, 'network', _('Interface Name'));
			o2.default = iface;
			o2.readonly = true;

			if (ssid === "hidden") {
				o2 = s2.option(form.Value, 'ssid', _('SSID (hidden)'));
				o2.placeholder = 'hidden SSID';
			}
			else {
				o2 = s2.option(form.Value, 'ssid', _('SSID'));
				o2.default = ssid;
			}
			o2.datatype = 'maxlength(32)';
			o2.rmempty = false;

			o2 = s2.option(form.Flag, 'ignore_bssid', _('Ignore BSSID'));
			if (ssid === "hidden") {
				o2.default = '0';
			}
			else {
				o2.default = '1';
			}

			o2 = s2.option(form.Value, 'bssid', _('BSSID'));
			o2.depends({ ignore_bssid: '0' });
			o2.datatype = 'macaddr';
			o2.rmempty = true;
			o2.default = bssid;

			o2 = s2.option(form.ListValue, 'encryption', _('Encryption'));
			o2.value('sae', _('WPA3 Pers. (SAE)'));
			o2.value('sae-mixed', _('WPA2/WPA3 Pers. (CCMP)'));
			o2.value('psk2', _('WPA2 Pers.'));
			o2.value('psk2+ccmp', _('WPA2 Pers. (CCMP)'));
			o2.value('psk2+tkip', _('WPA2 Pers. (TKIP)'));
			o2.value('psk', _('WPA Pers.'));
			o2.value('psk+ccmp', _('WPA Pers. (CCMP)'));
			o2.value('psk+tkip', _('WPA Pers. (TKIP)'));
			o2.value('psk-mixed+ccmp', _('WPA/WPA2 Pers. (CCMP)'));
			o2.value('psk-mixed+tkip', _('WPA/WPA2 Pers. (TKIP)'));
			o2.value('wpa3', _('WPA3 Ent.'));
			o2.value('wpa3-mixed', _('WPA2/WPA3 Ent.'));
			o2.value('wpa2+ccmp', _('WPA2 Ent. (CCMP)'));
			o2.value('wpa2+tkip', _('WPA2 Ent. (TKIP)'));
			o2.value('wpa+ccmp', _('WPA Ent. (CCMP)'));
			o2.value('wpa+tkip', _('WPA Ent. (TKIP)'));
			o2.value('wpa-mixed+ccmp', _('WPA/WPA2 Ent. (CCMP)'));
			o2.value('wpa-mixed+tkip', _('WPA/WPA2 Ent. (TKIP)'));
			o2.value('owe', _('WPA3 OWE (CCMP)'));
			o2.value('none', _('none'));
			o2.default = encryption;

			o2 = s2.option(form.Value, 'key', _('Password'));
			o2.depends({ encryption: 'sae', '!contains': true });
			o2.depends({ encryption: 'psk', '!contains': true });
			o2.depends({ encryption: 'wpa', '!contains': true });
			o2.datatype = 'wpakey';
			o2.password = true;

			o2 = s2.option(form.ListValue, 'eap_type', _('EAP-Method'));
			o2.depends({ encryption: 'wpa', '!contains': true });
			o2.value('tls', _('TLS'));
			o2.value('ttls', _('TTLS'));
			o2.value('peap', _('PEAP'));
			o2.value('fast', _('FAST'));
			o2.default = 'peap';

			o2 = s2.option(form.ListValue, 'auth', _('Authentication'));
			o2.depends({ encryption: 'wpa', '!contains': true });
			o2.value('PAP', _('PAP'));
			o2.value('CHAP', _('CHAP'));
			o2.value('MSCHAP', _('MSCHAP'));
			o2.value('MSCHAPV2', _('MSCHAPV2'));
			o2.value('EAP-GTC', _('EAP-GTC'));
			o2.value('EAP-MD5', _('EAP-MD5'));
			o2.value('EAP-MSCHAPV2', _('EAP-MSCHAPV2'));
			o2.value('EAP-TLS', _('EAP-TLS'));
			o2.value('auth=PAP', _('auth=PAP'));
			o2.value('auth=MSCHAPV2', _('auth=MSCHAPV2'));
			o2.default = 'EAP-MSCHAPV2';

			o2 = s2.option(form.Value, 'identify', _('Identify'));
			o2.depends({ encryption: 'wpa', '!contains': true });

			o2 = s2.option(form.Value, 'ca_cert', _('Path to CA-Certificate'));
			o2.depends({ eap_type: 'tls' });
			o2.rmempty = true;

			o2 = s2.option(form.Value, 'client_cert', _('Path to Client-Certificate'));
			o2.depends({ eap_type: 'tls' });
			o2.rmempty = true;

			o2 = s2.option(form.Value, 'priv_key', _('Path to Private Key'));
			o2.depends({ eap_type: 'tls' });
			o2.rmempty = true;

			o2 = s2.option(form.Value, 'priv_key_pwd', _('Password of Private Key'));
			o2.depends({ eap_type: 'tls' });
			o2.datatype = 'wpakey';
			o2.password = true;
			o2.rmempty = true;

			return m2.render().then(L.bind(function(elements) {
				ui.showModal(_('Add Uplink %q').replace(/%q/, '"%h"'.format(ssid)), [
					elements,
					E('div', { 'class': 'right' }, [
						E('button', {
							'class': 'btn',
							'click': ui.hideModal
						}, _('Dismiss')),
						'\xa0',
						E('button', {
							'class': 'cbi-button cbi-button-positive important',
							'click': ui.createHandlerFn(this, 'handleSave', m2)
						}, _('Save'))
					])
				]);
			}, this));
		};

		/*
			save new uplink
		*/
		s.handleSave = function(map, ev) {
			var w_sections = uci.sections('wireless', 'wifi-iface'),
			device = L.toArray(map.lookupOption('device', '_add_trm'))[0].formvalue('_add_trm'),
			network = L.toArray(map.lookupOption('network', '_add_trm'))[0].formvalue('_add_trm'),
			ssid = L.toArray(map.lookupOption('ssid', '_add_trm'))[0].formvalue('_add_trm'),
			ignore_bssid = L.toArray(map.lookupOption('ignore_bssid', '_add_trm'))[0].formvalue('_add_trm'),
			bssid = L.toArray(map.lookupOption('bssid', '_add_trm'))[0].formvalue('_add_trm'),
			encryption = L.toArray(map.lookupOption('encryption', '_add_trm'))[0].formvalue('_add_trm'),
			password = L.toArray(map.lookupOption('key', '_add_trm'))[0].formvalue('_add_trm');
			if (!ssid || ((encryption.includes('psk') || encryption.includes('wpa') || encryption.includes('sae')) && !password)) {
				return;
			}
			for (var i = 0; i < w_sections.length; i++) {
				if (w_sections[i].device === device && w_sections[i].ssid === ssid) {
					if (ignore_bssid === '1' || (ignore_bssid === '0' && w_sections[i].bssid === bssid)) {
						ui.hideModal();
						return;
					}
				}
			}

			var offset  = w_sections.length,
			new_sid = 'trm_uplink' + (++offset);
			while (uci.get('wireless', new_sid)) {
				new_sid = 'trm_uplink' + (++offset);
			}
			uci.add('wireless', 'wifi-iface', new_sid);
			uci.set('wireless', new_sid, 'device', device);
			uci.set('wireless', new_sid, 'mode', 'sta');
			uci.set('wireless', new_sid, 'network', network);
			uci.set('wireless', new_sid, 'ssid', ssid);
			if (ignore_bssid === '0') {
				uci.set('wireless', new_sid, 'bssid', bssid);
			}
			uci.set('wireless', new_sid, 'encryption', encryption);
			uci.set('wireless', new_sid, 'key', password);
			uci.set('wireless', new_sid, 'disabled', '1');
			handleSectionsAdd(network);
			uci.save();
			ui.hideModal();
		};
		return m.render();
	},
	handleReset: null
});