summaryrefslogtreecommitdiffstats
path: root/shorewall-controller.lua
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-04-08 15:13:38 +0000
committerMika Havela <mika.havela@gmail.com>2008-04-08 15:13:38 +0000
commitbe8a05d0e4ae337d2cee99c3197f6ef5bf5c5779 (patch)
tree83c5dd5a0649678a412bdbd82a394d5b2ec1342b /shorewall-controller.lua
parentf25fd756ddf5a1c7ac94d8eb2a665d828e82d322 (diff)
downloadacf-shorewall-be8a05d0e4ae337d2cee99c3197f6ef5bf5c5779.tar.bz2
acf-shorewall-be8a05d0e4ae337d2cee99c3197f6ef5bf5c5779.tar.xz
Cleaning up code.
git-svn-id: svn://svn.alpinelinux.org/acf/shorewall/trunk@961 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'shorewall-controller.lua')
-rw-r--r--shorewall-controller.lua98
1 files changed, 41 insertions, 57 deletions
diff --git a/shorewall-controller.lua b/shorewall-controller.lua
index 2a5e99f..3d0f7be 100644
--- a/shorewall-controller.lua
+++ b/shorewall-controller.lua
@@ -6,27 +6,24 @@ require("format")
local newrecordtxt = "[New]"
+-- ################################################################################
+-- LOCAL FUNCTIONS
+
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 displaycmdmanagement(disablestart,disablestop,disablerestart)
+local function displaycmdmanagement(pidofstatus)
-- Add a management buttons
local management = {}
----[[
+--[[
management.start = cfe({ name="cmdmanagement",
label="Program control-panel",
value="Start",
type="submit",
+ descr="When starting or restarting BGP, the web-page will freeze for some reason!",
})
management.stop = cfe({ name="cmdmanagement",
label="Program control-panel",
@@ -39,15 +36,17 @@ local function displaycmdmanagement(disablestart,disablestop,disablerestart)
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
+ -- 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
+ })
return management
end
+
local function displaycmdsave(self)
-- Add a cmd button to the view
local cmdsave = cfe({ name="cmdsave",
@@ -61,6 +60,13 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
+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
+
function editrecords(self,types,record,errormessage)
local recorddetails = {}
local edit = {}
@@ -598,10 +604,6 @@ function config(self)
type="submit",
})
- -- Management buttons
- -- Display management buttons
- local management = displaycmdmanagement(disablestart,disablestop,disablerestart)
-
-- Redirect if button is pressed
if (self.clientdata.params_cmd) and (self.clientdata.params) then
self.conf.action = "editrecords"
@@ -658,7 +660,6 @@ function config(self)
return {
status=status,
config=config,
- management = management,
option={ script=ENV["SCRIPT_NAME"],
prefix=self.conf.prefix,
controller = self.conf.controller,
@@ -671,20 +672,31 @@ function config(self)
end
function check(self)
- local cmdmanagement, cmdmanagementresult
+ -- Start/Stop/Restart process
+ local cmdmanagement, actionresult
if ( self.clientdata.cmdmanagement) then
- cmdmanagement = cfe({
+ cmdmanagement = cfe({
+ name="cmdmanagement",
+ label="Previous action result",
+ action=cfe({
name="cmdmanagement",
- value=string.lower(self.clientdata.cmdmanagement),
- })
- cmdmanagementresult, cmdmanagement = self.model:startstop_service( 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 = self.model.getstatus()
local config = self.model:configcheck()
- -- Display management buttons
- local management = displaycmdmanagement(disablestart,disablestop,disablerestart)
+ -- 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
return {
option={ script=ENV["SCRIPT_NAME"],
@@ -692,7 +704,6 @@ function check(self)
controller = self.conf.controller,
action = "expert",
link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, },
- cmdmanagement = cmdmanagement,
management = management,
config = config,
status = status,
@@ -703,14 +714,6 @@ function check(self)
end
function logfile(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
local status = self.model.getstatus()
local config = self.model:getlogfile()
@@ -721,8 +724,6 @@ function logfile(self)
controller = self.conf.controller,
action = "expert",
link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, },
- cmdmanagement = cmdmanagement,
- management = management,
config = config,
status = status,
startstop = startstop,
@@ -732,14 +733,6 @@ function logfile(self)
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
local status = self.model.getstatus()
local config = self.model:getfilelist()
@@ -750,8 +743,6 @@ function expert(self)
controller = self.conf.controller,
action = "expert",
link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, },
- cmdmanagement = cmdmanagement,
- management = management,
config = config,
status = status,
startstop = startstop,
@@ -761,14 +752,6 @@ function expert(self)
end
function edit(self)
- local cmdmanagement, cmdmanagementresult, modifications
- 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
if ( self.clientdata.cmdsave) then
@@ -785,6 +768,9 @@ function edit(self)
-- Display save button
config.cmdsave = displaycmdsave()
+ if (self.clientdata.cmdsave) then
+ config.cmdsave.descr="* Changes has been saved!"
+ end
return {
option={ script=ENV["SCRIPT_NAME"],
@@ -792,9 +778,7 @@ function edit(self)
controller = self.conf.controller,
action = "edit",
link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, },
- cmdmanagement = cmdmanagement,
modifications = modifications,
- management = management,
config = config,
status = status,
startstop = startstop,