Skip to content
This repository was archived by the owner on Jul 15, 2025. It is now read-only.

Commit b3f6f96

Browse files
committed
fix: user interface hangs if log file is missing
1 parent 0db99bc commit b3f6f96

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

  • src/usr/local/emhttp/plugins/tailscale/include
Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
<?php
22

3-
ini_set('memory_limit', '512M'); // Increase memory limit
3+
function getLog($log, $maxLines)
4+
{
5+
$allowed_files = ["/var/log/tailscale.log", "/var/log/tailscale-utils.log"];
6+
7+
if ( ! in_array($log, $allowed_files)) {
8+
return;
9+
}
410

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

7-
$log = $_POST['log'];
8-
if ( ! in_array($log, $allowed_files)) {
9-
return;
16+
$max = intval($maxLines);
17+
$lines = array_reverse(array_slice(file($log), -$max));
18+
19+
foreach ($lines as $line) {
20+
echo '<span class="text">', htmlspecialchars($line), "</span>";
21+
}
1022
}
1123

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

15-
foreach ($lines as $line) {
16-
echo '<span class="text">', htmlspecialchars($line), "</span>";
26+
try {
27+
getLog($_POST['log'], $_POST['max']);
28+
} catch (Throwable $e) {
29+
echo '<span class="text">', htmlspecialchars($e->getMessage()), "</span>";
1730
}
1831

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

0 commit comments

Comments
 (0)