6cf9f3edae4906be100d997283d0b0ed5672d2ca
[project/luci.git] / applications / luci-app-ksmbd / htdocs / luci-static / resources / view / ksmbd.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.exec('/usr/sbin/ksmbd.mountd', ['-V']), {}).then(function(res) { return L.toArray((res.stdout || '').match(/version : (\S+)/))[1] }),
12 L.resolveDefault(fs.exec('/sbin/modinfo', ['ksmbd']), {}).then(function(res) { return L.toArray((res.stdout || '').match(/version:\t(\S+)/))[1] }),
13 ]);
14 },
15 render: function(stats) {
16 var m, s, o, v;
17 v = '';
18
19 m = new form.Map('ksmbd', _('Network Shares'));
20
21 if (stats[2]) {
22 v = stats[2].trim();
23 }
24 if (stats[3]) {
25 v = v + ' Kmod: ' + stats[3].trim();
26 }
27 s = m.section(form.TypedSection, 'globals', 'Ksmbd: ' + 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 = 'Ksmbd on OpenWrt';
41
42 o = s.taboption('general', form.Flag, 'allow_legacy_protocols', _('Allow legacy (insecure) protocols/authentication.'),
43 _('Allow legacy smb(v1)/Lanman connections, needed for older devices without smb(v2.1/3) support.'));
44
45 o = s.taboption('template', form.TextValue, '_tmpl',
46 _('Edit the template that is used for generating the ksmbd configuration.'),
47 _("This is the content of the file '/etc/ksmbd/smb.conf.template' from which your ksmbd configuration will be generated. \
48 Values enclosed by pipe symbols ('|') should not be changed. They get their values from the 'General Settings' tab."));
49 o.rows = 20;
50 o.cfgvalue = function(section_id) {
51 return fs.trimmed('/etc/ksmbd/smb.conf.template');
52 };
53 o.write = function(section_id, formvalue) {
54 return fs.write('/etc/ksmbd/smb.conf.template', formvalue.trim().replace(/\r\n/g, '\n') + '\n');
55 };
56
57
58 s = m.section(form.TableSection, 'share', _('Shared Directories'),
59 _('Please add directories to share. Each directory refers to a folder on a mounted device.'));
60 s.anonymous = true;
61 s.addremove = true;
62
63 s.option(form.Value, 'name', _('Name'));
64 o = s.option(form.Value, 'path', _('Path'));
65 if (stats[0] && stats[1]) {
66 o.titleref = L.url('admin', 'system', 'mounts');
67 }
68
69 o = s.option(form.Flag, 'browseable', _('Browse-able'));
70 o.enabled = 'yes';
71 o.disabled = 'no';
72 o.default = 'yes';
73
74 o = s.option(form.Flag, 'read_only', _('Read-only'));
75 o.enabled = 'yes';
76 o.disabled = 'no';
77 o.default = 'no'; // smb.conf default is 'yes'
78 o.rmempty = false;
79
80 s.option(form.Flag, 'force_root', _('Force Root'));
81
82 o = s.option(form.Value, 'users', _('Allowed users'));
83 o.rmempty = true;
84
85 o = s.option(form.Flag, 'guest_ok', _('Allow guests'));
86 o.enabled = 'yes';
87 o.disabled = 'no';
88 o.default = 'yes'; // smb.conf default is 'no'
89 o.rmempty = false;
90
91 o = s.option(form.Flag, 'inherit_owner', _('Inherit owner'));
92 o.enabled = 'yes';
93 o.disabled = 'no';
94 o.default = 'no';
95
96 o = s.option(form.Flag, 'hide_dot_files', _('Hide dot files'));
97 o.enabled = 'yes';
98 o.disabled = 'no';
99 o.default = 'yes';
100
101 o = s.option(form.Value, 'create_mask', _('Create mask'));
102 o.maxlength = 4;
103 o.default = '0666'; // smb.conf default is '0744'
104 o.placeholder = '0666';
105 o.rmempty = false;
106
107 o = s.option(form.Value, 'dir_mask', _('Directory mask'));
108 o.maxlength = 4;
109 o.default = '0777'; // smb.conf default is '0755'
110 o.placeholder = '0777';
111 o.rmempty = false;
112
113 return m.render();
114 }
115 });