summaryrefslogtreecommitdiffstats
path: root/tinydns-model.lua
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-04-04 15:16:09 +0000
committerMika Havela <mika.havela@gmail.com>2008-04-04 15:16:09 +0000
commita084d26cb2a9226faa39750e32c3fbacf217c16c (patch)
tree647602157746ee52210b167f7588b1b647b51e4f /tinydns-model.lua
parent97326d4f4a87147c3885c879da99101afd36371e (diff)
downloadacf-tinydns-a084d26cb2a9226faa39750e32c3fbacf217c16c.tar.bz2
acf-tinydns-a084d26cb2a9226faa39750e32c3fbacf217c16c.tar.xz
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
Diffstat (limited to 'tinydns-model.lua')
-rw-r--r--tinydns-model.lua88
1 files changed, 88 insertions, 0 deletions
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