mirror of
https://github.com/unraid/webgui.git
synced 2026-01-28 20:49:04 -06:00
Improved syslog reading
This commit is contained in:
@@ -4,8 +4,8 @@ Icon="icon-log"
|
||||
Tag="list"
|
||||
---
|
||||
<?PHP
|
||||
/* Copyright 2005-2020, Lime Technology
|
||||
* Copyright 2012-2020, Bergware International.
|
||||
/* Copyright 2005-2022, Lime Technology
|
||||
* Copyright 2012-2022, Bergware International.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
@@ -16,38 +16,40 @@ Tag="list"
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
$zip = htmlspecialchars(str_replace(' ','_',strtolower($var['NAME'])));
|
||||
$log = '/var/log/syslog';
|
||||
$cfg = '/boot/config/rsyslog.cfg';
|
||||
$select = '';
|
||||
$zip = htmlspecialchars(str_replace(' ','_',strtolower($var['NAME'])));
|
||||
$log = '/var/log/syslog';
|
||||
$cfg = '/boot/config/rsyslog.cfg';
|
||||
$select = [];
|
||||
if (file_exists($cfg)) {
|
||||
$syslog = parse_ini_file($cfg);
|
||||
if ($syslog['local_server'] && $logs = glob($syslog['server_folder'].'/syslog-*.log',GLOB_NOSORT)) {
|
||||
$select = "<select onchange='showLog(this.value)'>";
|
||||
$select .= mk_option(1,$log,'syslog');
|
||||
natsort($logs);
|
||||
foreach ($logs as $file) $select .= mk_option(1,$file,basename($file));
|
||||
$select .= "</select>";
|
||||
$select[] = "<select onchange='showLog(this.value)'>";
|
||||
$select[] = mk_option(1,$log,'syslog');
|
||||
foreach ($logs as $file) $select[] = mk_option(1,$file,basename($file));
|
||||
$select[] = "</select>";
|
||||
}
|
||||
}
|
||||
$select = implode($select);
|
||||
?>
|
||||
<style>span.log{display:block}</style>
|
||||
<script>
|
||||
var logfile = '<?=$log?>';
|
||||
var logfile = "<?=$log?>";
|
||||
|
||||
function zipfile(){
|
||||
var d = new Date();
|
||||
return '<?=$zip?>-'+logfile.split('/').reverse()[0].replace('.log','')+'-'+d.toISOString().substr(0,16).replace(/[-:]/g,'').replace('T','-')+'.zip';
|
||||
return "<?=$zip?>-"+logfile.split('/').reverse()[0].replace('.log','')+'-'+d.toISOString().substr(0,16).replace(/[-:]/g,'').replace('T','-')+'.zip';
|
||||
}
|
||||
function cleanUp(file) {
|
||||
if (document.hasFocus()) {
|
||||
$('input[value="_(Downloading)_..."]').val("_(Download)_").prop('disabled',false);
|
||||
$('input#download').val("_(Download)_").prop('disabled',false);
|
||||
$.post('/webGui/include/Download.php',{cmd:'delete',file:file});
|
||||
} else {
|
||||
setTimeout(function(){cleanUp(file);},2000);
|
||||
}
|
||||
}
|
||||
function syslog(file) {
|
||||
$('input[value="_(Download)_"]').val("_(Downloading)_...").prop('disabled',true);
|
||||
$('input#download').val("_(Downloading)_...").prop('disabled',true);
|
||||
$.post('/webGui/include/Download.php',{cmd:'save',source:logfile,file:file},function(zip) {
|
||||
location = zip;
|
||||
setTimeout(function(){cleanUp(file);},4000);
|
||||
@@ -101,4 +103,4 @@ $(function() {
|
||||
$('.tabs').append("<span class='status'><?=$select?><span class='lite label'><label>_(Text)_<input type='checkbox' class='ctrl' onclick='highlight(!this.checked,\"N\")' checked></label></span><span class='error label'><label>_(Error)_<input type='checkbox' onclick='highlight(this.checked,\"E\")' checked></label></span><span class='warn label'><label>_(Warning)_<input type='checkbox' onclick='highlight(this.checked,\"W\")' checked></label></span><span class='system label'><label>_(System)_<input type='checkbox' onclick='highlight(this.checked,\"S\")' checked></label></span><span class='array label'><label>_(Array)_<input type='checkbox' onclick='highlight(this.checked,\"A\")' checked></label></span><span class='login label'><label>_(Login)_<input type='checkbox' onclick='highlight(this.checked,\"L\")' checked></label></span><span class='lite label'><input type='checkbox' class='ctrl' onclick='toggle(this.checked)' checked></span></span>");
|
||||
</script>
|
||||
<pre class='up'></pre>
|
||||
<input type="button" value="_(Download)_" onclick="syslog(zipfile())"><input type="button" value="_(Refresh)_" onclick="showLog(logfile)"><input type="button" value="_(Done)_" onclick="done()">
|
||||
<input type="button" id="download" value="_(Download)_" onclick="syslog(zipfile())"><input type="button" value="_(Refresh)_" onclick="showLog(logfile)"><input type="button" value="_(Done)_" onclick="done()">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2020, Lime Technology
|
||||
* Copyright 2012-2020, Bergware International.
|
||||
/* Copyright 2005-2022, Lime Technology
|
||||
* Copyright 2012-2022, Bergware International.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
@@ -14,20 +14,21 @@
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/webGui/include/ColorCoding.php";
|
||||
|
||||
$logs = glob($_POST['log'].'*',GLOB_NOSORT);
|
||||
usort($logs, create_function('$a,$b', 'return filemtime($a)-filemtime($b);'));
|
||||
array_multisort(array_map('filemtime',($logs = glob($_POST['log'].'*',GLOB_NOSORT))),SORT_ASC,$logs);
|
||||
$sum = array_sum(array_map(function($log){return count(file($log));},$logs));
|
||||
$max = 5000;
|
||||
$row = 0;
|
||||
|
||||
foreach ($logs as $log) {
|
||||
$i=0;
|
||||
$line_count = intval(exec("wc -l '$log'"));
|
||||
$fh = fopen($log, "r");
|
||||
$fh = fopen($log,'r');
|
||||
while (($line = fgets($fh)) !== false) {
|
||||
$i++;
|
||||
if ($i < $line_count - 3000) {
|
||||
continue;
|
||||
if ($max < $sum - $row++) continue;
|
||||
$span = '<span class="log text">';
|
||||
foreach ($match as $type) foreach ($type['text'] as $text) if (preg_match("/$text/i",$line)) {
|
||||
$span = '<span class="log '.$type['class'].'">';
|
||||
break 2;
|
||||
}
|
||||
$span = "span class='text'";
|
||||
foreach ($match as $type) foreach ($type['text'] as $text) if (preg_match("/$text/i",$line)) {$span = "span class='{$type['class']}'"; break 2;}
|
||||
echo "<$span>".htmlspecialchars($line)."</span>";
|
||||
echo $span,htmlspecialchars(rtrim($line,"\n")),"</span>";
|
||||
}
|
||||
fclose($fh);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user