<?php if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } $deviceMsg = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'revoke_device') { CSRF::enforce(); RBAC::enforce('modify.security'); $deviceId = (int)($_POST['device_id'] ?? 0); if ($deviceId > 0) { Database::execute("DELETE FROM device_bindings WHERE id = :id", [':id' => $deviceId]); Events::record(Events::CAT_SECURITY, 'device.revoked', 'device_binding', $deviceId, [], $_SESSION['admin_id']); $deviceMsg = 'Device binding revoked.'; } } $devices = []; try { $devices = Database::fetchAll("SELECT db.*, u.username FROM device_bindings db LEFT JOIN users u ON db.user_id = u.id ORDER BY db.last_seen DESC"); } catch (\Throwable $e) {} $activeCount = 0; $staleCount = 0; $now = time(); foreach ($devices as $d) { $lastSeen = strtotime($d['last_seen'] ?? ''); if ($lastSeen && ($now - $lastSeen) < 86400 * 7) $activeCount++; else $staleCount++; } 