false, 'msg' => 'Clé Vision non configurée.']; } $payload = [ 'app' => VISION_APP_ID, 'keyprog' => $keyprog, 'version' => cfg('app_version', '1.0'), 'hostname' => cfg('hostname', gethostname()), 'ip' => $_SERVER['SERVER_ADDR'] ?? '', ]; $ctx = stream_context_create(['http' => [ 'method' => 'POST', 'header' => "Content-Type: application/json\r\n", 'content' => json_encode($payload), 'timeout' => 5, 'ignore_errors' => true, ]]); $resp = @file_get_contents(VISION_API_URL . '/check', false, $ctx); if ($resp === false) { return ['valid' => true, 'msg' => 'Vision injoignable — mode dégradé.']; } $data = json_decode($resp, true); return [ 'valid' => (bool)($data['valid'] ?? false), 'msg' => $data['message'] ?? '', 'config' => $data['config'] ?? [], ]; } function vision_push_config(array $config): void { // Applique la config reçue depuis Vision en BDD foreach ($config as $key => $value) { cfg_set($key, $value); } } function vision_register(): bool { $keyprog = cfg('vision_keyprog', ''); if (!$keyprog) return false; $payload = [ 'app' => VISION_APP_ID, 'keyprog' => $keyprog, 'hostname' => cfg('hostname', gethostname()), 'domain' => cfg('domain', ''), 'version' => cfg('app_version', '1.0'), 'accounts' => (int)db()->query('SELECT COUNT(*) FROM accounts WHERE active=1')->fetchColumn(), ]; $ctx = stream_context_create(['http' => [ 'method' => 'POST', 'header' => "Content-Type: application/json\r\n", 'content' => json_encode($payload), 'timeout' => 5, 'ignore_errors' => true, ]]); $resp = @file_get_contents(VISION_API_URL . '/register', false, $ctx); return $resp !== false; }