From bf94690223cd2b0821a969655bf9f3e7a0944d71 Mon Sep 17 00:00:00 2001 From: hummypkg Date: Wed, 17 Dec 2014 23:02:55 +0000 Subject: [PATCH] new log viewer git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@2084 2a923420-c742-0410-a762-8d5b09965624 --- CONTROL/control | 2 +- webif/html/diag/clearlog.jim | 22 --- webif/html/diag/diag.jim | 16 +- webif/html/diag/script.js | 26 --- .../bindwithdelay/bindWithDelay.js | 56 +++++++ .../tablesorter2/images/pager/first.png | Bin 0 -> 720 bytes .../tablesorter2/images/pager/last.png | Bin 0 -> 737 bytes .../tablesorter2/images/pager/loading.gif | Bin 0 -> 416 bytes .../tablesorter2/images/pager/next.png | Bin 0 -> 736 bytes .../tablesorter2/images/pager/prev.png | Bin 0 -> 745 bytes webif/html/log/_lib.jim | 12 ++ webif/html/log/act.jim | 24 +++ webif/html/log/fetch.jim | 32 ++++ webif/html/log/index.jim | 90 +++++++++++ webif/html/log/loginfo.jim | 26 +++ webif/html/log/script.js | 149 ++++++++++++++++++ webif/html/log/style.css | 38 +++++ 17 files changed, 434 insertions(+), 59 deletions(-) delete mode 100755 webif/html/diag/clearlog.jim create mode 100644 webif/html/lib/jquery.plugin/bindwithdelay/bindWithDelay.js create mode 100644 webif/html/lib/jquery.plugin/tablesorter2/images/pager/first.png create mode 100644 webif/html/lib/jquery.plugin/tablesorter2/images/pager/last.png create mode 100644 webif/html/lib/jquery.plugin/tablesorter2/images/pager/loading.gif create mode 100644 webif/html/lib/jquery.plugin/tablesorter2/images/pager/next.png create mode 100644 webif/html/lib/jquery.plugin/tablesorter2/images/pager/prev.png create mode 100755 webif/html/log/_lib.jim create mode 100755 webif/html/log/act.jim create mode 100755 webif/html/log/fetch.jim create mode 100755 webif/html/log/index.jim create mode 100755 webif/html/log/loginfo.jim create mode 100644 webif/html/log/script.js create mode 100644 webif/html/log/style.css diff --git a/CONTROL/control b/CONTROL/control index d753d04..3477f4e 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,7 +1,7 @@ Package: webif Priority: optional Section: web -Version: 1.0.18 +Version: 1.0.18-1 Architecture: mipsel Maintainer: af123@hummypkg.org.uk Depends: webif-channelicons(>=1.1.14),lighttpd(>=1.4.35-2),jim(>=0.75-1),jim-oo,jim-sqlite3(>=0.75),jim-cgi(>=0.7),jim-binary(>=0.75),service-control(>=1.2),busybox(>=1.20.2-1),lsof(>=4.87),epg(>=1.0.14),hmt(>=1.1.21),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2-1),stripts(>=1.2.5-3),smartmontools,tmenu(>=1.08),ffmpeg,id3v2,multienv(>=1.6),tcpping(>=1.1),mongoose diff --git a/webif/html/diag/clearlog.jim b/webif/html/diag/clearlog.jim deleted file mode 100755 index 8212770..0000000 --- a/webif/html/diag/clearlog.jim +++ /dev/null @@ -1,22 +0,0 @@ -#!/mod/bin/jimsh - -package require cgi -source /mod/webif/lib/setup - -httpheader - -set logdirs {/var/log /mod/tmp /mnt/hd3} -set logext {.log} - -set log [cgi_get file 0] -set unlink [cgi_get unlink 0] - -set ldir [file dirname $log] -if {[file dirname $log] in $logdirs && [file extension $log] in $logext} { - file copy -force "/dev/null" $log - if {$unlink} { file delete $log } - puts "Cleared $log" - exit -} -puts "Cannot clear $log" - diff --git a/webif/html/diag/diag.jim b/webif/html/diag/diag.jim index a58686e..28da729 100755 --- a/webif/html/diag/diag.jim +++ b/webif/html/diag/diag.jim @@ -12,7 +12,6 @@ pkg loaddiagmeta set smv [system modversion 1] - puts {
Utilities @@ -167,17 +166,14 @@ View: View Log Files } -foreach file [lsort [concat \ - [glob -nocomplain /var/log/*.log] \ - [glob -nocomplain /mod/tmp/*.log] \ - [glob -nocomplain /mnt/hd3/*.log] \ -]] { - puts " +source /mod/webif/html/log/_lib.jim +foreach file [lsort -command logsort $loglist] { + puts " - [file tail $file] + + [file tail $file] + ([pretty_size [file size $file]]) - - Clear
" } diff --git a/webif/html/diag/script.js b/webif/html/diag/script.js index b0ee720..8af35e6 100644 --- a/webif/html/diag/script.js +++ b/webif/html/diag/script.js @@ -27,32 +27,6 @@ $('#runfopkg').click(function() { }); }); -$('a.log').click(function(e) { - e.preventDefault(); - $('#results') - .slideDown() - .text('\n\nLoading log, please wait...\n\n') - .load('/cgi-bin/cat.jim?file=' + - encodeURIComponent($(this).attr('file')), function() { - $('#results').wrapInner('
');
-		});
-});
-
-$('a.logclear').click(function(e) {
-	var t = $(this);
-	e.preventDefault();
-	if (!confirm('Delete ' + $(this).attr('file') + '?'))
-		return;
-	$('#results')
-	    .slideDown()
-	    .text('\n\nClearing log, please wait...\n\n')
-	    .load('clearlog.jim?file=' +
-	        encodeURIComponent($(this).attr('file')), function() {
-	    		$('#results').wrapInner('
');
-			$(t).prev('span.lsize').html('0 bytes');
-		});
-});
-
 $('#runedit').click(function(e) {
 	e.preventDefault();
 	window.location = '/edit/edit.jim';
diff --git a/webif/html/lib/jquery.plugin/bindwithdelay/bindWithDelay.js b/webif/html/lib/jquery.plugin/bindwithdelay/bindWithDelay.js
new file mode 100644
index 0000000..a58f331
--- /dev/null
+++ b/webif/html/lib/jquery.plugin/bindwithdelay/bindWithDelay.js
@@ -0,0 +1,56 @@
+/*
+bindWithDelay jQuery plugin
+Author: Brian Grinstead
+MIT license: http://www.opensource.org/licenses/mit-license.php
+
+http://github.com/bgrins/bindWithDelay
+http://briangrinstead.com/files/bindWithDelay
+
+Usage:
+    See http://api.jquery.com/bind/
+    .bindWithDelay( eventType, [ eventData ], handler(eventObject), timeout, throttle )
+
+Examples:
+    $("#foo").bindWithDelay("click", function(e) { }, 100);
+    $(window).bindWithDelay("resize", { optional: "eventData" }, callback, 1000);
+    $(window).bindWithDelay("resize", callback, 1000, true);
+*/
+
+(function($) {
+
+$.fn.bindWithDelay = function( type, data, fn, timeout, throttle ) {
+
+    if ( $.isFunction( data ) ) {
+        throttle = timeout;
+        timeout = fn;
+        fn = data;
+        data = undefined;
+    }
+
+    // Allow delayed function to be removed with fn in unbind function
+    fn.guid = fn.guid || ($.guid && $.guid++);
+
+    // Bind each separately so that each element has its own delay
+    return this.each(function() {
+
+        var wait = null;
+
+        function cb() {
+            var e = $.extend(true, { }, arguments[0]);
+            var ctx = this;
+            var throttler = function() {
+                wait = null;
+                fn.apply(ctx, [e]);
+            };
+
+            if (!throttle) { clearTimeout(wait); wait = null; }
+            if (!wait) { wait = setTimeout(throttler, timeout); }
+        }
+
+        cb.guid = fn.guid;
+
+        $(this).bind(type, data, cb);
+    });
+};
+
+})(jQuery);
diff --git a/webif/html/lib/jquery.plugin/tablesorter2/images/pager/first.png b/webif/html/lib/jquery.plugin/tablesorter2/images/pager/first.png
new file mode 100644
index 0000000000000000000000000000000000000000..6f11fcb086b1bfa51bc5070ca45fac0a988c624c
GIT binary patch
literal 720
zcmV;>0x$iEP)ITpohD^Ctgf=H~o==W*|y0)VM;-LQd9lR=YF)677|
z!Jh8V_;KSkP5LJrlF9S+j0qkk+2iPm7~x{#{$ZSbvzK9J-4zqYVC)27V7~717pTZd
znit9v$VwYJS3ROyLxp^?0)a!0U)oMn7(0Xv0eUoZ@gH)t)d5_J+J%bT22oSJ)g^nf
zqQZVCEIYOm2+rB;rB+cID%~N1o%g50=A<=fWgC_GFUb)
z%s4&22M=t~3G+RMgR^pz#KbcfK)ZtsdJ$j@d{400GnQJeAz+sPu#&f$`6hKh0J%~V
zq(%oWs|qZyzh}{lfSK@dRK#JSxg@DDP3^*cD+kP0j(npKkSQvp3bk_uYtD5My##O+
z;RpcDs9R5c#9;NFP5{z^GN_^r%PX%(0OOZ~7+aNFP*XZk{E2|i#E`vI`YjCrsfz|V
zndEsDXoqvug2CxaF}ZvhdOaY6!{9q~KO+jO!o5Vk0qt%NcD}`cvVR;6QTNzYGWq-=
zUX+?7V0e7VLW2m6_>T!vT6W8eRsOC$*+0hNMWWwDsLfA)S*X-WV71;M{bCzza-4I45g$8m^55K?|L?r+odSTVNnJ96LXt|7TGI4L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;+4aEd;HM{A>I)B?7>yL4`Nc6h^we^ve
z3YC6fwXTqAQWr8=Cd?emR={YnNptkhuSFVP{Q?6Lt^
zqF4A?)Arx1JpP&Pyh<4sUhXnam)AJ@xmkE-VuVGbg_|=vm|INb-=FD!zVlDxJ_uiv
SXLQ>D0000yhD

