diff options
Diffstat (limited to 'tinydns-controller.lua')
-rw-r--r-- | tinydns-controller.lua | 169 |
1 files changed, 127 insertions, 42 deletions
diff --git a/tinydns-controller.lua b/tinydns-controller.lua index a5f804d..612d1c9 100644 --- a/tinydns-controller.lua +++ b/tinydns-controller.lua @@ -1,5 +1,7 @@ module(..., package.seeall) +local newrecordtxt = "[New]" + local list_redir = function (self) self.conf.action = "status" self.conf.type = "redir" @@ -56,6 +58,24 @@ local function unpackoptions(t,array,descrfield) end end +local function unpackoptionstooriginal(t,array,filter) + for k,v in pairs(t) do + if not (v.option) then + if (type(v) == "table") then + unpackoptionstooriginal(v,array,filter) + end + else + if (v.orgrecordtable) and (v.orgrecordtable[2] == filter) then + table.insert(array, v.orgrecordtable) + end + end + end +end + + +-- ################################################################################ +-- PUBLIC FUNCTIONS + function status(self) local config = {} config.settings = {} @@ -173,15 +193,60 @@ function status(self) } end -function config(self) +function edit_records(self,types,record,errormessage) + local recorddetails = {} + local edit = {} + local config=self.model:getconfig() + + -- Fetch the original record into a table + local availablesigns = self.model.check_signs() + local prefix = availablesigns["reverse"][types] + 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) + unpackoptionstooriginal(domainoptions, domainopts,string.match(record, "^%S*")) + domainopts=unpack(domainopts) + + -- Display the inputfields (with the original record) + local numfields = math.max(#domainopts,#availablesigns["fieldlabels"][prefix]) + for fieldnum=2,tonumber(numfields) do + edit[fieldnum] = cfe({ + name=fieldnum, + value=domainopts[fieldnum], + label=availablesigns["fieldlabels"][prefix][fieldnum] or "", + }) + end + + table.insert(edit, cfe({ + name=#edit, + label="DEBUG: Original record", + value=domainopts.orgrecord, + errtxt="This field will go away soon! It's only for debugging!" + })) + + return { + edit=edit, + option={ script=ENV["SCRIPT_NAME"], + prefix=self.conf.prefix, + controller = self.conf.controller, + action = "config", + link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, }, + cmdsave=cmdsave, + cmddelete=cmddelete, + clientdata=clientdata, + debugtypes=types, + debugrecord=string.match(record, "^%S*"), + } +end +function config(self,messages) local config = self.model.getconfig(self) local debug = self.model.getdebug(self) local availablesigns = self.model.check_signs("prefix") -- LISTEN _________________________________________________________ -- Add button - config.cmdeditlisten = cfe ({ - name="cmdeditlisten", + config.listen_cmd = cfe ({ + name="listen_cmd", label="Save above changes", value="Save", type="submit", @@ -202,7 +267,7 @@ function config(self) table.insert(config.locations.option, n) end -- Add a [New] record to the options - table.insert(config.locations.option, "[New]") +-- table.insert(config.locations.option, newrecordtxt) -- Set size of the inputbox config.locations.size = #config.locations.option if (#config.locations.option == 1) then @@ -210,8 +275,8 @@ function config(self) end -- Add button - config.cmdeditlocations = cfe ({ - name="cmdeditlocations", + config.locations_cmd = cfe ({ + name="locations_cmd", label="Edit above location", value="Edit", descr="Mark a item in '" .. config.locations.label .. "'-list before pressing [Edit]", @@ -233,7 +298,7 @@ function config(self) -- 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]") +-- table.insert(config.nsourdomain.option, newrecordtxt) -- Set size of the inputbox config.nsourdomain.size = #config.nsourdomain.option if (#config.nsourdomain.option == 1) then @@ -241,13 +306,13 @@ function config(self) end -- Add button - config.cmdeditnsourdomain = cfe ({ - name="cmdeditnsourdomain", + config.nsourdomain_cmd = cfe ({ + name="nsourdomain_cmd", label="Edit above item", value="Edit", descr="Mark a item in '" .. config.nsourdomain.label .. "'-list before pressing [Edit]", type="submit", - disabled="yes", +-- disabled="yes", }) -- Nameservers _________________________________________________________ @@ -264,7 +329,7 @@ function config(self) -- 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.nsdomain.option, "[New]") +-- table.insert(config.nsdomain.option, newrecordtxt) -- Set size of the inputbox config.nsdomain.size = #config.nsdomain.option if (#config.nsdomain.option == 1) then @@ -272,13 +337,13 @@ function config(self) end -- Add button - config.cmdeditnsdomain = cfe ({ - name="cmdeditnsdomain", + config.nsdomain_cmd = cfe ({ + name="nsdomain_cmd", label="Edit above item", value="Edit", descr="Mark a item in '" .. config.nsdomain.label .. "'-list before pressing [Edit]", type="submit", - disabled="yes", +-- disabled="yes", }) -- Host _________________________________________________________ @@ -296,7 +361,7 @@ function config(self) -- 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]") +-- table.insert(config.host.option, newrecordtxt) -- Set size of the inputbox config.host.size = #config.host.option if (#config.host.option == 1) then @@ -304,13 +369,13 @@ function config(self) end -- Add button - config.cmdedithost = cfe ({ - name="cmdedithost", + config.host_cmd = cfe ({ + name="host_cmd", label="Edit above item", value="Edit", descr="Mark a item in '" .. config.host.label .. "'-list before pressing [Edit]", type="submit", - disabled="yes", +-- disabled="yes", }) -- Alias _________________________________________________________ @@ -328,7 +393,7 @@ function config(self) -- 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]") +-- table.insert(config.alias.option, newrecordtxt) -- Set size of the inputbox config.alias.size = #config.alias.option if (#config.alias.option == 1) then @@ -336,13 +401,13 @@ function config(self) end -- Add button - config.cmdeditalias = cfe ({ - name="cmdeditalias", + config.alias_cmd = cfe ({ + name="alias_cmd", label="Edit above item", value="Edit", descr="Mark a item in '" .. config.alias.label .. "'-list before pressing [Edit]", type="submit", - disabled="yes", +-- disabled="yes", }) -- MX _________________________________________________________ @@ -360,7 +425,7 @@ function config(self) -- 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]") +-- table.insert(config.mx.option, newrecordtxt) -- Set size of the inputbox config.mx.size = #config.mx.option if (#config.mx.option == 1) then @@ -368,13 +433,13 @@ function config(self) end -- Add button - config.cmdeditmx = cfe ({ - name="cmdeditmx", + config.mx_cmd = cfe ({ + name="mx_cmd", label="Edit above item", value="Edit", descr="Mark a item in '" .. config.mx.label .. "'-list before pressing [Edit]", type="submit", - disabled="yes", +-- disabled="yes", }) -- PTR _________________________________________________________ @@ -392,7 +457,7 @@ function config(self) -- 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]") +-- table.insert(config.ptr.option, newrecordtxt) -- Set size of the inputbox config.ptr.size = #config.ptr.option if (#config.ptr.option == 1) then @@ -400,13 +465,13 @@ function config(self) end -- Add button - config.cmdeditptr = cfe ({ - name="cmdeditptr", + config.ptr_cmd = cfe ({ + name="ptr_cmd", label="Edit above item", value="Edit", descr="Mark a item in '" .. config.ptr.label .. "'-list before pressing [Edit]", type="submit", - disabled="yes", +-- disabled="yes", }) -- Cname _________________________________________________________ @@ -424,7 +489,7 @@ function config(self) -- 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]") +-- table.insert(config.cname.option, newrecordtxt) -- Set size of the inputbox config.cname.size = #config.cname.option if (#config.cname.option == 1) then @@ -432,13 +497,13 @@ function config(self) end -- Add button - config.cmdeditcname = cfe ({ - name="cmdeditcname", + config.cname_cmd = cfe ({ + name="cname_cmd", label="Edit above item", value="Edit", descr="Mark a item in '" .. config.cname.label .. "'-list before pressing [Edit]", type="submit", - disabled="yes", +-- disabled="yes", }) -- SOA _________________________________________________________ @@ -456,7 +521,7 @@ function config(self) -- 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]") +-- table.insert(config.soa.option, newrecordtxt) -- Set size of the inputbox config.soa.size = #config.soa.option if (#config.soa.option == 1) then @@ -464,13 +529,13 @@ function config(self) end -- Add button - config.cmdeditsoa = cfe ({ - name="cmdeditsoa", + config.soa_cmd = cfe ({ + name="soa_cmd", label="Edit above item", value="Edit", descr="Mark a item in '" .. config.soa.label .. "'-list before pressing [Edit]", type="submit", - disabled="yes", +-- disabled="yes", }) -- GENERIC _________________________________________________________ @@ -488,7 +553,7 @@ function config(self) -- 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]") +-- table.insert(config.generic.option, newrecordtxt) -- Set size of the inputbox config.generic.size = #config.generic.option if (#config.generic.option == 1) then @@ -496,13 +561,13 @@ function config(self) end -- Add button - config.cmdeditgeneric = cfe ({ - name="cmdeditgeneric", + config.generic_cmd = cfe ({ + name="generic_cmd", label="Edit above item", value="Edit", descr="Mark a item in '" .. config.generic.label .. "'-list before pressing [Edit]", type="submit", - disabled="yes", +-- disabled="yes", }) @@ -523,18 +588,38 @@ function config(self) end end +--[[ config.debuglevels = cfe ({ name="debuglevels", label="Level1", type="select", option=domainoptions, }) +--]] + -- Redirect if button is pressed *********************************** + local tags = {"locations", "nsourdomain", "nsdomain", "host", "alias", "mx", "ptr", "cname", "soa", "generic", } + for k,tag in pairs(tags) do + if (self.clientdata[tag .. "_cmd"]) and (self.clientdata[tag]) then + self.conf.action = "edit_records" + self.conf.type = "redir" + return edit_records(self,tag, self.clientdata[tag]) + elseif (self.clientdata[tag .. "_cmd"]) and not (self.clientdata[tag]) then + config[tag .. "_cmd"]["errtxt"] = "You need to specify a record to edit!" + end + end + return ({ status=getstatus(self), config=config, + option={ script=ENV["SCRIPT_NAME"], + prefix=self.conf.prefix, + controller = self.conf.controller, + action = "config", + link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, }, + }) end |