diff options
author | Mika Havela <mika.havela@gmail.com> | 2007-11-29 15:08:41 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2007-11-29 15:08:41 +0000 |
commit | 3a4f180a70063a185a8eab0e1409b255f0762861 (patch) | |
tree | 96280af931e67a8de34d00577c8651fa468697b3 /shorewall-model.lua | |
parent | d81ce7886c20e537161083279e9bc96cf6b74290 (diff) | |
download | acf-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
Diffstat (limited to 'shorewall-model.lua')
-rw-r--r-- | shorewall-model.lua | 31 |
1 files changed, 27 insertions, 4 deletions
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 |