module(..., package.seeall) local list_redir = function (self) self.conf.action = "status" self.conf.type = "redir" error (self.conf) end mvc = {} mvc.on_load = function(self, parent) if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then self.worker[self.conf.action] = list_redir(self) end end local function getstatus(self) local status = self.model.getstatus() if (#status.status.value > 0) then status.status.value = "Enabled" else status.status.value = "Disabled" end 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 locations=self.model.getlocations(self) local availablesigns = self.model.check_signs("prefix") config.locations = cfe ({ name="locations", label="Defining locations", value=locations, }) local prefix = "." local domainoptions = self.model.getconfigobjects(self,prefix) if (#domainoptions > 0) then config.settings.nsourdomain = cfe ({ name="nsourdomain", label=availablesigns[prefix], value=domainoptions, }) end local prefix = "&" local domainoptions = self.model.getconfigobjects(self,prefix) if (#domainoptions > 0) then config.settings.nsdomain = cfe ({ name="nsdomain", label=availablesigns[prefix], value=domainoptions, }) end local prefix = "=" local domainoptions = self.model.getconfigobjects(self,prefix) if (#domainoptions > 0) then config.settings.host = cfe ({ name="host", label=availablesigns[prefix], value=domainoptions, }) end local prefix = "+" local domainoptions = self.model.getconfigobjects(self,prefix) if (#domainoptions > 0) then config.settings.alias = cfe ({ name="alias", label=availablesigns[prefix], value=domainoptions, }) end local prefix = "@" local domainoptions = self.model.getconfigobjects(self,prefix) if (#domainoptions > 0) then config.settings.mx = cfe ({ name="mx", label=availablesigns[prefix], value=domainoptions, }) end local prefix = "^" local domainoptions = self.model.getconfigobjects(self,prefix) if (#domainoptions > 0) then config.settings.ptr = cfe ({ name="ptr", label=availablesigns[prefix], value=domainoptions, }) end local prefix = "C" local domainoptions = self.model.getconfigobjects(self,prefix) if (#domainoptions > 0) then config.settings.cname = cfe ({ name="cname", label=availablesigns[prefix], value=domainoptions, }) end local prefix = "Z" local domainoptions = self.model.getconfigobjects(self,prefix) if (#domainoptions > 0) then config.settings.soa = cfe ({ name="soa", label=availablesigns[prefix], value=domainoptions, }) end local prefix = ":" local domainoptions = self.model.getconfigobjects(self,prefix) if (#domainoptions > 0) then config.settings.generic = cfe ({ name="generic", label=availablesigns[prefix], value=domainoptions, }) end --[[ -- This could be used for DEBUGGING config.settings.all = cfe ({ name="generic", label="All available records", value=self.model.getconfigobjects(self), }) --]] local counter 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") -- 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 -- 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 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", }) -- DEBUGGING local level1 = {} local level2 = {} local level3 = {} local domainoptions = self.model.getconfigobjects(self) for k1,v1 in pairs(domainoptions) do table.insert(level1, v1.label) for k2,v2 in pairs(v1) do table.insert(level2, v2.label) if (type(v2) == "table") then for k3,v3 in pairs(v2) do table.insert(level3, v3.label) end end end end config.debuglevels = cfe ({ name="debuglevels", label="Level1", type="select", option=domainoptions, }) return ({ status=getstatus(self), config=config, }) end