#!/usr/bin/env php
<?php
/**
 * Session 真实访客缓存辅助验证
 */
if (PHP_SAPI !== 'cli') {
    exit(1);
}

require_once dirname(__DIR__) . '/lib/Cloak/VisitorRepository.php';

$_SESSION = [];
$_SERVER['HTTP_HOST'] = 'cloaka.test';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';

cloak_session_mark_real_visitor();

$ok = (
    ($_SESSION['check_result'] ?? '') === 'true'
    && ($_SESSION['visit_to_2'] ?? '') === '2'
    && ($_SESSION['visit_to_3'] ?? '') === '3'
    && !empty($_SESSION['gcuid'])
);

cloak_session_clear_real_visitor();

$cleared = !isset($_SESSION['check_result']);

echo json_encode(['ok' => $ok && $cleared], JSON_UNESCAPED_UNICODE) . "\n";
exit($ok && $cleared ? 0 : 1);
