Merge pull request #1735 from sumpfralle/olsr-jsoninfo-parser-handle-empty-result
[oweals/luci.git] / protocols / luci-proto-ppp / htdocs / luci-static / resources / protocol / pppoa.js
1 'use strict';
2 'require uci';
3 'require form';
4 'require network';
5
6 network.registerPatternVirtual(/^pppoa-.+$/);
7
8 function write_keepalive(section_id, value) {
9         var f_opt = this.map.lookupOption('_keepalive_failure', section_id),
10             i_opt = this.map.lookupOption('_keepalive_interval', section_id),
11             f = (f_opt != null) ? +f_opt[0].formvalue(section_id) : null,
12             i = (i_opt != null) ? +i_opt[0].formvalue(section_id) : null;
13
14         if (f == null || f == '' || isNaN(f))
15                 f = 0;
16
17         if (i == null || i == '' || isNaN(i) || i < 1)
18                 i = 1;
19
20         if (f > 0)
21                 uci.set('network', section_id, 'keepalive', '%d %d'.format(f, i));
22         else
23                 uci.unset('network', section_id, 'keepalive');
24 }
25
26 return network.registerProtocol('pppoa', {
27         getI18n: function() {
28                 return _('PPPoATM');
29         },
30
31         getIfname: function() {
32                 return this._ubus('l3_device') || 'pppoa-%s'.format(this.sid);
33         },
34
35         getOpkgPackage: function() {
36                 return 'ppp-mod-pppoa';
37         },
38
39         isFloating: function() {
40                 return true;
41         },
42
43         isVirtual: function() {
44                 return true;
45         },
46
47         getDevices: function() {
48                 return null;
49         },
50
51         containsDevice: function(ifname) {
52                 return (network.getIfnameOf(ifname) == this.getIfname());
53         },
54
55         renderFormOptions: function(s) {
56                 var dev = this.getL3Device() || this.getDevice(), o;
57
58                 o = s.taboption('general', form.ListValue, 'encaps', _('PPPoA Encapsulation'));
59                 o.value('vc', 'VC-Mux');
60                 o.value('llc', 'LLC');
61
62                 o = s.taboption('general', form.Value, 'atmdev', _('ATM device number'));
63                 o.default  = '0';
64                 o.datatype = 'uinteger';
65
66                 o = s.taboption('general', form.Value, 'vci', _('ATM Virtual Channel Identifier (VCI)'));
67                 o.default  = '35';
68                 o.datatype = 'uinteger';
69
70                 o = s.taboption('general', form.Value, 'vpi', _('ATM Virtual Path Identifier (VPI)'));
71                 o.default  = '8';
72                 o.datatype = 'uinteger';
73
74                 s.taboption('general', form.Value, 'username', _('PAP/CHAP username'));
75
76                 o = s.taboption('general', form.Value, 'password', _('PAP/CHAP password'));
77                 o.password = true;
78
79                 if (L.hasSystemFeature('ipv6')) {
80                         o = s.taboption('advanced', form.ListValue, 'ipv6', _('Obtain IPv6-Address'), _('Enable IPv6 negotiation on the PPP link'));
81                         o.value('auto', _('Automatic'));
82                         o.value('0', _('Disabled'));
83                         o.value('1', _('Manual'));
84                         o.default = 'auto';
85                 }
86
87                 o = s.taboption('advanced', form.Flag, 'defaultroute', _('Use default gateway'), _('If unchecked, no default route is configured'));
88                 o.default = o.enabled;
89
90                 o = s.taboption('advanced', form.Flag, 'peerdns', _('Use DNS servers advertised by peer'), _('If unchecked, the advertised DNS server addresses are ignored'));
91                 o.default = o.enabled;
92
93                 o = s.taboption('advanced', form.DynamicList, 'dns', _('Use custom DNS servers'));
94                 o.depends('peerdns', '0');
95                 o.datatype = 'ipaddr';
96                 o.cast     = 'string';
97
98                 o = s.taboption('advanced', form.Value, 'metric', _('Use gateway metric'));
99                 o.placeholder = '0';
100                 o.datatype    = 'uinteger';
101
102                 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'));
103                 o.placeholder = '0';
104                 o.datatype    = 'uinteger';
105                 o.write       = write_keepalive;
106                 o.remove      = write_keepalive;
107                 o.cfgvalue = function(section_id) {
108                         var v = uci.get('network', section_id, 'keepalive');
109                         if (typeof(v) == 'string' && v != '') {
110                                 var m = v.match(/^(\d+)[ ,]\d+$/);
111                                 return m ? m[1] : v;
112                         }
113                 };
114
115                 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'));
116                 o.placeholder = '5';
117                 o.datatype    = 'min(1)';
118                 o.write       = write_keepalive;
119                 o.remove      = write_keepalive;
120                 o.cfgvalue = function(section_id) {
121                         var v = uci.get('network', section_id, 'keepalive');
122                         if (typeof(v) == 'string' && v != '') {
123                                 var m = v.match(/^\d+[ ,](\d+)$/);
124                                 return m ? m[1] : v;
125                         }
126                 };
127
128                 o = s.taboption('advanced', form.Value, 'demand', _('Inactivity timeout'), _('Close inactive connection after the given amount of seconds, use 0 to persist connection'));
129                 o.placeholder = '0';
130                 o.datatype    = 'uinteger';
131
132                 o = s.taboption('advanced', form.Value, 'mtu', _('Override MTU'));
133                 o.placeholder = dev ? (dev.getMTU() || '1500') : '1500';
134                 o.datatype    = 'max(9200)';
135         }
136 });