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 0000000..6f11fcb
Binary files /dev/null and b/webif/html/lib/jquery.plugin/tablesorter2/images/pager/first.png differ
diff --git a/webif/html/lib/jquery.plugin/tablesorter2/images/pager/last.png b/webif/html/lib/jquery.plugin/tablesorter2/images/pager/last.png
new file mode 100644
index 0000000..7207935
Binary files /dev/null and b/webif/html/lib/jquery.plugin/tablesorter2/images/pager/last.png differ
diff --git a/webif/html/lib/jquery.plugin/tablesorter2/images/pager/loading.gif b/webif/html/lib/jquery.plugin/tablesorter2/images/pager/loading.gif
new file mode 100644
index 0000000..7205471
Binary files /dev/null and b/webif/html/lib/jquery.plugin/tablesorter2/images/pager/loading.gif differ
diff --git a/webif/html/lib/jquery.plugin/tablesorter2/images/pager/next.png b/webif/html/lib/jquery.plugin/tablesorter2/images/pager/next.png
new file mode 100644
index 0000000..4a2f9d4
Binary files /dev/null and b/webif/html/lib/jquery.plugin/tablesorter2/images/pager/next.png differ
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 0000000..15d1584
Binary files /dev/null and b/webif/html/lib/jquery.plugin/tablesorter2/images/pager/prev.png differ
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; +} +