summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2007-11-29 15:08:41 +0000
committerMika Havela <mika.havela@gmail.com>2007-11-29 15:08:41 +0000
commit3a4f180a70063a185a8eab0e1409b255f0762861 (patch)
tree96280af931e67a8de34d00577c8651fa468697b3
parentd81ce7886c20e537161083279e9bc96cf6b74290 (diff)
downloadacf-shorewall-3a4f180a70063a185a8eab0e1409b255f0762861.tar.bz2
acf-shorewall-3a4f180a70063a185a8eab0e1409b255f0762861.tar.xz
Modifying file is now possible
git-svn-id: svn://svn.alpinelinux.org/acf/shorewall/trunk@386 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--shorewall-controller.lua17
-rw-r--r--shorewall-edit-html.lsp19
-rw-r--r--shorewall-model.lua31
3 files changed, 55 insertions, 12 deletions
diff --git a/shorewall-controller.lua b/shorewall-controller.lua
index 0b9b3ac..094dcf9 100644
--- a/shorewall-controller.lua
+++ b/shorewall-controller.lua
@@ -28,6 +28,21 @@ end
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 } )
+ local filecontent = self.clientdata.modifications or ""
+ if self.clientdata.cmd == "update" 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
+ end
end
diff --git a/shorewall-edit-html.lsp b/shorewall-edit-html.lsp
index f1c4958..98c4abe 100644
--- a/shorewall-edit-html.lsp
+++ b/shorewall-edit-html.lsp
@@ -1,6 +1,7 @@
<? local view = ... ?>
<html>
<body>
+
<h1>Edit configuration</h1>
<h2>Details</h2>
@@ -14,20 +15,24 @@
<dt>Last modified</dt>
<dd><?= view.filecontent.filedetails.mtimelong ?></dd>
-<dt>Mode</dt>
-<dd><?= view.filecontent.filedetails.mode ?></dd>
+<h2>Content</h2>
-<dt>Owner:Group</dt>
-<dd><?= view.filecontent.filedetails.gid ?>:<?= view.filecontent.filedetails.group ?></dd>
+<form name="myform" action="" method="POST">
+<input name="name" type=hidden value="<?= view.filecontent.filedetails.name ?>" style="width:100%">
+<textarea name="modifications" style="width:100%;height:400px;"><?= view.filecontent.value ?></textarea>
-<h2>Content</h2>
-<textarea name="" style="width:100%;height:400px;"><?= view.filecontent.value ?></textarea>
+<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.filedetails) do
+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 ce436c4..b57e354 100644
--- a/shorewall-model.lua
+++ b/shorewall-model.lua
@@ -1,15 +1,19 @@
-- shorewall model methods
module (..., package.seeall)
+local baseurl = "/etc/shorewall/"
+
local function file_info ( path )
require("posix")
- modfiledetails = {}
+-- modfiledetails = {}
local filedetails = posix.stat(path)
- filedetails["owner"]=rawget((posix.getgroup(filedetails["uid"])),"1")
+ 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)
+ filedetails["size"]=filedetails["size"] .. " bytes"
return filedetails
end
@@ -32,20 +36,23 @@ end
function get_filelist ()
- local filepath = "/etc/shorewall/"
+ 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} )
table.insert ( listed_files , {name=name, longname=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 = "/etc/shorewall/" .. name
+ local path = baseurl .. name
+ file_content = nil
local available_files = get_filelist()
for k,v in pairs(available_files) do
if ( available_files[k].name == name ) then
@@ -58,4 +65,20 @@ 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)
+ file:close()
+ if (err ~= nil) then
+ local filedetails = file_info(path)
+ file_content = {name=name, value=file_result, filedetails=filedetails, err=err}
+ end
+ end
+ end
+ return file_content
+end