시놀로지 원격 로그 뷰어 추가

This commit is contained in:
seo
2026-07-25 19:52:38 +09:00
parent 3aff2748e8
commit 756464643c
5 changed files with 254 additions and 5 deletions
+59
View File
@@ -121,6 +121,58 @@ function dmesg_log(): array
];
}
function text_log_tail(string $path, string $label, int $limit = 500): array
{
$limit = max(1, min(1000, $limit));
$stat = sh(['/usr/bin/stat', '-c', '%s|%Y', $path], true, 3);
if ((int)$stat['code'] !== 0) {
return [
'path' => $path,
'available' => false,
'lines' => [],
'line_count' => 0,
'size_bytes' => 0,
'updated_at' => null,
'message' => $label . ' log is not available yet.',
];
}
$parts = explode('|', trim((string)$stat['out']), 2);
$size = (int)($parts[0] ?? 0);
$mtime = (int)($parts[1] ?? 0);
$tail = sh(['/usr/bin/tail', '-n', (string)$limit, $path], true, 4);
if ((int)$tail['code'] !== 0) {
return [
'path' => $path,
'available' => false,
'lines' => [],
'line_count' => 0,
'size_bytes' => $size,
'updated_at' => $mtime > 0 ? date('Y-m-d H:i:s', $mtime) : null,
'message' => 'failed to open ' . $label . ' log.',
];
}
$lines = array_values(array_filter(
preg_split('/\R/', trim((string)$tail['out'])) ?: [],
static fn($line): bool => trim((string)$line) !== ''
));
return [
'path' => $path,
'available' => true,
'lines' => array_reverse($lines),
'line_count' => count($lines),
'size_bytes' => $size,
'updated_at' => $mtime > 0 ? date('Y-m-d H:i:s', $mtime) : null,
];
}
function synology_remote_log(): array
{
return text_log_tail('/var/log/remote/synology/chaegeon.log', 'synology remote');
}
function command_first_line(array $cmd, bool $root = false, int $timeout = 3): string
{
$result = sh($cmd, $root, $timeout);
@@ -4288,6 +4340,13 @@ function control_api_dispatch(): void
]);
}
if ($action === 'synology_log') {
json_out([
'ok' => true,
'data' => synology_remote_log(),
]);
}
if ($action === 'status') {
json_out([
'ok' => true,