summaryrefslogtreecommitdiffstats
path: root/shorewall-model.lua
blob: ce436c4ecfd0d7a24b1a050d3e3f9f0bb3e371e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
-- shorewall model methods
module (..., package.seeall)

local function file_info ( path )
	require("posix")
	modfiledetails = {}
	local filedetails = posix.stat(path)	
	filedetails["owner"]=rawget((posix.getgroup(filedetails["uid"])),"1")
	filedetails["group"]=rawget((posix.getgroup(filedetails["gid"])),"name")
	filedetails["atimelong"]=os.date("%c", filedetails["atime"])
	filedetails["mtimelong"]=os.date("%c", filedetails["mtime"])
	filedetails["longname"]=path

	return filedetails
end

-- ################################################################################
-- PUBLIC FUNCTIONS

function get_status ()
	local f,error = io.popen("/sbin/shorewall status")
	local fake = f:read("*l")
	local fake = f:read("*l")
	local programstatus = f:read("*l")
	local programstate = f:read("*l")
	f:close()
	local f,error = io.popen("/sbin/shorewall version")
	local programversion = f:read("*l")
	f:close()
	return {programversion=programversion,programstatus=programstatus,programstate=programstate}
end


function get_filelist ()
	local filepath = "/etc/shorewall/"
	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 = file_info(filepath .. name)
			table.insert ( listed_files , {name=name, longname=filepath .. name, filedetails=filedetails} )
		end
	end
	return listed_files
end

function get_filecontent (self, name)
	local path = "/etc/shorewall/" .. name
	local available_files = get_filelist()
	for k,v in pairs(available_files) do
		if ( available_files[k].name == name ) then
			local file = io.open( path )
			local file_result = file:read("*a") or "unknown"
			file:close()
			local filedetails = file_info(path)
			file_content = cfe{name=name, value=file_result, filedetails=filedetails}
		end
	end
	return file_content
end