PC WOL 대상 주소 정정
This commit is contained in:
1 parent
4fb9af695c
commit
61ad4af4ae
3 files changed
+4
-61
No files matched your search
+2
-59
@@ -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');
|
||||
|
||||
Reference in new issue
Block a user