From 15f6d121de6842fe5702a34ab50a47b9df5797e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sun, 29 Dec 2019 00:26:57 +0100 Subject: [PATCH] fix extendedgitgraph live output --- www/commands/extendedgitgraph_status.php | 46 +++++++++++++++++------- www/commands/server_gitwebhook.php | 2 ++ www/extern/egg/ExtendedGitGraph2.php | 1 + www/extern/egg/Logger.php | 22 ++++++++++++ www/pages/api.php | 10 +++++- 5 files changed, 67 insertions(+), 14 deletions(-) diff --git a/www/commands/extendedgitgraph_status.php b/www/commands/extendedgitgraph_status.php index 1b93d9b..e39ee5e 100644 --- a/www/commands/extendedgitgraph_status.php +++ b/www/commands/extendedgitgraph_status.php @@ -2,21 +2,41 @@ global $CONFIG; -if (session_status() !== PHP_SESSION_ACTIVE) session_start(); - -$svar = $CONFIG['extendedgitgraph']['session_var']; - -if (isset($_GET['clear'])) if (key_exists($svar, $_SESSION)) $_SESSION[$svar] = ''; - -if (key_exists($svar, $_SESSION)) +if ($CONFIG['extendedgitgraph']['output_file']) { - if ($_SESSION[$svar] === '') echo '[[ NO OUTPUT ]]'; - else echo $_SESSION[$svar] === ''; + $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']; + + 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 '[[ NO SESSION STARTED ]]'; + } } else { - echo '[[ NO SESSION STARTED ]]'; + echo '[[ NO USEFUL LOGGER CONFIGURED ]]'; } - - -return; \ No newline at end of file diff --git a/www/commands/server_gitwebhook.php b/www/commands/server_gitwebhook.php index ac9932a..1876fd8 100644 --- a/www/commands/server_gitwebhook.php +++ b/www/commands/server_gitwebhook.php @@ -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' }"; \ No newline at end of file diff --git a/www/extern/egg/ExtendedGitGraph2.php b/www/extern/egg/ExtendedGitGraph2.php index 355922e..62b796f 100644 --- a/www/extern/egg/ExtendedGitGraph2.php +++ b/www/extern/egg/ExtendedGitGraph2.php @@ -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 = []; diff --git a/www/extern/egg/Logger.php b/www/extern/egg/Logger.php index 727b011..4b766a2 100644 --- a/www/extern/egg/Logger.php +++ b/www/extern/egg/Logger.php @@ -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(); } diff --git a/www/pages/api.php b/www/pages/api.php index 5d89174..025a402 100644 --- a/www/pages/api.php +++ b/www/pages/api.php @@ -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.'); }