From 37b4a15a9a0e07504188b96567d500085b035b4d Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Fri, 1 Feb 2008 18:14:36 +0000 Subject: Changed shorewall so that it reports/uses cfe's instead! git-svn-id: svn://svn.alpinelinux.org/acf/shorewall/trunk@682 ab2d0c66-481e-0410-8bed-d214d4d58bed --- shorewall-check-html.lsp | 128 +++++++++----- shorewall-controller.lua | 407 ++++++++++++++++++++++++++++++++++++++------- shorewall-edit-html.lsp | 159 ++++++++++++------ shorewall-expert-html.lsp | 64 ++++--- shorewall-logfile-html.lsp | 111 ++++++++++--- shorewall-model.lua | 278 +++++++++++++++++++++++++++++-- shorewall-status-html.lsp | 51 ++++-- 7 files changed, 976 insertions(+), 222 deletions(-) diff --git a/shorewall-check-html.lsp b/shorewall-check-html.lsp index 75f019b..8aee254 100644 --- a/shorewall-check-html.lsp +++ b/shorewall-check-html.lsp @@ -1,49 +1,91 @@ - - -

SYSTEM INFO

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

CONFIGURATION

- -

CHECK CONFIG

- - -

MANAGEMENT

- -
-
Preform check of configs
-
-
- -
-
Program controll-panel
-
- - - -
-
- - -
-
Previous action result
-
-
+ + +") + 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

+ + +

CONFIGURATION

+ + +

CHECK CONFIGURATION

