diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-04-08 15:13:54 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-04-08 15:13:54 +0000 |
commit | 132a51a124fb1fa5e48f3b0982b9742572bc922c (patch) | |
tree | 8f776bdec1d5228dad70a6ae9a87c02037c1e6cf /snort-controller.lua | |
parent | 4baa9420979051e89c0758fd66ce71f0179b1532 (diff) | |
download | acf-snort-132a51a124fb1fa5e48f3b0982b9742572bc922c.tar.bz2 acf-snort-132a51a124fb1fa5e48f3b0982b9742572bc922c.tar.xz |
Cleaning up code.
git-svn-id: svn://svn.alpinelinux.org/acf/snort/trunk@962 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'snort-controller.lua')
-rw-r--r-- | snort-controller.lua | 91 |
1 files changed, 46 insertions, 45 deletions
diff --git a/snort-controller.lua b/snort-controller.lua index 926bab3..bc49d4a 100644 --- a/snort-controller.lua +++ b/snort-controller.lua @@ -1,32 +1,18 @@ module (..., package.seeall) + +-- Load libraries require("posix") --- Cause an http redirect to our "read" action --- We use the self.conf table because it already has prefix,controller,etc --- The redir code is defined in the application error handler (acf-controller) -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 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 displaycmdmanagement(disablestart,disablestop,disablerestart) +local function displaycmdmanagement(pidofstatus) -- Add a management buttons local management = {} management.start = cfe({ name="cmdmanagement", @@ -44,19 +30,38 @@ 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) local srvcmdresult = nil local srvcmd = self.clientdata.srvcmd - local status = getstatus(self) + local status = self.model:getstatus(self) local alerts,alertresult = self.model:read_alert() return ({ @@ -76,7 +81,7 @@ function expert(self) end -- Start/Stop/Restart process - local cmdmanagement + local cmdmanagement, actionresult if ( self.clientdata.cmdmanagement) then cmdmanagement = cfe({ name="cmdmanagement", @@ -86,10 +91,10 @@ function expert(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 = getstatus(self) + local status = self.model:getstatus(self) local file = self.model:get_filedetails() -- Add buttons @@ -103,26 +108,22 @@ function expert(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 + if (status) and (status.version) and (#status.version.value == 0) then + management.start.disabled = "yes" + management.stop.disabled = "yes" + management.restart.disabled = "yes" end - -- Display management buttons - local management = displaycmdmanagement(disablestart,disablestop,disablerestart) - - - --- if ( cmd ~= nil ) then --- startstop = self.model:startstop_service( cmd ) --- end return ( { management = management, - cmdmanagement = cmdmanagement, status = status, file = file, modifications = modifications, |