literal 0
HcmV?d00001

diff --git a/webif/html/lib/jquery.plugin/tablesorter2/images/pager/prev.png b/webif/html/lib/jquery.plugin/tablesorter2/images/pager/prev.png
new file mode 100644
index 0000000000000000000000000000000000000000..15d1584bdbb2c26a9fc4c8269aa54615a58a4657
GIT binary patch
literal 745
zcmV1hlor
z)=Ec^h7>5J3?Bj(D6|X+0|UcQj&m*_Qg!D|-c07sd7pF6opXl(U}#WhWg0W$d_xV%ATb~UcS*dC+@kfS*m{?64KBH-eM78JQAu#&2c
z7TM!?0X98;&a@msh@1ehFDx4~_smCS0rm@Z$dv@5Y^ec>Jl}_`uDh5!i#cpZh5&_)
z{y|~cgJzZ1d%`?CxkdJIg%by0u(~PqB0%Zdj?maMmYO=M!=;B#0>~5_5YO>&?w*4H
z@LRbi!eNPrxg`gUUIeK8JG(3%R{o~|7so$K+8_qZe0Iz($pKd%d&oOhA&AGYXkKE`
zO8~w=kN^smCS05H!-WT*2mpbXAJK6B{s*`+;U?8|s%XO8{Hs1d`DH6am$(L0coEX9
z)c+Ho)WS9-4?6~g4NrO@c2FaKCYmmR!DQ~YpfIn+s8pr^?KThtmU&}3Kr*7R^y^Rk
z5Xsb_*=oc3w-9KI@B4=+yK6a8uQ@#oTkf1PnlL+NjAm=Zh)+xqld|idFEF=^(avw|
z4U*w)Kx6;tnV0ZXQD@SHtHr7{`Y12
bpX>Y!%!CO%>C8GV00000NkvXXu0mjfJYGkQ

literal 0
HcmV?d00001

diff --git a/webif/html/log/_lib.jim b/webif/html/log/_lib.jim
new file mode 100755
index 0000000..b7b265c
--- /dev/null
+++ b/webif/html/log/_lib.jim
@@ -0,0 +1,12 @@
+#!/mod/bin/jimsh
+
+set loglist [concat \
+    [glob -nocomplain /var/log/*.log] \
+    [glob -nocomplain /mod/tmp/*.log] \
+    [glob -nocomplain /mnt/hd3/*.log]
+]
+
+proc logsort {a b} {
+	return [string compare [file tail $a] [file tail $b]]
+}
+
diff --git a/webif/html/log/act.jim b/webif/html/log/act.jim
new file mode 100755
index 0000000..d14198c
--- /dev/null
+++ b/webif/html/log/act.jim
@@ -0,0 +1,24 @@
+#!/mod/bin/jimsh
+
+package require cgi
+source /mod/webif/lib/setup
+
+source _lib.jim
+
+cgi_input
+
+set file [cgi_get file "-"]
+if {$file ni $loglist} { exit }
+
+set action [cgi_get action -]
+
+switch $action {
+    clear {
+        file copy -force "/dev/null" $file
+        puts "Cleared $file"
+        exit
+    }
+}
+
+puts "Unknown action."
+
diff --git a/webif/html/log/fetch.jim b/webif/html/log/fetch.jim
new file mode 100755
index 0000000..0b0bf1c
--- /dev/null
+++ b/webif/html/log/fetch.jim
@@ -0,0 +1,32 @@
+#!/mod/bin/jimsh
+
+package require cgi
+source /mod/webif/lib/setup
+
+source _lib.jim
+
+cgi_input
+#cgi_dump
+
+httpheader
+
+set file [cgi_get file "-"]
+if {$file eq "-"} { set file "/var/log/humaxtv.log" }
+if {$file ni $loglist} { exit }
+
+set lines [cgi_get lines 0]
+
+if {$lines} {
+	set fp [popen [list tail -n $lines $file]]
+} else {
+	set fp [open $file r]
+}
+set l 1
+while {![$fp eof]} {
+	$fp gets line
+	if {[$fp eof]} break
+	puts "$l[cgi_quote_html $line]"
+	incr l
+}
+$fp close
+
diff --git a/webif/html/log/index.jim b/webif/html/log/index.jim
new file mode 100755
index 0000000..11bc4df
--- /dev/null
+++ b/webif/html/log/index.jim
@@ -0,0 +1,90 @@
+#!/mod/bin/jimsh
+
+package require cgi
+source /mod/webif/lib/setup
+require pretty_size system.class pkg.class
+source _lib.jim
+
+set logf [cgi_get log -]
+
+jqplugin enadis tablesorter2 bindwithdelay highlight
+jscss script.js style.css
+header
+
+puts "
+
+Log File: + First + Prev + + Next + Last + + lines +
+" +} + +puts " + + + + + +
+ + +
+ +
+[pager] + +
+Highlight: + +
+ + + + + + + +
LineText
+ +[pager] + +
+" + +footer + diff --git a/webif/html/log/loginfo.jim b/webif/html/log/loginfo.jim new file mode 100755 index 0000000..78dfc94 --- /dev/null +++ b/webif/html/log/loginfo.jim @@ -0,0 +1,26 @@ +#!/mod/bin/jimsh + +package require cgi +source /mod/webif/lib/setup +require pretty_size + +source _lib.jim + +cgi_input +#cgi_dump + +set file [cgi_get file "-"] +if {$file eq "-"} { set file "/var/log/humaxtv.log" } +if {$file ni $loglist} { exit } + +httpheader "application/json" + +lassign [exec wc -l $file] lines + +puts "{ + \"size\": \"[file size $file]\", + \"pretty_size\": \"[pretty_size [file size $file]]\", + \"lines\": \"$lines\" +} +" + diff --git a/webif/html/log/script.js b/webif/html/log/script.js new file mode 100644 index 0000000..2dc2dbf --- /dev/null +++ b/webif/html/log/script.js @@ -0,0 +1,149 @@ + +$(function() { + +// 0 - client side +// 1 - server side +var mode = -1; +var logfile; +var logdata; + +var pageroptions = { + container: $('.pager'), + output: 'Showing {startRow} - {endRow} / {filteredRows}', + size: 50, + fixedHeight: true, + removeRows: false, + cssGoto: '.gotoPage' +}; + +var pageroptionsajax = $.extend({ + ajaxUrl: 'fetch.jim?page={page}&size={size}&{sortList:col}&{filterList:fcol}', + customAjaxUrl: function(table, url) { + var nurl = 'fetch.jim?file=' + encodeURIComponent(logfile) + + '&' + url.substring(10); + alert(nurl); + return nurl; + } +}, pageroptions); + +function loadlog_ajax() +{ + $('#loginfo').append(' (Ajax)'); + if (mode != 1) + { + //$('#logtab').trigger('destroy.pager'); + $('#logtab').tablesorterPager(pageroptionsajax); + $('#logtab').trigger('pageSet', 0); + mode = 1; + } + loadedlog(); +} + +function loadlog_entire(data) +{ + var lines = 0; + + if (data.lines > 5000) + { + lines = 5000; + $('#loginfo').append(' - showing 5000 most recent.'); + } + + $.get('fetch.jim', { + 'file': logfile, + 'lines': lines + }, function(data) { + if (mode != 0) + { + $('#logtab').trigger('destroy.pager'); + $('#logtab').tablesorterPager(pageroptions); + mode = 0; + } + $('#logtab tbody').html(data).trigger('update'); + $('#logtab').trigger('update'); + loadedlog(); + }); +} + +function loadlog(file, ajax) +{ + $('button').button('disable'); + + if (!file || file == '0') + return; + + $('#logarea').slideDown(); + $('#loginfo').empty(); + $('#loading').show('fast'); + $('#logtab tbody').empty(); + + // Fetch log info + $.getJSON('loginfo.jim', { 'file': file }, function(data) { + $('#loginfo').html(data.pretty_size + + ' (' + data.lines + ' line' + + (data.lines == 1 ? "" : "s") + ')'); + logfile = file; + logdata = data; + if (ajax) + loadlog_ajax(data); + else + loadlog_entire(data); + }); +} + +function loadedlog() +{ + $('#logtab') + .trigger('filterReset') + .trigger('sorton', [[[0,1]]]); + $('#loading').hide('fast'); + + $('button').button('enable'); + + if (logdata.lines == 0) + { + $('#logtab tbody') + .html('Log is empty...'); + $('#clear').button('disable'); + } + + var hl = $('#highlight').val(); + if (hl && hl.length) + $('#highlight').trigger('keyup'); +} + +$('#logtab') + .tablesorter({ + theme: 'green', + sortList: [[0,1]], + headerTemplate : '{content} {icon}', + widthFixed: true, + widgets: ['zebra', 'filter'] + }); + +$('#clear').button({icons: { primary: "ui-icon-trash" }}) + .on('click', function() { + if (confirm('Are you sure you wish to clear ' + logfile + '?')) + $.get('act.jim', { + 'file': logfile, + 'action': 'clear' + }, function() { + loadlog(logfile); + }); + }); + +$('#reload').button({icons: { primary: "ui-icon-refresh" }}) + .on('click', function() { + $('#log').trigger('change'); + }); + +$('#highlight').bindWithDelay('keyup', function(e) { + $('#logtab tbody').removeHighlight().highlight($(this).val()); +}, 500); + +$('#log').on('change', function() { + loadlog($('#log').val()) +}).trigger('change'); + +}); + diff --git a/webif/html/log/style.css b/webif/html/log/style.css new file mode 100644 index 0000000..26ebc31 --- /dev/null +++ b/webif/html/log/style.css @@ -0,0 +1,38 @@ + +div#logarea +{ + padding-top: 1em; +} + +th.line +{ + width: 10px; +} + +div.pager +{ + padding: 5px; +} + +td +{ + padding: 3px !important; +} + +#buttons +{ + padding-left: 2em; +} + +#highlight_div +{ + padding-left: 5em; +} + +#highlight +{ + padding: 5px 10px; + border-style: none; + box-sharow: none; +} +