Upload via GUI (267 Dateien)
This commit is contained in:
@@ -9,12 +9,82 @@
|
||||
* Sicherheitsgründen vom Server gelöscht oder zumindest gesperrt werden.
|
||||
*/
|
||||
|
||||
// Sicherheits-Header und Sitzungs-Cookie des Assistenten
|
||||
header('X-Frame-Options: DENY');
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
header('Referrer-Policy: no-referrer');
|
||||
header('Cache-Control: no-store');
|
||||
header('X-Robots-Tag: noindex, nofollow');
|
||||
$installHttps = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || strtolower(trim(explode(',', (string) ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? ''))[0])) === 'https';
|
||||
session_set_cookie_params(['lifetime' => 0, 'path' => '/', 'secure' => $installHttps, 'httponly' => true, 'samesite' => 'Lax']);
|
||||
session_start();
|
||||
|
||||
define('ROOT_DIR', dirname(__DIR__));
|
||||
define('LOCK_FILE', __DIR__ . '/.installed');
|
||||
require_once ROOT_DIR . '/database/sqlite_schema.php';
|
||||
|
||||
/** Gleiche Regeln wie im Programm (validate_password_strength), damit das Admin-Konto nicht schwächer ist als alle anderen. */
|
||||
function install_password_error(string $p): ?string
|
||||
{
|
||||
if (strlen($p) < 10) return 'Das Admin-Passwort muss mindestens 10 Zeichen lang sein.';
|
||||
if (!preg_match('/[A-Z]/', $p)) return 'Das Admin-Passwort muss mindestens einen Großbuchstaben enthalten.';
|
||||
if (!preg_match('/[a-z]/', $p)) return 'Das Admin-Passwort muss mindestens einen Kleinbuchstaben enthalten.';
|
||||
if (!preg_match('/[0-9]/', $p)) return 'Das Admin-Passwort muss mindestens eine Ziffer enthalten.';
|
||||
if (!preg_match('/[^A-Za-z0-9]/', $p)) return 'Das Admin-Passwort muss mindestens ein Sonderzeichen enthalten.';
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Verständliche Meldung zu einem Datenbankfehler (mit dem technischen Text dahinter). */
|
||||
function install_db_error(Throwable $e): string
|
||||
{
|
||||
$code = (int) ($e instanceof PDOException ? ($e->errorInfo[1] ?? $e->getCode()) : 0);
|
||||
$hint = match (true) {
|
||||
$code === 1045 => 'Benutzername oder Passwort der Datenbank stimmen nicht.',
|
||||
$code === 1049 => 'Die Datenbank existiert nicht. Legen Sie sie zuerst (leer) an, z. B. im Hosting-Bereich.',
|
||||
$code === 1044 => 'Der Datenbank-Benutzer hat keine Rechte auf diese Datenbank.',
|
||||
$code === 2002 || $code === 2006 => 'Der Datenbank-Server ist nicht erreichbar. Prüfen Sie Host (und Port, z. B. localhost:3306).',
|
||||
$code === 2054 => 'Der Datenbank-Server verlangt eine Anmeldemethode, die diese PHP-Version nicht unterstützt.',
|
||||
default => 'Prüfen Sie Host, Datenbankname, Benutzer und Passwort.',
|
||||
};
|
||||
return 'Datenbankverbindung fehlgeschlagen. ' . $hint . ' (Technisch: ' . $e->getMessage() . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Schreibt die Konfiguration so, dass sie sicher gilt: auch wenn schon eine (alte, z. B. mitgelieferte) config.php liegt,
|
||||
* die dem Webserver nicht gehört oder nicht beschreibbar ist, und mit Löschen des PHP-Zwischenspeichers (OPcache),
|
||||
* damit nicht weiter die alte Version geladen wird.
|
||||
*/
|
||||
function install_write_config(string $path, string $content): bool
|
||||
{
|
||||
$ok = @file_put_contents($path, $content) !== false;
|
||||
if (!$ok && is_file($path)) {
|
||||
@chmod($path, 0644);
|
||||
$ok = @file_put_contents($path, $content) !== false;
|
||||
if (!$ok && @unlink($path)) $ok = @file_put_contents($path, $content) !== false; // Datei gehört einem anderen Benutzer, der Ordner aber nicht
|
||||
}
|
||||
if ($ok) {
|
||||
clearstatcache(true, $path);
|
||||
if (function_exists('opcache_invalidate')) @opcache_invalidate($path, true);
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
/** Liest die geschriebene Konfiguration frisch ein und prüft, dass genau die eingegebenen Daten darin stehen. Gibt null oder eine Fehlermeldung zurück. */
|
||||
function install_verify_config(string $path, array $expected): ?string
|
||||
{
|
||||
if (function_exists('opcache_invalidate')) @opcache_invalidate($path, true);
|
||||
$onDisk = (string) @file_get_contents($path);
|
||||
if (!str_contains($onDisk, var_export((string) $expected['app_key'], true))) return 'Die Konfigurationsdatei enthält nicht die neuen Daten. Prüfen Sie die Schreibrechte auf config/config.php.';
|
||||
$loaded = @include $path;
|
||||
$db = is_array($loaded) ? (array) ($loaded['db'] ?? []) : [];
|
||||
foreach (['driver', 'host', 'name', 'user', 'pass'] as $k) {
|
||||
if ((string) ($db[$k] ?? '') !== (string) $expected['db'][$k]) {
|
||||
return 'Die Konfiguration wurde geschrieben, PHP liefert aber noch eine ältere Version (Zwischenspeicher/OPcache des Servers). Laden Sie PHP neu (Hosting-Oberfläche) oder warten Sie einige Minuten und starten Sie die Installation erneut.';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function h(?string $s): string
|
||||
{
|
||||
return htmlspecialchars($s ?? '', ENT_QUOTES, 'UTF-8');
|
||||
@@ -22,7 +92,7 @@ function h(?string $s): string
|
||||
|
||||
// URL der aktuellen Installation automatisch erkennen
|
||||
$detectedUrl = (function(): string {
|
||||
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
||||
$scheme = $GLOBALS['installHttps'] ? 'https' : 'http';
|
||||
$host = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? 'localhost';
|
||||
// install/ vom Pfad entfernen → Root-URL
|
||||
$path = rtrim(dirname($_SERVER['SCRIPT_NAME'] ?? ''), '/\\');
|
||||
@@ -55,22 +125,33 @@ $existingInstallation = (function (): bool {
|
||||
$alreadyInstalled = file_exists(LOCK_FILE) || $existingInstallation;
|
||||
$errors = [];
|
||||
$success = false;
|
||||
$manualConfig = null;
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Anforderungsprüfung
|
||||
// ---------------------------------------------------------------
|
||||
// Ordner anlegen, die für den Betrieb nötig sind (falls beim Hochladen leer weggelassen)
|
||||
foreach (['uploads', 'backups', 'plugins', 'app_downloads', 'config'] as $__dir) {
|
||||
if (!is_dir(ROOT_DIR . '/' . $__dir)) @mkdir(ROOT_DIR . '/' . $__dir, 0755, true);
|
||||
}
|
||||
$checks = [
|
||||
['label' => 'PHP-Version 8.1 oder neuer (gefunden: ' . PHP_VERSION . ')', 'ok' => version_compare(PHP_VERSION, '8.1.0', '>=')],
|
||||
['label' => 'PHP-Version 8.2 oder neuer (gefunden: ' . PHP_VERSION . ')', 'ok' => version_compare(PHP_VERSION, '8.2.0', '>=')],
|
||||
['label' => 'PDO-Erweiterung', 'ok' => extension_loaded('pdo')],
|
||||
['label' => 'PDO MySQL-Treiber (für Produktivbetrieb)', 'ok' => extension_loaded('pdo_mysql'), 'optional' => true],
|
||||
['label' => 'PDO SQLite-Treiber (optional, für lokale Tests)', 'ok' => extension_loaded('pdo_sqlite'), 'optional' => true],
|
||||
['label' => 'Mindestens ein Datenbanktreiber (MySQL oder SQLite)', 'ok' => extension_loaded('pdo_mysql') || extension_loaded('pdo_sqlite')],
|
||||
['label' => 'mbstring-Erweiterung', 'ok' => extension_loaded('mbstring')],
|
||||
['label' => 'openssl-Erweiterung (Verschlüsselung der Zugangsdaten, Signaturen)', 'ok' => extension_loaded('openssl')],
|
||||
['label' => 'json-Erweiterung', 'ok' => extension_loaded('json')],
|
||||
['label' => 'curl-Erweiterung (optional: Webhooks, Plugin-Katalog, Updates)', 'ok' => extension_loaded('curl'), 'optional' => true],
|
||||
['label' => 'zip-Erweiterung (optional: Plugins, Themes, Update per ZIP, Backups)', 'ok' => extension_loaded('zip'), 'optional' => true],
|
||||
['label' => 'IMAP-Erweiterung (optional, nur für E-Mail-zu-Ticket)', 'ok' => extension_loaded('imap'), 'optional' => true],
|
||||
['label' => 'Verzeichnis config/ ist beschreibbar', 'ok' => is_writable(ROOT_DIR . '/config')],
|
||||
['label' => 'Verzeichnis uploads/ ist beschreibbar', 'ok' => is_writable(ROOT_DIR . '/uploads')],
|
||||
['label' => 'Verzeichnis database/ ist beschreibbar', 'ok' => is_writable(ROOT_DIR . '/database')],
|
||||
['label' => 'Verzeichnis database/ ist beschreibbar (nur für SQLite nötig)', 'ok' => is_writable(ROOT_DIR . '/database'), 'optional' => true],
|
||||
['label' => 'Verzeichnis backups/ ist beschreibbar (für Backups)', 'ok' => is_writable(ROOT_DIR . '/backups'), 'optional' => true],
|
||||
['label' => 'HTTPS (empfohlen: Anmeldedaten sonst unverschlüsselt)', 'ok' => $installHttps, 'optional' => true],
|
||||
];
|
||||
|
||||
$requiredOk = true;
|
||||
foreach ($checks as $c) {
|
||||
if (empty($c['optional']) && !$c['ok']) {
|
||||
@@ -97,7 +178,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$alreadyInstalled && $requiredOk)
|
||||
if ($siteUrl === '') $errors[] = 'Bitte die URL der Installation angeben (z.B. https://support.firma.de).';
|
||||
if ($adminName === '') $errors[] = 'Bitte einen Namen für das Admin-Konto angeben.';
|
||||
if (!filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) $errors[] = 'Bitte eine gültige Admin-E-Mail-Adresse angeben.';
|
||||
if (strlen($adminPass) < 8) $errors[] = 'Das Admin-Passwort muss mindestens 8 Zeichen lang sein.';
|
||||
if (($pwError = install_password_error($adminPass)) !== null) $errors[] = $pwError;
|
||||
if ($adminPass !== $adminPass2) $errors[] = 'Die beiden Passwörter stimmen nicht überein.';
|
||||
if (!extension_loaded('pdo_' . $driver)) $errors[] = "Die PHP-Erweiterung pdo_{$driver} ist nicht installiert.";
|
||||
|
||||
@@ -127,13 +208,24 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$alreadyInstalled && $requiredOk)
|
||||
$dsn = sprintf('mysql:host=%s;dbname=%s;charset=utf8mb4', $dbConfig['host'], $dbConfig['name']);
|
||||
$pdo = new PDO($dsn, $dbConfig['user'], $dbConfig['pass']);
|
||||
} else {
|
||||
// Nur bei gewähltem SQLite wird eine Datenbank-Datei angelegt, und nur für diese Installation:
|
||||
// Bricht sie ab, wird die halbfertige Datei am Ende des Aufrufs wieder entfernt.
|
||||
@unlink($dbConfig['sqlite_path']);
|
||||
$sqlitePath = $dbConfig['sqlite_path'];
|
||||
register_shutdown_function(function () use (&$success, &$pdo, &$stmt, $sqlitePath) {
|
||||
if ($success) return;
|
||||
// Verbindung und Statements schließen, sonst lässt sich die Datei (vor allem unter Windows) nicht löschen
|
||||
$stmt = null;
|
||||
$pdo = null;
|
||||
gc_collect_cycles();
|
||||
foreach ([$sqlitePath, $sqlitePath . '-wal', $sqlitePath . '-shm'] as $leftover) @unlink($leftover);
|
||||
});
|
||||
$pdo = new PDO('sqlite:' . $dbConfig['sqlite_path']);
|
||||
$pdo->exec('PRAGMA foreign_keys = ON;');
|
||||
}
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
} catch (Throwable $e) {
|
||||
$errors[] = 'Datenbankverbindung fehlgeschlagen: ' . $e->getMessage();
|
||||
$errors[] = install_db_error($e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +239,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$alreadyInstalled && $requiredOk)
|
||||
|
||||
// Vordefiniertes Demo-Admin-Konto entfernen und durch das hier
|
||||
// eingegebene, echte Admin-Konto ersetzen.
|
||||
$pdo->exec("DELETE FROM staff WHERE email = 'admin@example.com'");
|
||||
$pdo->prepare('DELETE FROM staff WHERE email IN (?, ?)')->execute(['admin@example.com', $adminEmail]);
|
||||
$stmt = $pdo->prepare(
|
||||
'INSERT INTO staff (name, email, password_hash, role, department_id, is_active, created_at) VALUES (?,?,?,?,?,1,?)'
|
||||
);
|
||||
@@ -240,11 +332,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$alreadyInstalled && $requiredOk)
|
||||
. " * WICHTIG: app_key niemals ändern – verschlüsselte Werte in der DB werden sonst unlesbar.\n"
|
||||
. " */\n\nreturn " . var_export($configArray, true) . ";\n";
|
||||
|
||||
if (file_put_contents(ROOT_DIR . '/config/config.php', $php) === false) {
|
||||
$errors[] = 'config/config.php konnte nicht geschrieben werden. Bitte Schreibrechte des Verzeichnisses prüfen.';
|
||||
$cfgPath = ROOT_DIR . '/config/config.php';
|
||||
if (!install_write_config($cfgPath, $php)) {
|
||||
$errors[] = 'config/config.php konnte nicht geschrieben werden. Die Datenbank ist eingerichtet. Speichern Sie den unten angezeigten Inhalt als config/config.php auf dem Server (oder geben Sie dem Webserver Schreibrechte auf den Ordner config/) und laden Sie die Seite neu.';
|
||||
$manualConfig = $php;
|
||||
} else {
|
||||
file_put_contents(LOCK_FILE, date('Y-m-d H:i:s') . " von " . ($_SERVER['REMOTE_ADDR'] ?? 'CLI'));
|
||||
$success = true;
|
||||
@chmod($cfgPath, 0640); // enthält Schlüssel und Datenbank-Passwort
|
||||
if (($verifyError = install_verify_config($cfgPath, $configArray)) !== null) {
|
||||
$errors[] = $verifyError;
|
||||
$manualConfig = $php;
|
||||
} else {
|
||||
// Programm-Migrationen (Schritte mit Code statt SQL) jetzt mit der fertigen Konfiguration einspielen: Fehler erscheinen hier
|
||||
// und nicht erst beim ersten Seitenaufruf. Scheitert das, wird die Konfiguration wieder entfernt, damit ein neuer Versuch möglich ist.
|
||||
try {
|
||||
require_once ROOT_DIR . '/includes/db.php';
|
||||
require_once ROOT_DIR . '/includes/functions.php';
|
||||
get_db();
|
||||
@file_put_contents(LOCK_FILE, date('Y-m-d H:i:s') . ' von ' . ($_SERVER['REMOTE_ADDR'] ?? 'CLI'));
|
||||
$success = true;
|
||||
} catch (Throwable $e) {
|
||||
@unlink($cfgPath);
|
||||
$errors[] = 'Fehler beim Einspielen der Datenbank-Änderungen: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -491,7 +601,7 @@ html, body {
|
||||
box-shadow: 0 0 0 3px rgba(15,111,106,.12);
|
||||
}
|
||||
.i-field input::placeholder { color: #b0bac6; }
|
||||
.i-field .i-hint {
|
||||
.i-hint, .i-field .i-hint {
|
||||
font-size: .74rem;
|
||||
color: var(--muted);
|
||||
margin-top: 4px;
|
||||
@@ -715,9 +825,11 @@ code {
|
||||
<div class="i-card" style="text-align:center;padding:40px 28px">
|
||||
<div class="i-success-icon">🔒</div>
|
||||
<h2 style="margin-bottom:10px">Bereits installiert</h2>
|
||||
<p style="color:var(--muted);font-size:.9rem;margin-bottom:6px">
|
||||
Eingerichtet am <strong><?= h(is_file(LOCK_FILE) ? (string) file_get_contents(LOCK_FILE) : "bereits vorhandener Konfiguration") ?></strong>
|
||||
</p>
|
||||
<?php if (is_file(LOCK_FILE)): ?>
|
||||
<p style="color:var(--muted);font-size:.9rem;margin-bottom:6px">Eingerichtet am <strong><?= h((string) file_get_contents(LOCK_FILE)) ?></strong></p>
|
||||
<?php else: ?>
|
||||
<p style="color:var(--muted);font-size:.9rem;margin-bottom:6px">Es gibt bereits eine Konfiguration mit Datenbank und Mitarbeiterkonten. Eine Neuinstallation würde diese Daten überschreiben und ist deshalb gesperrt.</p>
|
||||
<?php endif; ?>
|
||||
<div class="i-alert warning" style="margin-top:20px;text-align:left">
|
||||
<span class="i-alert-icon">⚠️</span>
|
||||
<span>Bitte das Verzeichnis <code>install/</code> vom Server löschen, um diese Seite zu deaktivieren.</span>
|
||||
@@ -726,8 +838,8 @@ code {
|
||||
<a href="/login.php" class="i-btn-primary">Kundenportal</a>
|
||||
<a href="/staff/login.php" class="i-btn-secondary">Mitarbeiter-Login</a>
|
||||
</div>
|
||||
<p style="font-size:.75rem;color:var(--muted);margin-top:16px">
|
||||
Zum Wiederholen: <code>install/.installed</code> löschen
|
||||
<p style="font-size:.75rem;color:var(--muted);margin-top:16px;line-height:1.6">
|
||||
Wirklich neu installieren? Erst ein Backup der Daten anlegen, dann <code>config/config.php</code>, <code>install/.installed</code> und die Datenbank (bei SQLite die Datei <code>database/deskhub.sqlite</code>) entfernen. Alle bisherigen Daten gehen dabei verloren.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -779,6 +891,13 @@ code {
|
||||
<?php foreach ($errors as $err): ?>
|
||||
<div class="i-alert error"><span class="i-alert-icon">✗</span><span><?= h($err) ?></span></div>
|
||||
<?php endforeach; ?>
|
||||
<?php if ($manualConfig !== null): ?>
|
||||
<div class="i-card">
|
||||
<div class="i-card-title">Inhalt für config/config.php</div>
|
||||
<div class="i-hint" style="margin-bottom:10px">Enthält Schlüssel und Datenbank-Passwort: nur auf dem Server speichern, nirgends weitergeben.</div>
|
||||
<textarea readonly rows="14" style="width:100%;font-family:monospace;font-size:.78rem" onclick="this.select()"><?= h($manualConfig) ?></textarea>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Step 2: Configuration form -->
|
||||
<div class="i-card">
|
||||
@@ -825,7 +944,7 @@ code {
|
||||
<input type="password" id="db_pass" name="db_pass" placeholder="••••••••">
|
||||
</div>
|
||||
</div>
|
||||
<p class="i-hint" style="margin-bottom:16px">Die Datenbank muss bereits existieren (leer) — Tabellen werden automatisch angelegt.</p>
|
||||
<div class="i-hint" style="margin-bottom:16px">Die Datenbank muss bereits existieren (leer). Tabellen werden automatisch angelegt.</div>
|
||||
</div>
|
||||
|
||||
<!-- Website -->
|
||||
@@ -849,7 +968,7 @@ code {
|
||||
</div>
|
||||
<div class="i-field">
|
||||
<label for="admin_email">E-Mail</label>
|
||||
<input type="email" id="admin_email" name="admin_email" value="<?= h($_POST['admin_email'] ?? '') ?>" placeholder="admin@firma.de" required>
|
||||
<input type="email" id="admin_email" name="admin_email" autocapitalize="none" autocorrect="off" spellcheck="false" value="<?= h($_POST['admin_email'] ?? '') ?>" placeholder="admin@firma.de" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="i-row">
|
||||
@@ -857,6 +976,7 @@ code {
|
||||
<label for="admin_password">Passwort</label>
|
||||
<input type="password" id="admin_password" name="admin_password" placeholder="••••••••" required>
|
||||
<div class="i-pw-bar"><div class="i-pw-fill" id="pw-fill"></div></div>
|
||||
<div class="i-hint">Mindestens 10 Zeichen mit Groß- und Kleinbuchstaben, Ziffer und Sonderzeichen.</div>
|
||||
</div>
|
||||
<div class="i-field">
|
||||
<label for="admin_password2">Passwort wiederholen</label>
|
||||
@@ -888,17 +1008,24 @@ document.querySelectorAll('.i-driver-tab input[type=radio]').forEach(function(ra
|
||||
});
|
||||
});
|
||||
|
||||
// Doppelklick verhindern: sonst startet die Installation zweimal
|
||||
var installForm = document.getElementById('install-form');
|
||||
if (installForm) installForm.addEventListener('submit', function() {
|
||||
var b = installForm.querySelector('button[type=submit]');
|
||||
if (b) { b.disabled = true; b.textContent = 'Wird installiert …'; }
|
||||
});
|
||||
|
||||
// Password strength bar
|
||||
var pwInput = document.getElementById('admin_password');
|
||||
var pwFill = document.getElementById('pw-fill');
|
||||
if (pwInput && pwFill) {
|
||||
pwInput.addEventListener('input', function() {
|
||||
var v = this.value, score = 0;
|
||||
if (v.length >= 8) score++;
|
||||
if (v.length >= 12) score++;
|
||||
if (/[A-Z]/.test(v)) score++;
|
||||
if (v.length >= 10) score++;
|
||||
if (/[A-Z]/.test(v) && /[a-z]/.test(v)) score++;
|
||||
if (/[0-9]/.test(v)) score++;
|
||||
if (/[^A-Za-z0-9]/.test(v)) score++;
|
||||
if (v.length >= 14) score++;
|
||||
var colors = ['#ef4444','#f97316','#eab308','#22c55e','#16a34a'];
|
||||
var widths = ['20%','40%','60%','80%','100%'];
|
||||
pwFill.style.width = score > 0 ? widths[score-1] : '0%';
|
||||
|
||||
Reference in New Issue
Block a user