diff options
-rw-r--r-- | logfiles-controller.lua | 12 | ||||
-rw-r--r-- | logfiles-model.lua | 32 | ||||
-rw-r--r-- | logfiles-status-html.lsp | 33 | ||||
-rw-r--r-- | logfiles-view-html.lsp | 34 | ||||
-rw-r--r-- | logfiles.menu | 2 |
5 files changed, 86 insertions, 27 deletions
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 @@ +<? local view = ... ?> +<html> +<body> +<h1>Available Logfiles</h1> + +<TABLE> + <TR style="background:#eee;font-weight:bold;"> + <TD style="padding-right:20px;white-space:nowrap;">Delete</TD> + <TD style="padding-right:20px;white-space:nowrap;">Save</TD> + <TD style="padding-right:20px;white-space:nowrap;">View</TD> + <TD style="padding-right:20px;white-space:nowrap;" align="right">Size</TD> + <TD style="padding-right:20px;white-space:nowrap;" align="right">Last Modified</TD> + <TD style="white-space:nowrap;" WIDTH="90%">File</TD> + </TR> + +<? for i = 1, table.maxn(view.logfile) do ?> + <TR > + <TD style="padding-right:20px;white-space:nowrap;"> + <? if view.logfile[i].del then ?> + <?= html.link{value = view.url .. view.logfile[i].del, label=view.logfile[i].inuse } ?> + <? else ?> + <?= view.logfile[i].inuse ?> + <? end ?></TD> + <TD style="padding-right:20px;white-space:nowrap;"><?= html.link{value = view.url .. view.logfile[i].view, label="View" } ?></TD> + <TD style="padding-right:20px;white-space:nowrap;"><?= html.link{value = view.url .. view.logfile[i].save, label="Download" } ?></TD> + <TD style="padding-right:20px;white-space:nowrap;" align="right"><?= view.logfile[i].size ?></TD> + <TD style="padding-right:20px;white-space:nowrap;" align="right"><?= view.logfile[i].lastmod ?></TD> + <TD style="white-space:nowrap;"><?= view.logfile[i].name ?></TD> + </TR> +<? end ?> +</TABLE> +</body> +</html> 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 @@ <? local view = ... ?> -<html> -<body> -<h1>View file</h1> + +<h1>LOGFILE</h1> + +<h2>Details</h2> + +<dl> +<dt>File name</dt> +<dd><?= view.logfile.details.path ?></dd> +</dl> + +<dl> +<dt>File size</dt> +<dd><?= view.logfile.details.size ?></dd> +</dl> + +<dl> +<dt>Last modified</dt> +<dd><?= view.logfile.details.mtime ?></dd> +</dl> + +<h2>Content</h2> <textarea name=""><? io.write(view.logfile.value) ?></textarea> -</body> -</html> + +<? +--[[ DEBUG INFORMATION +require("debugs") +io.write(debugs.variables(view)) +--]] +?> + 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 |