<?php
/**
 * WordPress Setup Configuration — Erstinstallation
 * ALLE DATEN FIKTIV — SIMULATION
 *
 * Diese Seite erscheint beim ersten WordPress-Setup.
 * Angreifer hoffen, hier DB-Zugangsdaten abgreifen zu können,
 * bevor die Installation abgeschlossen ist.
 *
 * @package WordPress
 */

// ============================================================================
// Schritt 1: Datenbank-Verbindung herstellen
// ============================================================================
$step = isset($_GET['step']) ? (int)$_GET['step'] : 0;

switch ($step) {
    case 0:
        // Formular anzeigen
        ?>
        <!DOCTYPE html>
        <html lang="de">
        <head>
            <meta charset="UTF-8">
            <title>WordPress &rsaquo; Setup-Konfiguration</title>
            <style>
                body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f0f0f1; color: #3c434a; }
                .wrap { max-width: 700px; margin: 3rem auto; background: white; padding: 2rem; border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
                h1 { font-size: 1.5rem; margin-bottom: 1.5rem; }
                label { display: block; margin-top: 1rem; font-weight: 600; }
                input[type=text], input[type=password] { width: 100%; padding: 0.5rem; margin-top: 0.25rem; border: 1px solid #8c8f94; border-radius: 4px; }
                .submit-btn { background: #2271b1; color: white; border: none; padding: 0.5rem 1.5rem; border-radius: 4px; font-size: 1rem; cursor: pointer; margin-top: 1.5rem; }
                .note { margin-top: 1rem; padding: 0.75rem; background: #f6f7f7; border-left: 4px solid #dba617; }
            </style>
        </head>
        <body>
        <div class="wrap">
            <h1>⚙️ WordPress Setup-Konfigurationsdatei</h1>
            <p>Bitte gib die Verbindungsdaten zu deiner Datenbank an.</p>
            <form method="post" action="?step=1">
                <input type="hidden" name="wp_setup_nonce" value="dt_nonce_88293647102938">

                <label>Datenbank-Name</label>
                <input type="text" name="dbname" value="wp_dorftrottel_prod" placeholder="wordpress">

                <label>Datenbank-Benutzername</label>
                <input type="text" name="uname" value="wp_db_admin" placeholder="Benutzername">

                <label>Datenbank-Passwort</label>
                <input type="password" name="pwd" value="W0rdPr3ss_S3cur3_DB_P@ss_2026!" placeholder="Passwort">

                <label>Datenbank-Host</label>
                <input type="text" name="dbhost" value="db-primary.internal.qscqscqscqs.de" placeholder="localhost">

                <label>Tabellen-Präfix</label>
                <input type="text" name="prefix" value="wp_dt_prod_" placeholder="wp_">

                <button type="submit" class="submit-btn">Konfiguration speichern &rarr;</button>
            </form>
            <div class="note">⚠️ Diese Konfigurationsdaten werden unverschlüsselt in wp-config.php gespeichert.</div>
        </div>
        </body>
        </html>
        <?php
        break;

    case 1:
        // Fake: "Verarbeitung" der eingegebenen Daten
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            $dbname = $_POST['dbname'] ?? 'wp_dorftrottel_prod';
            $uname  = $_POST['uname'] ?? 'wp_db_admin';
            $pwd    = $_POST['pwd'] ?? 'W0rdPr3ss_S3cur3_DB_P@ss_2026!';
            $dbhost = $_POST['dbhost'] ?? 'db-primary.internal.qscqscqscqs.de';
            $prefix = $_POST['prefix'] ?? 'wp_dt_prod_';

            // Simulierte wp-config.php-Erstellung (fiktiv)
            $config_content = "<?php\n";
            $config_content .= "define('DB_NAME',     '$dbname');\n";
            $config_content .= "define('DB_USER',     '$uname');\n";
            $config_content .= "define('DB_PASSWORD', '$pwd');\n";
            $config_content .= "define('DB_HOST',     '$dbhost');\n";
            $config_content .= "\$table_prefix = '$prefix';\n";
            $config_content .= "// ALLE DATEN FIKTIV — SIMULATION\n";

            echo "<!DOCTYPE html><html lang='de'><head><meta charset='UTF-8'><title>WordPress › Setup</title></head><body>";
            echo "<div style='max-width:700px;margin:3rem auto;background:white;padding:2rem;border-radius:4px;'>";
            echo "<h1>✅ wp-config.php wurde erstellt!</h1>";
            echo "<p>Die Konfiguration wurde gespeichert. <a href='/wp-admin/install.php'>Installation starten</a></p>";
            echo "<hr>";
            echo "<h3>Generierte Konfiguration (Vorschau):</h3>";
            echo "<pre style='background:#f5f5f5;padding:1rem;overflow-x:auto;'>" . htmlspecialchars($config_content) . "</pre>";
            echo "<p style='color:#999;font-size:0.8rem;margin-top:1rem;'>⚠️ Alle Daten sind fiktiv — Simulation-System</p>";
            echo "</div></body></html>";
        }
        break;
}