+ + + + +
+

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 8218b4d..27da886 100644 --- a/shorewall-controller.lua +++ b/shorewall-controller.lua @@ -1,95 +1,386 @@ module(..., package.seeall) --- Cause an http redirect to our "read" action --- 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 = "status" self.conf.type = "redir" error (self.conf) end -mvc={} +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 -logfile = function (self) - return ( {status = self.model:getstatus(), logfile = self.model:get_logfile(), url = url } ) +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 displaycmdsave(self) + -- Add a cmd button to the view + local cmdsave = cfe({ name="cmdsave", + label="Save/Apply above settings", + value="Save", + type="submit", + }) + return cmdsave +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) + return { status=getstatus(self) } end -check = function(self) - local check = nil - if (self.clientdata.cmd) then - if self.clientdata.cmd == "stop" then - self.conf.action = "confirmation" - self.conf.type = "redir" +--[=[ +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() + + -- 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 - check = self.model:startstop_service(self.clientdata.cmd) - check = self.clientdata.cmd + 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 - check = self.model:check_config() + disablestop = "yes" end - return ( {status = self.model:getstatus(), - check = check, - previousaction = self.clientdata.cmd, - confirm_url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller .. "/confirmation" } ) + -- 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 + if ( self.clientdata.cmdmanagement) then + cmdmanagement = cfe({ + name="cmdmanagement", + value=string.lower(self.clientdata.cmdmanagement), + }) + cmdmanagementresult, cmdmanagement = self.model:startstop_service( cmdmanagement ) + end -status = function(self) - if self.clientdata.cmd == "check" then - self.conf.action = "check" - self.conf.type = "redir" - error (self.conf) +--[[ + -- Save changes + local modifications = self.clientdata.filecontent or "" + if ( self.clientdata.cmdsave) then + modifications = self.model:updatefilecontent(modifications) end --- if self.clientdata.cmd == "restart" then --- return ( {programstats = self.model:restart_service(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) --- end - return ( {status = self.model:getstatus(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) -end +--]] + + local status = getstatus(self) + 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) + + return { + option={ script=ENV["SCRIPT_NAME"], + prefix=self.conf.prefix, + controller = self.conf.controller, + action = "expert", }, + cmdmanagement = cmdmanagement, + management = management, + config = config, + status = status, + startstop = startstop, + debugclientdata = self.clientdata, + } -expert = function(self) - return ( {status = self.model:getstatus(),filelist = self.model:get_filelist(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) end -edit = function (self) - local name = self.clientdata.name or "" - if (name == "") then - self.conf.action = "status" - self.conf.type = "redir" +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 modifications = self.clientdata.modifications or "" - local cmd = self.clientdata.cmd - local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller - if ( modifications ~= "") then - modifications = self.model:update_filecontent(name,modifications) +--[[ + -- Save changes + local modifications = self.clientdata.filecontent or "" + if ( self.clientdata.cmdsave) then + modifications = self.model:updatefilecontent(modifications) end +--]] + local status = getstatus(self) + local config = self.model:getlogfile() + + + -- Display save button +-- config.cmdsave = displaycmdsave() - if ( cmd ~= nil ) then - startstop = self.model:startstop_service( cmd ) +--[[ + -- 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 - return ( {name=name,startstop = startstop, - status = self.model:getstatus(), - file = self.model:get_filedetails(name), - modifications = modifications, - url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, - confirm_url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller .. "/confirmation", } ) + -- Display management buttons + local management = displaycmdmanagement(disablestart,disablestop,disablerestart) +--]] + + return { + option={ script=ENV["SCRIPT_NAME"], + prefix=self.conf.prefix, + controller = self.conf.controller, + action = "expert", }, + cmdmanagement = cmdmanagement, + management = management, + config = config, + status = status, + startstop = startstop, + debugclientdata = self.clientdata, + } + end -confirmation = function (self) - local confirm = self.clientdata.confirm - if ( confirm ~= nil ) then - startstop = self.model:startstop_service( confirm ) +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 + +--[[ + -- Save changes + local modifications = self.clientdata.filecontent or "" + if ( self.clientdata.cmdsave) then + modifications = self.model:updatefilecontent(modifications) end - return ( {startstop = startstop, - previousaction = self.clientdata.cmd, - status = self.model:getstatus(), - confirm_url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller .. "/confirmation", - url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, } ) +--]] + local status = getstatus(self) + 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, + controller = self.conf.controller, + action = "expert", }, + cmdmanagement = cmdmanagement, + management = management, + config = config, + status = status, + startstop = startstop, + debugclientdata = self.clientdata, + } + 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 + 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 config = self.model:getfiledetails(cfe({ + name="editfile", + value=self.clientdata.name, + })) + + -- 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 = "edit", }, + cmdmanagement = cmdmanagement, + modifications = modifications, + management = management, + config = config, + status = status, + startstop = startstop, + debugclientdata = self.clientdata, + } + +end diff --git a/shorewall-edit-html.lsp b/shorewall-edit-html.lsp index 3e7a472..bc9b409 100644 --- a/shorewall-edit-html.lsp +++ b/shorewall-edit-html.lsp @@ -1,73 +1,122 @@ - - -

SYSTEM INFO

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

CONFIGURATION

+ +DEBUGGING

DEBUG INFO: CFE

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

Expert config

-

File details

+

SYSTEM INFO

+ -
-
File name
-
-
+

CONFIGURATION

+ +
" method="POST"> -
-
File size
-
-
+

EXPERT CONFIGURATION

+

FILE DETAILS

+ -
-
Last modified
-
-
+ -

File content

+ - - - +

FILE CONTENT

+ + -

Save and apply above settings

-
-
Apply settings
-
-
+

SAVE AND APPLY ABOVE SETTINGS

+
-

MANAGEMENT

+ -
-
Program controll-panel
-
- - - -
-
+ +
+

MANAGEMENT

+
+
+
+ + + + + +
+ + 0) then ?> +
Previous action result
+
+ +
+
- -
-
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 2e2c1da..5a27555 100644 --- a/shorewall-expert-html.lsp +++ b/shorewall-expert-html.lsp @@ -1,42 +1,66 @@ - -

SYSTEM INFO

+ +DEBUGGING

DEBUG INFO: CFE

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

Expert config

List of configfiles

+ - - - + + + - + - - - + + +
FileSizeLast ModifiedFileSizeLast Modified
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 f509a1d..e7d32b2 100644 --- a/shorewall-logfile-html.lsp +++ b/shorewall-logfile-html.lsp @@ -1,32 +1,103 @@ - + +DEBUGGING

DEBUG INFO: CFE

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

+

SYSTEM INFO

+ -
-
Program status
-
-
+

LOGIFLES

+

DETAILS

+ +

FILE DETAILS

+ -
-
Program version
-
-
+

FILE CONTENT

-

LOGFILE

-

Details

+ +
+

MANAGEMENT

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

Content

- + DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") --]] ?> diff --git a/shorewall-model.lua b/shorewall-model.lua index fe9c18e..cc6a85f 100644 --- a/shorewall-model.lua +++ b/shorewall-model.lua @@ -1,3 +1,270 @@ +module(..., package.seeall) + +require("fs") +require("procps") +require("getopts") +require("format") +require("daemoncontrol") +require("validator") + +local configfile = "/etc/shorewall/shorewall.conf" +local processname = "shorewall" +local baseurl = "/etc/shorewall/" + +local config = {} + +local function getloglevels() + local loglevels = {} + for i=1,8 do + table.insert(loglevels,i) + end + return loglevels +end + +local function getdetails() + local f,error = io.popen("/sbin/shorewall status") + local fake = f:read("*l") + local fake = f:read("*l") + local programstatus = f:read("*l") or "" + local programstate = f:read("*l") or "" + f:close() + local f,error = io.popen("/sbin/shorewall version") + local programversion = "shorewall-" .. f:read("*l") + f:close() + return programversion,programstatus,programstate +end + +-- ################################################################################ +-- PUBLIC FUNCTIONS + +-- action should be a CFE +function startstop_service ( self, action ) + local cmd = action.value + local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, cmd) + action.descr=cmdmessage + action.errtxt=cmderror + -- Reporting back (true|false, the original acition) + return cmdresult,action + +end + +function getstatus() + local status = {} + local programversion,programstatus,programstate = getdetails() + status.version = cfe({ name = "version", + label="Program version", + value=programversion, + }) + status.status = cfe({ name="status", + label="Program status", + value=programstatus, + }) + status.state = cfe({ name="state", + label="Program reports", + value=programstate, + }) + + return status +end + +function configcheck () + local check = {} + local f,err = io.popen("/bin/echo -n '>> Check starts at: ';/bin/date; /bin/echo; /etc/init.d/shorewall check; /bin/echo; /bin/echo -n '>> Check stops at: '; /bin/date;") + local checkresult = f:read("*a") + f:close() + check.checkresult = cfe({ name = "checkresult", + type="longtext", + label="Result of checking config", + value=checkresult, + }) + return check +end + +function getlogfile () + local logfile = {} + local cmdaction = "cat /var/log/messages | grep Shorewall" + local f, error = io.popen(cmdaction ,r) + local checkresult = f:read("*a") + f:close() + logfile.checkresult = cfe({ name = "checkresult", + type="longtext", + label="Result of logfiles", + value=checkresult, + }) + logfile.filename = cfe({ + name="filename", + label="File name", + value=cmdaction, + }) + return logfile +end + +function getfilelist () + local filepath = baseurl + local listed_files = {} + + local k,v + for name in posix.files(filepath) do + if not string.match(name, "^%.") and not string.match(name, "^Makefile") then + local filedetails = fs.stat(filepath .. name) + table.insert ( listed_files , cfe({name=name, value=filepath .. name, mtime=filedetails.mtime, size=filedetails.size,}) ) + end + end + + table.sort(listed_files, function (a,b) return (a.name < b.name) end ) + + return listed_files +end + +function getfiledetails(self,search) + local file = {} + local path = nil + --Validate filename + local available_files = getfilelist() + for k,v in pairs(available_files) do + if ( tostring(available_files[k]["value"]) == tostring(search.value) ) then + path = tostring(search.value) + end + end + if not (path) or (path == "") then + file["filename"] = search + file["filename"]["label"] = "File name" + file["filename"]["errtxt"] = "Invalid path!" + return file + end + + local filedetails = fs.stat(path) + file["filename"] = cfe({ + name="filename", + label="File name", + value=path, + }) + file["filesize"] = cfe({ + name="filesize", + label="File size", + value=filedetails.size, + }) + file["mtime"] = cfe({ + name="mtime", + label="File name", + value=filedetails.mtime, + }) + file["filecontent"] = cfe({ + type="longtext", + name="filecontent", + label="File content", + value=fs.read_file(path), + }) + + return file +end + + +-- IMPORTANT! This function is a exception! It's not fed with CFE's +-- Parameter should be one of the ones defined in the variable 'variabletranslator'. +-- value should be whatever the new value should be. +function setconfigs(self,parameter,value) + -- Set variables + local variable = "SYSLOGD_OPTS" + local variabletranslator = ({ + logfile = "-O", + loglevel = "-l", + smallerlogs = "-S", + maxsize = "-s", + numrotate = "-b", + localandnetworklog = "-L", + remotelogging = "-R", + }) + cmdparameter = variabletranslator[parameter] + + -- Report a error if someone tryes to use a invalid parameter + if not (cmdparameter) then + local availablevariables = "" + for k,v in pairs(variabletranslator) do + availablevariables = k .. ", " .. availablevariables + end + parameter = parameter or "" + return false, cfe({ + name="syslog.model.setconfigs()", + errtxt="'" .. parameter .. "' is not a valid parameter!\nValid options are: " .. availablevariables, + }) + end + + --TODO: Validate so that user cant add values with '-' (could cause major breakage next time you do getopts) + + -- This config-file only accepts one type of parameters (report error if someone uses wrong parameter) + if not (string.find(cmdparameter, "-%a$")) then + return false, cfe({ + name="syslog.model.setconfigs()", + errtxt="Parameter must be formated '-a' (where a is one upper/lowercase letter [a-z])", + }) + end + + -- Validate userinput (if valid path/filename) + if (value) and (cmdparameter == "-O") then + local cmdresult, cmdmessage = validator.is_valid_filename(value, "/var/log" ) + if not (cmdresult) then + return false, cfe({ + name="syslog.model.setconfigs()", + errtxt=cmdmessage, + }) + end + end + + -- Validate userinput (Has the user entered a valid hostname and/or port) + if (value) and (cmdparameter == "-R") then + local hostport = format.string_to_table(value, ":") + local host = hostport[1] + local port = hostport[2] + if (port) and not (validator.is_port(port)) then + return false, cfe({ + name="syslog.model.setconfigs.getopts.setoptsinfile()", + errtxt="You entered '" .. tostring(port) .. "' as port - This is not valid!", + }) + end + end + + -- Set/Unset checkbox variables + if (value) and ((cmdparameter == "-S") or (cmdparameter == "-L")) then value = "" end + + local cmdresult, cmdmessage, cmderror = getopts.setoptsinfile(configfile,variable,cmdparameter,value) + if (cmderror) then + return false, cfe({ + name="syslog.model.setconfigs.getopts.setoptsinfile()", + errtxt=cmderror, + }) + end + return true, cfe({ + name="syslog.model.setconfigs()", + value=cmdmessage, + }) +end + +-- modifications should be a CFE +function updatefilecontent (self, filetochange) + local path = nil + --Validate filename + local available_files = getfilelist() + for k,v in pairs(available_files) do + if ( tostring(available_files[k]["value"]) == tostring(filetochange.name) ) then + path = tostring(filetochange.name) + end + end + if not (path) then + filetochange.errtxt = "Invalid path!" + return filetochange + end + + local file_result,err = fs.write_file(path, format.dostounix(filetochange.value)) + return file_result, err +end + + + + + +--[===[ + -- shorewall model methods module (..., package.seeall) require("format") @@ -13,15 +280,6 @@ function startstop_service ( self, state ) return daemoncontrol.daemoncontrol("shorewall", state) end -function check_config () - check = nil - check = {} - local f,err = io.popen("/bin/echo -n '>> Check starts at: ';/bin/date; /bin/echo; /etc/init.d/shorewall check; /bin/echo; /bin/echo -n '>> Check stops at: '; /bin/date;") - check.result = f:read("*a") - f:close() - check["error"]=err - return check -end function getstatus () local f,error = io.popen("/sbin/shorewall status") @@ -91,4 +349,4 @@ function update_filecontent (self, name, modifications) end return name, file_content end - +--]===] diff --git a/shorewall-status-html.lsp b/shorewall-status-html.lsp index 12b2a98..2dc6a2c 100644 --- a/shorewall-status-html.lsp +++ b/shorewall-status-html.lsp @@ -1,26 +1,45 @@ - + -

SYSTEM INFO

+") + 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") -
-
Program status
-
-
+ 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 +?> -
-
Program version
-
-
+

SYSTEM INFO

+

PROGRAM SPECIFIC OPTIONS/INFORMATION

-
-
Program reports
-
-
+ + DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") --]] ?> + -- cgit v1.2.3