From be8a05d0e4ae337d2cee99c3197f6ef5bf5c5779 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Tue, 8 Apr 2008 15:13:38 +0000 Subject: Cleaning up code. git-svn-id: svn://svn.alpinelinux.org/acf/shorewall/trunk@961 ab2d0c66-481e-0410-8bed-d214d4d58bed --- shorewall-check-html.lsp | 91 +++++++++---------------------------- shorewall-config-html.lsp | 56 ++--------------------- shorewall-confirmation-html.lsp | 12 ----- shorewall-controller.lua | 98 +++++++++++++++++----------------------- shorewall-edit-html.lsp | 99 +++++++---------------------------------- shorewall-expert-html.lsp | 34 ++------------ shorewall-html.lsp | 75 ++++--------------------------- shorewall-logfile-html.lsp | 85 +++-------------------------------- shorewall-model.lua | 50 +++++++-------------- shorewall-status-html.lsp | 40 +++++------------ 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 @@ - - -") - for k,v in pairs(tags) do - if (myform[v]) then - local val = myform[v] - io.write("\t 0) then io.write(" class='error'") end - io.write(">" .. val.label .. "\n") - - io.write("\t\t
" .. val.value .. "\n") - if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end - if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end - io.write("\t\t
\n") - end - end - io.write("") -end + ") - for k,v in pairs(tags) do - if (myform[v]) then - local val = myform[v] - io.write("\t 0) then io.write(" class='error'") end - io.write(">" .. val.label .. "\n") - - io.write("\t\t
" .. html.form[val.type](val) .. "\n") - if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end - if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end - io.write("\t\t
\n") - end - end - io.write("") -end +--[[ DEBUG INFORMATION +io.write("

DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(view)) +io.write("
") +--]] ?> -

SYSTEM INFO

+
+

CONFIGURATION

@@ -55,37 +26,15 @@ informationform(myform,tags) io.write(html.form[form.config.checkresult.type](form.config.checkresult)) ?> - - -
-

MANAGEMENT

-
-
-
- - - - - -
- - 0) then ?> -
Previous action result
-
- -
-
- - - +
DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] +-- Management buttons +local myform = form.management +local tags = { "restart" } +if (myform) then + io.write("

MANAGEMENT

\n
") + displaymanagement(myform,tags) + io.write("
") +end ?> +
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 @@ - - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> - - 0) then - val.class = "error" - io.write(" class='error'") - end - io.write(">" .. val.label .. "") - io.write("\n\t\t
") - if (viewtype == "viewonly") then - io.write(val.value) - elseif (val.type == "radio") and (type(val.option) == "table") and (#val.option > 0) then - io.write("") - for k1,v1 in pairs(val.option) do - io.write(tostring(v1.label) .. ":") - io.write("") - end - io.write("") - else - io.write(html.form[val.type](val)) - end - if (val.descr) and (#val.descr > 0) then io.write("\n\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

") end - if (#val.errtxt > 0) then io.write("\n\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

") end - io.write("\n\t\t
\n") - end - end -end + -

SYSTEM INFO

-

CONFIGURATION

@@ -109,11 +67,3 @@ displayinfo(myform,tags) ?>
- -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> 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 @@ -

SYSTEM INFO

- -
-
Program status
-
-
- -
-
Program version
-
-
-

SECURITY CONFIRMATION

Are you sure you want to preform the previous action?

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
 ... 
in BLACK text + errtxt="", --Content of this variable is displayed as
 ... 
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 @@ - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] + - 0) then io.write(" class='error'") end - io.write(">" .. val.label .. "\n") - - io.write("\t\t
" .. val.value .. "\n") - if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end - if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end - io.write("\t\t
\n") - end - end -end -?> - 0) then io.write(" class='error'") end - io.write(">" .. val.label .. "\n") - - io.write("\t\t
" .. html.form[val.type](val) .. "\n") - if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end - if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end - io.write("\t\t
\n") - end - end -end -?> -

SYSTEM INFO

@@ -60,18 +20,13 @@ informationform(myform,tags)

FILE DETAILS

+
- - -

FILE CONTENT

- -MANAGEMENT\n
") + displaymanagement(myform,tags) + io.write("
") +end ?> -
-

MANAGEMENT

-
-
-
- - - - - -
- - 0) then ?> -
Previous action result
-
- -
-
- - + -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> 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 @@ - + DEBUGGING

