mirror of
https://github.com/unraid/webgui.git
synced 2026-05-02 07:49:20 -05:00
Make LOG Windows behavior more obvious to user
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2021, Lime Technology
|
||||
* Copyright 2012-2021, 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,
|
||||
@@ -12,17 +12,25 @@
|
||||
?>
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
|
||||
// add translations
|
||||
$_SERVER['REQUEST_URI'] = '';
|
||||
require_once "$docroot/webGui/include/Translations.php";
|
||||
require_once "$docroot/webGui/include/Secure.php";
|
||||
require_once "$docroot/webGui/include/Helpers.php";
|
||||
require_once "$docroot/webGui/include/Wrappers.php";
|
||||
|
||||
// Get the webGui configuration preferences
|
||||
extract(parse_plugin_cfg('dynamix',true));
|
||||
|
||||
$rows = 80;
|
||||
$wait = "read -N 1 -p '\n** "._('Press ANY KEY to close this window')." ** '";
|
||||
|
||||
// set tty window font size
|
||||
exec("sed -ri 's/fontSize=[0-9]+/fontSize=${display['tty']}/' /etc/default/ttyd");
|
||||
if (isset($display['tty'])) exec("sed -ri 's/fontSize=[0-9]+/fontSize={$display['tty']}/' /etc/default/ttyd");
|
||||
|
||||
function command($path,$file) {
|
||||
return (file_exists($file) && substr($file,0,strlen($path))==$path) ? "tail -f -n 60 '$file'" : "read";
|
||||
global $rows,$wait;
|
||||
return (file_exists($file) && substr($file,0,strlen($path))==$path) ? "tail -f -n $rows '$file'" : $wait;
|
||||
}
|
||||
switch ($_GET['tag']) {
|
||||
case 'ttyd':
|
||||
@@ -38,34 +46,41 @@ case 'ttyd':
|
||||
if ($retval != 0) exec("ttyd-exec -i '$sock' bash --login");
|
||||
break;
|
||||
case 'syslog':
|
||||
// read syslog file
|
||||
$path = '/var/log/';
|
||||
$file = realpath($path.$_GET['name']);
|
||||
$sock = "/var/run/syslog.sock";
|
||||
exec("ttyd-exec -o -i '$sock' ".command($path,$file));
|
||||
@unlink($sock);
|
||||
exec("ttyd-exec -i '$sock' ".command($path,$file));
|
||||
break;
|
||||
case 'log':
|
||||
// read vm log file
|
||||
$path = '/var/log/';
|
||||
$name = unbundle($_GET['name']);
|
||||
$file = realpath($path.$_GET['more']);
|
||||
$sock = "/var/tmp/$name.sock";
|
||||
exec("ttyd-exec -o -i '$sock' ".command($path,$file));
|
||||
@unlink($sock);
|
||||
exec("ttyd-exec -i '$sock' ".command($path,$file));
|
||||
break;
|
||||
case 'docker':
|
||||
$name = unbundle($_GET['name']);
|
||||
$more = unbundle($_GET['more']) ?: 'sh';
|
||||
$docker = "/var/tmp/$name.run.sh";
|
||||
if ($more=='.log') {
|
||||
// read docker container log
|
||||
$sock = "/var/tmp/$name.log.sock";
|
||||
file_put_contents($docker,"#!/bin/bash\ndocker logs -f -n 60 '$name'\nread\n");
|
||||
chmod($docker,0755);
|
||||
exec("ttyd-exec -o -i '$sock' $docker");
|
||||
if (empty(exec("docker ps --filter=name='$name' --format={{.Names}}"))) {
|
||||
// container stopped - read log and wait for user input
|
||||
$docker = "/var/tmp/$name.run.sh";
|
||||
file_put_contents($docker,"#!/bin/bash\ndocker logs -n $rows '$name'\n$wait\n");
|
||||
chmod($docker,0755);
|
||||
} else {
|
||||
// container started - read log continuously
|
||||
$docker = "docker logs -f -n $rows '$name'";
|
||||
}
|
||||
exec("ttyd-exec -i '$sock' $docker");
|
||||
} else {
|
||||
// docker console command
|
||||
$sock = "/var/tmp/$name.sock";
|
||||
exec("ttyd-exec -o -i '$sock' docker exec -it '$name' $more");
|
||||
exec("ttyd-exec -i '$sock' docker exec -it '$name' $more");
|
||||
}
|
||||
@unlink($sock);
|
||||
break;
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user