From f14ce45bcdcbbe99cb5693966019d0deb39371e5 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Mon, 3 Mar 2008 14:55:02 +0000 Subject: Some changes to get 'save' button to work in expert-tab git-svn-id: svn://svn.alpinelinux.org/acf/snort/trunk@785 ab2d0c66-481e-0410-8bed-d214d4d58bed --- snort-controller.lua | 105 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 92 insertions(+), 13 deletions(-) (limited to 'snort-controller.lua') diff --git a/snort-controller.lua b/snort-controller.lua index 19d55ea..926bab3 100644 --- a/snort-controller.lua +++ b/snort-controller.lua @@ -4,7 +4,7 @@ require("posix") -- 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) - self.conf.action = "read" + self.conf.action = "status" self.conf.type = "redir" error (self.conf) end @@ -16,36 +16,115 @@ mvc.on_load = function(self, parent) 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) + -- 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) local srvcmdresult = nil local srvcmd = self.clientdata.srvcmd - if (srvcmd ~= nil) then - srvcmdresult = self.model:startstop_service(srvcmd) - end + local status = getstatus(self) + local alerts,alertresult = self.model:read_alert() - return ({status = self.model:getstatus(), - srvcmdresult=srvcmdresult, + return ({ + status = status, alerts=alerts, alertresult=alertresult, url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} ) end function expert(self) - local modifications = self.clientdata.modifications or "" local cmd = self.clientdata.cmd local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller - if ( modifications ~= "") then + local modifications = self.clientdata.filecontent or "" + if ( self.clientdata.cmdsave ) then modifications = self.model:update_filecontent(modifications) end - if ( cmd ~= nil ) then - startstop = self.model:startstop_service( cmd ) + -- Start/Stop/Restart process + local cmdmanagement + 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) + }), + }) + local actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action ) + end + + local status = getstatus(self) + local file = self.model:get_filedetails() + + -- Add buttons + file.cmdsave = cfe ({ + name="cmdsave", + label="Apply settings", + value="Apply", + type="submit", + }) + if (self.clientdata.cmdsave) then + 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" end + -- Display management buttons + local management = displaycmdmanagement(disablestart,disablestop,disablerestart) + + + +-- if ( cmd ~= nil ) then +-- startstop = self.model:startstop_service( cmd ) +-- end - return ( {startstop = startstop, - status = self.model:getstatus(), - file = self.model:get_filedetails(), + return ( { + management = management, + cmdmanagement = cmdmanagement, + status = status, + file = file, modifications = modifications, url = url, } ) end -- cgit v1.2.3