Bug fixes: - UniFiController: add CURLOPT_TIMEOUT (10s) and CURLOPT_CONNECTTIMEOUT (5s) to login() and apiRequest() — prevents page freeze when controller unreachable - UniFiController: fix login response validation for UniFi OS API which returns a user object instead of meta.rc=ok - admin/sites.php: add JS loading state on form submit to give visual feedback - login.php: handle new 'rate_limited' return value from Auth::login() New features: - Database: in-memory settings cache eliminates redundant DB queries per request - Auth: login rate limiting (10 attempts per 10 min per IP/email) via login_attempts table - admin/vouchers.php: CSV export with UTF-8 BOM for Excel compatibility - admin/vouchers.php: client-side pagination (50 per page) - index.php: QR code display after voucher creation (qrcodejs CDN) - Mailer: sendTestEmail() method - admin/settings.php: SMTP test button with AJAX handler - database.sql: add login_attempts and audit_log tables Readme: condensed from ~420 to ~220 lines, removed duplicated sections, M365 Azure Portal walkthrough, contribution guidelines, update/migration section https://claude.ai/code/session_01UsuvFAmmeagtQa14QA4iaq
79 lines
No EOL
2.5 KiB
PHP
79 lines
No EOL
2.5 KiB
PHP
<?php
|
|
class Database {
|
|
private static $instance = null;
|
|
private $pdo;
|
|
private $settingsCache = [];
|
|
|
|
private function __construct() {
|
|
try {
|
|
$this->pdo = new PDO(
|
|
"mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4",
|
|
DB_USER,
|
|
DB_PASS,
|
|
[
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
PDO::ATTR_EMULATE_PREPARES => false
|
|
]
|
|
);
|
|
} catch (PDOException $e) {
|
|
die("Datenbankverbindung fehlgeschlagen: " . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public static function getInstance() {
|
|
if (self::$instance === null) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
public function getConnection() {
|
|
return $this->pdo;
|
|
}
|
|
|
|
// Helper-Methode für Queries
|
|
public function query($sql, $params = []) {
|
|
$stmt = $this->pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
return $stmt;
|
|
}
|
|
|
|
// Helper für einzelnen Datensatz
|
|
public function fetchOne($sql, $params = []) {
|
|
$stmt = $this->query($sql, $params);
|
|
return $stmt->fetch();
|
|
}
|
|
|
|
// Helper für mehrere Datensätze
|
|
public function fetchAll($sql, $params = []) {
|
|
$stmt = $this->query($sql, $params);
|
|
return $stmt->fetchAll();
|
|
}
|
|
|
|
// Helper für Insert/Update mit Rückgabe der ID
|
|
public function execute($sql, $params = []) {
|
|
$this->query($sql, $params);
|
|
return $this->pdo->lastInsertId();
|
|
}
|
|
|
|
// Settings-Helper
|
|
public function getSetting($key, $default = null) {
|
|
if (array_key_exists($key, $this->settingsCache)) {
|
|
return $this->settingsCache[$key] ?? $default;
|
|
}
|
|
$result = $this->fetchOne("SELECT setting_value FROM settings WHERE setting_key = ?", [$key]);
|
|
$value = $result ? $result['setting_value'] : null;
|
|
$this->settingsCache[$key] = $value;
|
|
return $value ?? $default;
|
|
}
|
|
|
|
public function setSetting($key, $value) {
|
|
$this->query(
|
|
"INSERT INTO settings (setting_key, setting_value) VALUES (?, ?)
|
|
ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value)",
|
|
[$key, $value]
|
|
);
|
|
$this->settingsCache[$key] = $value;
|
|
}
|
|
} |