summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-01-15 13:44:22 +0000
committerMika Havela <mika.havela@gmail.com>2008-01-15 13:44:22 +0000
commit91f600e62d83f942e722dd18e7c42c244557a610 (patch)
treeb1374d3109b9140da0f0fecde2a8d739e091f9b3
parent880d1fbbed5e15454383dccf7c3497a8772df118 (diff)
downloadacf-shorewall-91f600e62d83f942e722dd18e7c42c244557a610.tar.bz2
acf-shorewall-91f600e62d83f942e722dd18e7c42c244557a610.tar.xz
Created a confirmation when you start/stop/restart the firewall.
git-svn-id: svn://svn.alpinelinux.org/acf/shorewall/trunk@572 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--Makefile3
-rw-r--r--shorewall-check-html.lsp41
-rw-r--r--shorewall-controller.lua81
-rw-r--r--shorewall-edit-html.lsp62
-rw-r--r--shorewall-expert-html.lsp (renamed from shorewall-advanced-html.lsp)23
-rw-r--r--shorewall-logfile-html.lsp13
-rw-r--r--shorewall-model.lua68
-rw-r--r--shorewall-status-html.lsp12
8 files changed, 188 insertions, 115 deletions
diff --git a/Makefile b/Makefile
index 829531e..bb42a3d 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ PACKAGE=acf-$(APP_NAME)
VERSION=2.0_alpha3
APP_DIST=\
- shorewall-advanced-html.lsp \
+ shorewall-expert-html.lsp \
shorewall-check-html.lsp \
shorewall-controller.lua \
shorewall-edit-html.lsp \
@@ -11,6 +11,7 @@ APP_DIST=\
shorewall-model.lua \
shorewall-status-html.lsp \
shorewall.menu \
+ shorewall-confirmation-html \
EXTRA_DIST=README Makefile config.mk
diff --git a/shorewall-check-html.lsp b/shorewall-check-html.lsp
index c41480a..e470d44 100644
--- a/shorewall-check-html.lsp
+++ b/shorewall-check-html.lsp
@@ -1,16 +1,45 @@
<? local view = ... ?>
-<h1>Firewall configuration</h1>
+<h1>SYSTEM INFO</h1>
-<h2>SHOREWALL CHECK RESULT</h2>
+<dt>Program status</dt>
+<DD><?= view.status.status ?></DD>
+
+<dt>Program version</dt>
+<dd><?= view.status.version ?></dd>
+
+<h1>CONFIGURATION</h1>
+
+<h2>CHECK CONFIG</h2>
<textarea name="checkresult"><?= view.check.result ?></textarea>
-<h2>MANAGEMENT</h2>
+<H1>MANAGEMENT</H1>
+<dl>
<dt>Preform check of configs</dt>
-<dd><form name="check" action="" method="POST"><input type=submit name="cmd" value="check" class="submit"></form></dd>
+<dd><form name="check" action="" method="POST"><input type=submit name="check" value="check" class="submit"></form></dd>
+</dl>
+
+<dl>
+<dt>Program controll-panel</dt>
+<dd><form name="cmd" action="<?= view.confirm_url ?>" method="POST">
+<input type=submit class="submit" name="cmd" value="start">
+<input type=submit class="submit" name="cmd" value="stop">
+<input type=submit class="submit" name="cmd" value="restart">
+</form></dd>
+</dl>
-<dt>Preform fw restart</dt>
-<dd><form name="check" action="<? io.write(view.url .. "/read") ?>" method="POST"><input type=submit name="cmd" value="restart" class="submit"></form><? if (view.check.restart) then io.write(view.programstats.restart) end ?></dd>
+<? if (view.startstop) and (view.startstop.cmdresult) then ?>
+<dl>
+<dt>Previous action result</dt>
+<dd><pre><?= view.startstop.cmdresult?></pre></dd>
+</dl>
+<? end ?>
+<?
+--[[ DEBUG INFORMATION
+require("debugs")
+io.write(debugs.variables(view))
+--]]
+?>
diff --git a/shorewall-controller.lua b/shorewall-controller.lua
index 6b47dbb..8218b4d 100644
--- a/shorewall-controller.lua
+++ b/shorewall-controller.lua
@@ -17,14 +17,25 @@ mvc.on_load = function(self, parent)
end
logfile = function (self)
- return ( {logfile = self.model:get_logfile(), url = url } )
+ return ( {status = self.model:getstatus(), logfile = self.model:get_logfile(), url = url } )
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 } )
+ local check = nil
+ if (self.clientdata.cmd) then
+ if self.clientdata.cmd == "stop" then
+ self.conf.action = "confirmation"
+ self.conf.type = "redir"
+ end
+ check = self.model:startstop_service(self.clientdata.cmd)
+ check = self.clientdata.cmd
+ else
+ check = self.model:check_config()
end
- return ( {check = self.model:check_config(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
+ return ( {status = self.model:getstatus(),
+ check = check,
+ previousaction = self.clientdata.cmd,
+ confirm_url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller .. "/confirmation" } )
end
@@ -34,33 +45,51 @@ status = function(self)
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 ( {status = self.model:get_status(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
+-- if self.clientdata.cmd == "restart" then
+-- return ( {programstats = self.model:restart_service(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
+-- end
+ return ( {status = self.model:getstatus(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
end
-advanced = function(self)
- return ( {filelist = self.model:get_filelist(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
+expert = function(self)
+ return ( {status = self.model:getstatus(),filelist = self.model:get_filelist(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
end
edit = function (self)
- local filename = self.clientdata.name or ""
- local filecontent = self.clientdata.modifications or ""
- 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)
- else
- return me
- end
- else
- local me = ( {filecontent = self.model:get_filecontent(filename), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
- if ( me.filecontent == nil ) then
- list_redir(self)
- else
- return me
- end
+ local name = self.clientdata.name or ""
+ if (name == "") then
+ self.conf.action = "status"
+ self.conf.type = "redir"
+ end
+ local modifications = self.clientdata.modifications or ""
+ local cmd = self.clientdata.cmd
+ local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
+
+ if ( modifications ~= "") then
+ modifications = self.model:update_filecontent(name,modifications)
+ end
+
+ if ( cmd ~= nil ) then
+ startstop = self.model:startstop_service( cmd )
+ end
+
+ return ( {name=name,startstop = startstop,
+ status = self.model:getstatus(),
+ file = self.model:get_filedetails(name),
+ modifications = modifications,
+ url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller,
+ confirm_url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller .. "/confirmation", } )
+end
+
+confirmation = function (self)
+ local confirm = self.clientdata.confirm
+ if ( confirm ~= nil ) then
+ startstop = self.model:startstop_service( confirm )
end
+ return ( {startstop = startstop,
+ previousaction = self.clientdata.cmd,
+ status = self.model:getstatus(),
+ confirm_url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller .. "/confirmation",
+ url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, } )
end
diff --git a/shorewall-edit-html.lsp b/shorewall-edit-html.lsp
index c1d2537..c3384bb 100644
--- a/shorewall-edit-html.lsp
+++ b/shorewall-edit-html.lsp
@@ -1,27 +1,61 @@
<? local view = ... ?>
-<html>
-<body>
-<h1>Edit configuration</h1>
+<h1>SYSTEM INFO</h1>
-<h2>Details</h2>
+<dt>Program status</dt>
+<DD><?= view.status.status ?></DD>
+
+<dt>Program version</dt>
+<dd><?= view.status.version ?></dd>
+
+<h1>CONFIGURATION</h1>
+
+<H2>Expert config</H2>
+
+<h3>File details</h3>
<dt>File name</dt>
-<dd><?= view.filecontent.filedetails.longname ?></dd>
+<dd><?= view.file.details.path ?></dd>
<dt>File size</dt>
-<dd><?= view.filecontent.filedetails.size ?></dd>
+<dd><?= view.file.details.size ?></dd>
<dt>Last modified</dt>
-<dd><?= view.filecontent.filedetails.mtimelong ?></dd>
+<dd><?= view.file.details.mtime ?></dd>
-<h2>Content</h2>
+<h3>File content</h3>
<form name="myform" action="" method="POST">
-<input name="name" type=hidden value="<?= view.filecontent.filedetails.name ?>">
-<textarea name="modifications"><?= view.filecontent.value ?></textarea>
-
-<input type="submit" name="cmd" value="update" class="submit"><p class="error"><?= view.filecontent.errtxt ?></p></form>
+<input name="name" type=hidden value="<?= view.file.details.path ?>">
+<textarea name="modifications"><?= view.file.content ?></textarea>
+
+<H2>Save and apply above settings</H2>
+<DT>Apply settings</DT>
+<DD><input class="submit" type="submit" value="Apply"/></DD>
+</form>
+
+<H1>MANAGEMENT</H1>
+
+<dl>
+<dt>Program controll-panel</dt>
+<dd><form name="cmd" action="<?= view.confirm_url ?>" method="POST">
+<input type=submit class="submit" name="cmd" value="start">
+<input type=submit class="submit" name="cmd" value="stop">
+<input type=submit class="submit" name="cmd" value="restart">
+</form></dd>
+</dl>
+
+<? if (view.startstop) and (view.startstop.cmdresult) then ?>
+<dl>
+<dt>Previous action result</dt>
+<dd><pre><?= view.startstop.cmdresult?></pre></dd>
+</dl>
+<? end ?>
+
+<?
+--[[ DEBUG INFORMATION
+require("debugs")
+io.write(debugs.variables(view))
+--]]
+?>
-</body>
-</html>
diff --git a/shorewall-advanced-html.lsp b/shorewall-expert-html.lsp
index 7bff100..1b638ca 100644
--- a/shorewall-advanced-html.lsp
+++ b/shorewall-expert-html.lsp
@@ -1,9 +1,16 @@
<? local view = ... ?>
+<h1>SYSTEM INFO</h1>
-<h1>Firewall configuration</h1>
+<dt>Program status</dt>
+<DD><?= view.status.status ?></DD>
+<dt>Program version</dt>
+<dd><?= view.status.version ?></dd>
-<h2>List of configfiles</h2>
+<h1>CONFIGURATION</h1>
+
+<h2>Expert config</h2>
+<h3>List of configfiles</h3>
<TABLE>
<TR style="background:#eee;font-weight:bold;">
@@ -15,9 +22,17 @@
<? for i = 1, table.maxn(view.filelist) do ?>
<TR>
- <TD><?= html.link{value = view.url .. "/edit?name=" .. view.filelist[i].name , label=view.filelist[i].name } ?></TD>
+ <TD><?= html.link{value = view.url .. "/edit?name=" .. view.filelist[i].path , label=view.filelist[i].name } ?></TD>
<TD style="padding-right:10px" align="right"><?= view.filelist[i].filedetails.size ?></TD>
- <TD><?= view.filelist[i].filedetails.mtimelong ?></TD>
+ <TD><?= view.filelist[i].filedetails.mtime ?></TD>
</TR>
<? end ?>
</TABLE>
+
+<?
+--[[ DEBUG INFORMATION
+require("debugs")
+io.write(debugs.variables(view))
+--]]
+?>
+
diff --git a/shorewall-logfile-html.lsp b/shorewall-logfile-html.lsp
index 593a8d1..709fdba 100644
--- a/shorewall-logfile-html.lsp
+++ b/shorewall-logfile-html.lsp
@@ -1,6 +1,13 @@
<? local view = ... ?>
-<html>
-<body>
+
+<h1>SYSTEM INFO</h1>
+
+<dt>Program status</dt>
+<DD><?= view.status.status ?></DD>
+
+<dt>Program version</dt>
+<dd><?= view.status.version ?></dd>
+
<h1>LOGFILE</h1>
<h2>Details</h2>
@@ -10,8 +17,6 @@
<h2>Content</h2>
<textarea name=""><? io.write(view.logfile.value) ?></textarea>
-</body>
-</html>
<?
--[[ DEBUG INFORMATION
diff --git a/shorewall-model.lua b/shorewall-model.lua
index b3a8abe..fe9c18e 100644
--- a/shorewall-model.lua
+++ b/shorewall-model.lua
@@ -1,34 +1,18 @@
-- shorewall model methods
module (..., package.seeall)
require("format")
+require("fs")
+require("daemoncontrol")
local baseurl = "/etc/shorewall/"
-local function file_info ( path )
- require("posix")
- local filedetails = posix.stat(path)
- filedetails["owner"]=rawget((posix.getpasswd(filedetails["uid"])),"name")
- filedetails["group"]=rawget((posix.getgroup(filedetails["gid"])),"name")
- filedetails["atimelong"]=os.date("%c", filedetails["atime"])
- filedetails["mtimelong"]=os.date("%c", filedetails["mtime"])
- filedetails["longname"]=path
- filedetails["name"]=basename(path)
-
- if ( filedetails["size"] > 1073741824 ) then
- filedetails["size"]=((filedetails["size"]/1073741824) - (filedetails["size"]/1073741824%0.1)) .. "G"
- elseif ( filedetails["size"] > 1048576 ) then
- filedetails["size"]=((filedetails["size"]/1048576) - (filedetails["size"]/1048576%0.1)) .. "M"
- elseif ( filedetails["size"] > 1024 ) then
- filedetails["size"]=((filedetails["size"]/1024) - (filedetails["size"]/1024%0.1)) .. "k"
- else
- filedetails["size"]=filedetails["size"]
- end
- return filedetails
-end
-
-- ################################################################################
-- PUBLIC FUNCTIONS
+function startstop_service ( self, state )
+ return daemoncontrol.daemoncontrol("shorewall", state)
+end
+
function check_config ()
check = nil
check = {}
@@ -39,21 +23,12 @@ function check_config ()
return check
end
-function restart_service ()
- local f,err = io.popen("/etc/init.d/shorewall restart")
- local restart = f:read("*a")
- f:close()
- local status = get_status()
- status.restart = restart
- return status
-end
-
-function get_status ()
+function getstatus ()
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")
+ local programstatus = f:read("*l") or ""
+ local programstate = f:read("*l") or ""
f:close()
local f,error = io.popen("/sbin/shorewall version")
local programversion = "shorewall-" .. f:read("*l")
@@ -61,32 +36,28 @@ function get_status ()
return {version=programversion,status=programstatus,state=programstate}
end
-
function get_filelist ()
local filepath = baseurl
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} )
+ local filedetails = fs.stat(filepath .. name)
+ table.insert ( listed_files , {name=name, path=filepath .. name, filedetails=filedetails} )
end
end
table.sort(listed_files, function (a,b) return (a.name < b.name) end )
return listed_files
end
-function get_filecontent (self, name)
- local path = baseurl .. name
- file_content = nil
+function get_filedetails (self, name)
+ local name = basename(name)
+ local path = baseurl .. basename(name)
+ local file_content = nil
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}
+ file_content = cfe{name=name, content=fs.read_file(path), details=fs.stat(path)}
end
end
return file_content
@@ -104,7 +75,8 @@ function get_logfile ()
end
function update_filecontent (self, name, modifications)
- path = baseurl .. name
+ path = baseurl .. basename(name)
+ name=basename(name)
local available_files = get_filelist()
for k,v in pairs(available_files) do
if ( available_files[k].name == name ) then
@@ -112,11 +84,11 @@ function update_filecontent (self, name, modifications)
local file_result,err = file:write(format.dostounix(modifications))
file:close()
if (err ~= nil) then
- local filedetails = file_info(path)
+ local filedetails = fs.stat(path)
file_content = {name=name, value=file_result, filedetails=filedetails, err=err}
end
end
end
- return file_content
+ return name, file_content
end
diff --git a/shorewall-status-html.lsp b/shorewall-status-html.lsp
index bb9a0d7..d4ba1f6 100644
--- a/shorewall-status-html.lsp
+++ b/shorewall-status-html.lsp
@@ -12,18 +12,6 @@
<dt>Program reports</dt>
<dd><?= view.status.state ?></dd>
-
-<? --[[ ?>
-<H2>MANAGEMENT</H2>
-<dt>Preform check of configs</dt>
-<dd><form name="check" action="" method="POST"><input type="submit" name="cmd" value="check" class="submit"></form></dd>
-<? --]] ?>
-
-<? --[[ ?>
-<dt>Preform fw restart</dt>
-<dd><form name="restart" action="" method="POST"><input type="submit" name="cmd" value="restart" class="submit"></form><? if (view.programstats.restart) then io.write(view.programstats.restart) end ?></dd>
-<? --]] ?>
-
<?
--[[ DEBUG INFORMATION
require("debugs")