<?php
session_start();
if (!isset($_SESSION['eggzie_iboPlayer3']) || !isset($_SESSION['reseller_name'])) {
    echo "ERRO: Não autenticado";
    exit();
}

$reseller_name = $_SESSION['reseller_name'];
$mac = isset($_GET['mac']) ? strtoupper(trim($_GET['mac'])) : '';

if (empty($mac) || !preg_match('/^([0-9A-F]{2}:){7}[0-9A-F]{2}$/', $mac)) {
    echo "ERRO: MAC inválido";
    exit();
}

$db = new SQLite3('../a/.eggziedb.db');
require_once 'sync_mac_consistency.php';

if (syncMacPlaylists($db, $mac, $reseller_name)) {
    echo "OK";
} else {
    echo "ERRO: " . $db->lastErrorMsg();
}
?>