From f9975a98a1e3404c2f75ed093f8de47f89b339e5 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Wed, 28 Nov 2007 17:23:26 +0000 Subject: 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 --- shorewall-controller.lua | 113 +++++++---------------------------------------- shorewall-edit-html.lsp | 28 ++++++++++++ shorewall-list-html.lsp | 10 +++++ shorewall-model.lua | 60 +++++++++++++++++++++++++ shorewall-module.lua | 4 -- shorewall-read-html.lsp | 67 +++++++++++----------------- 6 files changed, 139 insertions(+), 143 deletions(-) create mode 100644 shorewall-edit-html.lsp create mode 100644 shorewall-list-html.lsp create mode 100644 shorewall-model.lua delete mode 100644 shorewall-module.lua 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 --- /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 - diff --git a/shorewall-edit-html.lsp b/shorewall-edit-html.lsp new file mode 100644 index 0000000..3e12554 --- /dev/null +++ b/shorewall-edit-html.lsp @@ -0,0 +1,28 @@ + + + +

Edit configuration

+ +

Details

+ +
File name
+
+ +
File size
+
+ +
Last modified
+
+ +
Mode
+
+ +
Owner:Group
+
:
+ +

Content

+ + + + + diff --git a/shorewall-list-html.lsp b/shorewall-list-html.lsp new file mode 100644 index 0000000..424349a --- /dev/null +++ b/shorewall-list-html.lsp @@ -0,0 +1,10 @@ + + +

Firewall configuration

+ +

EXISTING FILES

+ + +
+
Last modified:
+ diff --git a/shorewall-model.lua b/shorewall-model.lua new file mode 100644 index 0000000..bf42891 --- /dev/null +++ b/shorewall-model.lua @@ -0,0 +1,60 @@ +-- shorewall model methods +module (..., package.seeall) + +local function XXXfile_info ( path ) + local file = io.popen("ls -lh " .. path ) + local file_info_result = file:read("*a") or "unknown" + file:close() + local size,lastmod = string.match(file_info_result, "^%S+%s+%S+%s+%S+%s+%S+%s+(%S+)%s+(%S+%s+%S+%s+%S+)" ) + return {lastmod=lastmod,size=size, longname=path} +end +local function file_info ( path ) + require("posix") + filedetails = posix.stat(path) + filedetails.longname = path + return filedetails +end + + +function get_status () + local f,error = io.popen("/sbin/shorewall status") + local fake = f:read("*l") + local fake = f:read("*l") + local programstatus = f:read("*l") + local programstate = f:read("*l") + f:close() + local f,error = io.popen("/sbin/shorewall version") + local programversion = f:read("*l") + f:close() + return {programversion=programversion,programstatus=programstatus,programstate=programstate} +end + + +function get_filelist () + local filepath = "/etc/shorewall/" + local listed_files = {} + local k,v + for name in posix.files(filepath) do + if not string.match(name, "^%.") and not string.match(name, "^Makefile") then + local filedetails = file_info(filepath .. name) + table.insert ( listed_files , {name=name, longname=filepath .. name, filedetails=filedetails} ) + end + end + return listed_files +end + +function get_filecontent (self, name) + local path = "/etc/shorewall/" .. name + local available_files = get_filelist() + for k,v in pairs(available_files) do + if ( available_files[k].name == name ) then + local file = io.open( path ) + local file_result = file:read("*a") or "unknown" + file:close() + local filedetails = file_info(path) + file_content = cfe{name=name, value=file_result, filedetails=filedetails} + end + end + return file_content +end + diff --git a/shorewall-module.lua b/shorewall-module.lua deleted file mode 100644 index a05ae0d..0000000 --- a/shorewall-module.lua +++ /dev/null @@ -1,4 +0,0 @@ --- shorewall model methods -module (..., package.seeall) - - diff --git a/shorewall-read-html.lsp b/shorewall-read-html.lsp index 21f614f..af700b1 100644 --- a/shorewall-read-html.lsp +++ b/shorewall-read-html.lsp @@ -4,95 +4,78 @@

GENERAL

-
shorewall.conf
+
Modify global configuration settings.
-
params
+
Define variables used in the other configuratino files.
-
zones
+
Name network partions. Firewal rules are applied to defined zones.
-
interfaces
+
Map physical interfaces to named zones.
-
hosts
+
Map individual hosts or networks to named zones.

FIREWALLING

-
policy
+
Set default rules (policies) for zones.
-
rules
+
Define exceptions to policies.
-
routestopped
+
Define hosts that can access this host when the firewall is "stopped".
-
tunnels
+
Specify ipsec tunel endpoints.
-
blacklist
+
List ip addresses or names that should be denied all access to the firewall.

NAT

-
masq
+
Define dynamic Masquerading or DNAT tables.
-
nat
+
Define static Network Address Translation tables.

QOS

-
tos
+
Specify type of service markers for packets traversing the firewall.
-
tcdevices
+
Define traffic control devices.
-
tcclasses
+
Define traffic control classes.
-
tcrules
+
Define traffic control rules.

OTHER

-
View all files/configs
+
Provide a autogenerated list of files in '/etc/shorewall'.

SYSTEM INFO

Program version
-
+
+ +
Program status
+
+ +
Program state
+
+

MANAGEMENT

Program Status
[running|not]
- -

- - - -

-- cgit v1.2.3