treewide: remove rendundant proto handler options
[project/luci.git] / protocols / luci-proto-pppossh / htdocs / luci-static / resources / protocol / pppossh.js
1 'use strict';
2 'require uci';
3 'require form';
4 'require network';
5
6 network.registerPatternVirtual(/^pppossh-.+$/);
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('pppossh', {
27 getI18n: function() {
28 return _('PPPoSSH');
29 },
30
31 getIfname: function() {
32 return this._ubus('l3_device') || 'pppossh-%s'.format(this.sid);
33 },
34
35 getOpkgPackage: function() {
36 return 'pppossh';
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 o;
57
58 o = s.taboption('general', form.Value, 'sshuser', _('SSH username'));
59 o.rmempty = false;
60 o.validate = function(section_id, value) {
61 var id_opt = this.section.children.filter(function(o) { return o.option == 'identity' })[0];
62 if (id_opt && value.length) {
63 var input = this.map.findElement('id', id_opt.cbid(section_id)).querySelector('input[type="text"]');
64 if (input)
65 input.placeholder = (value == 'root' ? '/root' : '/home/' + value) + '/.ssh/id_rsa';
66 }
67 return true;
68 };
69
70 o = s.taboption('general', form.Value, 'server', _('SSH server address'));
71 o.datatype = 'host(0)';
72 o.rmempty = false;
73
74 o = s.taboption('general', form.Value, 'port', _('SSH server port'));
75 o.datatype = 'port';
76 o.optional = true;
77 o.placeholder = 22;
78
79 o = s.taboption('general', form.Value, 'ssh_options', _('Extra SSH command options'));
80 o.optional = true;
81
82 o = s.taboption('general', form.DynamicList, 'identity', _('List of SSH key files for auth'));
83 o.optional = true;
84 o.datatype = 'file';
85
86 o = s.taboption('general', form.Value, 'ipaddr', _('Local IP address to assign'));
87 o.datatype = 'ipaddr("nomask")';
88
89 o = s.taboption('general', form.Value, 'peeraddr', _('Peer IP address to assign'));
90 o.datatype = 'ipaddr("nomask")';
91
92 if (L.hasSystemFeature('ipv6')) {
93 o = s.taboption('advanced', form.Flag, 'ipv6', _('Obtain IPv6-Address'), _('Enable IPv6 negotiation on the PPP link'));
94 o.default = o.disabled;
95 }
96
97 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'));
98 o.placeholder = '0';
99 o.datatype = 'uinteger';
100 o.write = write_keepalive;
101 o.remove = write_keepalive;
102 o.cfgvalue = function(section_id) {
103 var v = uci.get('network', section_id, 'keepalive');
104 if (typeof(v) == 'string' && v != '') {
105 var m = v.match(/^(\d+)[ ,]\d+$/);
106 return m ? m[1] : v;
107 }
108 };
109
110 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'));
111 o.placeholder = '5';
112 o.datatype = 'min(1)';
113 o.write = write_keepalive;
114 o.remove = write_keepalive;
115 o.cfgvalue = function(section_id) {
116 var v = uci.get('network', section_id, 'keepalive');
117 if (typeof(v) == 'string' && v != '') {
118 var m = v.match(/^\d+[ ,](\d+)$/);
119 return m ? m[1] : v;
120 }
121 };
122
123 o = s.taboption('advanced', form.Value, 'demand', _('Inactivity timeout'), _('Close inactive connection after the given amount of seconds, use 0 to persist connection'));
124 o.placeholder = '0';
125 o.datatype = 'uinteger';
126 }
127 });