21 lines
672 B
PHP
21 lines
672 B
PHP
<?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]);
|
|
} |