-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: user interface hangs if log file is missing
- Loading branch information
Showing
1 changed file
with
22 additions
and
9 deletions.
There are no files selected for viewing
31 changes: 22 additions & 9 deletions
31
src/usr/local/emhttp/plugins/tailscale/include/get_log.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |