Tor log implementation
This commit is contained in:
21
web/api/tor_log.php
Normal file
21
web/api/tor_log.php
Normal 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]);
|
||||
}
|
||||
Reference in New Issue
Block a user