diff options
Diffstat (limited to 'app/shorewall-controller.lua')
-rw-r--r-- | app/shorewall-controller.lua | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/app/shorewall-controller.lua b/app/shorewall-controller.lua deleted file mode 100644 index f1583cf..0000000 --- a/app/shorewall-controller.lua +++ /dev/null @@ -1,102 +0,0 @@ -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 - -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 - -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 - 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 - |