From 73433bf9ea9a0f7f56203bafa111821bb47856cf Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Tue, 4 Mar 2008 08:49:41 +0000 Subject: Added the missing (example)-page. Added functionallity so that the page has live data git-svn-id: svn://svn.alpinelinux.org/acf/shorewall/trunk@799 ab2d0c66-481e-0410-8bed-d214d4d58bed --- shorewall-check-html.lsp | 2 +- shorewall-config-html.lsp | 141 ++++++++++++++++++++++++++ shorewall-controller.lua | 245 +++++++--------------------------------------- shorewall-model.lua | 30 +++++- 4 files changed, 204 insertions(+), 214 deletions(-) create mode 100644 shorewall-config-html.lsp diff --git a/shorewall-check-html.lsp b/shorewall-check-html.lsp index 8aee254..38d788b 100644 --- a/shorewall-check-html.lsp +++ b/shorewall-check-html.lsp @@ -58,7 +58,7 @@ io.write(html.form[form.config.checkresult.type](form.config.checkresult))
diff --git a/shorewall-config-html.lsp b/shorewall-config-html.lsp new file mode 100644 index 0000000..3523ed6 --- /dev/null +++ b/shorewall-config-html.lsp @@ -0,0 +1,141 @@ + + +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

+ + +

Advanced configuration

+

Parameters

+
+ +
+ +

Interfaces

+
+ +
+ + + +

Defince zones

+
+ +
+ +

Default policies

+
+ +
+ +

Rules

+
+ +
+ +
+ + + +
+

