luci-app-samba4: add macOS compatibility option and Apple Timemachine support
[project/luci.git] / applications / luci-app-samba4 / luasrc / model / cbi / samba4.lua
1 -- Licensed to the public under the Apache License 2.0.
2
3 m = Map("samba4", translate("Network Shares"))
4
5 s = m:section(TypedSection, "samba", "Samba")
6 s.anonymous = true
7
8 s:tab("general", translate("General Settings"))
9 s:tab("template", translate("Edit Template"))
10
11 s:taboption("general", Value, "name", translate("Hostname"))
12 s:taboption("general", Value, "description", translate("Description"))
13 s:taboption("general", Value, "workgroup", translate("Workgroup"))
14 h = s:taboption("general", Flag, "homes", translate("Share home-directories"),
15 translate("Allow system users to reach their home directories via " ..
16 "network shares"))
17 h.rmempty = false
18
19 macos = s:taboption("general", Flag, "macos", translate("Enable macOS compatible shares"),
20 translate("Enables Apple's AAPL extension globally and adds macOS compatibility options to all shares."))
21 macos.rmempty = false
22
23 if nixio.fs.access("/usr/sbin/nmbd") then
24 s:taboption("general", Flag, "disable_netbios", translate("Disable Netbios"))
25 end
26 if nixio.fs.access("/usr/sbin/samba") then
27 s:taboption("general", Flag, "disable_ad_dc", translate("Disable Active Directory Domain Controller"))
28 end
29 if nixio.fs.access("/usr/sbin/winbindd") then
30 s:taboption("general", Flag, "disable_winbind", translate("Disable Winbind"))
31 end
32
33 tmpl = s:taboption("template", Value, "_tmpl",
34 translate("Edit the template that is used for generating the samba configuration."),
35 translate("This is the content of the file '/etc/samba/smb.conf.template' from which your samba configuration will be generated. " ..
36 "Values enclosed by pipe symbols ('|') should not be changed. They get their values from the 'General Settings' tab."))
37
38 tmpl.template = "cbi/tvalue"
39 tmpl.rows = 20
40
41 function tmpl.cfgvalue(self, section)
42 return nixio.fs.readfile("/etc/samba/smb.conf.template")
43 end
44
45 function tmpl.write(self, section, value)
46 value = value:gsub("\r\n?", "\n")
47 nixio.fs.writefile("/etc/samba/smb.conf.template", value)
48 end
49
50
51 s = m:section(TypedSection, "sambashare", translate("Shared Directories")
52 , translate("Please add directories to share. Each directory refers to a folder on a mounted device."))
53 s.anonymous = true
54 s.addremove = true
55 s.template = "cbi/tblsection"
56
57 s:option(Value, "name", translate("Name"))
58 pth = s:option(Value, "path", translate("Path"))
59 if nixio.fs.access("/etc/config/fstab") then
60 pth.titleref = luci.dispatcher.build_url("admin", "system", "fstab")
61 end
62
63 br = s:option(Flag, "browseable", translate("Browse-able"))
64 br.enabled = "yes"
65 br.disabled = "no"
66 br.default = "yes"
67
68 ro = s:option(Flag, "read_only", translate("Read-only"))
69 ro.enabled = "yes"
70 ro.disabled = "no"
71 ro.default = "yes"
72
73 s:option(Flag, "force_root", translate("Force Root"))
74
75 au = s:option(Value, "users", translate("Allowed users"))
76 au.rmempty = true
77
78 go = s:option(Flag, "guest_ok", translate("Allow guests"))
79 go.enabled = "yes"
80 go.disabled = "no"
81 go.default = "no"
82
83 gon = s:option(Flag, "guest_only", translate("Guests only"))
84 gon.enabled = "yes"
85 gon.disabled = "no"
86 gon.default = "no"
87
88 iown = s:option(Flag, "inherit_owner", translate("Inherit owner"))
89 iown.enabled = "yes"
90 iown.disabled = "no"
91 iown.default = "no"
92
93 cm = s:option(Value, "create_mask", translate("Create mask"))
94 cm.rmempty = true
95 cm.maxlength = 4
96 cm.placeholder = "0666"
97
98 dm = s:option(Value, "dir_mask", translate("Directory mask"))
99 dm.rmempty = true
100 dm.maxlength = 4
101 dm.placeholder = "0777"
102
103 vfs = s:option(Value, "vfs_objects", translate("Vfs objects"))
104 vfs.rmempty = true
105
106 s:option(Flag, "timemachine", translate("Apple Time-machine share"))
107
108 tms = s:option(Value, "timemachine_maxsize", translate("Time-machine size in GB"))
109 tms.rmempty = true
110 tms.maxlength = 5
111
112 return m