diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-02-16 11:13:56 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-02-16 11:13:56 +0000 |
commit | 335d503c6f8c54ab66a02fc8454525b628bb9255 (patch) | |
tree | 5b61fd65e6103065849e8b65f7a2d5df23604981 /tinydns-model.lua | |
parent | 9be3927959b864d02284faea9dc383c2a6279eb3 (diff) | |
download | acf-tinydns-335d503c6f8c54ab66a02fc8454525b628bb9255.tar.bz2 acf-tinydns-335d503c6f8c54ab66a02fc8454525b628bb9255.tar.xz |
Added a sampleconfig that shows some output. Still a long way to go
git-svn-id: svn://svn.alpinelinux.org/acf/tinydns/trunk@728 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'tinydns-model.lua')
-rw-r--r-- | tinydns-model.lua | 88 |
1 files changed, 84 insertions, 4 deletions
diff --git a/tinydns-model.lua b/tinydns-model.lua index a3f8a10..7a24740 100644 --- a/tinydns-model.lua +++ b/tinydns-model.lua @@ -3,6 +3,7 @@ module(..., package.seeall) require("procps") require("getopts") require("fs") +require("format") local configdir local datafile @@ -37,15 +38,25 @@ 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",}} + local output = {prefix={ + ['.']="Name server for your domain", + ['&']="Name server", + ['=']="Host", + ['+']="Alias", + ['@']="Mail exchanger", + ['=']="Host", + ['^']="PTR record", + ['C']="Canonical Name", + ['Z']="SOA record", + [':']="Generic record", + ['%']="Client location", + }} output = output[sign] return output end ---]] -- Return a table with the config-content of a file -- Commented/Blank lines are ignored @@ -83,6 +94,22 @@ local function recursedir(path, filearray) end end +-- Functin to split items into a table +local function split_config_items(orgitem) + local delimiter = ":" + local output = {} + output = format.string_to_table(string.sub(orgitem,1,1) .. ":" .. string.sub(orgitem,2),delimiter) + output.type = check_signs("prefix") + output.type = output.type[string.sub(orgitem,1,1)] or "unknown" +-- for k,v in pairs(cnffile) do +-- local configcontent = get_value_from_file(v) +-- if (configcontent) then +-- table.insert(configfiles, v) +-- end +-- end + return output +end + -- Feed the configfiles table with list of all availage configfiles local function searchforconfigfiles() local cnffile = {} @@ -93,6 +120,10 @@ local function searchforconfigfiles() table.insert(configfiles, v) end end + + -- Debug option (adds the sampleconfig content) + table.insert(configfiles, "/usr/share/acf/app/tinydns/sampleconfig.conf") + end searchforconfigfiles() -- ################################################################################ @@ -102,6 +133,7 @@ searchforconfigfiles() function getstatus() local status = {} local version,versionerrtxt = get_version() + local config = getconfig() status.version = cfe({ name = "version", label="Program version", value=version, @@ -111,12 +143,17 @@ function getstatus() label="Program status", value=procps.pidof(processname), }) + + status.locations = config.locations + return status end -- Return config-information function getconfig() local config = {} + local configobjects = {} + local locations = {} local version,versionerrtxt = get_version() local listenaddr = getopts.getoptsfromfile_onperline(configfile,"IP") or {} config.listen = cfe({ @@ -124,7 +161,49 @@ function getconfig() label="IP address to listen on", value=listenaddr.IP or "", }) + --Loop through all available configfiles + for k,v in pairs(configfiles) do + local filecontent, fileresult + fileresult, filecontent = get_value_from_file(v) + for kk,vv in pairs(filecontent) do + local filecontent_table = split_config_items(vv) + + -- This is mostly for debugging + -- This table contains all available configs + table.insert(configobjects, cfe({ + name=vv, + value=vv, + option=filecontent_table, + })) + -- Create a table with location items + -- Containing all objects that start with % + if (filecontent_table[1] == "%") then + if not (locations[filecontent_table[2]]) then + locations[filecontent_table[2]] = {} + end + table.insert(locations[filecontent_table[2]], cfe({ + name=filecontent_table[2]..filecontent_table[3], + label=filecontent_table["type"], + value=vv, + option=filecontent_table, + })) + end + + end + end + config.locations = cfe({ + name = "locations", + label="Configured locations", + value=locations, + }) +---[[ + config.configitems = cfe({ + name = "configitems", + label="Config items", + value=configobjects, + }) +--]] return config end @@ -172,13 +251,14 @@ function getdebug() table.insert(configitems,vv) end end +--[[ debug.configitems = cfe({ name = "configitems", label="configitems", option=configitems, type="select", }) - +--]] debug.configfiles = cfe({ name = "configfiles", label="configfiles", |