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
62
63
64
65
66
67
68
69
70
71
72
73
74
|
local mymodule = {}
-- Load libraries
modelfunctions = require("modelfunctions")
fs = require("acf.fs")
format = require("acf.format")
-- Set variables
local configfile = "/etc/shorewall/shorewall.conf"
local processname = "shorewall"
local packagename = "shorewall-shell"
local baseurl = "/etc/shorewall/"
-- ################################################################################
-- PUBLIC FUNCTIONS
function mymodule.getstatus()
return modelfunctions.getstatus(processname, packagename, "Shorewall Status")
end
function mymodule.getstatusdetails()
local programstate, errtxt = modelfunctions.run_executable({"shorewall", "status"}, true)
return cfe({ value=programstate, label="Shorewall status report", errtxt=errtxt })
end
function mymodule.get_startstop(self, clientdata)
return modelfunctions.get_startstop(processname)
end
function mymodule.startstop_service(self, startstop, action)
return modelfunctions.startstop_service(startstop, action)
end
function mymodule.getlogfile ()
local logfilepath = format.parse_ini_file(fs.read_file(configfile) or "","","LOGFILE") or ""
return cfe({ value=logfilepath, label="Shorewall logfile" })
end
function mymodule.getfilelist ()
local listed_files = {}
if fs.is_dir(baseurl) then
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
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
local function is_valid_filename(filename)
local available_files = mymodule.getfilelist()
for i,file in ipairs(available_files.value) do
if file.filename == filename then
return true
end
end
return false
end
function mymodule.getfiledetails(filename)
return modelfunctions.getfiledetails(filename, is_valid_filename)
end
function mymodule.updatefiledetails(self, filedetails)
return modelfunctions.setfiledetails(self, filedetails, is_valid_filename)
end
return mymodule
|