From 677fad56f7bdb62174abe692ea4b248062e7da24 Mon Sep 17 00:00:00 2001 From: seo Date: Sat, 25 Jul 2026 20:00:22 +0900 Subject: [PATCH] =?UTF-8?q?=EC=8B=9C=EB=86=80=EB=A1=9C=EC=A7=80=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=20=ED=91=9C=EC=8B=9C=20=EC=9E=A1=EC=9D=8C=20?= =?UTF-8?q?=ED=95=84=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- public/api.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 78 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 88346f2..9455a39 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Control은 라즈베리파이/리눅스 호스트의 팬과 시스템 상태를 - `public/api.php?action=settings_reset`: 설정 모달 값을 기본값으로 초기화 - `public/api.php?action=touch_display_save`: `/boot/firmware/config.txt`, `/boot/firmware/cmdline.txt`에 DSI 터치 디스플레이 부팅 설정 저장 - `public/api.php?action=touch_display_runtime_save`: DSI 터치 디스플레이 백라이트 밝기와 백라이트 전원 즉시 적용 -- `public/api.php?action=synology_log`: 라즈베리파이에 저장된 시놀로지 원격 로그 최근 500줄 조회 +- `public/api.php?action=synology_log`: 라즈베리파이에 저장된 시놀로지 원격 로그를 표시용 필터로 걸러 최근 500줄 조회 - `public/api.php?action=dmesg`: dmesg 로그 조회 - `public/api.php?action=reboot`: 확인 단어와 관리자 암호 재검증 후 sudo reboot 실행 diff --git a/public/api.php b/public/api.php index 430354f..d1dde1b 100644 --- a/public/api.php +++ b/public/api.php @@ -121,9 +121,10 @@ function dmesg_log(): array ]; } -function text_log_tail(string $path, string $label, int $limit = 500): array +function text_log_tail(string $path, string $label, int $limit = 500, ?callable $lineFilter = null, int $displayLimit = 500): array { - $limit = max(1, min(1000, $limit)); + $limit = max(1, min(10000, $limit)); + $displayLimit = max(1, min(1000, $displayLimit)); $stat = sh(['/usr/bin/stat', '-c', '%s|%Y', $path], true, 3); if ((int)$stat['code'] !== 0) { return [ @@ -157,20 +158,93 @@ function text_log_tail(string $path, string $label, int $limit = 500): array preg_split('/\R/', trim((string)$tail['out'])) ?: [], static fn($line): bool => trim((string)$line) !== '' )); + $rawLineCount = count($lines); + if ($lineFilter !== null) { + $lines = array_values(array_filter($lines, $lineFilter)); + } + if (count($lines) > $displayLimit) { + $lines = array_slice($lines, -$displayLimit); + } return [ 'path' => $path, 'available' => true, 'lines' => array_reverse($lines), 'line_count' => count($lines), + 'raw_line_count' => $rawLineCount, 'size_bytes' => $size, 'updated_at' => $mtime > 0 ? date('Y-m-d H:i:s', $mtime) : null, ]; } +function synology_remote_log_visible(string $line): bool +{ + if (str_contains($line, 'Last message ') && str_contains($line, 'suppressed by syslog-ng')) { + return false; + } + + if (preg_match('/\ssynotifyd\[\d+\]\s/', $line)) { + return false; + } + + if (preg_match('/\ssynoelasticd\[\d+\]\s/', $line)) { + $noise = [ + '(UpsertByID)', + '(SetByID)', + '(DelByID)', + '(DelByQuery)', + '(Commit) Commit: fileindex_', + ]; + foreach ($noise as $needle) { + if (str_contains($line, $needle)) { + return false; + } + } + } + + if (preg_match('/\sfileindexd\[\d+\]\s/', $line)) { + $noise = [ + 'ProcessOP BEGIN: IndexUpsert', + 'ProcessOP DONE!: IndexUpsert', + 'ProcessOP SKIPPED: IndexUpsert', + 'ProcessOP BEGIN: IndexReindex', + 'ProcessOP DONE!: IndexReindex', + 'ProcessOP SKIPPED: IndexReindex', + '(Process) Worker<', + 'PrepareTmpOPtree', + 'CheckClearOldTmpOPtree', + 'BuildTree', + 'Commit [fileindex_', + ]; + foreach ($noise as $needle) { + if (str_contains($line, $needle)) { + return false; + } + } + } + + if (preg_match('/\sscemd\[\d+\]\s/', $line)) { + $noise = [ + 'Could not open file `/dev/i2c-1', + 'Could not open file `/dev/i2c/1', + 'Fail to initLedBrightnessConfig', + 'No brightness setting', + 'Fail to init config list', + 'Fail to set led brightness.', + ]; + foreach ($noise as $needle) { + if (str_contains($line, $needle)) { + return false; + } + } + } + + return true; +} + function synology_remote_log(): array { - return text_log_tail('/var/log/remote/synology/chaegeon.log', 'synology remote'); + return text_log_tail('/var/log/remote/synology/chaegeon.log', 'synology remote', 5000, 'synology_remote_log_visible'); } function command_first_line(array $cmd, bool $root = false, int $timeout = 3): string