From a084d26cb2a9226faa39750e32c3fbacf217c16c Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Fri, 4 Apr 2008 15:16:09 +0000 Subject: Creating a expert tab so you can edit the config-files. git-svn-id: svn://svn.alpinelinux.org/acf/tinydns/trunk@945 ab2d0c66-481e-0410-8bed-d214d4d58bed --- tinydns-model.lua | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) (limited to 'tinydns-model.lua') diff --git a/tinydns-model.lua b/tinydns-model.lua index 00918ca..11f1101 100644 --- a/tinydns-model.lua +++ b/tinydns-model.lua @@ -12,6 +12,7 @@ local configitems = {} local processname = "tinydns" local configfile = "/etc/conf.d/" .. processname +local baseurl = "/etc/tinydns/" local initdoptions = getopts.getoptsfromfile_onperline("/etc/init.d/" .. processname) if (initdoptions) then configdir = initdoptions.DATADIR @@ -637,6 +638,22 @@ function getconfigobjects(self,filter_type, filter_levels) return domains_filtered end +-- Function to recursively inserts all filenames in a dir into an array +local function recursedir(path, filearray) + local k,v + for k,v in pairs(posix.dir(path) or {}) do + -- Ignore files that begins with a '.' + if not string.match(v, "^%.") then + local f = path .. "/" .. v + -- If subfolder exists, list files in this subfolder + if (posix.stat(f).type == "directory") then + recursedir(f, filearray) + else + table.insert(filearray, f) + end + end + end +end -- ################################################################################ -- DEBUG INFORMATION (Everything below will be deleted in the future) @@ -698,3 +715,74 @@ function getdebug() return debug end + +function getfilelist () + local listed_files = {} + for k,v in pairs{baseurl} do + recursedir(v, listed_files) + end +-- table.sort(listed_files, function (a,b) return (a.name < b.name) end ) + + return listed_files +end + +function get_filedetails(self,path) +-- local path +-- if (num == "2") then +-- path = configfile2 +-- else +-- path = configfile +-- end + local file = {} + local filedetails = {} + local config = {} + local filenameerrtxt + if (path) and (fs.is_file(path)) then + filedetails = fs.stat(path) + config = getconfig(path) + else + config = {} + config.filename = {} + config["filename"]["errtxt"]="Config file '".. path .. "' is missing!" + end + + file["filename" .. (num or "")] = cfe({ + name="filename" .. (num or ""), + label="File name", + value=path, + errtxt=filenameerrtxt + }) + file["filesize" .. (num or "")] = cfe({ + name="filesize" .. (num or ""), + label="File size", + value=filedetails.size or 0, + }) + file["mtime" .. (num or "")] = cfe({ + name="mtime" .. (num or ""), + label="File date", + value=filedetails.mtime or "---", + }) + file["filecontent" .. (num or "")] = cfe({ + type="longtext", + name="filecontent" .. (num or ""), + label="File content", + value=fs.read_file(path), + }) + + -- Sum all errors into one cfe + local sumerrors = "" + for k,v in pairs(config) do + if (config[k]) and (config[k]["errtxt"]) and (config[k]["errtxt"] ~= "") then + sumerrors = sumerrors .. config[k]["errtxt"] .. "\n" + end + end + if (sumerrors ~= "") then + file["sumerrors" .. (num or "")] = cfe ({ + name="sumerrors" .. (num or ""), + label = "Configuration errors", + errtxt = string.match(sumerrors, "(.-)\n$"), + }) + end + + return file +end -- cgit v1.2.3