summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-02-15 17:09:55 +0000
committerMika Havela <mika.havela@gmail.com>2008-02-15 17:09:55 +0000
commitde0371bc26857be6e92a23ccaaaae5936a2c740e (patch)
tree2df86f8c0cf69b7078d2ac80dae1a4b110b051d5
parent0c3c51279de900006c67697187c108e7141e1fd1 (diff)
downloadacf-tinydns-de0371bc26857be6e92a23ccaaaae5936a2c740e.tar.bz2
acf-tinydns-de0371bc26857be6e92a23ccaaaae5936a2c740e.tar.xz
Starting to read config-files.
There is some debug output where you can se some default parameters and a list of all objects in the config-files. git-svn-id: svn://svn.alpinelinux.org/acf/tinydns/trunk@725 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--tinydns-controller.lua10
-rw-r--r--tinydns-model.lua150
-rw-r--r--tinydns-status-html.lsp36
-rw-r--r--tinydns.menu1
4 files changed, 172 insertions, 25 deletions
diff --git a/tinydns-controller.lua b/tinydns-controller.lua
index b6840d1..4e6efca 100644
--- a/tinydns-controller.lua
+++ b/tinydns-controller.lua
@@ -27,3 +27,13 @@ function status(self)
return { status=getstatus(self) }
end
+function config(self)
+ local config = self.model.getconfig(self)
+ local debug = self.model.getdebug(self)
+ return ({
+ status=getstatus(self),
+ config=config,
+ debug=debug,
+ })
+end
+
diff --git a/tinydns-model.lua b/tinydns-model.lua
index b6fa385..a3f8a10 100644
--- a/tinydns-model.lua
+++ b/tinydns-model.lua
@@ -1,9 +1,24 @@
module(..., package.seeall)
require("procps")
+require("getopts")
+require("fs")
+
+local configdir
+local datafile
+local configfiles = {}
+local configitems = {}
local processname = "tinydns"
-local configfile = "???"
+local configfile = "/etc/conf.d/" .. processname
+local initdoptions = getopts.getoptsfromfile_onperline("/etc/init.d/" .. processname)
+if (initdoptions) then
+ configdir = initdoptions.DATADIR
+ datafile = initdoptions.ROOT .. "/data" or "/var/cache/data"
+else
+ configdir = "/etc/" .. processname
+ datafile = "/var/cache/data"
+end
-- ################################################################################
-- LOCAL FUNCTIONS
@@ -22,9 +37,68 @@ local function get_version()
return cmd_output_result,cmd_output_error
end
+--[[
+-- This function could be used to check that valid parameters are used in different places
+local function check_signs(sign)
+ local output = {}
+ local output = {prefix={"Z", "&", "=", "+", "@", "C",}}
+ output = output[sign]
+ return output
+end
+--]]
+
+-- Return a table with the config-content of a file
+-- Commented/Blank lines are ignored
+local function get_value_from_file(file)
+ local output = {}
+ local filecontent = fs.read_file_as_array(file)
+ for i=1,table.maxn(filecontent) do
+ local l = filecontent[i]
+ if not (string.find ( l, "^[;#].*" )) and not (string.find (l, "^%s*$")) then
+ table.insert(output, string.match(l,"(.-)%s*$"))
+ end
+ end
+ if (#output > 0) then
+ return true, output
+ else
+ return false, output
+ end
+
+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
+
+-- Feed the configfiles table with list of all availage configfiles
+local function searchforconfigfiles()
+ local cnffile = {}
+ recursedir(configdir, cnffile)
+ for k,v in pairs(cnffile) do
+ local configcontent = get_value_from_file(v)
+ if (configcontent) then
+ table.insert(configfiles, v)
+ end
+ end
+end
+searchforconfigfiles()
-- ################################################################################
-- PUBLIC FUNCTIONS
+-- Present some general status
function getstatus()
local status = {}
local version,versionerrtxt = get_version()
@@ -40,3 +114,77 @@ function getstatus()
return status
end
+-- Return config-information
+function getconfig()
+ local config = {}
+ local version,versionerrtxt = get_version()
+ local listenaddr = getopts.getoptsfromfile_onperline(configfile,"IP") or {}
+ config.listen = cfe({
+ name = "listen",
+ label="IP address to listen on",
+ value=listenaddr.IP or "",
+ })
+
+ return config
+end
+
+
+-- ################################################################################
+-- DEBUG INFORMATION (Everything below will be deleted in the future)
+
+function getdebug()
+ local debug = {}
+
+--[[
+ local signs = get_available_signs("prefix") or {}
+ debug.debugprefixes = cfe({
+ name = "debugprefixes",
+ label="Available prefixes",
+ option=signs,
+ type="select",
+ size=table.maxn(signs)+1,
+ })
+
+ local signs = get_available_signs("suffix") or {}
+ debug.debugsuffixes = cfe({
+ name = "debugsuffixes",
+ label="Available suffixes",
+ option=signs,
+ type="select",
+ size=table.maxn(signs)+1,
+ })
+--]]
+ debug.configdir = cfe({
+ name = "configdir",
+ label="configdir",
+ value=configdir,
+ })
+ debug.datafile = cfe({
+ name = "datafile",
+ label="datafile",
+ value=datafile,
+ })
+
+ for k,v in pairs(configfiles) do
+ local cnfcontent
+ fake, cnfcontent = get_value_from_file(v)
+ for kk,vv in pairs(cnfcontent) do
+ table.insert(configitems,vv)
+ end
+ end
+ debug.configitems = cfe({
+ name = "configitems",
+ label="configitems",
+ option=configitems,
+ type="select",
+ })
+
+ debug.configfiles = cfe({
+ name = "configfiles",
+ label="configfiles",
+ option=configfiles,
+ type="select",
+ })
+
+ return debug
+end
diff --git a/tinydns-status-html.lsp b/tinydns-status-html.lsp
index 20b5dcc..b8ac060 100644
--- a/tinydns-status-html.lsp
+++ b/tinydns-status-html.lsp
@@ -7,34 +7,22 @@ io.write("</span>")
--]]
?>
<?
-function informationform(myform,tags)
+function displayinfo(myform,tags,viewonly)
io.write("<DL>")
for k,v in pairs(tags) do
- if (myform[v]) then
+ if (myform[v]) and (myform[v]["value"]) then
local val = myform[v]
io.write("\t<DT")
- if (#val.errtxt > 0) then io.write(" class='error'") end
+ if (#val.errtxt > 0) then
+ val.class = "error"
+ io.write(" class='error'")
+ end
io.write(">" .. val.label .. "</DT>\n")
-
- io.write("\t\t<DD>" .. val.value .. "\n")
- if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
- if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
- io.write("\t\t</DD>\n")
- end
- end
- io.write("</DL>")
-end
-
-function configform(myform,tags)
- io.write("<DL>")
- for k,v in pairs(tags) do
- if (myform[v]) then
- local val = myform[v]
- io.write("\t<DT")
- if (#val.errtxt > 0) then io.write(" class='error'") end
- io.write(">" .. val.label .. "</DT>\n")
-
- io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n")
+ if (viewonly) then
+ io.write("\t\t<DD>" .. val.value .. "\n")
+ else
+ io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n")
+ end
if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
io.write("\t\t</DD>\n")
@@ -48,7 +36,7 @@ end
<?
local myform = form.status
local tags = { "status", "version", }
-informationform(myform,tags)
+displayinfo(myform,tags,"viewonly")
?>
<?
diff --git a/tinydns.menu b/tinydns.menu
index 88f2449..705c58b 100644
--- a/tinydns.menu
+++ b/tinydns.menu
@@ -1,2 +1,3 @@
#CAT GROUP/DESC TAB ACTION
Networking 10DNS Status status
+Networking 10DNS Config config