From 3d8dfcb04685f17bb12cf56ea6beb50009f3b483 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 24 Aug 2009 08:30:37 +0000 Subject: 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.0 --- Makefile | 2 +- samba-controller.lua | 6 +++- samba-model.lua | 93 +++++++++++++++++++++++++++++++--------------------- samba.menu | 2 +- samba.roles | 4 +-- 5 files changed, 64 insertions(+), 43 deletions(-) diff --git a/Makefile b/Makefile index b265ccb..117f9b7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ APP_NAME=samba PACKAGE=acf-$(APP_NAME) -VERSION=0.2.1 +VERSION=0.3.0 APP_DIST=\ samba* \ diff --git a/samba-controller.lua b/samba-controller.lua index b810bb9..e3f1a4f 100644 --- a/samba-controller.lua +++ b/samba-controller.lua @@ -13,8 +13,12 @@ function startstop(self) return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.clientdata) end +function listfiles(self) + return self.model.listconfigfiles() +end + function expert(self) - return controllerfunctions.handle_form(self, self.model.getconfigfile, self.model.setconfigfile, self.clientdata, "Save", "Edit Config", "Configuration Saved") + return controllerfunctions.handle_form(self, function() return self.model.getconfigfile(self.clientdata.filename) end, self.model.setconfigfile, self.clientdata, "Save", "Edit Samba File", "File Saved") end function join(self) 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 diff --git a/samba.menu b/samba.menu index cac650c..af59f61 100644 --- a/samba.menu +++ b/samba.menu @@ -2,4 +2,4 @@ Applications 20Samba Status status Applications 20Samba Shares listshares Applications 20Samba Join_Domain join -Applications 20Samba Expert expert +Applications 20Samba Expert listfiles diff --git a/samba.roles b/samba.roles index 9bcf187..a8fd23a 100644 --- a/samba.roles +++ b/samba.roles @@ -1,4 +1,4 @@ USER=samba:status,samba:startstop,samba:listshares EDITOR=samba:join,samba:editshare,samba:deleteshare,samba:createshare -EXPERT=samba:expert -ADMIN=samba:status,samba:startstop,samba:listshares,samba:join,samba:editshare,samba:deleteshare,samba:createshare,samba:expert +EXPERT=samba:listfiles,samba:expert +ADMIN=samba:status,samba:startstop,samba:listshares,samba:join,samba:editshare,samba:deleteshare,samba:createshare,samba:listfiles,samba:expert -- cgit v1.2.3