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 displaycmdsave(self) -- Add a cmd button to the view local cmdsave = cfe({ name="cmdsave", label="Save/Apply above settings", value="Save", type="submit", }) return cmdsave end local function displaycmdmanagement(disablestart,disablestop,disablerestart) -- 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", }) -- Disable management buttons based on if the process is running or not if (disablestart) then management.start.disabled = "yes" end if (disablestop) then management.stop.disabled = "yes" end if (disablerestart) then management.restart.disabled = "yes" end return management end function status(self) return { status=getstatus(self) } end function config(self) local cmdmanagement, cmdmanagementresult local cmdsavereply = {} local cmdsaveresult = {} if ( self.clientdata.cmdmanagement) then cmdmanagement = cfe({ name="cmdmanagement", value=string.lower(self.clientdata.cmdmanagement), }) cmdmanagementresult, cmdmanagement = self.model:startstop_service( cmdmanagement ) end if ( self.clientdata.cmdsave) then --[[ local variables="logfile loglevel smallerlogs maxsize numrotate localandnetworklog remotelogging" -- Advanced-config options -- local variables="remotelogging" -- Guided-config options for var in string.gmatch(variables, "%S+") do -- Send nil instead of "" causes the parameter to be removed/deleted/empty/unset the variable in the config-file if (self.clientdata[var] == "") then self.clientdata[var] = nil end cmdsaveresult[var], cmdsavereply[var] = self.model:setconfigs( var,self.clientdata[var] ) end --]] end local status = getstatus(self) local config = self.model.getconfig() -- Write out erros from previous cmdsave actions for k,v in pairs(cmdsaveresult) do if not (v) then config[k]["errtxt"] = tostring(cmdsavereply[k]["errtxt"]) end end -- Display save button config.cmdsave = displaycmdsave() -- Add a test button to the view config.cmdtest = cfe({ name="cmdtest", label="Test saved settings", value="Test", type="submit", }) -- FIXME: This is temporary disabling the buttons (until they work) config.cmdsave["disabled"] = "yes" config.cmdtest["disabled"] = "yes" --[[ -- Management buttons local disablestart,disablestop,disablerestart -- Disable management buttons based on if the process is running or not if (string.lower(status.status.value) == "enabled" ) then disablestart = "yes" else disablestop = "yes" end -- Disable management buttons if there exist errors in the config for k,v in pairs(config) do if (config[k]["errtxt"] ~= "") then disablestart = "yes" disablestop = "yes" disablerestart = "yes" break end end -- Display management buttons local management = displaycmdmanagement(disablestart,disablestop,disablerestart) --]] return { option={ script=ENV["SCRIPT_NAME"], prefix=self.conf.prefix, controller = self.conf.controller, action = "config", }, status = status, cmdmanagement = cmdmanagement, management = management, config = config, debugclientdata = self.clientdata, } end function expert(self) local cmdmanagement, cmdmanagementresult if ( self.clientdata.cmdmanagement) then cmdmanagement = cfe({ name="cmdmanagement", value=string.lower(self.clientdata.cmdmanagement), }) cmdmanagementresult, cmdmanagement = self.model:startstop_service( cmdmanagement ) end -- Save changes local modifications = self.clientdata.filecontent or "" if ( self.clientdata.cmdsave) then modifications = self.model:update_filecontent(modifications) end local status = getstatus(self) local config = self.model:get_filedetails() -- Display save button config.cmdsave = displaycmdsave() --[[ -- Management buttons local disablestart,disablestop,disablerestart -- Disable management buttons based on if the process is running or not if (string.lower(status.status.value) == "enabled" ) then disablestart = "yes" else disablestop = "yes" end -- Disable management buttons if there exist errors in the config for k,v in pairs(config) do if (config[k]["errtxt"] ~= "") then disablestart = "yes" disablestop = "yes" disablerestart = "yes" break end end -- Display management buttons local management = displaycmdmanagement(disablestart,disablestop,disablerestart) --]] return { option={ script=ENV["SCRIPT_NAME"], prefix=self.conf.prefix, controller = self.conf.controller, action = "expert", }, cmdmanagement = cmdmanagement, management = management, config = config, status = status, startstop = startstop, debugclientdata = self.clientdata, } end