summaryrefslogtreecommitdiffstats
path: root/logfiles-model.lua
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2007-11-20 12:35:24 +0000
committerMika Havela <mika.havela@gmail.com>2007-11-20 12:35:24 +0000
commit92db7c97a2b949afed04f5bc8b1b825917aa1d9a (patch)
tree730655b9c41d7e39b5094b0e4c7dc134d8cc5778 /logfiles-model.lua
parent42fca55dcb13d2a7e6d127b11a1dbc54bff531fa (diff)
downloadacf-alpine-baselayout-92db7c97a2b949afed04f5bc8b1b825917aa1d9a.tar.bz2
acf-alpine-baselayout-92db7c97a2b949afed04f5bc8b1b825917aa1d9a.tar.xz
Added some comments and redirect page when entering invalid url
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@343 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'logfiles-model.lua')
-rw-r--r--logfiles-model.lua65
1 files changed, 35 insertions, 30 deletions
diff --git a/logfiles-model.lua b/logfiles-model.lua
index 8587e21..39a3e4f 100644
--- a/logfiles-model.lua
+++ b/logfiles-model.lua
@@ -1,32 +1,40 @@
+-- acf model for displaying logfiles recusivly
module (..., package.seeall)
-- no initializer in model - use controller.init for that
+-- Function to get detailed information on a specific file.
local function file_info ( path )
- local file = io.popen("ls -lh " .. path )
- local file_inuse = io.popen("fuser " .. path )
+ -- Load dependencys
split = require("split")
+ -- Get size, changedate...
+ local file = io.popen("ls -lh " .. path )
local file_info_result = file:read("*a") or "unknown"
+ file:close()
+ local size = rawget(split("%s+", file_info_result),5)
+ local lastmod = rawget(split("%s+", file_info_result),6) .. " " .. rawget(split("%s+", file_info_result),7) .. " " .. rawget(split("%s+", file_info_result),8)
+ -- Check if file is in use
+ local file_inuse = io.popen("fuser " .. path )
local fileinuseresult = file_inuse:read("*a") or "unkown"
+ file_inuse:close()
if fileinuseresult == "" then
fileinuseresult = "Delete"
+ fileinuseurl = "/delete?name=" .. path
else
fileinuseresult = "in use"
+ fileinuseurl = nil
end
- local size = rawget(split("%s+", file_info_result),5)
- local lastmod = rawget(split("%s+", file_info_result),6) .. " " .. rawget(split("%s+", file_info_result),7) .. " " .. rawget(split("%s+", file_info_result),8)
- file:close()
- file_inuse:close()
- return lastmod,size,fileinuseresult
+ return lastmod,size,fileinuseresult,fileinuseurl
end
--- function to recursively inserts all filenames in a dir into an array
-function recursedir(path, filearray)
+-- Function to recursively inserts all filenames in a dir into an array
+local function recursedir(path, filearray)
local k,v
for k,v in pairs(posix.dir(path) or {}) do
- -- we ignore files that begins with a '.'
+ -- Ignore files that begins with a '.'
if not string.match(v, "^%.") then
local f = path .. "/" .. v
+ -- If subfolder exists, list files in this subfolder
if (posix.stat(f).type == "directory") then
recursedir(f, filearray)
else
@@ -36,71 +44,68 @@ function recursedir(path, filearray)
end
end
+-- Function to list available files for view/delete
local function list_files ( ... )
+ -- Create a header for the view and create variables
local listed_files = { cfe{inuse="Delete", save="Save", view="View",
size="Size", lastmod="Last Modified", name="File"} }
local open_files = {}
--- split = require("split")
local files = {}
local k,v
-
- -- generate a singe table with all the files
+ -- Generate a singe table with all the files
for k,v in pairs{...} do
recursedir(v, files)
end
-
+ -- Loop through each file and present its info
for k,v in pairs(files) do
- local lastmod,size,fileinuseresult = file_info(v)
- if ( fileinuseresult == "Delete" ) then
- del="/delete?name=" .. v
- else
- del=nil
- end
- table.insert ( listed_files , cfe{inuse=fileinuseresult, del=del, save="/download?name=" .. v, view="/view?name=" .. v, size=size, lastmod=lastmod, name=v, type="", id=k} )
+ -- Get info on this specific file and put it in a table
+ local lastmod,size,fileinuseresult,fileinuseurl = file_info(v)
+ table.insert ( listed_files , cfe{inuse=fileinuseresult, del=fileinuseurl, save="/download?name=" .. v, view="/view?name=" .. v, size=size, lastmod=lastmod, name=v, type="", id=k} )
end
return listed_files
end
+-- Function to check if a file is deletable, and if it is, then delete it.
local function checkfilefordelete ( filetodelete )
local deletedfile = {}
+ deletedfile = cfe{value=nil, type="text", option=nil, errtxt="File '" .. filetodelete .. "' has not been deleted!"}
+ -- Get a list of files that could be deleted
local available_files = get()
for k,v in pairs(available_files) do
if ( available_files[k].name == filetodelete ) then
+ -- Check if file is deletable (or in use)
if ( available_files[k].del ) then
local status, err = os.remove( filetodelete )
if not ( err ) then
deletedfile = cfe{value="File '" .. filetodelete .. "' has been successfully deleted!", type="text", option=nil, errtxt=err}
+ else
+ deletedfile = cfe{value=nil, type="text", option=nil, errtxt=err}
end
else
end
end
end
- if not ( deletedfile.value ) then
- if not ( err ) then
- err = "The file is not accepted for removal!"
- end
- deletedfile = cfe{value="File '" .. filetodelete .. "' has not been deleted!", type="text", option=nil, errtxt=err}
- end
return deletedfile
end
local function checkfileforview ( path )
local file = {}
+ -- Get a list of files that could be viewed
local available_files = get()
- filecontent = cfe{value="", type="longtext", option=nil, errtxt="You are not allowed to view this file!"}
+ filecontent = cfe{value=nil, type="longtext", option=nil, errtxt="You are not allowed to view this file!"}
for k,v in pairs(available_files) do
if ( available_files[k].name == path ) then
local file = io.open( path )
local file_result = file:read("*a") or "unknown"
file:close()
- err=nil
- filecontent = cfe{value=file_result, type="text", option=nil, name=basename(path), errtxt=err}
+ filecontent = cfe{value=file_result, type="text", option=nil, name=basename(path), errtxt=nil}
end
end
return filecontent
end
get = function (self)
+ -- These folders (and their subfolers) are going to be listed
return list_files( "/var/log", "/tmp/squid/log" )
end