summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--shorewall-controller.lua17
-rw-r--r--shorewall-edit-html.lsp42
-rw-r--r--shorewall-model.lua26
-rw-r--r--shorewall-read-html.lsp51
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 @@
<html>
<body>
+
<h1>Edit configuration</h1>
+<? --[[ DEBUG INFORMATION...?>
+<span style='color:#D2691E;font-family:courier;'>------------ START DEBUG INFORMATION ------------
+<h3>THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES</h2>
+<?
+--print ("<span style='color:darkblue;font-family:courier;'>")
+for a,b in pairs(view) do
+ if not (type(b) == "table") then
+ print ("<b>" .. a .. "</b>: ><span2 style='color:black'>" .. b .. "</span2><<BR>")
+ else
+ print ("<b>" .. a .. "</b>:...<BR>")
+ for c,d in pairs(view[a]) do
+ if not (type(d) == "table") then
+ print ("<b> { " .. c .. "</b>: ><span2 style='color:black'>" .. d .. "</span2>< <B> }</B><BR>")
+ else
+ print ("<b> { " .. c .. "</b>:...<BR>")
+ for e,f in pairs(view[a][c]) do
+ if not (type(f) == "table") then
+ print ("<b> { { " .. e .. "</b>: ><span2 style='color:black'>" .. f .. "</span2>< <B> } }</B><BR>")
+ else
+ print ("<b> { { " .. e .. "</b>:... (table is not visible at the moment)<BR>")
+ 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 ------------</span>")
+?>
+<? --]] ?>
+
<h2>Details</h2>
<dt>File name</dt>
@@ -23,16 +55,6 @@
<input type="submit" name="cmd" value="update"><p class="error"><?= view.filecontent.errtxt ?></p></form>
-<? --[[ DEBUG INFORMATION...?>
-<h2>DEUB INFO</h2>
-<?
-for a,b in pairs(view.filecontent) do
-print (a,b .. "<BR>")
-end
-?>
-<? --]] ?>
-
-
</body>
</html>
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 @@
<dt><?= html.link{value = view.url .. "/edit?name=tcrules", label="tcrules" } ?></dt>
<dd>Define traffic control rules.</dd>
-<h2>OTHER</h2>
+<h2>SHOW CONFIG FILES</h2>
<dt><?= html.link{value = view.url .. "/list", label="View all files/configs" } ?></dt>
<dd>Provide a autogenerated list of files in '/etc/shorewall'.</dd>
@@ -74,8 +74,53 @@
<dt>Program state</dt>
<dd><?= view.programstats.programstate ?></dd>
+<? --[[
+<dt>Show shorewall details</dt>
+<dd>[connections] Displays the IP connections currently being tracked by the firewall</dd>
+--]] ?>
<h2>MANAGEMENT</h2>
-<dt>Program Status</dt>
-<dd>[running|not]</dd>
+<dt>Preform check of configs</dt>
+<dd><form name="check" action="" method="POST"><input type=submit name="cmd" value="check" style="width:100px"></form></dd>
+
+<dt>Preform restart of firewall</dt>
+<dd><form name="restart" action="" method="POST"><input type=submit name="cmd" value="restart" style="width:100px"></form><? if (view.programstats.restart) then io.write(view.programstats.restart) end ?></dd>
+
+<? --[[
+<dt>Preform refresh of configs</dt>
+<dd><form action="xxx" method="POST"><input type=submit name="cmd" value="refresh" style="width:100px"></form> Involves black list, ECN control rules, and traffic shaping...</dd>
+--]] ?>
+
+
+<? --[[ DEBUG INFORMATION...?>
+<span style='color:#D2691E;font-family:courier;'>
+<h3>THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES</h2>
+------------ START DEBUG INFORMATION ------------<BR>
+<?
+--print ("<span style='color:darkblue;font-family:courier;'>")
+for a,b in pairs(view) do
+ if not (type(b) == "table") then
+ print ("<b>" .. a .. "</b>: ><span2 style='color:black'>" .. b .. "</span2><<BR>")
+ else
+ print ("<b>" .. a .. "</b>:...<BR>")
+ for c,d in pairs(view[a]) do
+ if not (type(d) == "table") then
+ print ("<b> { " .. c .. "</b>: ><span2 style='color:black'>" .. d .. "</span2>< <B> }</B><BR>")
+ else
+ print ("<b> { " .. c .. "</b>:...<BR>")
+ for e,f in pairs(view[a][c]) do
+ if not (type(f) == "table") then
+ print ("<b> { { " .. e .. "</b>: ><span2 style='color:black'>" .. f .. "</span2>< <B> } }</B><BR>")
+ else
+ print ("<b> { { " .. e .. "</b>:... (table is not visible at the moment)<BR>")
+ 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 ------------</span>")
+?>
+<? --]] ?>