<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Проверка безопасности</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .challenge-box {
            background: white;
            padding: 40px;
            border-radius: 10px;
            box-shadow: 0 10px 40px rgba(0,0,0,0.2);
            text-align: center;
            max-width: 400px;
        }
        .spinner {
            border: 4px solid #f3f3f3;
            border-top: 4px solid #667eea;
            border-radius: 50%;
            width: 50px;
            height: 50px;
            animation: spin 1s linear infinite;
            margin: 20px auto;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <div class="challenge-box">
        <h2>Проверка браузера</h2>
        <div class="spinner"></div>
        <p id="status">Подождите, идет проверка...</p>
    </div>

    <script>
        function generateToken() {
            return Array.from(crypto.getRandomValues(new Uint8Array(16)))
                .map(b => b.toString(16).padStart(2, '0'))
                .join('');
        }

        function setCookie(name, value, seconds) {
            const date = new Date();
            date.setTime(date.getTime() + (seconds * 1000));
            document.cookie = name + "=" + value +
                             "; expires=" + date.toUTCString() +
                             "; path=/;" +
                             "; SameSite=Lax";
        }

        function getCookie(name) {
            const value = `; ${document.cookie}`;
            const parts = value.split(`; ${name}=`);
            if (parts.length === 2) return parts.pop().split(';').shift();
            return null;
        }

        function getOriginalUrl() {
            const params = new URLSearchParams(window.location.search);
            return decodeURIComponent(params.get('return') || '/');
        }

        const existingCookie = getCookie('security_check');
        if (existingCookie && existingCookie.match(/^[a-f0-9]{32}\.[0-9]{10}$/)) {
            window.location.href = getOriginalUrl();
        } else {
            const token = generateToken();
            const timestamp = Math.floor(Date.now() / 1000);
            const cookieValue = token + '.' + timestamp;
            setCookie('security_check', cookieValue, 3600);

            setTimeout(function() {
                const checkCookie = getCookie('security_check');
                if (checkCookie) {
                    document.getElementById('status').textContent = 'Проверка пройдена, перенаправление...';
                    setTimeout(function() {
                        window.location.href = getOriginalUrl();
                    }, 500);
                } else {
                    document.getElementById('status').textContent = 'Ошибка: включите cookies в браузере';
                }
            }, 300);
        }
    </script>
</body>
</html>
