From 61ad4af4ae9612e1cd6cf5f3442ea1b836e5afbb Mon Sep 17 00:00:00 2001 From: seo Date: Sat, 29 Aug 2026 02:42:43 +0900 Subject: [PATCH] =?UTF-8?q?PC=20WOL=20=EB=8C=80=EC=83=81=20=EC=A3=BC?= =?UTF-8?q?=EC=86=8C=20=EC=A0=95=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- public/api.php | 61 ++------------------------------------------ touch_panel/panel.py | 2 +- 3 files changed, 4 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 9a72873..ff0fe0e 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ cd /var/www/control 각 타일에는 글자 아래에 세 개의 작은 표시등을 두며 읽기/업로드는 초록, 쓰기/다운로드는 주황, 오류/드롭 증가는 빨강으로 표시합니다. 활동 표시등은 이벤트 감지 후 120ms 동안 유지하고, 오류 표시등은 2초 동안 유지해 너무 짧은 이벤트도 눈에 보이게 합니다. 네트워크 카드 오른쪽 값은 항상 `D n`으로 드롭 누적을 표시합니다. `LOCAL`은 `lo`, `UPLINK`는 기본 라우트 인터페이스 기준입니다. 라즈베리파이 `ETH1`은 컴퓨터와 연결된 물리 포트 단독 카운터이며 `br0`는 합산하지 않습니다. `SSD I/O`의 값은 `/run/control-rpi-disk-temp` 캐시 파일의 `/dev/sda` Samsung T7 디스크 자체 온도입니다. 캐시 파일은 root로 실행되는 `control-rpi-disk-temp.service`가 몇 초마다 `smartctl -d sntasmedia`로 갱신하므로 GUI 패널은 sudo를 반복 실행하지 않습니다. -하단 `PC` 버튼은 `192.168.50.73`에 1초마다 ping을 보내 켜짐 여부를 표시하고, 꺼져 있을 때 누르면 DHCP lease에서 해당 IP의 현재 MAC을 찾아 WOL magic packet을 보냅니다. 주황은 WOL 후 최대 1분 동안 컴퓨터 응답 대기 표시, 빨강은 magic packet 전송 실패 시 5초 또는 1분 대기 후 응답 실패 시 1분 표시입니다. +하단 `PC` 버튼은 `192.168.50.112`에 1초마다 ping을 보내 켜짐 여부를 표시하고, 꺼져 있을 때 누르면 DHCP lease에서 해당 IP의 현재 MAC을 찾아 WOL magic packet을 보냅니다. 주황은 WOL 후 최대 1분 동안 컴퓨터 응답 대기 표시, 빨강은 magic packet 전송 실패 시 5초 또는 1분 대기 후 응답 실패 시 1분 표시입니다. GUI 자동 실행은 데스크톱 autostart가 1차 기준입니다. diff --git a/public/api.php b/public/api.php index e587b0f..c51d946 100644 --- a/public/api.php +++ b/public/api.php @@ -3423,69 +3423,12 @@ function remember_lan_wol_clients(array $rows): void } } -function seed_lan_wol_clients_from_observed(array $leases, array $aliases = [], string $iface = 'eth1'): void -{ - if ($leases === []) { - return; - } - - try { - $pdo = db(); - $rows = $pdo->query(" - SELECT mac, last_ip, hostname, last_seen_at - FROM wifi_observed_sessions - WHERE band = 'LAN' - ")->fetchAll(); - if ($rows === []) { - return; - } - - $upsert = $pdo->prepare(" - INSERT INTO lan_wol_clients - (mac, iface, last_ip, hostname, first_seen_at, last_seen_at) - VALUES - (:mac, :iface, :last_ip, :hostname, :last_seen_at, :last_seen_at) - ON DUPLICATE KEY UPDATE - iface = VALUES(iface), - last_ip = COALESCE(VALUES(last_ip), last_ip), - hostname = COALESCE(VALUES(hostname), hostname), - last_seen_at = GREATEST(last_seen_at, VALUES(last_seen_at)) - "); - - foreach ($rows as $row) { - $mac = strtolower((string)($row['mac'] ?? '')); - if (!wifi_valid_mac($mac) || !isset($leases[$mac])) { - continue; - } - - $lease = $leases[$mac]; - $leaseHostname = (string)($lease['hostname'] ?? 'N/A'); - $hostname = $aliases[$mac] ?? ($leaseHostname === 'N/A' ? (string)($row['hostname'] ?? '') : $leaseHostname); - $lastSeenAt = (string)($row['last_seen_at'] ?? ''); - if ($lastSeenAt === '') { - $lastSeenAt = date('Y-m-d H:i:s.v'); - } - - $upsert->execute([ - ':mac' => $mac, - ':iface' => $iface, - ':last_ip' => (string)($lease['ip'] ?? ($row['last_ip'] ?? '')), - ':hostname' => $hostname === '' || $hostname === 'N/A' ? null : $hostname, - ':last_seen_at' => $lastSeenAt, - ]); - } - } catch (Throwable) { - } -} - function lan_wol_candidate_macs(array $leases, string $iface = 'eth1'): array { if ($leases === []) { return []; } - seed_lan_wol_clients_from_observed($leases, [], $iface); - try { $stmt = db()->prepare(" SELECT mac @@ -3559,7 +3502,7 @@ function send_wake_on_lan(string $mac, string $broadcast = '192.168.50.255', int } $lanMacs = array_fill_keys(lan_wol_candidate_macs($leases), true); - if (!isset($lanMacs[$mac]) && !isset($leases[$mac])) { + if (!isset($lanMacs[$mac])) { throw new InvalidArgumentException('not_lan_client'); } @@ -3603,7 +3546,7 @@ function wake_lan_status(string $mac): array $leases = dnsmasq_leases(); $activeLanMacs = array_fill_keys(lan_fdb_macs(), true); $wolCandidateMacs = array_fill_keys(lan_wol_candidate_macs($leases), true); - $known = isset($activeLanMacs[$mac]) || isset($wolCandidateMacs[$mac]) || isset($leases[$mac]); + $known = isset($activeLanMacs[$mac]) || isset($wolCandidateMacs[$mac]); if (!$known) { throw new InvalidArgumentException('unknown_dhcp_client'); diff --git a/touch_panel/panel.py b/touch_panel/panel.py index 721c9fd..f5db2a1 100755 --- a/touch_panel/panel.py +++ b/touch_panel/panel.py @@ -27,7 +27,7 @@ NET_GROUPS = { "wifi5": ["wlan1"], } -PC_IP = "192.168.50.73" +PC_IP = "192.168.50.112" PC_DHCP_LEASE_FILE = "/var/lib/misc/dnsmasq.leases" SYNOLOGY_PING_HOST = "chaegeon.com" SYNOLOGY_SSH = [