<?php
// index.php - Honeypot Fake Admin Portal
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Pragma: no-cache");
?>
<!DOCTYPE html>
<html lang="pl">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>IT Party</title>
    <link
        href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Rajdhani:wght@300;500;700&display=swap"
        rel="stylesheet">
    <script src="https://unpkg.com/html5-qrcode" type="text/javascript"></script>
    <style>
        :root {
            --alert-red: #ff3333;
            --stark-cyan: #00f3ff;
            --hud-bg: rgba(10, 0, 0, 0.9);
            --hud-border: #ff3333;
        }

        body {
            background-color: #000;
            background-image:
                radial-gradient(circle at 50% 50%, #2e0505 0%, #000000 100%),
                linear-gradient(0deg, rgba(255, 51, 51, 0.05) 1px, transparent 1px);
            background-size: 100% 100%, 40px 40px;
            color: var(--alert-red);
            font-family: 'Rajdhani', sans-serif;
            margin: 0;
            padding: 0;
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            overflow: hidden;
        }

        #ui-container {
            width: 90%;
            max-width: 500px;
            background: var(--hud-bg);
            border: 2px solid var(--hud-border);
            padding: 40px;
            box-sizing: border-box;
            box-shadow: 0 0 50px rgba(255, 51, 51, 0.4);
            text-align: center;
        }

        h1 {
            font-family: 'Orbitron', sans-serif;
            font-size: 1.5rem;
            letter-spacing: 5px;
            margin-bottom: 30px;
            color: var(--stark-cyan);
            text-shadow: 0 0 10px var(--stark-cyan);
        }

        .warning-box {
            border: 1px dashed var(--alert-red);
            padding: 20px;
            margin-bottom: 30px;
            background: rgba(255, 0, 0, 0.1);
        }

        .scanner-frame {
            width: 100%;
            aspect-ratio: 1;
            border: 2px solid var(--alert-red);
            background: #000;
            margin-bottom: 20px;
        }

        #status-msg {
            font-weight: bold;
            text-transform: uppercase;
            letter-spacing: 2px;
            min-height: 2em;
        }

        .hacker-alert {
            display: none;
            animation: blink 0.5s infinite;
        }

        @keyframes blink {

            0%,
            100% {
                opacity: 1;
            }

            50% {
                opacity: 0.3;
            }
        }

        .btn-large {
            background: transparent;
            border: 2px solid var(--alert-red);
            color: var(--alert-red);
            padding: 15px 30px;
            font-family: 'Orbitron';
            text-transform: uppercase;
            cursor: pointer;
            transition: 0.3s;
            margin-top: 20px;
        }

        .btn-large:hover {
            background: var(--alert-red);
            color: #000;
        }
    </style>
</head>

<body>

    <div id="ui-container">
        <h1>PANEL ZARZĄDZANIA SYSTEMEM</h1>

        <div id="pre-auth">
            <div class="warning-box"
                style="border-color: var(--stark-cyan); background: rgba(0, 243, 255, 0.05); color: var(--stark-cyan);">
                <p style="font-size: 1.2rem; margin: 0;"><strong>AUTORYZACJA WYMAGANA</strong></p>
                <p style="font-size: 0.8rem;">ZALOGUJ SIĘ, ABY UZYSKAĆ DOSTĘP DO USTAWIEŃ ZAAWANSOWANYCH.</p>
            </div>

            <div id="reader" class="scanner-frame" style="border-color: var(--stark-cyan);"></div>
            <div id="status-msg" style="color: var(--stark-cyan);">OCZEKIWANIE NA IDENTYFIKATOR UPRAWNIEŃ (QR)</div>
            <p style="font-size: 0.7rem; color: #555; margin-top: 10px;">ID: SI-ADMIN-CORE-V4.2</p>
        </div>

        <div id="post-auth" style="display: none;">
            <h2 class="hacker-alert" style="font-size: 2rem; margin-bottom: 10px;">WYKRYTO PRÓBĘ HAKOWANIA!</h2>
            <div class="warning-box" style="border-style: solid; border-width: 3px;">
                <p style="font-size: 1.1rem; color: #fff;">Witaj, <span id="hacker-name"
                        style="color: var(--stark-cyan);">NIECNOTO</span>!</p>
                <p>Ładnie to tak próbować włamać się do panela administratora?</p>
                <p style="font-size: 1.5rem; margin-top: 20px;">KARA: <span
                        style="font-size: 2.5rem; font-weight: 900;">-50 PKT</span></p>
                <p style="font-size: 0.9rem; margin-top: 10px; opacity: 0.8;">Twoje punkty zostały pomyślnie usunięte.
                    Miłego dnia i powodzenia w legalnym zdobywaniu punktów!</p>
            </div>
        </div>
    </div>

    <script>
        const html5QrCode = new Html5Qrcode("reader");
        let isPenalizing = false;

        window.onload = () => {
            startScanner();
        };

        function startScanner() {
            const config = { fps: 10, qrbox: { width: 250, height: 250 } };
            html5QrCode.start({ facingMode: "environment" }, config, onScanSuccess)
                .catch(err => {
                    document.getElementById('status-msg').innerText = "SYSTEM OFFLINE: " + err;
                });
        }

        function onScanSuccess(qrCode) {
            if (isPenalizing) return;
            html5QrCode.stop().then(() => {
                document.getElementById('status-msg').innerText = "IDENTYFIKACJA...";
                identifyAndPenalize(qrCode);
            });
        }

        async function identifyAndPenalize(qrCode) {
            isPenalizing = true;
            try {
                // Pierwszy krok: Identifikacja gościa
                const checkResp = await fetch('check_guest.php', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ qr_code: qrCode })
                });
                const guestData = await checkResp.json();

                if (guestData.status === 'success') {
                    // Drugi krok: Nałożenie kary
                    const penalizeResp = await fetch('penalize_hacker.php', {
                        method: 'POST',
                        headers: { 'Content-Type': 'application/json' },
                        body: JSON.stringify({ guest_id: guestData.guest_id })
                    });
                    const penaltyResult = await penalizeResp.json();

                    if (penaltyResult.status === 'success') {
                        document.getElementById('hacker-name').innerText = guestData.guest_name;
                        document.getElementById('pre-auth').style.display = 'none';
                        document.getElementById('post-auth').style.display = 'block';
                        // Optional sound could be added here
                    } else {
                        alert("Błąd protokołu karnego.");
                        location.reload();
                    }
                } else {
                    document.getElementById('status-msg').innerText = "NIEZNANY IDENTYFIKATOR. DOSTĘP ZABLOKOWANY.";
                    setTimeout(startScanner, 2000);
                    isPenalizing = false;
                }
            } catch (e) {
                console.error(e);
                alert("Błąd krytyczny sytemu.");
                location.reload();
            }
        }
    </script>

</body>

</html>