diff options
author | Ted Trask <ttrask01@yahoo.com> | 2009-08-24 08:30:37 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2009-08-24 08:30:37 +0000 |
commit | 3d8dfcb04685f17bb12cf56ea6beb50009f3b483 (patch) | |
tree | 55c8a20511af3f8fce433f166605eb287170a7c0 /samba-model.lua | |
parent | 2162ccd34f3de703adbf71c450e637f0553b1379 (diff) | |
download | acf-samba-3d8dfcb04685f17bb12cf56ea6beb50009f3b483.tar.bz2 acf-samba-3d8dfcb04685f17bb12cf56ea6beb50009f3b483.tar.xz |
Added ability to edit conf.d file, and modified join too add AD and to read from config rather than write. Bumped to version 0.3.0v0.3.0
Diffstat (limited to 'samba-model.lua')
-rw-r--r-- | samba-model.lua | 93 |
1 files changed, 55 insertions, 38 deletions
diff --git a/samba-model.lua b/samba-model.lua index d55971b..59dabb9 100644 --- a/samba-model.lua +++ b/samba-model.lua @@ -10,6 +10,7 @@ require("format") -- Set variables local configfile = "/etc/samba/smb.conf" local confdfile = "/etc/conf.d/samba" +local filelist = {configfile, confdfile} local processname = "samba" local packagename = "samba" @@ -109,63 +110,79 @@ function getstatus() return modelfunctions.getstatus(processname, packagename, "Samba Status") end -function getconfigfile() - return modelfunctions.getfiledetails(configfile) +function listconfigfiles() + local listed_files = {} + for i,name in ipairs(filelist) do + local filedetails = fs.stat(name) or {} + table.insert ( listed_files , {filename=name, mtime=filedetails.mtime or "---", filesize=filedetails.size or "0"} ) + end + table.sort(listed_files, function (a,b) return (a.filename < b.filename) end ) + + return cfe({ type="list", value=listed_files, label="Samba File List" }) +end + +function getconfigfile(filename) + return modelfunctions.getfiledetails(filename, filelist) end function setconfigfile(filedetails) - return modelfunctions.setfiledetails(filedetails, {configfile}) + return modelfunctions.setfiledetails(filedetails, filelist) 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) or {} - 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") or "" - f:close() - if string.find(status, "^sh:") then status = "Error - not installed" end + local status = {} + local errtxt = "Unable to determine join type" + local join + if config and config.global and config.global.security then + if config.global.security:lower() == "ads" then + status[#status+1] = "Testing AD join" + errtxt = nil + join = "ads" + elseif config.global.security:lower() == "domain" then + status[#status+1] = "Testing NT4-style join" + errtxt = nil + join = "rpc" + end + end + if not errtxt then + local cmd = path.."net "..join.." testjoin 2>&1" + local f = io.popen(cmd) + status[#status+1] = f:read("*a") or "" + f:close() + if string.find(status[#status], "^sh:") then status[#status] = "Error - not installed" end + end - return cfe({ type="group", value=connect, label="Join a Domain", descr=status }) + return cfe({ type="group", value=connect, label="Join a Domain", descr=table.concat(status, "\n"), errtxt=errtxt }) end function set_join(connect) configcontent = configcontent or fs.read_file(configfile) or "" + config = config or format.parse_ini_file(configcontent) 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"..format.escapespecialcharacters(connect.value.login.value).."%"..format.escapespecialcharacters(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) or "" - local list = format.parse_ini_file(content, "", "daemon_list") or '""' - if not string.find(list, "winbind") then - content = format.update_ini_file(content, "", "daemon_list", string.gsub(list, '"$', ' winbind"')) - fs.write_file(confdfile, content) + connect.errtxt = "Unable to determine join type" + local join + if config and config.global and config.global.security then + if config.global.security == "ads" then + connect.errtxt = nil + join = "ads" + elseif config.global.security == "domain" then + connect.errtxt = nil + join = "rpc" + end + end + if not errtxt then + local cmd = path.."net "..join.." join -U"..format.escapespecialcharacters(connect.value.login.value).."%"..format.escapespecialcharacters(connect.value.password.value).." 2>&1" + local f = io.popen(cmd) + connect.descr = f:read("*a") or "" + f:close() + if string.find(connect.descr, "^sh:") then connect.descr = "Error - not installed" end end return connect |