module(..., package.seeall) -- Set variables local newrecordtxt = "[New]" -- ################################################################################ -- LOCAL FUNCTIONS 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 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 local function displaycmdmanagement(pidofstatus) -- Add a management buttons local management = {} management.start = cfe({ name="cmdmanagement", label="Program control-panel", value="Start", type="submit", }) management.stop = cfe({ name="cmdmanagement", label="Program control-panel", value="Stop", type="submit", }) management.restart = cfe({ name="cmdmanagement", label="Program control-panel", value="Restart", type="submit", }) -- next CFE can be used to present the result of the previous action management.actionresult = cfe({ name="actionresult", label="Previous action result", descr="", --Content of this variable is displayed as
...in BLACK text errtxt="", --Content of this variable is displayed as
...in RED text }) -- Disable management buttons based on if the process is running or not if (pidofstatus) then management.start.disabled = "yes" else management.stop.disabled = "yes" management.restart.disabled = "yes" end return management end -- ################################################################################ -- PUBLIC FUNCTIONS default_action = "status" 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 expert(self) -- Start/Stop/Restart process local cmdmanagement, actionresult if ( self.clientdata.cmdmanagement) then cmdmanagement = cfe({ name="cmdmanagement", label="Previous action result", action=cfe({ name="cmdmanagement", value=string.lower(self.clientdata.cmdmanagement), -- This row contains start/stop/restart (one of these commands) }), }) actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action ) end local status = getstatus(self) local config = self.model:getfilelist() -- Management buttons (Hide/show buttons local pidofstatus if (string.lower(status.status.value) == "enabled" ) then pidofstatus = true end management = displaycmdmanagement(pidofstatus) if (actionresult) then management.actionresult.descr=cmdmanagement.descr management.actionresult.errtxt=cmdmanagement.errtxt end if (status) and (status.version) and (#status.version.value == 0) then management.start.disabled = "yes" management.stop.disabled = "yes" management.restart.disabled = "yes" end return { option={ script=ENV["SCRIPT_NAME"], prefix=self.conf.prefix, controller = self.conf.controller, action = "expert", link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, }, management = management, config = config, status = status, startstop = startstop, debugclientdata = self.clientdata, } end function edit(self) -- Save changes if ( self.clientdata.cmdsave) then local filetochange = cfe ({ name=self.clientdata.name, value=self.clientdata.filecontent, }) modifications = self.model:updatefilecontent(filetochange) end if not (self.model:valid_filename(self.clientdata.name)) then self.conf.action = "status" self.conf.type = "redir" error (self.conf) end local status = getstatus(self) local file = self.model:get_filedetails(self.clientdata.name) -- Add a cmd button to the view file.cmdsave = cfe({ name="cmdsave", label="Save/Apply above settings", value="Save", type="submit", }) if (modifications) then file.cmdsave.descr="* Changes has been saved!" end return { option={ script=ENV["SCRIPT_NAME"], prefix=self.conf.prefix, controller = self.conf.controller, action = "edit", extra = "", link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, }, modifications = modifications, file = file, status = status, startstop = startstop, debugclientdata = self.clientdata, } end