summaryrefslogtreecommitdiffstats
path: root/shorewall-controller.lua
diff options
context:
space:
mode:
authorAlexander Poslavsky <alexander.poslavsky@gmail.com>2007-11-02 09:24:00 +0000
committerAlexander Poslavsky <alexander.poslavsky@gmail.com>2007-11-02 09:24:00 +0000
commit1f2bc0676beae8672512edc37fff46a5e76b02a2 (patch)
tree4a7d66914a0954a5c449a040d9e5712087048f97 /shorewall-controller.lua
parent2f6b7570cdf277f1c3889464fd7705b089e1eac4 (diff)
downloadacf-shorewall-1f2bc0676beae8672512edc37fff46a5e76b02a2.tar.bz2
acf-shorewall-1f2bc0676beae8672512edc37fff46a5e76b02a2.tar.xz
trying to get shorewall to install+status indicator
git-svn-id: svn://svn.alpinelinux.org/acf/shorewall/trunk@251 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'shorewall-controller.lua')
-rw-r--r--shorewall-controller.lua117
1 files changed, 117 insertions, 0 deletions
diff --git a/shorewall-controller.lua b/shorewall-controller.lua
new file mode 100644
index 0000000..1c87fbe
--- /dev/null
+++ b/shorewall-controller.lua
@@ -0,0 +1,117 @@
+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
+ --there has to be cute, standard way of loading models into controller
+ self.cfgfile = self:soft_require("cfgfile-model")
+ setmetatable(self.cfgfile, self.cfgfile)
+ self.cfgfile.__index = self.worker
+ self.service = self:soft_require("service-model")
+ setmetatable(self.service, self.service)
+ self.service.__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
+
+local function getNotes(self)
+ ret = {}
+ for k,v in pairs(self.cfgfile:list(nil)) do
+ if v.status then
+ ret[#ret + 1] = {
+ content = "There are some configuration changes. Please do not forget to save."
+ }
+ break
+ end
+ end
+ return ret
+end
+
+read = function(self)
+ return {
+ list=self.cfgfile:list(function(x) return x.app == "firewall" end),
+ script=ENV["SCRIPT_NAME"],
+ prefix=self.conf.prefix,
+ controller=self.conf.controller,
+ action="update",
+ note=getNotes(self),
+ }
+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
+
+local function service(self, action)
+ local id = tonumber(self.clientdata.id) or -1
+ local svc = self.service:list("firewall")
+ local ret = {
+ script=ENV["SCRIPT_NAME"],
+ prefix=self.conf.prefix,
+ controller = self.conf.controller,
+ action={},
+ title="Firewall",
+ text={},
+ active={ id=id }
+ }
+ for i,s in pairs(svc) do
+ for i,a in ipairs(s.actions) do
+ ret.action[#ret.action + 1] = {
+ name = a,
+ section = s.name .. " (" .. tostring(s.status) .. ")",
+ id = s.id,
+ label = a,
+ }
+ end
+ end
+ if self.clientdata[action] then
+ local result, report = self.service:update(id, action)
+ local label = "Error"
+ if result then
+ ret.active.action = action
+ label = "Report"
+ end
+ ret.text[#ret.text + 1] = { label=label, content=report }
+ end
+ ret.note=getNotes(self)
+ return ret
+end
+
+start = function(self) return service(self, "start") end
+stop = function(self) return service(self, "stop") end
+restart = function(self) return service(self, "restart") end
+