luci-app-samba4: add support for new UCI option
[oweals/luci.git] / applications / luci-app-samba4 / htdocs / luci-static / resources / view / samba4.js
1 'use strict';
2 'require fs';
3 'require form';
4 'require tools.widgets as widgets';
5
6 return L.view.extend({
7         load: function() {
8                 return Promise.all([
9                         L.resolveDefault(fs.stat('/sbin/block'), null),
10                         L.resolveDefault(fs.stat('/etc/config/fstab'), null),
11                         L.resolveDefault(fs.stat('/usr/sbin/nmbd'), {}),
12                         L.resolveDefault(fs.stat('/usr/sbin/samba'), {}),
13                         L.resolveDefault(fs.stat('/usr/sbin/winbindd'), {}),
14                         L.resolveDefault(fs.exec('/usr/sbin/smbd', ['-V']), null),
15                 ]);
16         },
17         render: function(stats) {
18                 var m, s, o, v;
19                 v = '';
20                 
21                 m = new form.Map('samba4', _('Network Shares'));
22
23                 if (stats[5] && stats[5].code === 0) {
24                         v = stats[5].stdout.trim();
25                 }
26                 s = m.section(form.TypedSection, 'samba', 'Samba ' + v);
27                 s.anonymous = true;
28
29                 s.tab('general',  _('General Settings'));
30                 s.tab('template', _('Edit Template'));
31
32                 s.taboption('general', widgets.NetworkSelect, 'interface', _('Interface'),
33                         _('Listen only on the given interface or, if unspecified, on lan'));
34
35                 o = s.taboption('general', form.Value, 'workgroup', _('Workgroup'));
36                 o.placeholder = 'WORKGROUP';
37
38                 o = s.taboption('general', form.Value, 'description', _('Description'));
39                 o.placeholder = 'Samba4 on OpenWrt';
40                 
41                 s.taboption('general', form.Flag, 'disable_async_io', _('Force synchronous  I/O'),
42                         _('On lower-end devices may increase speeds, by forceing synchronous I/O instead of the default asynchronous.'));
43
44                 o = s.taboption('general', form.Flag, 'macos', _('Enable macOS compatible shares'),
45                         _('Enables Apple\'s AAPL extension globally and adds macOS compatibility options to all shares.'));
46                         
47                 o = s.taboption('general', form.Flag, 'allow_legacy_protocols', _('Allow legacy (insecure) protocols/authentication.'),
48                         _('Allow legacy smb(v1)/Lanman connections, needed for older devices without smb(v2.1/3) support.'));
49
50                 if (stats[2].type === 'file') {
51                         s.taboption('general', form.Flag, 'disable_netbios', _('Disable Netbios')) 
52                 }
53                 if (stats[3].type === 'file') {
54                         s.taboption('general', form.Flag, 'disable_ad_dc', _('Disable Active Directory Domain Controller')) 
55                 }
56                 if (stats[4].type === 'file') {
57                         s.taboption('general', form.Flag, 'disable_winbind', _('Disable Winbind')) 
58                 }
59                 
60                 o = s.taboption('template', form.TextValue, '_tmpl',
61                         _('Edit the template that is used for generating the samba configuration.'),
62                         _("This is the content of the file '/etc/samba/smb.conf.template' from which your samba configuration will be generated. \
63                         Values enclosed by pipe symbols ('|') should not be changed. They get their values from the 'General Settings' tab."));
64                 o.rows = 20;
65                 o.cfgvalue = function(section_id) {
66                         return fs.trimmed('/etc/samba/smb.conf.template');
67                 };
68                 o.write = function(section_id, formvalue) {
69                         return fs.write('/etc/samba/smb.conf.template', formvalue.trim().replace(/\r\n/g, '\n') + '\n');
70                 };
71
72
73                 s = m.section(form.TableSection, 'sambashare', _('Shared Directories'),
74                         _('Please add directories to share. Each directory refers to a folder on a mounted device.'));
75                 s.anonymous = true;
76                 s.addremove = true;
77
78                 s.option(form.Value, 'name', _('Name'));
79                 o = s.option(form.Value, 'path', _('Path'));
80                 if (stats[0] && stats[1]) {
81                         o.titleref = L.url('admin', 'system', 'mounts');
82                 }
83
84                 o = s.option(form.Flag, 'browseable', _('Browse-able'));
85                 o.enabled = 'yes';
86                 o.disabled = 'no';
87                 o.default = 'yes';
88
89                 o = s.option(form.Flag, 'read_only', _('Read-only'));
90                 o.enabled = 'yes';
91                 o.disabled = 'no';
92                 o.default = 'no'; // smb.conf default is 'yes'
93                 o.rmempty = false;
94
95                 s.option(form.Flag, 'force_root', _('Force Root'));
96
97                 o = s.option(form.Value, 'users', _('Allowed users'));
98                 o.rmempty = true;
99
100                 o = s.option(form.Flag, 'guest_ok', _('Allow guests'));
101                 o.enabled = 'yes';
102                 o.disabled = 'no';
103                 o.default = 'yes'; // smb.conf default is 'no'
104                 o.rmempty = false;
105
106                 o = s.option(form.Flag, 'guest_only', _('Guests only'));
107                 o.enabled = 'yes';
108                 o.disabled = 'no';
109                 o.default = 'no';
110                 
111                 o = s.option(form.Flag, 'inherit_owner', _('Inherit owner'));
112                 o.enabled = 'yes';
113                 o.disabled = 'no';
114                 o.default = 'no';
115
116                 o = s.option(form.Value, 'create_mask', _('Create mask'));
117                 o.maxlength = 4;
118                 o.default = '0666'; // smb.conf default is '0744'
119                 o.placeholder = '0666';
120                 o.rmempty = false;
121
122                 o = s.option(form.Value, 'dir_mask', _('Directory mask'));
123                 o.maxlength = 4;
124                 o.default = '0777'; // smb.conf default is '0755'
125                 o.placeholder = '0777';
126                 o.rmempty = false;
127                 
128                 o = s.option(form.Value, 'vfs_objects', _('Vfs objects'));
129                 o.rmempty = true;
130                 
131                 s.option(form.Flag, 'timemachine', _('Apple Time-machine share'));
132                 
133                 o = s.option(form.Value, 'timemachine_maxsize', _('Time-machine size in GB'));
134                 o.rmempty = true;
135                 o.maxlength = 5;
136
137                 return m.render();
138         }
139 });