From 8de481d12806a87d77795291e4a560c935134d19 Mon Sep 17 00:00:00 2001 From: Alexander Poslavsky Date: Thu, 1 Nov 2007 13:09:27 +0000 Subject: test for general etc editing git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@241 ab2d0c66-481e-0410-8bed-d214d4d58bed --- app/cfgfile-model.lua | 85 +++++++++++++++++++++++++++++ app/cfgfile/firewall.cfg | 44 +++++++++++++++ app/shorewall/shorewall-controller.lua | 98 ++++++++++++++++++++++++++++++++++ app/shorewall/shorewall-html.lsp | 41 ++++++++++++++ app/shorewall/shorewall-read-html.lsp | 18 +++++++ app/shorewall/shorewall.menu | 2 + 6 files changed, 288 insertions(+) create mode 100644 app/cfgfile-model.lua create mode 100644 app/cfgfile/firewall.cfg create mode 100644 app/shorewall/shorewall-controller.lua create mode 100644 app/shorewall/shorewall-html.lsp create mode 100644 app/shorewall/shorewall-read-html.lsp create mode 100644 app/shorewall/shorewall.menu diff --git a/app/cfgfile-model.lua b/app/cfgfile-model.lua new file mode 100644 index 0000000..788ebc2 --- /dev/null +++ b/app/cfgfile-model.lua @@ -0,0 +1,85 @@ +module (..., package.seeall) + +require "fs" + + +--TODO this should be somehow figureoutable from acf info +local cfgdir = "/usr/share/acf/app/cfgfile" + +--TODO, in fs actually, find should use coroutines instead of reading +--all in table + +local files = nil + +--TODO might on demand load only part of config that is needed for this app +--but then TODO need to make persistent item ids +local function loadCfg() + if files ~= nil then return end + files = {} + for fname in fs.find(".*%.cfg", cfgdir) do + print ("LOADING FILE ", fname) + f = io.open(fname, 'r') + if f then + s = f:read("*a") + f:close() + if s then + c = loadstring("return ({\n" .. s .. "\n})") + if c then + for i,v in ipairs(c()) do + files[#files + 1] = v + end + end + end + end + end +end + +function list(self, app) + loadCfg() + ret = {} + for k,v in pairs(files) do + if v.app == app then + ret[#ret+1] = { + id=k, + app=v.app, + section=v.section, + name=v.name, + descr=v.descr, + } + end + end + return ret +end + +function get(self, id) + loadCfg() + local item = files[id] + if not item then return false end + local f = io.open(item.filename, "r") + local n = "" + if f then + n = f:read("*a") + f:close() + end + return true, { + id=cfe{ value=tostring(id) }, + content=cfe{ value=n, type="longtext" }, + name=cfe{ value=item.name } + } +end + + +function set(self, id, data) + loadCfg() + local item = files[id] + if not item then return false, date end + local f = io.open(item.filename, "w") + if f then + f:write(data.content.value) + f:close() + end + -- TODO update processing + return get(self, id) +end + + diff --git a/app/cfgfile/firewall.cfg b/app/cfgfile/firewall.cfg new file mode 100644 index 0000000..0a143d4 --- /dev/null +++ b/app/cfgfile/firewall.cfg @@ -0,0 +1,44 @@ +-- /* vim: set filetype=lua : */ +{ app="firewall", section="general", + name="params", filename="/etc/shorewall/params", + descr="Define variables used in the other configuration files." }, +{ app="firewall", section="general", + name="shorewall", filename="/etc/shorewall/shorewall.conf", + descr="Modify global configuration settings." }, +{ app="firewall", section="firewalling", + name="zones", filename="/etc/shorewall/zones", + descr="Name network partitions. Firewall rules are applied to defined zones." }, +{ app="firewall", section="firewalling", + name="interfaces", filename="/etc/shorewall/interfaces", + descr="Map physical interfaces to named zones." }, +{ app="firewall", section="firewalling", + name="hosts", filename="/etc/shorewall/hosts", + descr="Name specific hosts within zones." }, +{ app="firewall", section="firewalling", + name="policy", filename="/etc/shorewall/policy", + descr="Set default rules (policies) for zones." }, +{ app="firewall", section="firewalling", + name="rules", filename="/etc/shorewall/rules", + descr="Define exceptions to policies." }, +{ app="firewall", section="firewalling", + name="routestopped", filename="/etc/shorewall/routestopped", + descr="Define hosts that can access this host when the firewall is \"stopped\"" }, +{ app="firewall", section="firewalling", + name="tunnels", filename="/etc/shorewall/tunnels", + descr="Specify ipsec tunnel endpoints" }, +{ app="firewall", section="firewalling", + name="blacklist", filename="/etc/shorewall/blacklist", + descr="List ip addresses or names that should be denied all access to the firewall." }, +{ app="firewall", section="nat", + name="masq", filename="/etc/shorewall/masq", + descr="Define dynamic Masquerading or DNAT tables" }, +{ app="firewall", section="nat", + name="nat", filename="/etc/shorewall/nat", + descr="Define static Network Address Translation table" }, +{ app="firewall", section="qos", + name="tos", filename="/etc/shorewall/tos", + descr="Specify type of service markers for packets traversing the firewall." }, +{ app="firewall", section="qos", + name="tcrules", filename="/etc/shorewall/tcrules", + descr="Define traffic control rules." }, + diff --git a/app/shorewall/shorewall-controller.lua b/app/shorewall/shorewall-controller.lua new file mode 100644 index 0000000..78219b7 --- /dev/null +++ b/app/shorewall/shorewall-controller.lua @@ -0,0 +1,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 +-- /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 + diff --git a/app/shorewall/shorewall-html.lsp b/app/shorewall/shorewall-html.lsp new file mode 100644 index 0000000..efb1c38 --- /dev/null +++ b/app/shorewall/shorewall-html.lsp @@ -0,0 +1,41 @@ +

Edit

+ diff --git a/app/shorewall/shorewall-read-html.lsp b/app/shorewall/shorewall-read-html.lsp new file mode 100644 index 0000000..cf73662 --- /dev/null +++ b/app/shorewall/shorewall-read-html.lsp @@ -0,0 +1,18 @@ +

Edit

diff --git a/app/shorewall/shorewall.menu b/app/shorewall/shorewall.menu new file mode 100644 index 0000000..21066d5 --- /dev/null +++ b/app/shorewall/shorewall.menu @@ -0,0 +1,2 @@ +Networking Shorewall Define read + -- cgit v1.2.3