MANAGEMENT

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

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> diff --git a/shorewall-controller.lua b/shorewall-controller.lua index efcaa65..b2bc2bb 100644 --- a/shorewall-controller.lua +++ b/shorewall-controller.lua @@ -13,16 +13,6 @@ 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 = {} @@ -63,18 +53,36 @@ local function displaycmdsave(self) end function status(self) - return { status=getstatus(self) } + return { status=self.model.getstatus() } end function config(self) local config=self.model:getconfig() - local status=getstatus(self) + local status=self.model.getstatus() + + -- Redirect if button is pressed + if (self.clientdata.params_list_cmd) then + self.conf.action = "edit_params" + self.conf.type = "redir" + error (self.conf) + end -- Add a [New] record to the options table.insert(config.interfaces_list.option, "[New]") table.insert(config.zones_list.option, "[New]") table.insert(config.policies_list.option, "[New]") table.insert(config.rules_list.option, "[New]") + table.insert(config.params_list.option, "[New]") + + -- Add button + config.params_list_cmd = cfe ({ + name="params_list_cmd", + label="Edit above record", + value="Edit", + type="submit", +-- disabled="yes", + }) + config.params_list_cmd.descr="Mark a item in above list before pressing [" .. config.params_list_cmd.value .. "]" -- Add button config.interfaces_list_cmd = cfe ({ @@ -104,7 +112,7 @@ function config(self) type="submit", disabled="yes", }) - config.zones_list_cmd.descr="Mark a item in above list before pressing [" .. config.zones_list_cmd.value .. "]" + config.policies_list_cmd.descr="Mark a item in above list before pressing [" .. config.policies_list_cmd.value .. "]" -- Add button config.rules_list_cmd = cfe ({ @@ -114,7 +122,7 @@ function config(self) type="submit", disabled="yes", }) - config.zones_list_cmd.descr="Mark a item in above list before pressing [" .. config.zones_list_cmd.value .. "]" + config.rules_list_cmd.descr="Mark a item in above list before pressing [" .. config.rules_list_cmd.value .. "]" -- Management buttons -- Display management buttons @@ -125,77 +133,10 @@ function config(self) config=config, management = management, - } -end - ---[=[ -function config(self) - local cmdmanagement, cmdmanagementresult - local cmdsavereply = {} - local cmdsaveresult = {} - if ( self.clientdata.cmdmanagement) then - cmdmanagement = cfe({ - name="cmdmanagement", - value=string.lower(self.clientdata.cmdmanagement), - }) - cmdmanagementresult, cmdmanagement = self.model:startstop_service( cmdmanagement ) - end - if ( self.clientdata.cmdsave) then - local variables="logfile loglevel smallerlogs maxsize numrotate localandnetworklog remotelogging" -- Advanced-config options --- local variables="remotelogging" -- Guided-config options - for var in string.gmatch(variables, "%S+") do - -- Send nil instead of "" causes the parameter to be removed/deleted/empty/unset the variable in the config-file - if (self.clientdata[var] == "") then self.clientdata[var] = nil end - cmdsaveresult[var], cmdsavereply[var] = self.model:setconfigs( var,self.clientdata[var] ) - end - end - - local status = getstatus(self) - local config = self.model.getconfig() + clientdata=clientdata, - -- Write out erros from previous cmdsave actions - for k,v in pairs(cmdsaveresult) do - if not (v) then - config[k]["errtxt"] = tostring(cmdsavereply[k]["errtxt"]) - end - end - - -- Display save button - config.cmdsave = displaycmdsave() - - -- 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 - -- Disable management buttons if there exist errors in the config - for k,v in pairs(config) do - if (config[k]["errtxt"] ~= "") then - disablestart = "yes" - disablestop = "yes" - disablerestart = "yes" - break - end - end - -- Display management buttons - local management = displaycmdmanagement(disablestart,disablestop,disablerestart) - - return { - option={ script=ENV["SCRIPT_NAME"], - prefix=self.conf.prefix, - controller = self.conf.controller, - action = "config", }, - status = status, - cmdmanagement = cmdmanagement, - management = management, - config = config, - debugclientdata = self.clientdata, } end ---]=] function check(self) local cmdmanagement, cmdmanagementresult @@ -207,40 +148,9 @@ function check(self) cmdmanagementresult, cmdmanagement = self.model:startstop_service( cmdmanagement ) end ---[[ - -- Save changes - local modifications = self.clientdata.filecontent or "" - if ( self.clientdata.cmdsave) then - modifications = self.model:updatefilecontent(modifications) - end ---]] - - local status = getstatus(self) + local status = self.model.getstatus() local config = self.model:configcheck() - - -- Display save button --- config.cmdsave = displaycmdsave() - ---[[ - -- 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 - -- Disable management buttons if there exist errors in the config - for k,v in pairs(config) do - if (config[k]["errtxt"] ~= "") then - disablestart = "yes" - disablestop = "yes" - disablerestart = "yes" - break - end - end ---]] -- Display management buttons local management = displaycmdmanagement(disablestart,disablestop,disablerestart) @@ -269,43 +179,9 @@ function logfile(self) cmdmanagementresult, cmdmanagement = self.model:startstop_service( cmdmanagement ) end ---[[ - -- Save changes - local modifications = self.clientdata.filecontent or "" - if ( self.clientdata.cmdsave) then - modifications = self.model:updatefilecontent(modifications) - end ---]] - local status = getstatus(self) + local status = self.model.getstatus() local config = self.model:getlogfile() - - -- Display save button --- config.cmdsave = displaycmdsave() - ---[[ - -- 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 - -- Disable management buttons if there exist errors in the config - for k,v in pairs(config) do - if (config[k]["errtxt"] ~= "") then - disablestart = "yes" - disablestop = "yes" - disablerestart = "yes" - break - end - end - - -- Display management buttons - local management = displaycmdmanagement(disablestart,disablestop,disablerestart) ---]] - return { option={ script=ENV["SCRIPT_NAME"], prefix=self.conf.prefix, @@ -331,43 +207,9 @@ function expert(self) cmdmanagementresult, cmdmanagement = self.model:startstop_service( cmdmanagement ) end ---[[ - -- Save changes - local modifications = self.clientdata.filecontent or "" - if ( self.clientdata.cmdsave) then - modifications = self.model:updatefilecontent(modifications) - end ---]] - local status = getstatus(self) + local status = self.model.getstatus() local config = self.model:getfilelist() - - -- Display save button --- config.cmdsave = displaycmdsave() - ---[[ - -- 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 - -- Disable management buttons if there exist errors in the config - for k,v in pairs(config) do - if (config[k]["errtxt"] ~= "") then - disablestart = "yes" - disablestop = "yes" - disablerestart = "yes" - break - end - end - - -- Display management buttons - local management = displaycmdmanagement(disablestart,disablestop,disablerestart) ---]] - return { option={ script=ENV["SCRIPT_NAME"], prefix=self.conf.prefix, @@ -393,15 +235,14 @@ function edit(self) cmdmanagementresult, cmdmanagement = self.model:startstop_service( cmdmanagement ) end ----[[ -- Save changes if ( self.clientdata.cmdsave) then local filetochange = cfe ({ name=self.clientdata.filename, value=self.clientdata.filecontent, }) modifications = self.model:updatefilecontent(filetochange) self.clientdata.name = self.clientdata.filename end ---]] - local status = getstatus(self) + + local status = self.model.getstatus() local config = self.model:getfiledetails(cfe({ name="editfile", value=self.clientdata.name, @@ -410,28 +251,6 @@ function edit(self) -- Display save button config.cmdsave = displaycmdsave() ---[[ - -- 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 - -- Disable management buttons if there exist errors in the config - for k,v in pairs(config) do - if (config[k]["errtxt"] ~= "") then - disablestart = "yes" - disablestop = "yes" - disablerestart = "yes" - break - end - end - - -- Display management buttons - local management = displaycmdmanagement(disablestart,disablestop,disablerestart) ---]] return { option={ script=ENV["SCRIPT_NAME"], @@ -448,3 +267,11 @@ function edit(self) } end + +function edit_params(self) + + + return { + status=status, + } +end diff --git a/shorewall-model.lua b/shorewall-model.lua index cecf0a1..081f842 100644 --- a/shorewall-model.lua +++ b/shorewall-model.lua @@ -34,6 +34,20 @@ local function getdetails() return programversion,programstatus,programstate end +local function read_config(file) + local path = baseurl .. file + if not (fs.is_file(path)) then + return {} + end + local filecontent = fs.read_file_as_array(path) + local output = {} + for k,v in pairs(filecontent) do + if not string.find ( v, "^[;#].*" ) then + table.insert(output, v) + end + end + return output +end -- ################################################################################ -- PUBLIC FUNCTIONS @@ -51,11 +65,19 @@ end function getconfig() local config = {} + config.params_list = cfe({ + name = "params_list", + label="List of parameters", + type="select", + option=read_config("params"), + }) + config.params_list.size=#config.params_list.option + 1 + config.interfaces_list = cfe({ name = "interfaces_list", label="List of interfaces", type="select", - option={"BRN", "DMZ", "REZ", } + option=read_config("interfaces"), }) config.interfaces_list.size=#config.interfaces_list.option + 1 @@ -63,7 +85,7 @@ function getconfig() name = "zones_list", label="List of zones", type="select", - option={"BRN", "DMZ", "REZ", } + option=read_config("zones"), }) config.zones_list.size=#config.zones_list.option + 1 @@ -71,7 +93,7 @@ function getconfig() name = "policies_list", label="List of policies", type="select", - option={"ACCET BRN FW", } + option=read_config("policy"), }) config.policies_list.size=#config.policies_list.option + 1 @@ -79,7 +101,7 @@ function getconfig() name = "rules_list", label="List of rules", type="select", - option={"ACCET BRN FW", } + option=read_config("rules"), }) config.rules_list.size=#config.rules_list.option + 1 -- cgit v1.2.3