<?php
// check_mac.php
header('Content-Type: application/json');

if (isset($_GET['mac'])) {
    $mac = preg_replace('/[^0-9]/', '', $_GET['mac']);
    
    try {
        $db = new SQLite3('../a/.eggziedb.db');
        // Apenas verificamos se o MAC existe na tabela ibo
        $res = $db->querySingle("SELECT COUNT(*) FROM ibo WHERE mac_address = '$mac'");
        $db->close();

        echo json_encode(['exists' => ($res > 0)]);
    } catch (Exception $e) {
        echo json_encode(['exists' => false, 'error' => true]);
    }
}