diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-02-22 10:52:11 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-02-22 10:52:11 +0000 |
commit | 9c87ef46027f223be76d19ba0339f37c35ce23a5 (patch) | |
tree | 553ef372b50bff370866387c5a3f8d2b27816c1b /tinydns-model.lua | |
parent | 335d503c6f8c54ab66a02fc8454525b628bb9255 (diff) | |
download | acf-tinydns-9c87ef46027f223be76d19ba0339f37c35ce23a5.tar.bz2 acf-tinydns-9c87ef46027f223be76d19ba0339f37c35ce23a5.tar.xz |
Temporary save. Things are far from working
git-svn-id: svn://svn.alpinelinux.org/acf/tinydns/trunk@764 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'tinydns-model.lua')
-rw-r--r-- | tinydns-model.lua | 207 |
1 files changed, 196 insertions, 11 deletions
diff --git a/tinydns-model.lua b/tinydns-model.lua index 7a24740..4d08a57 100644 --- a/tinydns-model.lua +++ b/tinydns-model.lua @@ -126,6 +126,83 @@ local function searchforconfigfiles() end searchforconfigfiles() + + +local function recurseoutput(table,cnt) + if not (cnt) then cnt=0 end + cnt = cnt + 1 + for k,v in pairs(table or {}) do + if (type(v) == "string") then + io.write("<IMG SRC='/static/tango/16x16/devices/computer.png' width='16' height='16' alt STYLE='margin-left:"..cnt.."0px'> ".. + tostring(v) .. "</SPAN><BR>") + else + io.write("<SPAN STYLE='margin-left:"..cnt.."0px;font-wegith:strong;'> ".. + tostring(k) .. "</SPAN><BR>") + recurseoutput(v,cnt) + end + end +end + +-- Create table with doman levels +local function recursedomains(t,array,maxn,currnum) + if not (currnum) then currnum = maxn + 1 end + currnum = currnum - 1 + -- FIXME: The current level should hold information on previous level too! + if not (currnum == 0) then + if not (array[t[currnum]]) then + array[t[currnum]] = {} + end + recursedomains(t,array[t[currnum]],maxn,currnum) + end + + -- FIXME: This is a /really uggly/ hack to return the current table + -- If it's fixed nicely... it would be wonderful! + if (array[t[maxn]]) and + (array[t[maxn]][t[maxn-1]]) and + (array[t[maxn]][t[maxn-1]][t[maxn-2]]) and + (array[t[maxn]][t[maxn-1]][t[maxn-2]][t[maxn-3]]) and + (array[t[maxn]][t[maxn-1]][t[maxn-2]][t[maxn-3]][t[maxn-4]]) and + (array[t[maxn]][t[maxn-1]][t[maxn-2]][t[maxn-3]][t[maxn-4]][t[maxn-5]]) then + return array[t[maxn]][t[maxn-1]][t[maxn-2]][t[maxn-3]][t[maxn-4]][t[maxn-5]] + end + + if (array[t[maxn]]) and + (array[t[maxn]][t[maxn-1]]) and + (array[t[maxn]][t[maxn-1]][t[maxn-2]]) and + (array[t[maxn]][t[maxn-1]][t[maxn-2]][t[maxn-3]]) and + (array[t[maxn]][t[maxn-1]][t[maxn-2]][t[maxn-3]][t[maxn-4]]) then + return array[t[maxn]][t[maxn-1]][t[maxn-2]][t[maxn-3]][t[maxn-4]] + end + + if (array[t[maxn]]) and + (array[t[maxn]][t[maxn-1]]) and + (array[t[maxn]][t[maxn-1]][t[maxn-2]]) and + (array[t[maxn]][t[maxn-1]][t[maxn-2]][t[maxn-3]]) then + return array[t[maxn]][t[maxn-1]][t[maxn-2]][t[maxn-3]] + end + + if (array[t[maxn]]) and + (array[t[maxn]][t[maxn-1]]) and + (array[t[maxn]][t[maxn-1]][t[maxn-2]]) and + (array[t[maxn]][t[maxn-1]][t[maxn-2]][t[maxn-3]]) then + return array[t[maxn]][t[maxn-1]][t[maxn-2]][t[maxn-3]] + end + + if (array[t[maxn]]) and + (array[t[maxn]][t[maxn-1]]) and + (array[t[maxn]][t[maxn-1]][t[maxn-2]]) then + return array[t[maxn]][t[maxn-1]][t[maxn-2]] + end + + if (array[t[maxn]]) and (array[t[maxn]][t[maxn-1]]) then + return array[t[maxn]][t[maxn-1]] + end + + if (array[t[maxn]]) then + return array[t[maxn]] + end +end + -- ################################################################################ -- PUBLIC FUNCTIONS @@ -145,15 +222,19 @@ function getstatus() }) status.locations = config.locations + status.domains = config.domains return status end + -- Return config-information function getconfig() local config = {} local configobjects = {} local locations = {} + local domains = {} + local debug local version,versionerrtxt = get_version() local listenaddr = getopts.getoptsfromfile_onperline(configfile,"IP") or {} config.listen = cfe({ @@ -161,11 +242,13 @@ 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 domaindetails = {} local filecontent_table = split_config_items(vv) -- This is mostly for debugging @@ -182,21 +265,123 @@ function getconfig() 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, - })) + table.insert(locations[filecontent_table[2]], filecontent_table[3]) end + -- Create domain information tables + local domain, level1, level2, level3, level4, level5, level6, levels + if (filecontent_table[1] == "&") then + local descr=check_signs("prefix") + domain = format.string_to_table(filecontent_table[2], "%.") + domaindetails = cfe ({ + name=filecontent_table[2], + label=descr[filecontent_table[1]], + value=filecontent_table[2], + }) + end + + local value = filecontent_table[2] + local currenttable + if (type(domain) == "table") then + currenttable = recursedomains(domain, domains, table.maxn(domain)) + end + + -- FIXME: This is where we should put the information into the table! + if (domaindetails.value) then + table.insert (currenttable , domaindetails) + end + +--[[ + if (type(domain) == "table") then + levels = table.maxn(domain) + level1 = domain[levels] + + + if (level1) then + level2 = (domain[levels-1] or "unknown") .. "." + end + if (level2) and (domain[levels-2]) then + level3 = domain[levels-2] .. "." .. level2 + end + if (level3) and (domain[levels-3]) then + level4 = domain[levels-3] .. "." .. level3 + end + if (level4) and (domain[levels-4]) then + level5 = domain[levels-4] .. "." .. level4 + end + if (level5) and (domain[levels-5]) then + level6 = domain[levels-5] .. "." .. level5 + end + if (level6) and (domain[levels-6]) then + level7 = domain[(levels-6)] .. "." .. level6 + end + end + if (level1 ) and (#level1 > 0) and not (domain[levels] == "arpa") then + if not (domains[level1]) then + domains[level1] = {} + end + if (level2) and (#level2 > 0) then + if not (domains[level1][level2]) then + domains[level1][level2] = {} + end + if (level3) and (#level3 > 0) then + if not (domains[level1][level2][level3]) then + domains[level1][level2][level3] = {} + end + if (level4) and (#level4 > 0) then + if not (domains[level1][level2][level3][level4]) then + domains[level1][level2][level3][level4] = {} + end + if (level5) and (#level5 > 0) then + if not (domains[level1][level2][level3][level4][level5]) then + domains[level1][level2][level3][level4][level5] = {} + end + if (level6) and (#level6 > 0) then + if not (domains[level1][level2][level3][level4][level5][level6]) then + domains[level1][level2][level3][level4][level5][level6] = {} + end + if (level7) and (#level7 > 0) then + if not (domains[level1][level2][level3][level4][level5][level6][level7]) then + domains[level1][level2][level3][level4][level5][level6][level7] = {} + domains[level1][level2][level3][level4][level5][level6][level7] = {} + end + else + table.insert(domains[level1][level2][level3][level4][level5][level6], filecontent_table[4]) + end --level7 + else + table.insert(domains[level1][level2][level3][level4][level5], filecontent_table[4]) + end --level6 + else + table.insert(domains[level1][level2][level3][level4], filecontent_table[4]) + end --level5 + else + table.insert(domains[level1][level2][level3], filecontent_table[4]) + end --level4 + else + table.insert(domains[level1][level2], filecontent_table[4]) + end --level3 + else + table.insert(domains[level1], filecontent_table[4]) + end --level2 + end --level1 +--]] + + end end - config.locations = cfe({ - name = "locations", - label="Configured locations", + config.locations = cfe({ + name="locations", + label="Locations", value=locations, - }) + }) + + config.domains = cfe({ + name="domains", + label="Domains", + value=domains, + }) +-- config.domains = debug + ---[[ config.configitems = cfe({ name = "configitems", @@ -251,7 +436,7 @@ function getdebug() table.insert(configitems,vv) end end ---[[ +---[[ debug.configitems = cfe({ name = "configitems", label="configitems", |