From b49907bb90004ddd89420e1714bdac631d4cf4bd Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Tue, 15 Jan 2008 17:32:29 +0000 Subject: Cleaned up the code and using some librarys instead. git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@582 ab2d0c66-481e-0410-8bed-d214d4d58bed --- logfiles-controller.lua | 12 ++++++------ logfiles-model.lua | 32 +++++++++++++++++--------------- logfiles-status-html.lsp | 33 +++++++++++++++++++++++++++++++++ logfiles-view-html.lsp | 34 +++++++++++++++++++++++++++++----- logfiles.menu | 2 +- 5 files changed, 86 insertions(+), 27 deletions(-) create mode 100644 logfiles-status-html.lsp diff --git a/logfiles-controller.lua b/logfiles-controller.lua index 1a5ca30..c5a5896 100644 --- a/logfiles-controller.lua +++ b/logfiles-controller.lua @@ -4,7 +4,7 @@ module (..., package.seeall) -- We use the self.conf table because it already has prefix,controller,etc -- The redir code is defined in the application error handler (acf-controller) local list_redir = function (self) - self.conf.action = "read" + self.conf.action = "status" self.conf.type = "redir" error (self.conf) end @@ -18,7 +18,7 @@ end -- Public methods -read = function (self ) +status = function (self ) return ({logfile = self.model:get(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} ) end @@ -34,11 +34,11 @@ end view = function (self) local filetoview = self.clientdata.name or "" - local content = ({logfile = self.model:view(filetoview)} ) - if content.logfile.name == "" then - list_redir(self) - else + local content = { logfile=self.model:get_filedetails(filetoview)} + if (filetoview ~= "") and (content.logfile.name ~= nil) then return content + else + list_redir(self) end end diff --git a/logfiles-model.lua b/logfiles-model.lua index e0e0888..f00f7f4 100644 --- a/logfiles-model.lua +++ b/logfiles-model.lua @@ -1,19 +1,15 @@ -- acf model for displaying logfiles recusivly module (..., package.seeall) +require("fs") -- no initializer in model - use controller.init for that -- Function to get detailed information on a specific file. local function file_info ( 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 st = fs.stat(path) + local size = st.size + local lastmod = st.mtime local file_inuse = io.popen("fuser " .. path ) local fileinuseresult = file_inuse:read("*a") or "unkown" file_inuse:close() @@ -89,21 +85,27 @@ local function checkfilefordelete ( filetodelete ) end local function checkfileforview ( path ) - local file = {} - -- Get a list of files that could be viewed + local filecontent = nil local available_files = get() - 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() - filecontent = cfe{value=file_result, type="text", option=nil, name=basename(path), errtxt=nil} + filecontent = path end end return filecontent end +function get_filedetails(self,path) + local filedetails = {} + if (checkfileforview(path)) then + filedetails.details = fs.stat(path) + filedetails.value = fs.read_file(path) + filedetails.name = basename(path) + end + return filedetails +end + + get = function (self) -- These folders (and their subfolers) are going to be listed return list_files( "/var/log", "/tmp/squid/log" ) diff --git a/logfiles-status-html.lsp b/logfiles-status-html.lsp new file mode 100644 index 0000000..e5a1344 --- /dev/null +++ b/logfiles-status-html.lsp @@ -0,0 +1,33 @@ + + + +

Available Logfiles

+ + + + + + + + + + + + + + + + + + + + + +
DeleteSaveViewSizeLast ModifiedFile
+ + + + +
+ + diff --git a/logfiles-view-html.lsp b/logfiles-view-html.lsp index f148b86..0923230 100644 --- a/logfiles-view-html.lsp +++ b/logfiles-view-html.lsp @@ -1,7 +1,31 @@ - - -

View file

+ +

LOGFILE

+ +

Details

+ +
+
File name
+
+
+ +
+
File size
+
+
+ +
+
Last modified
+
+
+ +

Content

- - + + + diff --git a/logfiles.menu b/logfiles.menu index 68e2da1..f4a506a 100644 --- a/logfiles.menu +++ b/logfiles.menu @@ -1,2 +1,2 @@ #CAT GROUP/DESC TAB ACTION -System 50Logfiles Logfiles read +System 50Logfiles Logfiles status -- cgit v1.2.3