root/trunk/fon/samba3/files/etc/fonstated/RestartSamba @ 1309

Revision 1309, 2.6 KB (checked in by blogic, 4 years ago)

fixes Media mount

Line 
1#!/usr/bin/lua
2-- (c) 2008 john@phrozen.org GPLv2
3
4-- we use uci
5local uci = require("luci.model.uci").cursor()
6
7-- add the header of smb.conf
8function smb_header(s)
9        if not(s.name) then
10                s.name ="Fonera2.0"
11        end
12        if not(s.workgroup) then
13                s.workgroup = "Fonera"
14        end
15        if not(s.description) then
16                s.description = "La Fonera 2.0"
17        end
18        local f = io.open("/tmp/smb.conf", "w")
19        if f then
20                f:write("[global]\n")
21                f:write("       netbios name = "..s.name.."\n")
22                f:write("       workgroup = "..s.workgroup.."\n")
23                f:write("       server string = "..s.description.."\n")
24                f:write("       syslog = 10\n")
25                f:write("       encrypt passwords = true\n")
26                f:write("       passdb backend = smbpasswd\n")
27                f:write("       obey pam restrictions = yes\n")
28                f:write("       socket options = TCP_NODELAY\n")
29                f:write("       preferred master = yes\n")
30                f:write("       os level = 20\n")
31                f:write("       security = user\n")
32                f:write("       guest account = nobody\n")
33                f:write("       invalid users = root\n")
34                f:write("       domain master = Yes\n")
35                f:write("       unix extensions = no\n")
36                f:write("       smb passwd file = /etc/samba/smbpasswd\n\n")
37                f:close()
38        end
39end
40
41-- add a samba share to the config file
42function smb_add_share(s)
43        local f = io.open("/tmp/smb.conf", "a")
44        if f then
45                f:write("\n["..s.."]\n\tpath = /tmp/mounts/"..s.."\n")
46                f:write("\tread only = no\n")
47                f:write("\tguest ok = no\n")
48                f:write("\tcreate mask = 0700\n")
49                f:write("\tdirectory mask = 0700\n")
50                f:write("\tadmin users = fonero\n")
51                f:close()
52        end
53end
54
55-- add a samba share to the config file
56function smb_add_media_share()
57        local f = io.open("/tmp/smb.conf", "a")
58        if f then
59                f:write("\n[Media]\n\tpath = /tmp/mounts/\n")
60                f:write("\tread only = no\n")
61                f:write("\tguest ok = no\n")
62                f:write("\tcreate mask = 0700\n")
63                f:write("\tdirectory mask = 0700\n")
64                f:write("\tadmin users = fonero\n")
65                f:close()
66        end
67end
68
69-- samba is a registered service, so use the api to start/stop it
70local srv = require("luci.fon.service")
71local smbd = srv.Service("samba")
72local nmbd = srv.Service("samba_nmbd")
73
74-- samba may only run if the user has set the password and enabled the daemon
75local enable = uci:get("samba", "samba", "enable")
76
77-- stop it if it is running
78smbd:stop()
79nmbd:stop()
80
81-- restart if we are supposed to
82if enable == "1" then
83        -- create smb.conf
84        uci:foreach("samba", "samba", smb_header)
85        local d = luci.util.exec("ls /tmp/mounts/ | cut -d/ -f2")
86        local a = {}
87        local p
88        while(string.find(d, string.char(10))) do
89                local p = string.find(d, string.char(10))
90                print(string.sub(d, 1, p - 1))
91                smb_add_share(string.sub(d, 1, p - 1))
92                d = string.sub(d, p + 1)
93        end
94        smb_add_media_share()
95
96        -- start smbd
97        smbd:start("-D")
98        nmbd:start()
99end
Note: See TracBrowser for help on using the browser.