summaryrefslogtreecommitdiffstats
path: root/shorewall-model.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-09-22 20:58:06 +0000
committerTed Trask <ttrask01@yahoo.com>2008-09-22 20:58:06 +0000
commitca8952c1a3f5107563020604585ada9f6b088860 (patch)
tree637a8fbe876a688ad45b1b619f24947b3824a1cb /shorewall-model.lua
parent3f3cf113c69e8fc334ae6c12559a2e5ec8406a0b (diff)
downloadacf-shorewall-ca8952c1a3f5107563020604585ada9f6b088860.tar.bz2
acf-shorewall-ca8952c1a3f5107563020604585ada9f6b088860.tar.xz
Rewrite of shorewall to use new libraries, ... Moved statusbasic to status, status to details, expert to listfiles. Changed check to not have a page. Used links for status, edit, startstop. Didn't change config, so it still doesn't work.
git-svn-id: svn://svn.alpinelinux.org/acf/shorewall/trunk@1480 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'shorewall-model.lua')
-rw-r--r--shorewall-model.lua261
1 files changed, 76 insertions, 185 deletions
diff --git a/shorewall-model.lua b/shorewall-model.lua
index a8627c7..53e56d7 100644
--- a/shorewall-model.lua
+++ b/shorewall-model.lua
@@ -1,45 +1,21 @@
module(..., package.seeall)
-- Load libraries
+require("modelfunctions")
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
- 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
-
local function read_config(file)
local path = baseurl .. file
if not (fs.is_file(path)) then
@@ -59,7 +35,6 @@ local function read_config(file)
return output
end
----[[
local function addremove_config( addremove, file, value, orgvalue )
filepath = baseurl .. file
local cmdoutput
@@ -195,13 +170,81 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
-function modify_config(self, addremove, file, value, orgvalue )
- return addremove_config(addremove, file, value, orgvalue )
+function getstatus()
+ local status = modelfunctions.getstatus(processname, packagename, "Shorewall Status")
+ local details = getstatusdetails()
+ if string.match(details.value, "Shorewall is running") then
+ status.value.status.value = "Enabled"
+ end
+ return status
+end
+
+function getstatusdetails()
+ local f = io.popen("/sbin/shorewall status")
+ local programstate = f:read("*a") or ""
+ f:close()
+ return cfe({ value=programstate, label="Shorewall status report" })
+end
+
+function startstop_service(action)
+ return modelfunctions.startstop_service(processname, action)
+end
+
+function configcheck ()
+ local f = 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()
+ return cfe({ type="longtext", value=checkresult, label="Result of checking config" })
+end
+
+function getlogfile ()
+ local logfilepath = getopts.getoptsfromfile(configfile,"","LOGFILE") or ""
+ return cfe({ value=logfilepath, label="Shorewall logfile" })
+end
+
+function getfilelist ()
+ local listed_files = {}
+
+ for name in posix.files(baseurl) do
+ if not string.match(name, "^%.") and not string.match(name, "^Makefile") then
+ local filedetails = fs.stat(baseurl .. name)
+ table.insert ( listed_files , {filename=baseurl..name, mtime=filedetails.mtime, filesize=filedetails.size} )
+ end
+ end
+
+ table.sort(listed_files, function (a,b) return (a.filename < b.filename) end )
+
+ return cfe({ type="list", value=listed_files, label="Shorewall File List" })
+end
+
+function getfiledetails(filename)
+ --Validate filename
+ local available_files = getfilelist()
+ for i,file in ipairs(available_files.value) do
+ if file.filename == filename then
+ return modelfunctions.getfiledetails(filename)
+ end
+ end
+ local retval = modelfunctions.getfiledetails("")
+ retval.value.filename.value = filename
+ return retval
end
-function startstop_service ( self, action )
- local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, action)
- return cfe({ type="boolean", value=cmdresult, descr=cmdmessage, errtxt=cmderror, label=action.." result" })
+function updatefiledetails (filedetails)
+ local available_files = getfilelist()
+ for i,file in ipairs(available_files.value) do
+ if file.filename == filedetails.value.filename.value then
+ return modelfunctions.setfiledetails(filedetails)
+ end
+ end
+ filedetails.value.filename.errtxt = "Invalid Filename"
+ filedetails.errtxt = "Failed to save file"
+ return filedetails
+end
+
+--[[
+function modify_config(self, addremove, file, value, orgvalue )
+ return addremove_config(addremove, file, value, orgvalue )
end
function getconfig()
@@ -257,57 +300,6 @@ function getconfig()
end
-function getversion()
- local value, errtxt = processinfo.package_version(packagename)
- local version = cfe({ name = "version",
- label="Program version",
- value=value,
- errtxt=errtxt,
- })
- return version
-end
-function getautostart()
- local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname)
- local autostart = cfe({ name="autostart",
- label="Autostart sequence",
- value=autostart_sequense,
- errtxt=autostart_errtxt,
- })
- return autostart
-end
-
-function getstatus()
- local programversion,programstatus,programstate = getdetails()
- local status = cfe({ name="status",
- label="Program status",
- value=programstatus,
- })
- return status
-end
-function getstatusdetails()
- local details = {}
- local programversion,programstatus,programstate = getdetails()
- details.state = cfe({ name="state",
- label="Program reports",
- value=programstate,
- })
- return details
-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 get_defined_zones ()
local output = {}
for k,v in pairs(read_config("zones")) do
@@ -315,105 +307,4 @@ function get_defined_zones ()
end
return output
end
-
-function getlogfile ()
- local logfile = {}
- local logfilepath = getopts.getoptsfromfile(configfile,"","LOGFILE") or ""
- local cmdaction = "grep Shorewall " .. logfilepath
- 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
-
--- 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 false, filetochange
- end
-
- local file_result,err = fs.write_file(path, format.dostounix(filetochange.value))
- return true
-end
-
-
-
+--]]