diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-02-26 10:37:17 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-02-26 10:37:17 +0000 |
commit | 4fa3fad1139c72acd5051bc562161db06e259f32 (patch) | |
tree | fc533cf79aa846deff71c25b6dfd91af193f0196 /tinydns-controller.lua | |
parent | 122904f71112023b7257ac48239271e05b92fe81 (diff) | |
download | acf-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-controller.lua')
-rw-r--r-- | tinydns-controller.lua | 433 |
1 files changed, 379 insertions, 54 deletions
diff --git a/tinydns-controller.lua b/tinydns-controller.lua index 030257f..122470d 100644 --- a/tinydns-controller.lua +++ b/tinydns-controller.lua @@ -1,7 +1,5 @@ module(..., package.seeall) -local pvt = {} - local list_redir = function (self) self.conf.action = "status" self.conf.type = "redir" @@ -26,21 +24,51 @@ local function getstatus(self) return status end +local function filtertable(t,limit,counter) + if not (counter) then counter = 0 end + counter = counter + 1 + + if (t) then + for k,v in pairs(t) do + if (counter > (limit + 2)) then + t[k] = nil + end + if (type(t[k]) == "table") then + filtertable(v,limit,counter) + end + end + end +end + +local function unpackoptions(t,array,descrfield) + for k,v in pairs(t) do + if not (v.option) then + if (type(v) == "table") then + unpackoptions(v,array,descrfield) + end + else + if (v.option[descrfield]) and (v.option[descrfield].value) then + table.insert(array, v.label .. " (" .. v.option[descrfield].value .. ")") + else + table.insert(array, v.label) + end + end + end +end + function status(self) local config = {} config.settings = {} --- local array = {} local locations=self.model.getlocations(self) local availablesigns = self.model.check_signs("prefix") - config.locations = cfe ({ name="locations", - label="Locations", + label="Defining locations", value=locations, }) ---[[ +---[[ local prefix = "." config.settings.nsourdomain = cfe ({ name="nsourdomain", @@ -105,69 +133,366 @@ function status(self) }) --]] +--[[ config.settings.all = cfe ({ name="generic", label="All available records", value=self.model.getconfigobjects(self), }) - +--]] local counter --- colapse_output(config.settings, pvt) ----[[ - -- We count the rows of the previous columns - -- This counter is then used to set the default filter (when user has not entered any values) - -- FIXME: This is a uggly way of doing things. It's just a way to get going faster - local filterstage = 3 - - local mytable = config.settings - for k1,v1 in pairs(mytable) do - if not (counter) then counter = 0 end - if (type(v1) == "table") then - for k2,v2 in pairs(v1) do - if (type(v2) == "table") then - for s1,vs1 in pairs(v2) do - if (type(vs1) == "table") then - for s2,vs2 in pairs(vs1) do - if (filterstage) and (filterstage == 2) then - mytable[k1][k2][s1][s2] = {} -- Removes stage2 and above - else - - if (type(vs2) == "table") then - for s3,vs3 in pairs(vs2) do - if (filterstage) and (filterstage == 3) and not (vs3.name) then - mytable[k1][k2][s1][s2][s3] = {} -- Removes stage3 and above - end - end - end - - end - end - end - end - end - end - end + return { + status=getstatus(self), + config=config, + } +end + +function config(self) + local config = self.model.getconfig(self) + local debug = self.model.getdebug(self) + local availablesigns = self.model.check_signs("prefix") +-- local debug = self..status(self) +-- debug = self + + -- LISTEN _________________________________________________________ + -- Add button + config.cmdeditlisten = cfe ({ + name="cmdeditlisten", + label="Save above changes", + value="Save", + type="submit", + disabled="yes", + }) + + + -- LOCATIONS _________________________________________________________ + local locations=self.model.getlocations(self) + config.locations = cfe ({ + name="locations", + label="Locations", + option={}, + type="select", + }) + -- Add options + for n in pairs(locations) do + table.insert(config.locations.option, n) end ---]] - config.debug = cfe ({ - name="debug", - label="Counted rows", - value=pvt, - errtxt=" ", + -- Add a [New] record to the options + table.insert(config.locations.option, "[New]") + -- Set size of the inputbox + config.locations.size = #config.locations.option + if (#config.locations.option == 1) then + config.locations.size = #config.locations.option + 1 + end + + -- Add button + config.cmdeditlocations = cfe ({ + name="cmdeditlocations", + label="Edit above location", + value="Edit", + descr="Mark a item in '" .. config.locations.label .. "'-list before pressing [Edit]", + type="submit", + disabled="yes", }) + -- Nameservers _________________________________________________________ + local prefix = "." + local domainopts = {} + local domainoptions = self.model.getconfigobjects(self,prefix) + local descrfield = 2 -- This is the filed that is shown as description (in the select-box) + unpackoptions(domainoptions, domainopts,descrfield) + config.nsourdomain = cfe ({ + name="nsourdomain", + type="select", + label=availablesigns[prefix], + option=domainopts, + descr="Above records look like '.fqdn:ip:x:ttl:timestamp:lo' when they are in the config-file.", + }) + -- Add a [New] record to the options + table.insert(config.nsourdomain.option, "[New]") + -- Set size of the inputbox + config.nsourdomain.size = #config.nsourdomain.option + if (#config.nsourdomain.option == 1) then + config.nsourdomain.size = #config.nsourdomain.option + 1 + end + + -- Add button + config.cmdeditnsourdomain = cfe ({ + name="cmdeditnsourdomain", + label="Edit above item", + value="Edit", + descr="Mark a item in '" .. config.nsourdomain.label .. "'-list before pressing [Edit]", + type="submit", + disabled="yes", + }) + + -- Nameservers _________________________________________________________ + local prefix = "&" + local domainoptions = self.model.getconfigobjects(self,prefix) + local domainopts = {} + local descrfield = 2 -- This is the filed that is shown as description (in the select-box) + unpackoptions(domainoptions, domainopts,descrfield) + config.nsdomain = cfe ({ + name="nsdomain", + label=availablesigns[prefix], + type="select", + option=domainopts, + descr="Above records look like '&fqdn:ip:x:ttl:timestamp:lo' when they are in the config-file.", + }) + -- Add options +-- for n in pairs(locations) do +-- table.insert(config.nsdomain.option, n) +-- end + -- Add a [New] record to the options + table.insert(config.nsdomain.option, "[New]") + -- Set size of the inputbox + config.nsdomain.size = #config.nsdomain.option + if (#config.nsdomain.option == 1) then + config.nsdomain.size = #config.nsdomain.option + 1 + end + + -- Add button + config.cmdeditnsdomain = cfe ({ + name="cmdeditnsdomain", + label="Edit above item", + value="Edit", + descr="Mark a item in '" .. config.nsdomain.label .. "'-list before pressing [Edit]", + type="submit", + disabled="yes", + }) + + -- Host _________________________________________________________ + local prefix = "=" + local domainoptions = self.model.getconfigobjects(self,prefix) + local domainopts = {} + -- Filter out options + local descrfield = 2 -- This is the filed that is shown as description (in the select-box) + unpackoptions(domainoptions, domainopts,descrfield) + config.host = cfe ({ + name="host", + label=availablesigns[prefix], + type="select", + option=domainopts, + descr="Above records look like '=fqdn:ip:ttl:timestamp:lo' when they are in the config-file.", + }) + -- Add a [New] record to the options + table.insert(config.host.option, "[New]") + -- Set size of the inputbox + config.host.size = #config.host.option + if (#config.host.option == 1) then + config.host.size = #config.host.option + 1 + end + + -- Add button + config.cmdedithost = cfe ({ + name="cmdedithost", + label="Edit above item", + value="Edit", + descr="Mark a item in '" .. config.host.label .. "'-list before pressing [Edit]", + type="submit", + disabled="yes", + }) + + -- Alias _________________________________________________________ + local prefix = "+" + local domainoptions = self.model.getconfigobjects(self,prefix) + local domainopts = {} + -- Filter out options + local descrfield = 2 -- This is the filed that is shown as description (in the select-box) + unpackoptions(domainoptions, domainopts,descrfield) + config.alias = cfe ({ + name="alias", + label=availablesigns[prefix], + type="select", + option=domainopts, + descr="Above records look like '+fqdn:ip:ttl:timestamp:lo' when they are in the config-file.", + }) + -- Add a [New] record to the options + table.insert(config.alias.option, "[New]") + -- Set size of the inputbox + config.alias.size = #config.alias.option + if (#config.alias.option == 1) then + config.alias.size = #config.alias.option + 1 + end + + -- Add button + config.cmdeditalias = cfe ({ + name="cmdeditalias", + label="Edit above item", + value="Edit", + descr="Mark a item in '" .. config.alias.label .. "'-list before pressing [Edit]", + type="submit", + disabled="yes", + }) + + -- MX _________________________________________________________ + local prefix = "@" + local domainoptions = self.model.getconfigobjects(self,prefix) + local domainopts = {} + -- Filter out options + local descrfield = 2 -- This is the filed that is shown as description (in the select-box) + unpackoptions(domainoptions, domainopts,descrfield) + config.mx = cfe ({ + name="mx", + label=availablesigns[prefix], + type="select", + option=domainopts, + descr="Above records look like '@fqdn:ip:x:dist:ttl:timestamp:lo' when they are in the config-file.", + }) + -- Add a [New] record to the options + table.insert(config.mx.option, "[New]") + -- Set size of the inputbox + config.mx.size = #config.mx.option + if (#config.mx.option == 1) then + config.mx.size = #config.mx.option + 1 + end + + -- Add button + config.cmdeditmx = cfe ({ + name="cmdeditmx", + label="Edit above item", + value="Edit", + descr="Mark a item in '" .. config.mx.label .. "'-list before pressing [Edit]", + type="submit", + disabled="yes", + }) + + -- PTR _________________________________________________________ + local prefix = "^" + local domainoptions = self.model.getconfigobjects(self,prefix) + local domainopts = {} + -- Filter out options + local descrfield = 2 -- This is the filed that is shown as description (in the select-box) + unpackoptions(domainoptions, domainopts,descrfield) + config.ptr = cfe ({ + name="ptr", + label=availablesigns[prefix], + type="select", + option=domainopts, + descr="Above records look like '^fqdn:p:ttl:timestamp:lo' when they are in the config-file.", + }) + -- Add a [New] record to the options + table.insert(config.ptr.option, "[New]") + -- Set size of the inputbox + config.ptr.size = #config.ptr.option + if (#config.ptr.option == 1) then + config.ptr.size = #config.ptr.option + 1 + end + + -- Add button + config.cmdeditptr = cfe ({ + name="cmdeditptr", + label="Edit above item", + value="Edit", + descr="Mark a item in '" .. config.ptr.label .. "'-list before pressing [Edit]", + type="submit", + disabled="yes", + }) + + -- Cname _________________________________________________________ + local prefix = "C" + local domainoptions = self.model.getconfigobjects(self,prefix) + local domainopts = {} + -- Filter out options + local descrfield = 2 -- This is the filed that is shown as description (in the select-box) + unpackoptions(domainoptions, domainopts,descrfield) + config.cname = cfe ({ + name="cname", + label=availablesigns[prefix], + type="select", + option=domainopts, + descr="Above records look like 'Cfqdn:p:ttl:timestamp:lo' when they are in the config-file.", + }) + -- Add a [New] record to the options + table.insert(config.cname.option, "[New]") + -- Set size of the inputbox + config.cname.size = #config.cname.option + if (#config.cname.option == 1) then + config.cname.size = #config.cname.option + 1 + end + + -- Add button + config.cmdeditcname = cfe ({ + name="cmdeditcname", + label="Edit above item", + value="Edit", + descr="Mark a item in '" .. config.cname.label .. "'-list before pressing [Edit]", + type="submit", + disabled="yes", + }) + + -- SOA _________________________________________________________ + local prefix = "Z" + local domainoptions = self.model.getconfigobjects(self,prefix) + local domainopts = {} + -- Filter out options + local descrfield = 2 -- This is the filed that is shown as description (in the select-box) + unpackoptions(domainoptions, domainopts,descrfield) + config.soa = cfe ({ + name="soa", + label=availablesigns[prefix], + type="select", + option=domainopts, + descr="Above records look like 'Zfqdn:mname:rname:ser:ref:ret:exp:min:ttl:timestamp:lo' when they are in the config-file.", + }) + -- Add a [New] record to the options + table.insert(config.soa.option, "[New]") + -- Set size of the inputbox + config.soa.size = #config.soa.option + if (#config.soa.option == 1) then + config.soa.size = #config.soa.option + 1 + end + + -- Add button + config.cmdeditsoa = cfe ({ + name="cmdeditsoa", + label="Edit above item", + value="Edit", + descr="Mark a item in '" .. config.soa.label .. "'-list before pressing [Edit]", + type="submit", + disabled="yes", + }) + + -- GENERIC _________________________________________________________ + local prefix = ":" + local domainoptions = self.model.getconfigobjects(self,prefix) + local domainopts = {} + -- Filter out options + local descrfield = 2 -- This is the filed that is shown as description (in the select-box) + unpackoptions(domainoptions, domainopts,descrfield) + config.generic = cfe ({ + name="generic", + label=availablesigns[prefix], + type="select", + option=domainopts, + descr="Above records look like ':fqdn:n:rdata:ttl:timestamp:lo' when they are in the config-file.", + }) + -- Add a [New] record to the options + table.insert(config.generic.option, "[New]") + -- Set size of the inputbox + config.generic.size = #config.generic.option + if (#config.generic.option == 1) then + config.generic.size = #config.generic.option + 1 + end + + -- Add button + config.cmdeditgeneric = cfe ({ + name="cmdeditgeneric", + label="Edit above item", + value="Edit", + descr="Mark a item in '" .. config.generic.label .. "'-list before pressing [Edit]", + type="submit", + disabled="yes", + }) + + - return { status=getstatus(self), config=config } -end -function config(self) - local config = self.model.getconfigobjects(self) - local debug = self.model.getdebug(self) return ({ status=getstatus(self), config=config, - debug=debug, +-- debug=debug, }) end |