From 2beb00dd81c1f2dceeef0e62cf89d2d1b1109b6a Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Fri, 30 Nov 2007 16:41:55 +0000 Subject: Check and restart is now working! git-svn-id: svn://svn.alpinelinux.org/acf/shorewall/trunk@396 ab2d0c66-481e-0410-8bed-d214d4d58bed --- shorewall-controller.lua | 17 +++++++++++++++- shorewall-edit-html.lsp | 42 +++++++++++++++++++++++++++++---------- shorewall-model.lua | 26 ++++++++++++++++++++---- shorewall-read-html.lsp | 51 +++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 118 insertions(+), 18 deletions(-) diff --git a/shorewall-controller.lua b/shorewall-controller.lua index 094dcf9..07ec0b7 100644 --- a/shorewall-controller.lua +++ b/shorewall-controller.lua @@ -17,8 +17,23 @@ mvc.on_load = function(self, parent) end +check = function(self) + if self.clientdata.cmd == "restart" then + return ( {programstats = self.model:restart_service(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) + end + return ( {check = self.model:check_config(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) +end + read = function(self) + if self.clientdata.cmd == "check" then + self.conf.action = "check" + self.conf.type = "redir" + error (self.conf) + end + if self.clientdata.cmd == "restart" then + return ( {programstats = self.model:restart_service(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) + end return ( {programstats = self.model:get_status(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) end @@ -29,7 +44,7 @@ end edit = function (self) local filename = self.clientdata.name or "" local filecontent = self.clientdata.modifications or "" - if self.clientdata.cmd == "update" then + if ( filecontent ~= "") then local me = ( {filecontent = self.model:update_filecontent(filename,filecontent), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) if ( me.filecontent == nil ) then list_redir(self) diff --git a/shorewall-edit-html.lsp b/shorewall-edit-html.lsp index 98c4abe..86d5507 100644 --- a/shorewall-edit-html.lsp +++ b/shorewall-edit-html.lsp @@ -2,8 +2,40 @@ +

Edit configuration

+ +------------ START DEBUG INFORMATION ------------ +

THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES

+") +for a,b in pairs(view) do + if not (type(b) == "table") then + print ("" .. a .. ": >" .. b .. "<
") + else + print ("" .. a .. ":...
") + for c,d in pairs(view[a]) do + if not (type(d) == "table") then + print (" { " .. c .. ": >" .. d .. "< }
") + else + print (" { " .. c .. ":...
") + for e,f in pairs(view[a][c]) do + if not (type(f) == "table") then + print (" { { " .. e .. ": >" .. f .. "< } }
") + else + print (" { { " .. e .. ":... (table is not visible at the moment)
") + end + end + end + end + end +a,b,c,d,e,f,g,h,i,j = nil,nil,nil,nil,nil,nil,nil,nil,nil,nil +end +print ("------------ END DEBUG INFORMATION ------------
") +?> + +

Details

File name
@@ -23,16 +55,6 @@

- -

DEUB INFO

-") -end -?> - - - diff --git a/shorewall-model.lua b/shorewall-model.lua index b57e354..ca26ca8 100644 --- a/shorewall-model.lua +++ b/shorewall-model.lua @@ -1,11 +1,11 @@ -- shorewall model methods module (..., package.seeall) +require("format") local baseurl = "/etc/shorewall/" local function file_info ( path ) require("posix") --- modfiledetails = {} local filedetails = posix.stat(path) filedetails["owner"]=rawget((posix.getpasswd(filedetails["uid"])),"name") filedetails["group"]=rawget((posix.getgroup(filedetails["gid"])),"name") @@ -14,13 +14,31 @@ local function file_info ( path ) filedetails["longname"]=path filedetails["name"]=basename(path) filedetails["size"]=filedetails["size"] .. " bytes" - return filedetails end -- ################################################################################ -- PUBLIC FUNCTIONS +function check_config () + check = nil + check = {} + local f,err = io.popen("/etc/init.d/shorewall check") + check.result = f:read("*a") + f:close() + check["error"]=err + return check +end + +function restart_service () + -- FIXME: Read getstatus AFTER restart so the new 'restart date' is shown. + local status = get_status() + local f,err = io.popen("/etc/init.d/shorewall restart") + status.restart = f:read("*a") + f:close() + return status +end + function get_status () local f,error = io.popen("/sbin/shorewall status") local fake = f:read("*l") @@ -42,7 +60,6 @@ function get_filelist () 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} ) table.insert ( listed_files , {name=name, longname=filepath .. name, filedetails=filedetails} ) end end @@ -65,13 +82,14 @@ function get_filecontent (self, name) end return file_content end + function update_filecontent (self, name, modifications) path = baseurl .. 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, "w+" ) - local file_result,err = file:write(modifications) + local file_result,err = file:write(format.dostounix(modifications)) file:close() if (err ~= nil) then local filedetails = file_info(path) diff --git a/shorewall-read-html.lsp b/shorewall-read-html.lsp index af700b1..7f23c8f 100644 --- a/shorewall-read-html.lsp +++ b/shorewall-read-html.lsp @@ -58,7 +58,7 @@
Define traffic control rules.
-

OTHER

+

SHOW CONFIG FILES

Provide a autogenerated list of files in '/etc/shorewall'.
@@ -74,8 +74,53 @@
Program state
+Show shorewall details +
[connections] Displays the IP connections currently being tracked by the firewall
+--]] ?>

MANAGEMENT

-
Program Status
-
[running|not]
+
Preform check of configs
+
+ +
Preform restart of firewall
+
+ +Preform refresh of configs +
Involves black list, ECN control rules, and traffic shaping...
+--]] ?> + + + + +

THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES

+------------ START DEBUG INFORMATION ------------
+") +for a,b in pairs(view) do + if not (type(b) == "table") then + print ("" .. a .. ": >" .. b .. "<
") + else + print ("" .. a .. ":...
") + for c,d in pairs(view[a]) do + if not (type(d) == "table") then + print (" { " .. c .. ": >" .. d .. "< }
") + else + print (" { " .. c .. ":...
") + for e,f in pairs(view[a][c]) do + if not (type(f) == "table") then + print (" { { " .. e .. ": >" .. f .. "< } }
") + else + print (" { { " .. e .. ":... (table is not visible at the moment)
") + end + end + end + end + end +a,b,c,d,e,f,g,h,i,j = nil,nil,nil,nil,nil,nil,nil,nil,nil,nil +end +print ("------------ END DEBUG INFORMATION ------------
") +?> + -- cgit v1.2.3