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 | |
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
-rwxr-xr-x | sampleconfig.conf | 1 | ||||
-rw-r--r-- | tinydns-controller.lua | 1 | ||||
-rw-r--r-- | tinydns-model.lua | 207 | ||||
-rw-r--r-- | tinydns-status-html.lsp | 130 |
4 files changed, 300 insertions, 39 deletions
diff --git a/sampleconfig.conf b/sampleconfig.conf index e3e7b7f..a3f3c07 100755 --- a/sampleconfig.conf +++ b/sampleconfig.conf @@ -19,6 +19,7 @@ Zme.org:ns3.you.org.iseng.me.org:2007082204:1200:2048:864000:3600::: =www.me.org:208.74.141.33:3600:: =me.org:208.74.141.33:3600:: =test.me.org:208.74.141.33:3600:: +=levelseven.levelsix.levelfive.levelfour.levelthree.leveltwo.levelone:208.74.141.33:3600:: =www.test.me.org:208.74.141.33:3600:: Cdownload.me.org:download.me.org.google.com:3600:: diff --git a/tinydns-controller.lua b/tinydns-controller.lua index 4e6efca..43d6038 100644 --- a/tinydns-controller.lua +++ b/tinydns-controller.lua @@ -20,6 +20,7 @@ local function getstatus(self) else status.status.value = "Disabled" end + return status end 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", diff --git a/tinydns-status-html.lsp b/tinydns-status-html.lsp index 27fe91a..5d5bd1d 100644 --- a/tinydns-status-html.lsp +++ b/tinydns-status-html.lsp @@ -1,6 +1,6 @@ <? local form = ... ?> <? ---[[ DEBUG INFORMATION +---[[ DEBUG INFORMATION io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") io.write(html.cfe_unpack(form)) io.write("</span>") @@ -41,25 +41,25 @@ displayinfo(myform,tags,"viewonly") <H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2> <? -local v = "locations" +local myform = form.status.locations --displayinfo(myform,tags) io.write("<DL>") --for k,v in pairs(tags) do -if (myform[v]) and (myform[v]["value"]) then - local val = myform[v] +if (myform) and (myform.value) then + local val = myform io.write("\t<DT") if (#val.errtxt > 0) then - val.class = "error" +-- val.class = "error" io.write(" class='error'") end io.write(">" .. val.label .. "</DT>\n") io.write("\t\t<DD>\n") - for k,v in pairs(myform[v]["value"]) do + for k,v in pairs(myform.value) do io.write("<IMG SRC='/static/tango/16x16/places/start-here.png' width='16' height='16' alt> <B>" .. tostring(k) .. "</B>") for kk,vv in pairs(v) do - io.write(tostring("<BR>" ..vv.option[3]).. "\n") + io.write(tostring("<BR>" .. vv .. "\n")) end io.write("<BR>") end @@ -72,37 +72,111 @@ end io.write("</DL>") ?> + <? -local v = "types" ---displayinfo(myform,tags) -io.write("<DL>") ---for k,v in pairs(tags) do -if (myform[v]) and (myform[v]["value"]) then - local val = myform[v] - io.write("\t<DT") - if (#val.errtxt > 0) then - val.class = "error" - io.write(" class='error'") +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 - io.write(">" .. val.label .. "</DT>\n") - +end +?> +<? +local myform = form.status.domains +if (myform) and (myform.value) then + io.write("\t<DT") + io.write(">" .. myform.label .. "</DT>\n") io.write("\t\t<DD>\n") - for k,v in pairs(myform[v]["value"]) do - io.write("<IMG SRC='/static/tango/16x16/places/start-here.png' width='16' height='16' alt> <B>" .. tostring(k) .. "</B>") - for kk,vv in pairs(v) do - io.write(tostring("<BR>" ..vv.option[3]).. "\n") + + for k,v in pairs(myform.value) do + recurseoutput(v) + end + +--[[ +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 - io.write("<BR>") end +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") +--[[ + local output = k + io.write("<SPAN STYLE='margin-left:10px;font-weight:bold;'>".. k .. "</SPAN><BR>") + if (#v == 0) then + for k1,v1 in pairs(v) do + output = k1 .. "." .. output + io.write("<SPAN STYLE='margin-left:20px;font-weight:normal;font-weight:bold;'>".. output .. "</SPAN><BR>") + if (#v1 == 0) then + for k2,v2 in pairs(v1) do + output = k2 .. "." .. output + io.write("<SPAN STYLE='margin-left:30px;font-weight:normal;font-weight:bold;'>".. output .. "</SPAN><BR>") + if (#v2 == 0) then + for k3,v3 in pairs(v2) do + output = k3 .. "." .. output + io.write("<SPAN STYLE='margin-left:40px;font-weight:normal;font-weight:bold;'>".. output .. "</SPAN><BR>") + if (#v3 == 0) then + for k4,v4 in pairs(v3) do + output = k4 .. "." .. output + io.write("<SPAN STYLE='margin-left:50px;font-weight:normal;font-weight:bold;'>".. output .. "</SPAN><BR>") + if (#v4 == 0) then + for k5,v5 in pairs(v4) do + output = k5 .. "." .. output + io.write("<SPAN STYLE='margin-left:60px;font-weight:normal;font-weight:bold;'>".. output .. "</SPAN><BR>") + if (#v5 == 0) then + for k6,v6 in pairs(v5) do + output = k6 .. "." .. output + io.write("<SPAN STYLE='margin-left:70px;font-weight:normal;font-weight:bold;'>".. output .. "</SPAN><BR>") + end + else + computer(output,7) + end + end + else + computer(output,6) + end + end + else + computer(output,5) + end + end + else + computer(output,5) + end + end + else + computer(output,5) + end + end + else + computer(output,4) + end + end + --]] end ---end io.write("</DL>") +--]==] ?> + <? --[[ DEBUG INFORMATION io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") |