luci2: major changes to RPC implementation
[project/luci2/ui.git] / luci2 / htdocs / luci2 / view / system.admin.js
1 L.ui.view.extend({
2     execute: function() {
3         var m = new L.cbi.Map('dropbear', {
4             caption:     L.tr('SSH Access'),
5             description: L.tr('Dropbear offers SSH network shell access and an integrated SCP server'),
6             collabsible: true
7         });
8
9         var s1 = m.section(L.cbi.DummySection, '__password', {
10             caption:     L.tr('Router Password'),
11             description: L.tr('Changes the administrator password for accessing the device'),
12             readonly:    !this.options.acls.admin
13         });
14
15         var p1 = s1.option(L.cbi.PasswordValue, 'pass1', {
16             caption:     L.tr('Password'),
17             optional:    true
18         });
19
20         var p2 = s1.option(L.cbi.PasswordValue, 'pass2', {
21             caption:     L.tr('Confirmation'),
22             optional:    true,
23             datatype:    function(v) {
24                 var v1 = p1.formvalue('__password');
25                 if (v1 && v1.length && v != v1)
26                     return L.tr('Passwords must match!');
27                 return true;
28             }
29         });
30
31         p1.save = function(sid) { };
32         p2.save = function(sid) {
33             var v1 = p1.formvalue(sid);
34             var v2 = p2.formvalue(sid);
35             if (v2 && v2.length > 0 && v1 == v2)
36                 return L.system.setPassword('root', v2);
37         };
38
39
40         var s2 = m.section(L.cbi.TypedSection, 'dropbear', {
41             caption:     L.tr('SSH Server'),
42             description: L.tr('This sections define listening instances of the builtin Dropbear SSH server'),
43             addremove:   true,
44             add_caption: L.tr('Add instance ...'),
45             readonly:    !this.options.acls.admin
46         });
47
48         s2.option(L.cbi.NetworkList, 'Interface', {
49             caption:     L.tr('Interface'),
50             description: L.tr('Listen only on the given interface or, if unspecified, on all')
51         });
52
53         s2.option(L.cbi.InputValue, 'Port', {
54             caption:     L.tr('Port'),
55             description: L.tr('Specifies the listening port of this Dropbear instance'),
56             datatype:    'port',
57             placeholder: 22,
58             optional:    true
59         });
60
61         s2.option(L.cbi.CheckboxValue, 'PasswordAuth', {
62             caption:     L.tr('Password authentication'),
63             description: L.tr('Allow SSH password authentication'),
64             initial:     true,
65             enabled:     'on',
66             disabled:    'off'
67         });
68
69         s2.option(L.cbi.CheckboxValue, 'RootPasswordAuth', {
70             caption:     L.tr('Allow root logins with password'),
71             description: L.tr('Allow the root user to login with password'),
72             initial:     true,
73             enabled:     'on',
74             disabled:    'off'
75         });
76
77         s2.option(L.cbi.CheckboxValue, 'GatewayPorts', {
78             caption:     L.tr('Gateway ports'),
79             description: L.tr('Allow remote hosts to connect to local SSH forwarded ports'),
80             initial:     false,
81             enabled:     'on',
82             disabled:    'off'
83         });
84
85
86         var s3 = m.section(L.cbi.TableSection, '__keys', {
87             caption:     L.tr('SSH-Keys'),
88             description: L.tr('Here you can paste public SSH-Keys (one per line) for SSH public-key authentication.'),
89             addremove:   true,
90             add_caption: L.tr('Add key ...'),
91             readonly:    !this.options.acls.admin
92         });
93
94         s3.sections = function()
95         {
96             var k = [ ];
97             var l = this.keys ? this.keys.length : 0;
98
99             for (var i = 0; i < (l || 1); i++)
100                 k.push({ '.name': i.toString() });
101
102             return k;
103         };
104
105         s3.add    = function()    { this.keys.push('') };
106         s3.remove = function(sid) { this.keys.splice(parseInt(sid), 1) };
107
108         var c = s3.option(L.cbi.DummyValue, '__comment', {
109             caption:     L.tr('Comment'),
110             width:       '10%'
111         });
112
113         c.ucivalue = function(sid) {
114             var key = (s3.keys[parseInt(sid)] || '').split(/\s+/) || [ ];
115             return key[2] || '-';
116         };
117
118         var k = s3.option(L.cbi.InputValue, '__key', {
119             caption:     L.tr('Public key line'),
120             width:       '90%',
121             datatype:    function(key, elem) {
122                 var elems = (key || '-').toString().split(/\s+/);
123
124                 $('#' + elem.attr('id').replace(/key$/, 'comment')).text(elems[2] || '');
125
126                 if (elems.length < 2 || elems[0].indexOf('ssh-') != 0 ||
127                     !elems[1].match(/^(?:[A-Za-z0-9+/]{4})+(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/))
128                     return L.tr('Must be a valid SSH pubkey');
129
130                 return true;
131             }
132         });
133
134         k.load     = function(sid) { s3.keys = [ ]; return L.system.getSSHKeys().then(function(keys) { s3.keys = keys }) };
135         k.save     = function(sid) { if (sid == '0') return L.system.setSSHKeys(s3.keys) };
136         k.ucivalue = function(sid) { return s3.keys[parseInt(sid)] };
137
138         return m.insertInto('#map');
139     }
140 });