|
1 | 1 | <?php |
2 | 2 |
|
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 | + } |
4 | 10 |
|
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 | + } |
6 | 15 |
|
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 | + } |
10 | 22 | } |
11 | 23 |
|
12 | | -$max = intval($_POST['max']); |
13 | | -$lines = array_reverse(array_slice(file($log), -$max)); |
| 24 | +ini_set('memory_limit', '512M'); // Increase memory limit |
14 | 25 |
|
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>"; |
17 | 30 | } |
18 | 31 |
|
19 | 32 | ini_restore('memory_limit'); // Restore original memory limit |
0 commit comments