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