summaryrefslogtreecommitdiffstats
path: root/samba-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'samba-model.lua')
-rw-r--r--samba-model.lua96
1 files changed, 96 insertions, 0 deletions
diff --git a/samba-model.lua b/samba-model.lua
new file mode 100644
index 0000000..34f6ac3
--- /dev/null
+++ b/samba-model.lua
@@ -0,0 +1,96 @@
+module(..., package.seeall)
+
+-- Load libraries
+require("modelfunctions")
+require("validator")
+require("fs")
+require("posix")
+require("format")
+
+-- Set variables
+local configfile = "/etc/samba/smb.conf"
+local confdfile = "/etc/conf.d/samba"
+local processname = "smbd"
+local packagename = "samba"
+local initname = "samba"
+
+local configcontent
+local config
+
+local path="PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin "
+
+-- ################################################################################
+-- LOCAL FUNCTIONS
+
+-- ################################################################################
+-- PUBLIC FUNCTIONS
+
+function startstop_service(action)
+ return modelfunctions.startstop_service(initname, action)
+end
+
+function getstatus()
+ return modelfunctions.getstatus(processname, packagename, "Samba Status", initname)
+end
+
+function getconfigfile()
+ return modelfunctions.getfiledetails(configfile)
+end
+
+function setconfigfile(filedetails)
+ filedetails.value.filename.value = configfile
+ return modelfunctions.setfiledetails(filedetails)
+end
+
+function get_join()
+ local connect = {}
+ connect.domain = cfe({ label="Domain" })
+ --connect.style = cfe({ type="select", value="Active Directory", label="Domain Controller type", option={"Active Directory", "NT4-style"} })
+ connect.login = cfe({ label="Domain Controller login" })
+ connect.password = cfe({ label="Domain Controller password" })
+
+ configcontent = configcontent or fs.read_file(configfile) or ""
+ config = config or format.parse_ini_file(configcontent)
+ if config and config.global and config.global.workgroup then
+ connect.domain.value = config.global.workgroup
+ end
+
+ local f = io.popen(path.."net rpc testjoin 2<&1")
+ local status = f:read("*a")
+ f:close()
+
+ return cfe({ type="group", value=connect, label="Join a Domain", descr=status })
+end
+
+function set_join(connect)
+ configcontent = configcontent or fs.read_file(configfile) or ""
+
+ configcontent = format.update_ini_file(configcontent, "global", "security", "domain")
+ configcontent = format.update_ini_file(configcontent, "global", "workgroup", connect.value.domain.value)
+ configcontent = format.update_ini_file(configcontent, "global", "encrypt passwords", "yes")
+ configcontent = format.update_ini_file(configcontent, "global", "password server", "*")
+ fs.write_file(configfile, configcontent)
+ configcontent = nil
+ config = nil
+
+ local cmd = path
+ --if connect.value.style.value == "Active Directory" then
+ -- cmd = cmd .. "net ads join"
+ --else
+ cmd = cmd .. "net rpc join"
+ --end
+ cmd = cmd .. " -U"..connect.value.login.value.."%"..connect.value.password.value.." 2>&1"
+ local f = io.popen(cmd)
+ connect.descr = f:read("*a")
+ f:close()
+
+ -- the conf.d file doesn't automatically include winbindd
+ local content = fs.read_file(confdfile)
+ local list = format.parse_ini_file(content, "", "daemon_list")
+ if not string.find(list, "winbind") then
+ content = format.update_ini_file(content, "", "daemon_list", string.gsub(list, '"$', ' winbind"'))
+ fs.write_file(confdfile, content)
+ end
+
+ return connect
+end