Skip to content

Commit

Permalink
fix: user interface hangs if log file is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaser committed Sep 22, 2024
1 parent 0db99bc commit b3f6f96
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/usr/local/emhttp/plugins/tailscale/include/get_log.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
<?php

ini_set('memory_limit', '512M'); // Increase memory limit
function getLog($log, $maxLines)
{
$allowed_files = ["/var/log/tailscale.log", "/var/log/tailscale-utils.log"];

if ( ! in_array($log, $allowed_files)) {
return;
}

$allowed_files = ["/var/log/tailscale.log", "/var/log/tailscale-utils.log"];
if ( ! file_exists($log)) {
echo '<span class="text">', htmlspecialchars($log), " not found.</span>";
return;
}

$log = $_POST['log'];
if ( ! in_array($log, $allowed_files)) {
return;
$max = intval($maxLines);
$lines = array_reverse(array_slice(file($log), -$max));

foreach ($lines as $line) {
echo '<span class="text">', htmlspecialchars($line), "</span>";
}
}

$max = intval($_POST['max']);
$lines = array_reverse(array_slice(file($log), -$max));
ini_set('memory_limit', '512M'); // Increase memory limit

foreach ($lines as $line) {
echo '<span class="text">', htmlspecialchars($line), "</span>";
try {
getLog($_POST['log'], $_POST['max']);
} catch (Throwable $e) {
echo '<span class="text">', htmlspecialchars($e->getMessage()), "</span>";
}

ini_restore('memory_limit'); // Restore original memory limit

0 comments on commit b3f6f96

Please sign in to comment.