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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
module(..., package.seeall)
local list_redir = function(self)
self.conf.action = "read"
self.conf.type = "redir"
error(self.conf)
end
mvc={}
mvc.on_load = function(self, parent)
--TODO: This needs to be looked at
self.cfgfile = self:soft_require("cfgfile-model")
setmetatable(self.cfgfile, self.cfgfile)
self.cfgfile.__index = self.worker
if (self.worker[self.conf.action] == nil) or (self.conf.action == "init") then
self.worker[self.conf.action] = list_redir(self)
end
end
-- Public methods
-- <prefix>/hostname/get
read = function(self)
return {
list=self.cfgfile:list("firewall"),
script=ENV["SCRIPT_NAME"],
prefix=self.conf.prefix,
controller=self.conf.controller,
action="update",
}
end
update = function(self)
local id = tonumber(self.clientdata.id) or -1
local result
local data
result, data = self.cfgfile:get(id)
if not result then return list_redir(self) end
if self.clientdata.cmd then
for k,v in pairs (data) do
if self.clientdata[k] then
data[k].value = self.clientdata[k]
end
end
result, data = self.cfgfile:set(id, data)
if result then return list_redir(self) end
end
data.cmd = cfe { type="action", value="save", label="action" }
return cfe{ type="form",
option={ script=ENV["SCRIPT_NAME"],
prefix=self.conf.prefix,
controller = self.conf.controller,
action = "update",
extra = ""},
value = data}
end
--This is a work in progress, do not review
local function mkCtlRet(self)
return {
script=ENV["SCRIPT_NAME"],
prefix=self.conf.prefix,
controller = self.conf.controller,
action={
{ name="restart", label="Restart" },
{ name="start", label="Start" },
{ name="stop", label="Stop" },
{ name="reload", label="Reload", disabled=true },
},
title="Shorewall",
text={}
}
end
restart = function(self)
ret = mkCtlRet(self)
if self.clientdata.restart then
ret.active = "restart"
local f = io.popen("/etc/init.d/shorewall restart", "r")
if f then
local out = f:read("*a")
f:close()
ret.text[#ret.text + 1] = { label="Restarting", content=out }
else
ret.text[#ret.text + 1] = {
label="Error", content="Cannot run /etc/init.d/shorewall"
}
end
end
return ret
end
--create = update
--delete = update
|