netscan: respect status field from probe payloads (offline phones now correctly marked offline)

This commit is contained in:
2026-05-31 04:43:54 +00:00
parent 705ee4f5a7
commit ca3ae31826
+6 -3
View File
@@ -29,18 +29,21 @@ foreach ($devices as $d) {
$mac = trim($d['mac'] ?? ''); $mac = trim($d['mac'] ?? '');
$hostname = trim($d['hostname'] ?? ''); $hostname = trim($d['hostname'] ?? '');
$vendor = trim($d['vendor'] ?? ''); $vendor = trim($d['vendor'] ?? '');
// Respect explicit status from probe (e.g. phone probe knows if device is offline)
// Fall back to "online" for nmap results which only report reachable hosts
$status = in_array($d['status'] ?? '', ['online','offline']) ? $d['status'] : 'online';
if (!$ip) continue; if (!$ip) continue;
$discoveredIPs[] = $ip; $discoveredIPs[] = $ip;
JarvisDB::execute( JarvisDB::execute(
'INSERT INTO network_devices (ip, mac, hostname, status, last_seen) 'INSERT INTO network_devices (ip, mac, hostname, status, last_seen)
VALUES (?,?,?,"online",NOW()) VALUES (?,?,?,?,NOW())
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
mac = COALESCE(NULLIF(VALUES(mac),""), mac), mac = COALESCE(NULLIF(VALUES(mac),""), mac),
hostname = COALESCE(NULLIF(VALUES(hostname),""), hostname), hostname = COALESCE(NULLIF(VALUES(hostname),""), hostname),
status = "online", status = VALUES(status),
last_seen = NOW()', last_seen = NOW()',
[$ip, $mac ?: null, $hostname ?: $vendor ?: null] [$ip, $mac ?: null, $hostname ?: $vendor ?: null, $status]
); );
if ($vendor) { if ($vendor) {
JarvisDB::execute( JarvisDB::execute(