diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-04-08 15:12:27 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-04-08 15:12:27 +0000 |
commit | 814afcfdeeb9e92f7c7ce02f8176b9a9562580ef (patch) | |
tree | 3cac821f2855252067766998f55a142a6bd7728f /ipsectools-controller.lua | |
parent | 45f598e8eb50479e76bd9db538c8babfe0b2e2ef (diff) | |
download | acf-ipsec-tools-814afcfdeeb9e92f7c7ce02f8176b9a9562580ef.tar.bz2 acf-ipsec-tools-814afcfdeeb9e92f7c7ce02f8176b9a9562580ef.tar.xz |
Cleaning up code.
git-svn-id: svn://svn.alpinelinux.org/acf/ipsec-tools/trunk@957 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'ipsectools-controller.lua')
-rw-r--r-- | ipsectools-controller.lua | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/ipsectools-controller.lua b/ipsectools-controller.lua index ba0f667..9fa758c 100644 --- a/ipsectools-controller.lua +++ b/ipsectools-controller.lua @@ -1,23 +1,18 @@ module(..., package.seeall) --- This is the object/text used when we want to add a new record - +-- Load libraries require("format") -local list_redir = function (self) +-- ################################################################################ +-- LOCAL FUNCTIONS + +local function list_redir (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 displaycmdmanagement(disablestart,disablestop,disablerestart) +local function displaycmdmanagement(pidofstatus) -- Add a management buttons local management = {} management.start = cfe({ name="cmdmanagement", @@ -35,22 +30,39 @@ local function displaycmdmanagement(disablestart,disablestop,disablerestart) 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 <PRE> ... </PRE> in BLACK text + errtxt="", --Content of this variable is displayed as <PRE> ... </PRE> in RED text + }) -- 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 + if (pidofstatus) then + management.start.disabled = "yes" + else + management.stop.disabled = "yes" + management.restart.disabled = "yes" + end return management end -- ################################################################################ -- PUBLIC FUNCTIONS + +mvc = {} +function mvc.on_load(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 + function status(self) return { status=self.model.getstatus() } end -expert = function (self) +function expert (self) local modifications = self.clientdata.filecontent or "" local modifications2 = self.clientdata.filecontent2 or "" if ( self.clientdata.cmdsave ) then @@ -61,7 +73,7 @@ expert = function (self) local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller -- Start/Stop/Restart process - local cmdmanagement + local cmdmanagement, actionresult if ( self.clientdata.cmdmanagement) then cmdmanagement = cfe({ name="cmdmanagement", @@ -71,7 +83,7 @@ expert = function (self) value=string.lower(self.clientdata.cmdmanagement), -- This row contains start/stop/restart (one of these commands) }), }) - local actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action ) + actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action ) end local status=self.model.getstatus() @@ -89,16 +101,14 @@ expert = function (self) file.cmdsave.descr="* Changes has been saved!" end - -- 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" + -- 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 - -- Display management buttons - management = displaycmdmanagement(disablestart,disablestop,disablerestart) return ( { status = status, @@ -106,11 +116,10 @@ expert = function (self) file2 = file2, modifications = modifications, management = management, - cmdmanagement = cmdmanagement, url = url, } ) end -logfile = function (self) +function logfile (self) local status=self.model.getstatus() local logfile = self.model:get_logfile() |