1
0

fix extendedgitgraph live output

This commit is contained in:
Mike Schwörer 2019-12-29 00:26:57 +01:00
parent 0d0b8f64b1
commit 15f6d121de
5 changed files with 67 additions and 14 deletions

View File

@ -2,6 +2,24 @@
global $CONFIG;
if ($CONFIG['extendedgitgraph']['output_file'])
{
$lfile = $CONFIG['extendedgitgraph']['output_filepath'];
if (file_exists($lfile))
{
$data = file_get_contents($lfile);
if ($data === '') echo '[[ EMPTY ]]';
else echo $data;
}
else
{
echo '[[ FILE NOT FOUND ]]';
}
}
else if ($CONFIG['extendedgitgraph']['output_file'])
{
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
$svar = $CONFIG['extendedgitgraph']['session_var'];
@ -11,12 +29,14 @@ if (isset($_GET['clear'])) if (key_exists($svar, $_SESSION)) $_SESSION[$svar] =
if (key_exists($svar, $_SESSION))
{
if ($_SESSION[$svar] === '') echo '[[ NO OUTPUT ]]';
else echo $_SESSION[$svar] === '';
else echo $_SESSION[$svar];
}
else
{
echo '[[ NO SESSION STARTED ]]';
}
return;
}
else
{
echo '[[ NO USEFUL LOGGER CONFIGURED ]]';
}

View File

@ -25,3 +25,5 @@ $content = "REQUEST: " . $uri . "\r\n\r\n" .
"OUTPUT: " . $std . "\r\n\r\n";
sendMail("Webhook '$hook' triggered", $content, 'virtualadmin@mikescher.de', 'webserver-info@mikescher.com');
echo "{ 'status': 'ok', 'message': 'Webhook '$hook' triggered' }";

View File

@ -30,6 +30,7 @@ class ExtendedGitGraph2 implements ILogger
if ($config['output_session']) $this->logger []= new SessionLogger($config['session_var']);
if ($config['output_stdout']) $this->logger []= new OutputLogger();
if ($config['output_logfile']) $this->logger []= new FileLogger($config['logfile'], $config['logfile_count']);
if ($config['output_file']) $this->logger []= new SingleFileLogger($config['output_filepath']);
$this->sources = [];

View File

@ -42,6 +42,26 @@ class FileLogger implements ILogger
}
}
class SingleFileLogger implements ILogger
{
/** @var string $path */
private $path;
/**
* @var string $filename
*/
public function __construct($filename)
{
$this->path = $filename;
file_put_contents($this->path, '', FILE_TEXT);
}
public function proclog($text)
{
file_put_contents($this->path, $text . PHP_EOL , FILE_APPEND | LOCK_EX);
}
}
class SessionLogger implements ILogger
{
/** @var string $sessionvar */
@ -64,6 +84,8 @@ class SessionLogger implements ILogger
{
if (session_status() === PHP_SESSION_DISABLED) return;
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
$_SESSION[$this->sessionvar] .= $text . "\r\n";
session_commit();
}

View File

@ -76,7 +76,6 @@ $API_OPTIONS = [];
foreach ($_GET as $k => $v) $API_OPTIONS[strtolower($k)] = $v;
foreach ($OPTIONS['_urlparams'] as $k => $v) $API_OPTIONS[strtolower($k)] = $v;
try
{
/** @noinspection PhpIncludeInspection */
@ -86,4 +85,13 @@ catch (exception $e)
{
print("API Command failed with exception");
print($e);
$content =
"REQUEST: " . var_export($_REQUEST) . "\r\n\r\n" .
"IP: " . get_client_ip() . "\r\n\r\n" .
"ERROR: " . $e . "\r\n\r\n";
sendMail("Website API call failed", $content, 'virtualadmin@mikescher.de', 'webserver-info@mikescher.com');
httpDie(500, 'Error.');
}