DEBUG INFO: CFE

") @@ -7,31 +9,11 @@ io.write("
") --]] ?> -") - for k,v in pairs(tags) do - if (myform[v]) then - local val = myform[v] - io.write("\t 0) then io.write(" class='error'") end - io.write(">" .. val.label .. "\n") - - io.write("\t\t
" .. val.value .. "\n") - if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end - if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end - io.write("\t\t
\n") - end - end - io.write("") -end -?> -

SYSTEM INFO

CONFIGURATION

@@ -56,11 +38,3 @@ informationform(myform,tags) - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> 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 @@ - + DEBUGGING

DEBUG INFO: CFE

") @@ -7,68 +9,16 @@ io.write("
") --]] ?> - 0) then - val.class = "error" - io.write(" class='error'") - end - io.write(">" .. val.label .. "") - io.write("\n\t\t
") - if (viewtype == "viewonly") then - io.write(val.value) - elseif (val.type == "radio") and (type(val.option) == "table") and (#val.option > 0) then - io.write("") - for k1,v1 in pairs(val.option) do - io.write(tostring(v1.label) .. ":") - io.write("") - end - io.write("") - else - io.write(html.form[val.type](val)) - end - if (val.descr) and (#val.descr > 0) then io.write("\n\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

") end - if (#val.errtxt > 0) then io.write("\n\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

") end - io.write("\n\t\t
\n") - end - end -end -?> - - 0) then - v.class = "error" - io.write(" class='error'") - end - io.write(">" .. v.label .. "") - io.write("\n\t\t
") - io.write(html.form[v.type](v)) - if (v.descr) and (#v.descr > 0) then io.write("\n\t\t

" .. string.gsub(v.descr, "\n", "
") .. "

") end - if (#v.errtxt > 0) then io.write("\n\t\t

" .. string.gsub(v.errtxt, "\n", "
") .. "

") end - io.write("\n\t\t
\n") - end - end -end -?> -
-

EDIT PROPERTIES

- -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> - 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 @@ - + DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) +io.write(html.cfe_unpack(view)) io.write("
") --]] ?> -") - for k,v in pairs(tags) do - if (myform[v]) then - local val = myform[v] - io.write("\t 0) then io.write(" class='error'") end - io.write(">" .. val.label .. "\n") - - io.write("\t\t
" .. val.value .. "\n") - if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end - if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end - io.write("\t\t
\n") - end - end - io.write("
") -end -?> -") - for k,v in pairs(tags) do - if (myform[v]) then - local val = myform[v] - io.write("\t 0) then io.write(" class='error'") end - io.write(">" .. val.label .. "\n") - - io.write("\t\t
" .. html.form[val.type](val) .. "\n") - if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end - if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end - io.write("\t\t
\n") - end - end - io.write("") -end -?> - -

SYSTEM INFO

LOGIFLES

@@ -60,44 +22,9 @@ informationform(myform,tags)

FILE DETAILS

FILE CONTENT

- - - -
-

MANAGEMENT

-
-
-
- - - - - -
- - 0) then ?> -
Previous action result
-
- -
-
- - - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> 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!" .. -"
orgvalue:" .. tostring(orgvalue) .. -"
modifyrow:" .. tostring(modifyrow) .. -"
orgrecordtable:" .. table.concat(orgrecordtable, ";") .. -"
file:" .. tostring(file) .. -"
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!".. -"
orgvalue:" .. tostring(orgvalue) .. -"
modifyrow:" .. tostring(modifyrow) .. -"
orgrecordtable:" .. table.concat(orgrecordtable, ";") .. -"
file:" .. tostring(file) .. -"
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 @@ - - + ") - for k,v in pairs(tags) do - if (myform[v]) then - local val = myform[v] - io.write("\t 0) then io.write(" class='error'") end - io.write(">" .. val.label .. "\n") - - io.write("\t\t
" .. val.value .. "\n") - if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end - if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end - io.write("\t\t
\n") - end - end - io.write("") -end +--[[ DEBUG INFORMATION +io.write("

DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(view)) +io.write("
") +--]] ?>

SYSTEM INFO

PROGRAM SPECIFIC OPTIONS/INFORMATION

- - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] +displayinfo(myform,tags,"viewonly") ?> -- cgit v1.2.3