treewide: remove rendundant proto handler options
[project/luci.git] / protocols / luci-proto-modemmanager / htdocs / luci-static / resources / protocol / modemmanager.js
1 'use strict';
2 'require fs';
3 'require form';
4 'require network';
5
6 function getModemList() {
7 return fs.exec_direct('/usr/bin/mmcli', [ '-L' ]).then(function(res) {
8 var lines = (res || '').split(/\n/),
9 tasks = [];
10
11 for (var i = 0; i < lines.length; i++) {
12 var m = lines[i].match(/\/Modem\/(\d+)/);
13 if (m)
14 tasks.push(fs.exec_direct('/usr/bin/mmcli', [ '-m', m[1] ]));
15 }
16
17 return Promise.all(tasks).then(function(res) {
18 var modems = [];
19
20 for (var i = 0; i < res.length; i++) {
21 var man = res[i].match(/manufacturer: ([^\n]+)/),
22 mod = res[i].match(/model: ([^\n]+)/),
23 dev = res[i].match(/device: ([^\n]+)/);
24
25 if (dev) {
26 modems.push({
27 device: dev[1].trim(),
28 manufacturer: (man ? man[1].trim() : '') || '?',
29 model: (mod ? mod[1].trim() : '') || dev[1].trim()
30 });
31 }
32 }
33
34 return modems;
35 });
36 });
37 }
38
39 network.registerPatternVirtual(/^mobiledata-.+$/);
40 network.registerErrorCode('MM_CONNECT_FAILED', _('Connection attempt failed.'));
41 network.registerErrorCode('MM_DISCONNECT_IN_PROGRESS', _('Modem disconnection in progress. Please wait.'));
42 network.registerErrorCode('MM_CONNECT_IN_PROGRESS', _('Modem connection in progress. Please wait. This process will timeout after 2 minutes.'));
43 network.registerErrorCode('MM_TEARDOWN_IN_PROGRESS', _('Modem bearer teardown in progress.'));
44 network.registerErrorCode('MM_MODEM_DISABLED', _('Modem is disabled.'));
45 network.registerErrorCode('DEVICE_NOT_MANAGED', _('Device not managed by ModemManager.'));
46 network.registerErrorCode('INVALID_BEARER_LIST', _('Invalid bearer list. Possibly too many bearers created. This protocol supports one and only one bearer.'));
47 network.registerErrorCode('UNKNOWN_METHOD', _('Unknown and unsupported connection method.'));
48 network.registerErrorCode('DISCONNECT_FAILED', _('Disconnection attempt failed.'));
49
50 return network.registerProtocol('modemmanager', {
51 getI18n: function() {
52 return _('ModemManager');
53 },
54
55 getIfname: function() {
56 return this._ubus('l3_device') || 'modemmanager-%s'.format(this.sid);
57 },
58
59 getOpkgPackage: function() {
60 return 'modemmanager';
61 },
62
63 isFloating: function() {
64 return true;
65 },
66
67 isVirtual: function() {
68 return true;
69 },
70
71 getDevices: function() {
72 return null;
73 },
74
75 containsDevice: function(ifname) {
76 return (network.getIfnameOf(ifname) == this.getIfname());
77 },
78
79 renderFormOptions: function(s) {
80 var dev = this.getL3Device() || this.getDevice(), o;
81
82 o = s.taboption('general', form.ListValue, 'device', _('Modem device'));
83 o.rmempty = false;
84 o.load = function(section_id) {
85 return getModemList().then(L.bind(function(devices) {
86 for (var i = 0; i < devices.length; i++)
87 this.value(devices[i].device,
88 '%s - %s'.format(devices[i].manufacturer, devices[i].model));
89 return form.Value.prototype.load.apply(this, [section_id]);
90 }, this));
91 };
92
93 s.taboption('general', form.Value, 'apn', _('APN'));
94 s.taboption('general', form.Value, 'pincode', _('PIN'));
95
96 o = s.taboption('general', form.ListValue, 'auth', _('Authentication Type'));
97 o.value('both', _('PAP/CHAP (both)'));
98 o.value('pap', 'PAP');
99 o.value('chap', 'CHAP');
100 o.value('none', _('None'));
101 o.default = 'none';
102
103 o = s.taboption('general', form.Value, 'username', _('PAP/CHAP username'));
104 o.depends('auth', 'pap');
105 o.depends('auth', 'chap');
106 o.depends('auth', 'both');
107
108 o = s.taboption('general', form.Value, 'password', _('PAP/CHAP password'));
109 o.depends('auth', 'pap');
110 o.depends('auth', 'chap');
111 o.depends('auth', 'both');
112 o.password = true;
113
114 o = s.taboption('general', form.ListValue, 'iptype', _('IP Type'));
115 o.value('ipv4v6', _('IPv4/IPv6 (both - defaults to IPv4)'))
116 o.value('ipv4', _('IPv4 only'));
117 o.value('ipv6', _('IPv6 only'));
118 o.default = 'ipv4v6';
119
120 o = s.taboption('advanced', form.Value, 'mtu', _('Override MTU'));
121 o.placeholder = dev ? (dev.getMTU() || '1500') : '1500';
122 o.datatype = 'max(9200)';
123
124 o = s.taboption('general', form.Value, 'signalrate', _('Signal Refresh Rate'), _("In seconds"));
125 o.datatype = 'uinteger';
126 }
127 });