diff options
author | Mika Havela <mika.havela@gmail.com> | 2007-11-28 17:23:26 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2007-11-28 17:23:26 +0000 |
commit | f9975a98a1e3404c2f75ed093f8de47f89b339e5 (patch) | |
tree | b50c0c0a375067d72c10deb0ffac74a2336e0ed7 /shorewall-controller.lua | |
parent | 73bd0a6d99c0bdfc1db5432706a3aa577617b10c (diff) | |
download | acf-shorewall-f9975a98a1e3404c2f75ed093f8de47f89b339e5.tar.bz2 acf-shorewall-f9975a98a1e3404c2f75ed093f8de47f89b339e5.tar.xz |
Show files and their content starting to take shape
git-svn-id: svn://svn.alpinelinux.org/acf/shorewall/trunk@383 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'shorewall-controller.lua')
-rw-r--r-- | shorewall-controller.lua | 113 |
1 files changed, 16 insertions, 97 deletions
diff --git a/shorewall-controller.lua b/shorewall-controller.lua index 34bbc11..0b9b3ac 100644 --- a/shorewall-controller.lua +++ b/shorewall-controller.lua @@ -1,114 +1,33 @@ module(..., package.seeall) -local list_redir = function(self) - self.conf.action = "read" - self.conf.type = "redir" - error(self.conf) +-- Cause an http redirect to our "read" action +-- We use the self.conf table because it already has prefix,controller,etc +-- The redir code is defined in the application error handler (acf-controller) +local list_redir = function (self) + self.conf.action = "read" + self.conf.type = "redir" + error (self.conf) end -local cfgfile -local service - mvc={} mvc.on_load = function(self, parent) - cfgfile = self:new("cfgfile") - service = self:new("service") - if (self.worker[self.conf.action] == nil) or (self.conf.action == "init") then - self.worker[self.conf.action] = list_redir(self) - end + 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(cfgfile.model: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=cfgfile.model: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), - } + return ( {programstats = self.model:get_status(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) end -update = function(self) - local id = tonumber(self.clientdata.id) or -1 - local result - local data - - result, data = cfgfile.model: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 = cfgfile.model: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} +list = function(self) + return ( {filelist = self.model:get_filelist(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) end -local function serviceAction(self, action) - local id = tonumber(self.clientdata.id) or -1 - local svc = service.model: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 = service.model: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 +edit = function (self) + local filename = self.clientdata.name or "" + return ( {filecontent = self.model:get_filecontent(filename), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) end -start = function(self) return serviceAction(self, "start") end -stop = function(self) return serviceAction(self, "stop") end -restart = function(self) return serviceAction(self, "restart") end - |