summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--shorewall-check-html.lsp91
-rw-r--r--shorewall-config-html.lsp56
-rw-r--r--shorewall-confirmation-html.lsp12
-rw-r--r--shorewall-controller.lua98
-rw-r--r--shorewall-edit-html.lsp99
-rw-r--r--shorewall-expert-html.lsp34
-rw-r--r--shorewall-html.lsp75
-rw-r--r--shorewall-logfile-html.lsp85
-rw-r--r--shorewall-model.lua50
-rw-r--r--shorewall-status-html.lsp40
10 files changed, 125 insertions, 515 deletions
diff --git a/shorewall-check-html.lsp b/shorewall-check-html.lsp
index 3bd8831..7cfe4bf 100644
--- a/shorewall-check-html.lsp
+++ b/shorewall-check-html.lsp
@@ -1,51 +1,22 @@
-<? local form = ... ?>
-
-<?
-function informationform(myform,tags)
- io.write("<DL>")
- for k,v in pairs(tags) do
- if (myform[v]) then
- local val = myform[v]
- io.write("\t<DT")
- if (#val.errtxt > 0) then io.write(" class='error'") end
- io.write(">" .. val.label .. "</DT>\n")
-
- io.write("\t\t<DD>" .. val.value .. "\n")
- if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
- if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
- io.write("\t\t</DD>\n")
- end
- end
- io.write("</DL>")
-end
+<? local form = ...
+require("viewfunctions")
?>
<?
-function configform(myform,tags)
- io.write("<DL>")
- for k,v in pairs(tags) do
- if (myform[v]) then
- local val = myform[v]
- io.write("\t<DT")
- if (#val.errtxt > 0) then io.write(" class='error'") end
- io.write(">" .. val.label .. "</DT>\n")
-
- io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n")
- if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
- if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
- io.write("\t\t</DD>\n")
- end
- end
- io.write("</DL>")
-end
+--[[ DEBUG INFORMATION
+io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
+io.write(html.cfe_unpack(view))
+io.write("</span>")
+--]]
?>
-
<H1>SYSTEM INFO</H1>
+<DL>
<?
local myform = form.status
local tags = { "status", "version", "autostart", }
-informationform(myform,tags)
+displayinfo(myform,tags,"viewonly")
?>
+</DL>
<H1>CONFIGURATION</H1>
<? local myform = form.config ?>
@@ -55,37 +26,15 @@ informationform(myform,tags)
io.write(html.form[form.config.checkresult.type](form.config.checkresult))
?>
-
-<?
-local cmdform = form.management
-local tags = { "restart" }
-if (cmdform) and (cmdform[tags[1]]) then
-?>
- <form name="management" action="" method="POST">
- <H1>MANAGEMENT</H1>
- <dl>
- <dt><?= cmdform[tags[1]]["label"] ?></dt>
- <dd>
- <? for k,v in pairs(tags) do ?>
- <? if (cmdform[v]) then ?>
- <? io.write(html.form[cmdform[v].type](cmdform[v])) ?>
- <? end ?>
- <? end ?>
- </dd>
-
- <? if (form.cmdmanagement) and (#form.cmdmanagement.descr > 0) then ?>
- <dt>Previous action result</dt>
- <dd><pre><?= form.cmdmanagement.descr ?></pre></dd>
- <? end ?>
- </dl>
- </form>
-
-<? end ?>
-
+<form name="management" action="" method="POST">
<?
---[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
-io.write("</span>")
---]]
+-- Management buttons
+local myform = form.management
+local tags = { "restart" }
+if (myform) then
+ io.write("<H1>MANAGEMENT</H1>\n<DL>")
+ displaymanagement(myform,tags)
+ io.write("</DL>")
+end
?>
+</form>
diff --git a/shorewall-config-html.lsp b/shorewall-config-html.lsp
index 0a54950..80e0e9f 100644
--- a/shorewall-config-html.lsp
+++ b/shorewall-config-html.lsp
@@ -1,58 +1,16 @@
-<? local form = ... ?>
-
-<?
---[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
-io.write("</span>")
---]]
-?>
-
-<?
-function displayinfo(myform,tags,viewtype)
- for k,v in pairs(tags) do
- if (myform[v]) and (myform[v]["value"]) then
- local val = myform[v]
- io.write("\n\t<DT")
- if (#val.errtxt > 0) then
- val.class = "error"
- io.write(" class='error'")
- end
- io.write(">" .. val.label .. "</DT>")
- io.write("\n\t\t<DD>")
- if (viewtype == "viewonly") then
- io.write(val.value)
- elseif (val.type == "radio") and (type(val.option) == "table") and (#val.option > 0) then
- io.write("<span style='display:inline' class='" .. ( val.class or "") .. "'>")
- for k1,v1 in pairs(val.option) do
- io.write(tostring(v1.label) .. ":")
- io.write("<input style='margin-right:20px;margin-left:5px;' type='radio' class='" .. ( val.class or "") .. "' name='" .. val.name .. "'")
- if (tostring(val.value) == tostring(v1.value)) then io.write(" checked='yes'") end
- io.write(" value='" .. v1.value .. "'>")
- end
- io.write("</input></span>")
- else
- io.write(html.form[val.type](val))
- end
- if (val.descr) and (#val.descr > 0) then io.write("\n\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>") end
- if (#val.errtxt > 0) then io.write("\n\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>") end
- io.write("\n\t\t</DD>\n")
- end
- end
-end
+<? local form = ...
+require("viewfunctions")
?>
-
<H1>SYSTEM INFO</H1>
<DL>
<?
local myform = form.status
-local tags = { "status", "version", }
+local tags = { "status", "version", "autostart", }
displayinfo(myform,tags,"viewonly")
?>
</DL>
-
<form name="cmd" action="" method="POST">
<? local myform = form.config ?>
<h1>CONFIGURATION</h1>
@@ -109,11 +67,3 @@ displayinfo(myform,tags)
?>
</dl>
</form>
-
-<?
---[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
-io.write("</span>")
---]]
-?>
diff --git a/shorewall-confirmation-html.lsp b/shorewall-confirmation-html.lsp
index d416763..ba8cef7 100644
--- a/shorewall-confirmation-html.lsp
+++ b/shorewall-confirmation-html.lsp
@@ -1,17 +1,5 @@
<? local view = ... ?>
-<h1>SYSTEM INFO</h1>
-
-<DL>
-<dt>Program status</dt>
-<DD><?= view.status.status ?></DD>
-</DL>
-
-<DL>
-<dt>Program version</dt>
-<dd><?= view.status.version ?></dd>
-</DL>
-
<h1>SECURITY CONFIRMATION</h1>
<h2>Are you sure you want to preform the previous action?</h2>
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,
diff --git a/shorewall-edit-html.lsp b/shorewall-edit-html.lsp
index f1f7a75..6fde10f 100644
--- a/shorewall-edit-html.lsp
+++ b/shorewall-edit-html.lsp
@@ -1,53 +1,13 @@
-<? local form = ... ?>
-<?
---[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
-io.write("</span>")
---]]
+<? local form = ...
+require("viewfunctions")
?>
-<?
-function informationform(myform,tags)
- for k,v in pairs(tags) do
- if (myform[v]) then
- local val = myform[v]
- io.write("\t<DT")
- if (#val.errtxt > 0) then io.write(" class='error'") end
- io.write(">" .. val.label .. "</DT>\n")
-
- io.write("\t\t<DD>" .. val.value .. "\n")
- if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
- if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
- io.write("\t\t</DD>\n")
- end
- end
-end
-?>
-<?
-function configform(myform,tags)
- for k,v in pairs(tags) do
- if (myform[v]) then
- local val = myform[v]
- io.write("\t<DT")
- if (#val.errtxt > 0) then io.write(" class='error'") end
- io.write(">" .. val.label .. "</DT>\n")
-
- io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n")
- if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
- if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
- io.write("\t\t</DD>\n")
- end
- end
-end
-?>
-
<H1>SYSTEM INFO</H1>
<DL>
<?
local myform = form.status
local tags = { "status", "version", "autostart", }
-informationform(myform,tags)
+displayinfo(myform,tags,"viewonly")
?>
</DL>
@@ -60,18 +20,13 @@ informationform(myform,tags)
<H3>FILE DETAILS</H3>
<DL>
<?
-local tags = { "filename", }
-informationform(myform,tags)
+local tags = { "filename","filesize", "mtime", "sumerrors" }
+displayinfo(myform,tags,"viewonly")
?>
+</DL>
<? if (form.config.filecontent) then ?>
-<?
-local tags = { "filesize", "mtime", "sumerrors" }
-informationform(myform,tags)
-?>
-</DL>
-
<H3>FILE CONTENT</H3>
<input type="hidden" value="<?= myform.filename.value ?>" name="<?= myform.filename.name ?>">
<?
@@ -82,43 +37,21 @@ io.write(html.form[form.config.filecontent.type](form.config.filecontent))
<DL>
<?
local tags = { "cmdsave", }
-configform(myform,tags)
+displayinfo(myform,tags)
?>
</DL>
-</form>
<? end ?>
-<?
-local cmdform = form.management
+<?
+-- Management buttons
+local myform = form.management
local tags = { "start", "stop", "restart" }
-if (cmdform) and (cmdform[tags[1]]) then
+if (myform) then
+ io.write("<H1>MANAGEMENT</H1>\n<DL>")
+ displaymanagement(myform,tags)
+ io.write("</DL>")
+end
?>
- <form name="management" action="" method="POST">
- <H1>MANAGEMENT</H1>
- <dl>
- <dt><?= cmdform[tags[1]]["label"] ?></dt>
- <dd>
- <? for k,v in pairs(tags) do ?>
- <? if (cmdform[v]) then ?>
- <? io.write(html.form[cmdform[v].type](cmdform[v])) ?>
- <? end ?>
- <? end ?>
- </dd>
-
- <? if (form.cmdmanagement) and (#form.cmdmanagement.descr > 0) then ?>
- <dt>Previous action result</dt>
- <dd><pre><?= form.cmdmanagement.descr ?></pre></dd>
- <? end ?>
- </dl>
- </form>
-
-<? end ?>
+</form>
-<?
---[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
-io.write("</span>")
---]]
-?>
diff --git a/shorewall-expert-html.lsp b/shorewall-expert-html.lsp
index 0f7126c..cc2242c 100644
--- a/shorewall-expert-html.lsp
+++ b/shorewall-expert-html.lsp
@@ -1,4 +1,6 @@
-<? local form = ... ?>
+<? local form = ...
+require("viewfunctions")
+?>
<?
--[[ DEBUG INFORMATION
io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
@@ -7,31 +9,11 @@ io.write("</span>")
--]]
?>
-<?
-function informationform(myform,tags)
- io.write("<DL>")
- for k,v in pairs(tags) do
- if (myform[v]) then
- local val = myform[v]
- io.write("\t<DT")
- if (#val.errtxt > 0) then io.write(" class='error'") end
- io.write(">" .. val.label .. "</DT>\n")
-
- io.write("\t\t<DD>" .. val.value .. "\n")
- if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
- if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
- io.write("\t\t</DD>\n")
- end
- end
- io.write("</DL>")
-end
-?>
-
<H1>SYSTEM INFO</H1>
<?
local myform = form.status
local tags = { "status", "version", "autostart", }
-informationform(myform,tags)
+displayinfo(myform,tags,"viewonly")
?>
<h1>CONFIGURATION</h1>
@@ -56,11 +38,3 @@ informationform(myform,tags)
</TR>
<? end ?>
</TABLE>
-
-<?
---[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
-io.write("</span>")
---]]
-?>
diff --git a/shorewall-html.lsp b/shorewall-html.lsp
index 7f99407..a875a16 100644
--- a/shorewall-html.lsp
+++ b/shorewall-html.lsp
@@ -1,4 +1,6 @@
-<? local form = ... ?>
+<? local form = ...
+require("viewfunctions")
+?>
<?
--[[ DEBUG INFORMATION
io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
@@ -7,68 +9,16 @@ io.write("</span>")
--]]
?>
-<?
-function displayinfo(myform,tags,viewtype)
- for k,v in pairs(tags) do
- if (myform[v]) and (myform[v]["value"]) then
- local val = myform[v]
- io.write("\n\t<DT")
- if (#val.errtxt > 0) then
- val.class = "error"
- io.write(" class='error'")
- end
- io.write(">" .. val.label .. "</DT>")
- io.write("\n\t\t<DD>")
- if (viewtype == "viewonly") then
- io.write(val.value)
- elseif (val.type == "radio") and (type(val.option) == "table") and (#val.option > 0) then
- io.write("<span style='display:inline' class='" .. ( val.class or "") .. "'>")
- for k1,v1 in pairs(val.option) do
- io.write(tostring(v1.label) .. ":")
- io.write("<input style='margin-right:20px;margin-left:5px;' type='radio' class='" .. ( val.class or "") .. "' name='" .. val.name .. "'")
- if (tostring(val.value) == tostring(v1.value)) then io.write(" checked='yes'") end
- io.write(" value='" .. v1.value .. "'>")
- end
- io.write("</input></span>")
- else
- io.write(html.form[val.type](val))
- end
- if (val.descr) and (#val.descr > 0) then io.write("\n\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>") end
- if (#val.errtxt > 0) then io.write("\n\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>") end
- io.write("\n\t\t</DD>\n")
- end
- end
-end
-?>
-
-<?
-function displayinfo_special(myform)
- for i=1,#myform do
- local v = myform[i]
- if (v) and (v["value"]) then
- io.write("\n\t<DT")
- if (#v.errtxt > 0) then
- v.class = "error"
- io.write(" class='error'")
- end
- io.write(">" .. v.label .. "</DT>")
- io.write("\n\t\t<DD>")
- io.write(html.form[v.type](v))
- if (v.descr) and (#v.descr > 0) then io.write("\n\t\t<P CLASS='descr'>" .. string.gsub(v.descr, "\n", "<BR>") .. "</P>") end
- if (#v.errtxt > 0) then io.write("\n\t\t<P CLASS='error'>" .. string.gsub(v.errtxt, "\n", "<BR>") .. "</P>") end
- io.write("\n\t\t</DD>\n")
- end
- end
-end
-?>
-
<form name="cmd" action="<?= form.option.link ?>/<?= form.option.action ?>" method="POST">
-
<H1>EDIT PROPERTIES</H1>
<DL>
<?
local myform = form.edit
-displayinfo_special(myform)
+local tags = {}
+for i=1,#myform do
+ table.insert(tags,i)
+end
+displayinfo(myform,tags)
?>
<?
@@ -95,12 +45,3 @@ end
</DL>
</form>
-
-<?
---[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
-io.write("</span>")
---]]
-?>
-
diff --git a/shorewall-logfile-html.lsp b/shorewall-logfile-html.lsp
index 04fc548..8bb8560 100644
--- a/shorewall-logfile-html.lsp
+++ b/shorewall-logfile-html.lsp
@@ -1,57 +1,19 @@
-<? local form = ... ?>
+<? local form = ...
+require("viewfunctions")
+?>
<?
--[[ DEBUG INFORMATION
io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
+io.write(html.cfe_unpack(view))
io.write("</span>")
--]]
?>
-<?
-function informationform(myform,tags)
- io.write("<DL>")
- for k,v in pairs(tags) do
- if (myform[v]) then
- local val = myform[v]
- io.write("\t<DT")
- if (#val.errtxt > 0) then io.write(" class='error'") end
- io.write(">" .. val.label .. "</DT>\n")
-
- io.write("\t\t<DD>" .. val.value .. "\n")
- if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
- if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
- io.write("\t\t</DD>\n")
- end
- end
- io.write("</DL>")
-end
-?>
-<?
-function configform(myform,tags)
- io.write("<DL>")
- for k,v in pairs(tags) do
- if (myform[v]) then
- local val = myform[v]
- io.write("\t<DT")
- if (#val.errtxt > 0) then io.write(" class='error'") end
- io.write(">" .. val.label .. "</DT>\n")
-
- io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n")
- if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
- if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
- io.write("\t\t</DD>\n")
- end
- end
- io.write("</DL>")
-end
-?>
-
-
<H1>SYSTEM INFO</H1>
<?
local myform = form.status
local tags = { "status", "version", "autostart", }
-informationform(myform,tags)
+displayinfo(myform,tags,"viewonly")
?>
<H1>LOGIFLES</H1>
@@ -60,44 +22,9 @@ informationform(myform,tags)
<H3>FILE DETAILS</H3>
<?
local tags = { "filename", "filesize", "mtime", "sumerrors" }
-informationform(myform,tags)
+displayinfo(myform,tags,"viewonly")
?>
<H3>FILE CONTENT</H3><?
io.write(html.form[form.config.checkresult.type](form.config.checkresult))
?>
-
-
-<?
-local cmdform = form.management
-local tags = { "start", "stop", "restart" }
-if (cmdform) and (cmdform[tags[1]]) then
-?>
- <form name="management" action="" method="POST">
- <H1>MANAGEMENT</H1>
- <dl>
- <dt><?= cmdform[tags[1]]["label"] ?></dt>
- <dd>
- <? for k,v in pairs(tags) do ?>
- <? if (cmdform[v]) then ?>
- <? io.write(html.form[cmdform[v].type](cmdform[v])) ?>
- <? end ?>
- <? end ?>
- </dd>
-
- <? if (form.cmdmanagement) and (#form.cmdmanagement.descr > 0) then ?>
- <dt>Previous action result</dt>
- <dd><pre><?= form.cmdmanagement.descr ?></pre></dd>
- <? end ?>
- </dl>
- </form>
-
-<? end ?>
-
-<?
---[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
-io.write("</span>")
---]]
-?>
diff --git a/shorewall-model.lua b/shorewall-model.lua
index b12533d..7dee572 100644
--- a/shorewall-model.lua
+++ b/shorewall-model.lua
@@ -1,18 +1,24 @@
module(..., package.seeall)
+-- Load libraries
require("fs")
require("procps")
require("getopts")
require("format")
require("daemoncontrol")
require("validator")
+require("processinfo")
+-- Set variables
local configfile = "/etc/shorewall/shorewall.conf"
local processname = "shorewall"
+local packagename = "shorewall"
local baseurl = "/etc/shorewall/"
-
local config = {}
+-- ################################################################################
+-- LOCAL FUNCTIONS
+
local function getloglevels()
local loglevels = {}
for i=1,8 do
@@ -106,14 +112,7 @@ local function addremove_config( addremove, file, value, orgvalue )
else
return false, cfe({
name="model:addremove_config()",
- errtxt="Record was not deleted!" ..
-"<BR>orgvalue:" .. tostring(orgvalue) ..
-"<BR>modifyrow:" .. tostring(modifyrow) ..
-"<BR>orgrecordtable:" .. table.concat(orgrecordtable, ";") ..
-"<BR>file:" .. tostring(file) ..
-"<BR>filecontentarray:" .. table.concat(filecontentarray, ";") ..
-""
- ,
+ errtxt="Record was not deleted!",
})
end
@@ -169,14 +168,7 @@ local function addremove_config( addremove, file, value, orgvalue )
else
return false, cfe({
name="model:addremove_config()",
- errtxt="Record was not modified!"..
-"<BR>orgvalue:" .. tostring(orgvalue) ..
-"<BR>modifyrow:" .. tostring(modifyrow) ..
-"<BR>orgrecordtable:" .. table.concat(orgrecordtable, ";") ..
-"<BR>file:" .. tostring(file) ..
-"<BR>filecontentarray:" .. table.concat(filecontentarray, ";") ..
-""
-,
+ errtxt="Record was not modified!",
})
end
@@ -195,19 +187,6 @@ local function addremove_config( addremove, file, value, orgvalue )
end
--]]
-local function autostarts()
- local cmd_output_result, cmd_output_error
- local cmd = "/sbin/rc_status | egrep '^S' | egrep '" .. processname .."' 2>/dev/null"
- local f = io.popen( cmd )
- local cmdresult = f:read("*a")
- if (cmdresult) and (#cmdresult > 0) then
- cmd_output_result = "Process will autostart at next boot (at sequence '" .. string.match(cmdresult,"^%a+(%d%d)") .. "')"
- else
- cmd_output_error = "Not programmed to autostart"
- end
- f:close()
- return cmd_output_result,cmd_output_error
-end
-- ################################################################################
-- PUBLIC FUNCTIONS
@@ -276,21 +255,26 @@ end
function getstatus()
local status = {}
- local programversion,programstatus,programstate = getdetails()
+
+ local value, errtxt = processinfo.package_version(packagename)
status.version = cfe({ name = "version",
label="Program version",
- value=programversion,
+ value=value,
+ errtxt=errtxt,
})
+
+ local programversion,programstatus,programstate = getdetails()
status.status = cfe({ name="status",
label="Program status",
value=programstatus,
})
+
status.state = cfe({ name="state",
label="Program reports",
value=programstate,
})
- local autostart_sequense, autostart_errtxt = autostarts()
+ local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname)
status.autostart = cfe({ name="autostart",
label="Autostart sequence",
value=autostart_sequense,
diff --git a/shorewall-status-html.lsp b/shorewall-status-html.lsp
index e6cbd0d..27534fa 100644
--- a/shorewall-status-html.lsp
+++ b/shorewall-status-html.lsp
@@ -1,45 +1,25 @@
-<? local form = ... ?>
-
+<? local form = ...
+require("viewfunctions")
+?>
<?
-function informationform(myform,tags)
- io.write("<DL>")
- for k,v in pairs(tags) do
- if (myform[v]) then
- local val = myform[v]
- io.write("\t<DT")
- if (#val.errtxt > 0) then io.write(" class='error'") end
- io.write(">" .. val.label .. "</DT>\n")
-
- io.write("\t\t<DD>" .. val.value .. "\n")
- if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
- if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
- io.write("\t\t</DD>\n")
- end
- end
- io.write("</DL>")
-end
+--[[ DEBUG INFORMATION
+io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
+io.write(html.cfe_unpack(view))
+io.write("</span>")
+--]]
?>
<H1>SYSTEM INFO</H1>
<?
local myform = form.status
local tags = { "status", "version", "autostart", }
-informationform(myform,tags)
+displayinfo(myform,tags,"viewonly")
?>
<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2>
<?
local myform = form.status
local tags = { "state", }
-informationform(myform,tags)
-?>
-
-
-<?
---[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
-io.write("</span>")
---]]
+displayinfo(myform,tags,"viewonly")
?>