diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-09-03 13:51:14 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-09-03 13:51:14 +0000 |
commit | eb36e4c9737dee9dd3aaef56abcfcf6c407bd100 (patch) | |
tree | f823409966cb2c8152747236a312cbfe80c7e608 | |
parent | 3f22a6dd4d2336bf0c3409c400faa9f5488f0e32 (diff) | |
download | acf-alpine-baselayout-eb36e4c9737dee9dd3aaef56abcfcf6c407bd100.tar.bz2 acf-alpine-baselayout-eb36e4c9737dee9dd3aaef56abcfcf6c407bd100.tar.xz |
Added javascript tail functionality to logfiles.
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@1441 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | logfiles-controller.lua | 7 | ||||
-rw-r--r-- | logfiles-model.lua | 32 | ||||
-rw-r--r-- | logfiles-status-html.lsp | 2 | ||||
-rw-r--r-- | logfiles-tail-ajax.lsp | 12 | ||||
-rw-r--r-- | logfiles-tail-html.lsp | 46 |
5 files changed, 99 insertions, 0 deletions
diff --git a/logfiles-controller.lua b/logfiles-controller.lua index dc22115..2af76ee 100644 --- a/logfiles-controller.lua +++ b/logfiles-controller.lua @@ -24,3 +24,10 @@ download = function (self) return filecontent end + +tail = function (self) + if self.clientdata.offset then + self.conf.viewtype = "ajax" + end + return self.model.tail(self.clientdata.name, self.clientdata.offset) +end diff --git a/logfiles-model.lua b/logfiles-model.lua index 2ac4f5d..54aceee 100644 --- a/logfiles-model.lua +++ b/logfiles-model.lua @@ -76,6 +76,38 @@ get_filedetails = function (path) return filedetails end +tail = function(path, offset) + local filename = cfe({ value=path, label="File name", errtxt="File not found" }) + local filesize = cfe({ value="0", label="File size" }) + local filecontent = cfe({ type="longtext", label="File content" }) + local fileoffset = cfe({ value="0", label="File offset" }) + + local available_files = get() + for i,file in ipairs(available_files.value) do + if ( file.value.filename.value == path ) then + filename.errtxt = nil + local f = io.open(path) + if tonumber(offset) then + fileoffset.value = offset + offset = tonumber(offset) + if offset < 0 then + f:seek("end", offset) + else + f:seek("set", offset) + end + filecontent.value = f:read("*all") + filesize.value = f:seek() + else + filesize.value = f:seek("end") + fileoffset.value = filesize.value + end + f:close() + break + end + end + + return cfe({ type="group", value={filename=filename, filecontent=filecontent, filesize=filesize, fileoffset=fileoffset}, label="Tail Config file details" }) +end get = function () -- These folders (and their subfolers) are going to be listed diff --git a/logfiles-status-html.lsp b/logfiles-status-html.lsp index f25d8a4..d11e16d 100644 --- a/logfiles-status-html.lsp +++ b/logfiles-status-html.lsp @@ -9,6 +9,7 @@ <TR style="background:#eee;font-weight:bold;"> <TD style="padding-right:20px;white-space:nowrap;" class="header">Delete</TD> <TD style="padding-right:20px;white-space:nowrap;" class="header">View</TD> + <TD style="padding-right:20px;white-space:nowrap;" class="header">Tail</TD> <TD style="padding-right:20px;white-space:nowrap;" class="header">Save</TD> <TD style="padding-right:20px;white-space:nowrap;text-align:right;" class="header">Size</TD> <TD style="padding-right:20px;white-space:nowrap;" class="header">Last Modified</TD> @@ -24,6 +25,7 @@ <%= html.link{value = "delete?name="..file.value.filename.value, label="Delete" } %> <% end %></TD> <TD style="padding-right:20px;white-space:nowrap;"><%= html.link{value = "view?name="..file.value.filename.value, label="View" } %></TD> + <TD style="padding-right:20px;white-space:nowrap;"><%= html.link{value = "tail?name="..file.value.filename.value, label="Tail" } %></TD> <TD style="padding-right:20px;white-space:nowrap;"><%= html.link{value = "download?name="..file.value.filename.value, label="Download" } %></TD> <TD style="padding-right:20px;white-space:nowrap;text-align:right"><%= file.value.filesize.value %></TD> <TD style="padding-right:20px;white-space:nowrap;"><%= file.value.mtime.value %></TD> diff --git a/logfiles-tail-ajax.lsp b/logfiles-tail-ajax.lsp new file mode 100644 index 0000000..8697208 --- /dev/null +++ b/logfiles-tail-ajax.lsp @@ -0,0 +1,12 @@ +<% local view, viewlibrary, page_info = ... %> +<% + require("json") + require("html") +%> +Status: 200 OK +Content-Type: "application/json" +<% io.write("\n") %> +<% + view.value.filecontent.value = html.html_escape(view.value.filecontent.value) + print(json.encode(view)) +%> diff --git a/logfiles-tail-html.lsp b/logfiles-tail-html.lsp new file mode 100644 index 0000000..5b5d767 --- /dev/null +++ b/logfiles-tail-html.lsp @@ -0,0 +1,46 @@ +<% local form, viewlibrary, page_info = ... %> +<% require("viewfunctions") %> + +<script type="text/javascript" src="/js/jquery-latest.js"></script> +<script type="text/javascript"> + var currentoffset = -1024 + var ID + function Update(){ + $.getJSON( + '<%= page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action %>', + {name:'<%= form.value.filename.value %>', offset:currentoffset}, + function(data) { + data.value.filecontent.value = data.value.filecontent.value.split("\n").join("<br>\n"); + $("#filecontent").append(data.value.filecontent.value).scrollTop(999999999); + currentoffset = data.value.filesize.value; + $("DT:contains('File size')").next().text(currentoffset); + } + ); + ID=window.setTimeout("Update();", 1000); + } + $(function(){ + $("#Start").attr("disabled","disabled"); + <% if not form.value.filename.errtxt then %> + Update(); + <% else %> + $("#Stop").attr("disabled","disabled"); + <% end %> + }); +</script> + +<H1>Tail File</H1> +<DL> +<% +displayitem(form.value.filename) +displayitem(form.value.filesize) +%> +</DL> +<textarea id="filecontent"> +</textarea> +<DL> +<DT>Start / Stop tailing file</DT> +<DD> +<input TYPE="button" ID="Start" VALUE="Start" onClick='Update(); $("#Start").attr("disabled","disabled");$("#Stop").removeAttr("disabled");'> +<input TYPE="button" ID="Stop" VALUE="Stop" onClick='window.clearTimeout(ID); $("#Stop").attr("disabled","disabled");$("#Start").removeAttr("disabled");'> +</DD> +</DL> |