<?php
header('Content-Type: application/json; charset=utf-8');
require dirname(__DIR__) . '/config.php';

$token = isset($_GET['token']) ? trim($_GET['token']) : '';
if (!preg_match('/^[a-f0-9]{64}$/i', $token)) {
    http_response_code(400);
    echo json_encode(['ok'=>false]);
    exit;
}
$stmt = $pdo->prepare('SELECT nome, ativo, compartilhamento_ativo FROM dispositivos WHERE token=? LIMIT 1');
$stmt->execute([$token]);
$d = $stmt->fetch();
if (!$d) {
    http_response_code(404);
    echo json_encode(['ok'=>false]);
    exit;
}
echo json_encode(['ok'=>true,'dispositivo'=>$d]);
