<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Access Blocked</title>
    <script src="https://www.google.com/recaptcha/api.js" async defer></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            background: white;
            border-radius: 20px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
            max-width: 500px;
            width: 100%;
            padding: 40px;
            text-align: center;
        }

        .shield-icon {
            width: 80px;
            height: 80px;
            margin: 0 auto 20px;
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            animation: pulse 2s infinite;
        }

        @keyframes pulse {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(1.05); }
        }

        .shield-icon svg {
            width: 50px;
            height: 50px;
            fill: white;
        }

        h1 {
            color: #2d3748;
            font-size: 28px;
            margin-bottom: 10px;
            font-weight: 700;
        }

        .ip-address {
            color: #e53e3e;
            font-size: 24px;
            font-weight: 700;
            margin: 20px 0;
            padding: 15px;
            background: #fff5f5;
            border-radius: 10px;
            border: 2px solid #feb2b2;
        }

        .message {
            color: #4a5568;
            font-size: 16px;
            line-height: 1.6;
            margin-bottom: 30px;
        }

        .warning {
            background: #fffaf0;
            border: 2px solid #fbd38d;
            border-radius: 10px;
            padding: 15px;
            margin: 20px 0;
            color: #744210;
            font-size: 14px;
            font-weight: 600;
        }

        .captcha-container {
            display: flex;
            justify-content: center;
            margin: 30px 0;
            min-height: 78px;
        }

        .verify-button {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 15px 40px;
            font-size: 16px;
            font-weight: 600;
            border-radius: 10px;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
        }

        .verify-button:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
        }

        .verify-button:disabled {
            background: #cbd5e0;
            cursor: not-allowed;
            box-shadow: none;
        }

        .footer {
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid #e2e8f0;
            color: #718096;
            font-size: 12px;
        }

        #result-message {
            margin-top: 20px;
            padding: 15px;
            border-radius: 10px;
            font-weight: 600;
            display: none;
        }

        .success {
            background: #f0fff4;
            color: #22543d;
            border: 2px solid #9ae6b4;
        }

        .error {
            background: #fff5f5;
            color: #742a2a;
            border: 2px solid #feb2b2;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="shield-icon">
            <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                <path d="M12 1L3 5v6c0 5.55 3.84 10.74 9 12 5.16-1.26 9-6.45 9-12V5l-9-4zm0 10.99h7c-.53 4.12-3.28 7.79-7 8.94V12H5V6.3l7-3.11v8.8z"/>
            </svg>
        </div>

        <h1>Access Blocked</h1>

        <div class="ip-address" id="user-ip">
            Loading...
        </div>

        <p class="message">
            직접 IP 주소로의 접근이 감지되었습니다.<br>
            보안 검증을 완료하지 않으면 이 IP 주소는 차단됩니다.
        </p>

        <div class="warning">
            ⚠️ CAPTCHA 인증 실패 시 SSH 및 모든 웹 접근(80/443 포트)이 차단됩니다.
        </div>

        <div class="captcha-container">
            <div class="g-recaptcha" data-sitekey="YOUR_RECAPTCHA_SITE_KEY"></div>
        </div>

        <button class="verify-button" id="verify-btn" onclick="verifyAccess()">
            보안 검증 완료
        </button>

        <div id="result-message"></div>

        <div class="footer">
            접근 시간: <span id="access-time"></span><br>
            문의사항이 있으시면 시스템 관리자에게 연락하세요.
        </div>
    </div>

    <script>
        // 사용자 IP 주소 표시
        fetch('/api/get-ip')
            .then(response => response.json())
            .then(data => {
                document.getElementById('user-ip').textContent = data.ip + ' Blocked You.';
            })
            .catch(() => {
                document.getElementById('user-ip').textContent = 'IP Address Blocked';
            });

        // 접근 시간 표시
        document.getElementById('access-time').textContent = new Date().toLocaleString('ko-KR');

        // CAPTCHA 검증 및 접근 허용 요청
        function verifyAccess() {
            const response = grecaptcha.getResponse();

            if (!response) {
                showMessage('CAPTCHA를 완료해주세요.', 'error');
                return;
            }

            const btn = document.getElementById('verify-btn');
            btn.disabled = true;
            btn.textContent = '검증 중...';

            fetch('/api/verify-captcha', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    captcha_response: response
                })
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    showMessage('✓ 검증 완료! 잠시 후 홈페이지로 이동합니다.', 'success');
                    setTimeout(() => {
                        window.location.href = data.redirect || '/';
                    }, 2000);
                } else {
                    showMessage('✗ 검증 실패. 이 IP는 곧 차단됩니다.', 'error');
                    btn.disabled = false;
                    btn.textContent = '다시 시도';
                    grecaptcha.reset();
                }
            })
            .catch(error => {
                showMessage('✗ 서버 오류가 발생했습니다.', 'error');
                btn.disabled = false;
                btn.textContent = '다시 시도';
                grecaptcha.reset();
            });
        }

        function showMessage(text, type) {
            const msgEl = document.getElementById('result-message');
            msgEl.textContent = text;
            msgEl.className = type;
            msgEl.style.display = 'block';
        }
    </script>
</body>
</html>
