mirror of
https://github.com/unraid/webgui.git
synced 2026-01-02 23:50:21 -06:00
154 lines
6.1 KiB
Plaintext
154 lines
6.1 KiB
Plaintext
Menu="UNRAID-OS"
|
|
Title="System Log"
|
|
Icon="icon-log"
|
|
Tag="list"
|
|
---
|
|
<?PHP
|
|
/* Copyright 2005-2023, Lime Technology
|
|
* Copyright 2012-2023, 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,
|
|
* as published by the Free Software Foundation.
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*/
|
|
?>
|
|
<?
|
|
$zip = htmlspecialchars(str_replace(' ','_',strtolower($var['NAME'])));
|
|
$log = '/var/log/syslog';
|
|
$prev = '/boot/logs/syslog-previous';
|
|
$cfg = '/boot/config/rsyslog.cfg';
|
|
$max = 5000;
|
|
$select = [];
|
|
$logs = [];
|
|
if (file_exists($cfg)) {
|
|
$syslog = parse_ini_file($cfg);
|
|
if (!empty($syslog['local_server']) && !empty($syslog['server_folder']) && $logs = glob($syslog['server_folder'].'/syslog-*.log',GLOB_NOSORT)) {
|
|
natsort($logs);
|
|
}
|
|
}
|
|
if (file_exists($prev)) {
|
|
// add syslog-previous to front of logs array
|
|
array_unshift($logs, $prev);
|
|
}
|
|
if (count($logs)) {
|
|
// add syslog to front of logs array
|
|
array_unshift($logs, $log);
|
|
$select[] = "<select onchange='showLog(this.value)'>";
|
|
foreach ($logs as $file) $select[] = mk_option(1,$file,basename($file));
|
|
$select[] = "</select>";
|
|
}
|
|
$select = implode($select);
|
|
?>
|
|
<script>
|
|
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';
|
|
}
|
|
function cleanUp(file) {
|
|
if (document.hasFocus()) {
|
|
$('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#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);
|
|
});
|
|
}
|
|
function highlight(checked,line) {
|
|
var o = checked ? '-' : '';
|
|
var n = ($('span.text').css('display')=='none' && !checked) ? 'none' : '';
|
|
switch (line) {
|
|
case 'E': $('span.'+o+'error').css('display',n); $('span.error'+o).toggleClass('error -error error-'); break;
|
|
case 'W': $('span.'+o+'warn').css('display',n); $('span.warn'+o).toggleClass('warn -warn warn-'); break;
|
|
case 'S': $('span.'+o+'system').css('display',n); $('span.system'+o).toggleClass('system -system system-'); break;
|
|
case 'A': $('span.'+o+'array').css('display',n); $('span.array'+o).toggleClass('array -array array-'); break;
|
|
case 'L': $('span.'+o+'login').css('display',n); $('span.login'+o).toggleClass('login -login login-'); break;
|
|
case 'N': $('span.text,span[class^="-"]').css('display',checked ? 'none':''); break;
|
|
}
|
|
$('span.label').show();
|
|
}
|
|
function toggle(checked) {
|
|
highlight(checked,'E');
|
|
highlight(checked,'W');
|
|
highlight(checked,'S');
|
|
highlight(checked,'A');
|
|
highlight(checked,'L');
|
|
$('span.label input[type=checkbox]').not('.ctrl').prop('checked',checked);
|
|
}
|
|
<?if (_var($display,'resize')):?>
|
|
function resize() {
|
|
$('pre.up').height(Math.max(window.innerHeight-320,330));
|
|
}
|
|
<?endif;?>
|
|
|
|
function showLog(log) {
|
|
logfile = log;
|
|
$('span.label input[type=checkbox]').prop('checked', true);
|
|
$('span.label').each(function() {
|
|
var type = $(this).attr('class').replace('label', '').replace(/-/g, '');
|
|
$(this).removeClass().addClass(type + ' label');
|
|
});
|
|
timers.syslog = setTimeout(function() { $('div.spinner.fixed').show('slow'); }, 500);
|
|
|
|
$.post('/webGui/include/Syslog.php', { log: log, max: $('#max').val() || <?=$max?> }, function(data) {
|
|
clearTimeout(timers.syslog);
|
|
let logContainer = document.querySelector("pre.up");
|
|
if (!logContainer) return; // Safety check
|
|
|
|
$('pre.up').html(data);
|
|
$('div.spinner.fixed').hide('slow');
|
|
|
|
/* Ensuring reliable scroll behavior on Chrome */
|
|
function scrollToBottom() {
|
|
logContainer.style.scrollBehavior = 'smooth';
|
|
logContainer.scrollTop = logContainer.scrollHeight;
|
|
}
|
|
|
|
/* 1. Delay with setTimeout */
|
|
setTimeout(scrollToBottom, 50);
|
|
|
|
/* 2. Force Chrome to reflow/repaint */
|
|
logContainer.style.display = "none";
|
|
setTimeout(function() {
|
|
logContainer.style.display = "block";
|
|
scrollToBottom();
|
|
}, 10);
|
|
|
|
/* 3. Use requestAnimationFrame */
|
|
requestAnimationFrame(scrollToBottom);
|
|
|
|
/* 4. Repeat scroll a few times as a backup (Fixes rare cases in Chrome) */
|
|
setTimeout(scrollToBottom, 100);
|
|
setTimeout(scrollToBottom, 500);
|
|
});
|
|
}
|
|
|
|
$(function() {
|
|
$('input#max').on('keydown',function(e) {
|
|
if (e.keyCode === 13) {
|
|
e.preventDefault();
|
|
e.stopImmediatePropagation();
|
|
showLog(logfile);
|
|
}
|
|
});
|
|
<?if (_var($display,'resize')):?>
|
|
resize();
|
|
$(window).bind('resize',function(){resize();});
|
|
<?endif;?>
|
|
showLog(logfile);
|
|
});
|
|
$('.tabs').append("<span class='status'><span class='lite label'>_(Log size)_: <input type='number' id='max' value='' placeholder='<?=$max?>'></span><?=$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" id="download" value="_(Download)_" onclick="syslog(zipfile())"><input type="button" value="_(Refresh)_" onclick="showLog(logfile)"><input type="button" value="_(Done)_" onclick="done()">
|