<?php
require_once __DIR__ . '/../auth.php';
if (function_exists('require_login')) require_login('login.php');
require_once __DIR__ . '/../db_bootstrap.php';
if (function_exists('ensure_db')) ensure_db(true);
require_once __DIR__ . '/../airmax_monitor_lib.php';
header('Content-Type: application/json; charset=utf-8');

$conn = $GLOBALS['conn'] ?? null;
if (!($conn instanceof mysqli)) {
  echo json_encode(['ok'=>false,'reason'=>'db_not_ready'], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  exit;
}
echo json_encode(['ok'=>true] + airmax_probe_all($conn), JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
