diff options
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | config.mk | 11 | ||||
-rw-r--r-- | firewall.cfg (renamed from cfgfile/firewall.cfg) | 0 | ||||
-rw-r--r-- | shorewall-controller.lua | 117 | ||||
-rw-r--r-- | shorewall-html.lsp | 41 | ||||
-rw-r--r-- | shorewall-read-html.lsp | 27 | ||||
-rw-r--r-- | shorewall-restart-html.lsp | 71 | ||||
-rw-r--r-- | shorewall-start-html.lsp | 71 | ||||
-rw-r--r-- | shorewall-stop-html.lsp | 71 | ||||
-rw-r--r-- | shorewall.menu | 2 |
10 files changed, 416 insertions, 2 deletions
@@ -6,8 +6,10 @@ APP_DIST=\ shorewall-controller.lua \ shorewall-html.lsp \ shorewall-read-html.lsp \ - shorewall.menu \ - cfgfile/firewall.cfg + shorewall.menu + +APP_CFG=\ + firewall.cfg EXTRA_DIST=Makefile config.mk @@ -28,6 +30,7 @@ dist: $(tarball) install: mkdir -p "$(install_dir)" cp -a $(APP_DIST) "$(install_dir)" + cp -a $(APP_CFG) "$(cfgdir)" $(tarball): $(DISTFILES) rm -rf $(P) diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..f67accc --- /dev/null +++ b/config.mk @@ -0,0 +1,11 @@ +prefix=/usr +datadir=${prefix}/share +sysconfdir=${prefix}/etc +localstatedir=${prefix}/var +acfdir=${datadir}/acf +wwwdir=${acfdir}/www +cgibindir=${acfdir}/cgi-bin +appdir=${acfdir}/app +cfgdir=${appdir}/cfgfile +acflibdir=${acfdir}/lib +sessionsdir=${localstatedir}/lib/acf/sessions diff --git a/cfgfile/firewall.cfg b/firewall.cfg index 0a143d4..0a143d4 100644 --- a/cfgfile/firewall.cfg +++ b/firewall.cfg 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 + diff --git a/shorewall-html.lsp b/shorewall-html.lsp new file mode 100644 index 0000000..efb1c38 --- /dev/null +++ b/shorewall-html.lsp @@ -0,0 +1,41 @@ +<? +local form = ... +?><h1>Edit <?= form.value.name.value +?></h1><?= html.form.start{ + method="POST", + action= form.option.script .. "/" .. form.option.prefix + .. form.option.controller .. "/" .. form.option.action .. + form.option.extra +} +?><table><? +local myform = form.value +local tags = { + { "content", "longtext" }, + { "cmd", "action" }, + { "id", "hidden" }, +} + +for i,v in pairs(tags) do + local name = v[1] + local val = myform[name] + val.type = v[2] + ?><tr><td><? +--[[ + if val.label then + io.write(val.label) + elseif val.type ~= "hidden" then + io.write(name) + end +--]] + ?></td><td><? + if val.name == "" then val.name = name end + if val.type == "longtext" then + val.cols = 80 + val.rows = 24 + end + ?><?= html.form[val.type](val) + ?></td></tr><? +end +?></table><?= html.form.stop() +?> + diff --git a/shorewall-read-html.lsp b/shorewall-read-html.lsp new file mode 100644 index 0000000..0ea1ec8 --- /dev/null +++ b/shorewall-read-html.lsp @@ -0,0 +1,27 @@ +<? local view = ... ?> + +<h1>Edit</h1> + +<? --Status Block + for i,item in ipairs(view.note or {}) do + ?><p class='error'><?= item.content ?></p><? + end +?> + +<table border=0> +<? local sct="" +for i,item in ipairs(view.list) do + if item.section ~= sct then + ?><tr><td colspan='3'><h2><?= item.section ?></td></tr><? + sct = item.section + end + ?><tr><td><?= item.status or '' ?><? + ?><td><?= html.link{ + value = view.script .. view.prefix .. view.controller .. "/" + .. view.action .. "?id=" .. tostring(item.id), + label=item.name + } + ?></td><td><?= item.descr + ?></td></tr><? +end -- vim: set filetype=lua : ?> +</table> diff --git a/shorewall-restart-html.lsp b/shorewall-restart-html.lsp new file mode 100644 index 0000000..53d81b7 --- /dev/null +++ b/shorewall-restart-html.lsp @@ -0,0 +1,71 @@ +<? +local view = ... + +local function packURL(script, prefix, controller, action, extra) + ret = script .. "/" .. prefix .. controller .. "/" .. action + sep = '?' + for k,v in pairs(extra) do + ret = ret .. sep .. k .. '=' .. v + sep = '&' + end + return ret +end + +--[[ +view + script, prefix, controller + action[] + name, script, prefix, controller + section + id + label + disabled + active + id + action + title + text[] + label + content +--]] +?><h1><?= view.title +?></h1><? + +--Status Block + for i,item in ipairs(view.note or {}) do + ?><p class='error'><?= item.content ?></p><? + end + +local section = "" +for i,item in ipairs(view.action) do + if section ~= item.section then + section = item.section + ?><h2><?= section ?></h2><? + end + if item.disabled then + ?><i><?= item.label or item.name ?></i><? + else + ?><?= html.form.start { + method="POST", + action = packURL(item.script or view.script, + item.prefix or view.prefix, + item.controller or view.controller, + item.name, {}) + } ?><?= html.form.hidden { name="id", value=item.id } ?><? + local label = (item.label or item.name) + if item.id == view.active.id and item.name == view.active.action then + label = '['..label..']' + end + ?><?= html.form.submit { + name = item.name, value = label + } ?><?= html.form.stop() ?><? + end +end +for i,item in ipairs(view.text) do + if item.label then + ?><h2><?= item.label ?></h2><? + end + ?><pre><?= item.content ?></pre><? +end +-- vim: set filetype=lua : +?> diff --git a/shorewall-start-html.lsp b/shorewall-start-html.lsp new file mode 100644 index 0000000..53d81b7 --- /dev/null +++ b/shorewall-start-html.lsp @@ -0,0 +1,71 @@ +<? +local view = ... + +local function packURL(script, prefix, controller, action, extra) + ret = script .. "/" .. prefix .. controller .. "/" .. action + sep = '?' + for k,v in pairs(extra) do + ret = ret .. sep .. k .. '=' .. v + sep = '&' + end + return ret +end + +--[[ +view + script, prefix, controller + action[] + name, script, prefix, controller + section + id + label + disabled + active + id + action + title + text[] + label + content +--]] +?><h1><?= view.title +?></h1><? + +--Status Block + for i,item in ipairs(view.note or {}) do + ?><p class='error'><?= item.content ?></p><? + end + +local section = "" +for i,item in ipairs(view.action) do + if section ~= item.section then + section = item.section + ?><h2><?= section ?></h2><? + end + if item.disabled then + ?><i><?= item.label or item.name ?></i><? + else + ?><?= html.form.start { + method="POST", + action = packURL(item.script or view.script, + item.prefix or view.prefix, + item.controller or view.controller, + item.name, {}) + } ?><?= html.form.hidden { name="id", value=item.id } ?><? + local label = (item.label or item.name) + if item.id == view.active.id and item.name == view.active.action then + label = '['..label..']' + end + ?><?= html.form.submit { + name = item.name, value = label + } ?><?= html.form.stop() ?><? + end +end +for i,item in ipairs(view.text) do + if item.label then + ?><h2><?= item.label ?></h2><? + end + ?><pre><?= item.content ?></pre><? +end +-- vim: set filetype=lua : +?> diff --git a/shorewall-stop-html.lsp b/shorewall-stop-html.lsp new file mode 100644 index 0000000..53d81b7 --- /dev/null +++ b/shorewall-stop-html.lsp @@ -0,0 +1,71 @@ +<? +local view = ... + +local function packURL(script, prefix, controller, action, extra) + ret = script .. "/" .. prefix .. controller .. "/" .. action + sep = '?' + for k,v in pairs(extra) do + ret = ret .. sep .. k .. '=' .. v + sep = '&' + end + return ret +end + +--[[ +view + script, prefix, controller + action[] + name, script, prefix, controller + section + id + label + disabled + active + id + action + title + text[] + label + content +--]] +?><h1><?= view.title +?></h1><? + +--Status Block + for i,item in ipairs(view.note or {}) do + ?><p class='error'><?= item.content ?></p><? + end + +local section = "" +for i,item in ipairs(view.action) do + if section ~= item.section then + section = item.section + ?><h2><?= section ?></h2><? + end + if item.disabled then + ?><i><?= item.label or item.name ?></i><? + else + ?><?= html.form.start { + method="POST", + action = packURL(item.script or view.script, + item.prefix or view.prefix, + item.controller or view.controller, + item.name, {}) + } ?><?= html.form.hidden { name="id", value=item.id } ?><? + local label = (item.label or item.name) + if item.id == view.active.id and item.name == view.active.action then + label = '['..label..']' + end + ?><?= html.form.submit { + name = item.name, value = label + } ?><?= html.form.stop() ?><? + end +end +for i,item in ipairs(view.text) do + if item.label then + ?><h2><?= item.label ?></h2><? + end + ?><pre><?= item.content ?></pre><? +end +-- vim: set filetype=lua : +?> diff --git a/shorewall.menu b/shorewall.menu new file mode 100644 index 0000000..21066d5 --- /dev/null +++ b/shorewall.menu @@ -0,0 +1,2 @@ +Networking Shorewall Define read + |