diff options
author | Simon Rettberg | 2022-05-27 14:33:03 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-05-27 14:33:03 +0200 |
commit | 6b50640f3100de49b6475cc655b7dbe4fb37469a (patch) | |
tree | 62fa7d06fc7484e77f180da76b4f8b07f74f8d3d /modules-available/systemstatus | |
parent | [statistics] Fix displaying CPU core/thread info (diff) | |
download | slx-admin-6b50640f3100de49b6475cc655b7dbe4fb37469a.tar.gz slx-admin-6b50640f3100de49b6475cc655b7dbe4fb37469a.tar.xz slx-admin-6b50640f3100de49b6475cc655b7dbe4fb37469a.zip |
[systemstatus] lighttpd log: Filter some openssl errors
Diffstat (limited to 'modules-available/systemstatus')
-rw-r--r-- | modules-available/systemstatus/page.inc.php | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/modules-available/systemstatus/page.inc.php b/modules-available/systemstatus/page.inc.php index bf03112f..ca57de47 100644 --- a/modules-available/systemstatus/page.inc.php +++ b/modules-available/systemstatus/page.inc.php @@ -307,37 +307,36 @@ class Page_SystemStatus extends Page echo Render::parse('ajax-journal', ['modules' => [$output]]); } - protected function ajaxLighttpdLog() + private function grepLighttpdLog(string $file, int $num): array { - User::assertPermission("tab.lighttpdlog"); - $fh = @fopen('/var/log/lighttpd/error.log', 'r'); - if ($fh === false) { - echo 'Error opening log file'; - return; + $fh = @fopen($file, 'r'); + if ($fh === false) + return ['Error opening ' . $file]; + $ret = []; + fseek($fh, -($num * 2000), SEEK_END); + if (ftell($fh) > 0) { + // Throw away first line, as it's most likely incomplete + fgets($fh, 1000); } - fseek($fh, -6000, SEEK_END); - $data = fread($fh, 6000); - @fclose($fh); - if ($data === false) { - echo 'Error reading from log file'; - return; - } - // If we could read less, try the .1 file too - $amount = 6000 - strlen($data); - if ($amount > 100) { - $fh = @fopen('/var/log/lighttpd/error.log.1', 'r'); - if ($fh !== false) { - fseek($fh, -$amount, SEEK_END); - $data = fread($fh, $amount) . $data; - @fclose($fh); + while (($line = fgets($fh, 1000))) { + if (strpos($line, ':SSL routines:') === false + && strpos($line, ' SSL: -1 5 104 Connection reset by peer') === false) { + $ret[] = $line; } } - if (strlen($data) < 5990) { - $start = 0; - } else { - $start = strpos($data, "\n") + 1; + fclose($fh); + return array_slice($ret, -$num); + } + + protected function ajaxLighttpdLog() + { + User::assertPermission("tab.lighttpdlog"); + $lines = $this->grepLighttpdLog('/var/log/lighttpd/error.log', 60); + if (count($lines) < 50) { + $lines = array_merge( + $this->grepLighttpdLog('/var/log/lighttpd/error.log.1', 60 - count($lines)), $lines); } - echo '<pre>', htmlspecialchars(substr($data, $start), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'), '</pre>'; + echo '<pre>', htmlspecialchars(implode('', $lines), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'), '</pre>'; } protected function ajaxLdadpLog() |