summaryrefslogtreecommitdiffstats
path: root/tinydns-model.lua
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-02-26 10:37:17 +0000
committerMika Havela <mika.havela@gmail.com>2008-02-26 10:37:17 +0000
commit4fa3fad1139c72acd5051bc562161db06e259f32 (patch)
treefc533cf79aa846deff71c25b6dfd91af193f0196 /tinydns-model.lua
parent122904f71112023b7257ac48239271e05b92fe81 (diff)
downloadacf-tinydns-4fa3fad1139c72acd5051bc562161db06e259f32.tar.bz2
acf-tinydns-4fa3fad1139c72acd5051bc562161db06e259f32.tar.xz
Added functionallity for the config-tab. (Now showing current configs).
Editing config is still not possible. git-svn-id: svn://svn.alpinelinux.org/acf/tinydns/trunk@768 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'tinydns-model.lua')
-rw-r--r--tinydns-model.lua114
1 files changed, 93 insertions, 21 deletions
diff --git a/tinydns-model.lua b/tinydns-model.lua
index a073011..a68cda8 100644
--- a/tinydns-model.lua
+++ b/tinydns-model.lua
@@ -272,6 +272,39 @@ function getconfig(self,filter_type)
return config
end
+-- Example taken from PIL
+-- Sort by Keys
+local function pairsByKeys(t,f)
+ local a = {}
+
+ for n in pairs(t) do
+ -- This is to fix some bug when next table is indexnumber instead of name
+ if (tonumber(n) == nil) then
+ a[#a + 1] = n
+ end
+ end
+ table.sort(a,f)
+ local i = 0 -- iterator variable
+ return function () --iterator function
+ i = i + 1
+ return a[i], t[a[i]]
+ end
+end
+
+local function rebuild_table(t,domains_rebuilt)
+ if not (type(t) == "string") then
+ for k,v in pairs(t) do
+ if (tonumber(k)) then
+ table.insert(domains_rebuilt, v)
+ else
+ table.insert(domains_rebuilt, {label=k})
+ rebuild_table(v,domains_rebuilt[#domains_rebuilt])
+ end
+ end
+ table.sort(domains_rebuilt, function(a,b) return (a.label < b.label) end)
+ end
+end
+
-- If you enter 'filter_type' (this should be one of the options found in local function check_signs() ) then
-- the output will be filtered to only contain this type of data.
function getconfigobjects(self,filter_type)
@@ -304,14 +337,9 @@ function getconfigobjects(self,filter_type)
domain[i-1] = domain[i-1] .. "." .. domain[i]
end
- -- This is the main information on each object
- domaindetails = cfe ({
- name=filecontent_table[2],
- label=filecontent_table[2],
- })
-
+ local domainoptions = {}
-- Add details to the previous object
- table.insert(domaindetails, cfe ({
+ table.insert(domainoptions, cfe ({
name="type",
label="Type",
value=descr[filecontent_table[1]],
@@ -334,7 +362,7 @@ function getconfigobjects(self,filter_type)
label = "Type of record"
end
if (filecontent_table[3]) and (#filecontent_table[3]> 0) and (name) then
- table.insert(domaindetails, cfe ({
+ table.insert(domainoptions, cfe ({
name=name,
label=label,
value=filecontent_table[3],
@@ -358,7 +386,7 @@ function getconfigobjects(self,filter_type)
label = "Contact address"
end
if (filecontent_table[4]) and (#filecontent_table[4]> 0) and (name) then
- table.insert(domaindetails, cfe ({
+ table.insert(domainoptions, cfe ({
name=name,
label=label,
value=filecontent_table[4],
@@ -382,7 +410,7 @@ function getconfigobjects(self,filter_type)
label = "Serial number"
end
if (filecontent_table[5]) and (#filecontent_table[5]> 0) and (name) then
- table.insert(domaindetails, cfe ({
+ table.insert(domainoptions, cfe ({
name=name,
label=label,
value=filecontent_table[5],
@@ -407,7 +435,7 @@ function getconfigobjects(self,filter_type)
end
if (filecontent_table[6]) and (#filecontent_table[6]> 0) and (name) then
- table.insert(domaindetails, cfe ({
+ table.insert(domainoptions, cfe ({
name=name,
label=label,
value=filecontent_table[6],
@@ -431,7 +459,7 @@ function getconfigobjects(self,filter_type)
label = "Retry time"
end
if (filecontent_table[7]) and (#filecontent_table[7]> 0) and (name) then
- table.insert(domaindetails, cfe ({
+ table.insert(domainoptions, cfe ({
name=name,
label=label,
value=filecontent_table[7],
@@ -451,7 +479,7 @@ function getconfigobjects(self,filter_type)
label = "Expire time"
end
if (filecontent_table[8]) and (#filecontent_table[8]> 0) and (name) then
- table.insert(domaindetails, cfe ({
+ table.insert(domainoptions, cfe ({
name=name,
label=label,
value=filecontent_table[8],
@@ -461,28 +489,28 @@ function getconfigobjects(self,filter_type)
-- Set values and labels for field #9-12
if (filecontent_table[1] == "Z") then
if (filecontent_table[9]) and (#filecontent_table[9]> 0) then
- table.insert(domaindetails, cfe ({
+ table.insert(domainoptions, cfe ({
name="min",
label="Minimum time",
value=filecontent_table[9],
}))
end
if (filecontent_table[10]) and (#filecontent_table[10]> 0) then
- table.insert(domaindetails, cfe ({
+ table.insert(domainoptions, cfe ({
name="ttl",
label="Time to live",
value=filecontent_table[10],
}))
end
if (filecontent_table[11]) and (#filecontent_table[11]> 0) then
- table.insert(domaindetails, cfe ({
+ table.insert(domainoptions, cfe ({
name="timestamp",
label="Time stamp",
value=filecontent_table[11],
}))
end
if (filecontent_table[12]) and (#filecontent_table[12]> 0) then
- table.insert(domaindetails, cfe ({
+ table.insert(domainoptions, cfe ({
name="location",
label="Location",
value=filecontent_table[12],
@@ -491,8 +519,15 @@ function getconfigobjects(self,filter_type)
end
+ -- This is the main information on each object
+ domaindetails = cfe ({
+ name=filecontent_table[2],
+ label=filecontent_table[2],
+ option=domainoptions,
+ })
+
--[[
- table.insert(domaindetails, cfe ({
+ table.insert(domainoptions, cfe ({
name="debug",
label="Debug",
value=filter_type,
@@ -500,7 +535,6 @@ function getconfigobjects(self,filter_type)
--]]
end
-- * END * COMMONT SETTINGS ***************************************************************************************
-
-- Inject the previous data into the right table
local value = filecontent_table[2]
local currenttable
@@ -508,10 +542,11 @@ function getconfigobjects(self,filter_type)
currenttable = recursedomains(domain, domains, table.maxn(domain))
end
+---[[
if (domaindetails.value) then
table.insert (currenttable , domaindetails)
end
-
+--]]
end
end
@@ -519,8 +554,45 @@ function getconfigobjects(self,filter_type)
-- TODO: Sort the domains table!
-- Sorting is not possible when things is done as they are (se above)
-- problem comese when we use keynames instead of [1], [2], ...
+ -- Next we rebuild the domains table and do it so it can be sorted
+ local domains_sorted = {}
+
+ local domains_rebuilt = {}
+ rebuild_table(domains,domains_rebuilt)
+
+--[==[
+ for k1,v1 in pairsByKeys(domains) do
+ table.insert(domains_sorted, { name=k1 })
+ for k2,v2 in pairsByKeys(v1) do
+ table.insert(domains_sorted[#domains_sorted], { name=k2 })
+---[=[
+ if (v2) and (type(v2) == "table") then
+-- if not (v2.type) then
+ for k3,v3 in pairsByKeys(v2) do
+ if (v2[k3]["value"]) then
+ if not (domains_sorted[#domains_sorted][#domains_sorted[#domains_sorted]]["value"]) then
+ domains_sorted[#domains_sorted][#domains_sorted[#domains_sorted]]["value"] = {}
+ end
+-- table.insert(domains_sorted[#domains_sorted][#domains_sorted[#domains_sorted]]["value"], domains[k1][k2] )
+ else
+ table.insert(domains_sorted[#domains_sorted][#domains_sorted[#domains_sorted]], { name=k3 })
+ end
+ end
+-- else
+-- if not (domains_sorted[#domains_sorted][#domains_sorted[#domains_sorted]]["value"]) then
+-- domains_sorted[#domains_sorted][#domains_sorted[#domains_sorted]]["value"] = {}
+-- end
+-- table.insert(domains_sorted[#domains_sorted][#domains_sorted[#domains_sorted]]["value"], { name=v2, name=k3 } )
+-- end
+ end
+--]=]
+ end
+ end
+-- table.sort(domains_sorted)
+
+--]==]
- return domains
+ return domains_rebuilt
end