&machine_id=&hostname= */ define('VISION_LICENSE_URL', 'https://vision.copydev.fr/api/license.php'); define('VISION_PRODUCT', 'copymail'); function vision_machine_id(): string { $id = cfg('vision_machine_id', ''); if (!$id) { $id = strtolower('copymail-' . bin2hex(random_bytes(6))); cfg_set('vision_machine_id', $id); } return $id; } function vision_check(): array { $key = cfg('vision_license_key', ''); if (!$key) { return ['valid' => false, 'msg' => 'Licence non configurée.', 'unconfigured' => true]; } $url = VISION_LICENSE_URL . '?' . http_build_query([ 'key' => $key, 'machine_id' => vision_machine_id(), 'hostname' => cfg('hostname', gethostname()), ]); $ctx = stream_context_create(['http' => [ 'method' => 'GET', 'timeout' => 5, 'ignore_errors' => true, ]]); $resp = @file_get_contents($url, false, $ctx); if ($resp === false) { // Vision injoignable — on vérifie le délai offline autorisé $lastOk = (int)cfg('vision_last_ok', '0'); $timeout = (int)cfg('vision_offline_timeout', '72'); $elapsed = (time() - $lastOk) / 3600; if ($lastOk && $elapsed < $timeout) { return ['valid' => true, 'msg' => "Vision injoignable (mode dégradé, {$timeout}h max)", 'degraded' => true]; } return ['valid' => false, 'msg' => 'Vision injoignable et délai offline dépassé.']; } $data = json_decode($resp, true); if (!empty($data['valid'])) { cfg_set('vision_last_ok', (string)time()); cfg_set('vision_offline_timeout', (string)($data['offline_timeout_hours'] ?? 72)); return [ 'valid' => true, 'client' => $data['client'] ?? '', 'product' => $data['product'] ?? '', 'expires' => $data['expires_at'] ?? null, 'devices' => $data['max_devices'] ?? 1, ]; } return ['valid' => false, 'msg' => $data['message'] ?? 'Licence invalide.']; }