Tor log implementation

This commit is contained in:
2025-11-11 15:11:14 +01:00
parent 38ad3e23e1
commit a2a37b7e6c
3 changed files with 134 additions and 4 deletions

21
web/api/tor_log.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
require __DIR__ . '/../lib/app.php';
auth_require();
header('Content-Type: application/json');
$n = isset($_GET['n']) ? (int)$_GET['n'] : 500;
if ($n < 50) $n = 50;
if ($n > 5000) $n = 5000;
$level = isset($_GET['level']) ? strtolower($_GET['level']) : 'info';
$allowed = ['debug','info','notice','warning','err'];
if (!in_array($level, $allowed, true)) $level = 'info';
$cmd = sprintf('sudo /usr/local/bin/torpanel-logdump %d %s', $n, escapeshellarg($level));
exec($cmd . ' 2>&1', $out, $rc);
if ($rc === 0 && !empty($out)) {
echo json_encode(['ok' => true, 'lines' => $out]);
} else {
echo json_encode(['ok' => false, 'error' => 'no_log', 'rc' => $rc]);
}