treewide: consolidate {IPv4,IPv6,MAC} {address,gateway} spellings
[project/luci.git] / protocols / luci-proto-3g / htdocs / luci-static / resources / protocol / 3g.js
1 'use strict';
2 'require rpc';
3 'require uci';
4 'require form';
5 'require network';
6
7 var callFileList = rpc.declare({
8 object: 'file',
9 method: 'list',
10 params: [ 'path' ],
11 expect: { entries: [] },
12 filter: function(list, params) {
13 var rv = [];
14 for (var i = 0; i < list.length; i++)
15 if (list[i].name.match(/^tty[A-Z]/) || list[i].name.match(/^cdc-wdm/) || list[i].name.match(/^[0-9]+$/))
16 rv.push(params.path + list[i].name);
17 return rv.sort();
18 }
19 });
20
21 network.registerPatternVirtual(/^3g-.+$/);
22
23 function write_keepalive(section_id, value) {
24 var f_opt = this.map.lookupOption('_keepalive_failure', section_id),
25 i_opt = this.map.lookupOption('_keepalive_interval', section_id),
26 f = (f_opt != null) ? +f_opt[0].formvalue(section_id) : null,
27 i = (i_opt != null) ? +i_opt[0].formvalue(section_id) : null;
28
29 if (f == null || f == '' || isNaN(f))
30 f = 0;
31
32 if (i == null || i == '' || isNaN(i) || i < 1)
33 i = 1;
34
35 if (f > 0)
36 uci.set('network', section_id, 'keepalive', '%d %d'.format(f, i));
37 else
38 uci.unset('network', section_id, 'keepalive');
39 }
40
41 return network.registerProtocol('3g', {
42 getI18n: function() {
43 return _('UMTS/GPRS/EV-DO');
44 },
45
46 getIfname: function() {
47 return this._ubus('l3_device') || '3g-%s'.format(this.sid);
48 },
49
50 getOpkgPackage: function() {
51 return 'comgt';
52 },
53
54 isFloating: function() {
55 return true;
56 },
57
58 isVirtual: function() {
59 return true;
60 },
61
62 getDevices: function() {
63 return null;
64 },
65
66 containsDevice: function(ifname) {
67 return (network.getIfnameOf(ifname) == this.getIfname());
68 },
69
70 renderFormOptions: function(s) {
71 var o;
72
73 o = s.taboption('general', form.Value, '_modem_device', _('Modem device'));
74 o.ucioption = 'device';
75 o.rmempty = false;
76 o.load = function(section_id) {
77 return callFileList('/dev/').then(L.bind(function(devices) {
78 for (var i = 0; i < devices.length; i++)
79 this.value(devices[i]);
80 return callFileList('/dev/tts/');
81 }, this)).then(L.bind(function(devices) {
82 for (var i = 0; i < devices.length; i++)
83 this.value(devices[i]);
84 return form.Value.prototype.load.apply(this, [section_id]);
85 }, this));
86 };
87
88 o = s.taboption('general', form.Value, 'service', _('Service Type'));
89 o.value('', _('-- Please choose --'));
90 o.value('umts', 'UMTS/GPRS');
91 o.value('umts_only', _('UMTS only'));
92 o.value('gprs_only', _('GPRS only'));
93 o.value('evdo', 'CDMA/EV-DO');
94
95 s.taboption('general', form.Value, 'apn', _('APN'));
96 s.taboption('general', form.Value, 'pincode', _('PIN'));
97 s.taboption('general', form.Value, 'username', _('PAP/CHAP username'));
98
99 o = s.taboption('general', form.Value, 'password', _('PAP/CHAP password'));
100 o.password = true;
101
102 o = s.taboption('general', form.Value, 'dialnumber', _('Dial number'));
103 o.placeholder = '*99***1#';
104
105 if (L.hasSystemFeature('ipv6')) {
106 o = s.taboption('advanced', form.ListValue, 'ppp_ipv6', _('Obtain IPv6 address'));
107 o.ucioption = 'ipv6';
108 o.value('auto', _('Automatic'));
109 o.value('0', _('Disabled'));
110 o.value('1', _('Manual'));
111 o.default = 'auto';
112 }
113
114 o = s.taboption('advanced', form.Value, 'delay', _('Modem init timeout'), _('Maximum amount of seconds to wait for the modem to become ready'));
115 o.placeholder = '10';
116 o.datatype = 'min(1)';
117
118 o = s.taboption('advanced', form.Value, '_keepalive_failure', _('LCP echo failure threshold'), _('Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures'));
119 o.placeholder = '0';
120 o.datatype = 'uinteger';
121 o.write = write_keepalive;
122 o.remove = write_keepalive;
123 o.cfgvalue = function(section_id) {
124 var v = uci.get('network', section_id, 'keepalive');
125 if (typeof(v) == 'string' && v != '') {
126 var m = v.match(/^(\d+)[ ,]\d+$/);
127 return m ? m[1] : v;
128 }
129 };
130
131 o = s.taboption('advanced', form.Value, '_keepalive_interval', _('LCP echo interval'), _('Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold'));
132 o.placeholder = '5';
133 o.datatype = 'min(1)';
134 o.write = write_keepalive;
135 o.remove = write_keepalive;
136 o.cfgvalue = function(section_id) {
137 var v = uci.get('network', section_id, 'keepalive');
138 if (typeof(v) == 'string' && v != '') {
139 var m = v.match(/^\d+[ ,](\d+)$/);
140 return m ? m[1] : v;
141 }
142 };
143
144 o = s.taboption('advanced', form.Value, 'demand', _('Inactivity timeout'), _('Close inactive connection after the given amount of seconds, use 0 to persist connection'));
145 o.placeholder = '0';
146 o.datatype = 'uinteger';
147 }
148 });