From 9f0fe884ce4e0d8cb384be0e6ded294faed9bef3 Mon Sep 17 00:00:00 2001 From: TheOnlyMace <0815cracky@gmail.com> Date: Sat, 17 Jan 2026 00:16:30 +0100 Subject: [PATCH] refactor: Use mail-config.php as main config, deprecate config.php --- config/config.php | 172 +++-------------------------------------- config/mail-config.php | 59 ++++++++++++-- 2 files changed, 60 insertions(+), 171 deletions(-) diff --git a/config/config.php b/config/config.php index 139fce6..60968a7 100644 --- a/config/config.php +++ b/config/config.php @@ -1,171 +1,17 @@ 'smtp.gmail.com', // z.B. smtp.gmail.com - 'smtp_port' => 587, // 587 für TLS, 465 für SSL - 'smtp_username' => 'test@hexahost.de', // z.B. info@hexahost.de - 'smtp_password' => 'your-app-password', // Ihr SMTP-Passwort - 'smtp_encryption' => 'tls', // 'tls' oder 'ssl' - - // Absender-Einstellungen - 'from_email' => 'test@hexahost.de', // Absender-E-Mail - 'from_name' => 'HexaHost.de Kontaktformular', // Absender-Name - - // Empfänger-Einstellungen - 'to_email' => 'info@hexahost.de', // Empfänger-E-Mail - 'to_name' => 'HexaHost Support', // Empfänger-Name - - // Sicherheitseinstellungen - 'max_requests_per_hour' => 5, // Max. Anfragen pro Stunde pro IP - 'honeypot_field' => 'website', // Verstecktes Feld für Bot-Schutz - - // E-Mail-Template-Einstellungen - 'email_template' => 'html', // 'html' oder 'text' - 'include_ip_address' => true, // IP-Adresse in E-Mail anzeigen - 'include_timestamp' => true, // Zeitstempel in E-Mail anzeigen -]; - -// DNS-Einstellungen für Spam-Schutz (werden über DNS konfiguriert) -$dns_config = [ - // SPF Record (TXT Record in DNS) - 'spf_record' => 'v=spf1 include:_spf.hexahost.de ~all', - - // DMARC Record (TXT Record in DNS) - 'dmarc_record' => 'v=DMARC1; p=quarantine; rua=mailto:dmarc@hexahost.de', - - // DKIM wird über den Mail-Server konfiguriert -]; - -// Debug-Einstellungen (nur für Entwicklung) -$debug_config = [ - 'debug_mode' => false, // Debug-Modus aktivieren - 'log_errors' => true, // Fehler loggen - 'log_file' => 'contact_form_errors.log', // Log-Datei -]; - -// Exportiere Konfiguration für andere Dateien -if (!defined('HEXAHOST_CONFIG_LOADED')) { - define('HEXAHOST_CONFIG_LOADED', true); - - // Globale Variablen für andere Dateien - $GLOBALS['hexahost_smtp_config'] = $smtp_config; - $GLOBALS['hexahost_dns_config'] = $dns_config; - $GLOBALS['hexahost_debug_config'] = $debug_config; -} - -// Hilfsfunktion zum Abrufen der Konfiguration -function getHexaHostConfig($key = null) { - global $smtp_config, $dns_config, $debug_config; - - if ($key === null) { - return array_merge($smtp_config, $dns_config, $debug_config); - } - - if (isset($smtp_config[$key])) { - return $smtp_config[$key]; - } - - if (isset($dns_config[$key])) { - return $dns_config[$key]; - } - - if (isset($debug_config[$key])) { - return $debug_config[$key]; - } - - return null; -} - -// Debug-Funktion -function hexahostDebug($message, $type = 'info') { - global $debug_config; - - if (!$debug_config['debug_mode']) { - return; - } - - $timestamp = date('Y-m-d H:i:s'); - $log_message = "[$timestamp] [$type] $message" . PHP_EOL; - - if ($debug_config['log_errors']) { - error_log($log_message, 3, $debug_config['log_file']); - } - - if ($debug_config['debug_mode']) { - echo "\n"; - } -} - -// Validierung der SMTP-Konfiguration -function validateSMTPConfig() { - $config = getHexaHostConfig(); - $errors = []; - - // Prüfe ob alle erforderlichen Felder ausgefüllt sind - $required_fields = ['smtp_host', 'smtp_username', 'smtp_password', 'from_email', 'to_email']; - - foreach ($required_fields as $field) { - if (empty($config[$field]) || $config[$field] === 'YOUR_SMTP_' . strtoupper(substr($field, 5))) { - $errors[] = "Konfigurationsfehler: $field ist nicht korrekt eingestellt."; - } - } - - // Prüfe SMTP-Port - if (!is_numeric($config['smtp_port']) || $config['smtp_port'] < 1 || $config['smtp_port'] > 65535) { - $errors[] = "Konfigurationsfehler: Ungültiger SMTP-Port."; - } - - // Prüfe E-Mail-Format - if (!filter_var($config['from_email'], FILTER_VALIDATE_EMAIL)) { - $errors[] = "Konfigurationsfehler: Ungültige Absender-E-Mail."; - } - - if (!filter_var($config['to_email'], FILTER_VALIDATE_EMAIL)) { - $errors[] = "Konfigurationsfehler: Ungültige Empfänger-E-Mail."; - } - - return $errors; -} - -// Zeige Konfigurationsfehler an (nur im Debug-Modus) -if (getHexaHostConfig('debug_mode')) { - $config_errors = validateSMTPConfig(); - if (!empty($config_errors)) { - hexahostDebug('SMTP-Konfigurationsfehler: ' . implode(', ', $config_errors), 'error'); - } -} -?> \ No newline at end of file +// Lade die neue Konfiguration +require_once __DIR__ . '/mail-config.php'; +?> diff --git a/config/mail-config.php b/config/mail-config.php index 6e10b72..46f0164 100644 --- a/config/mail-config.php +++ b/config/mail-config.php @@ -140,16 +140,59 @@ function isValidEmail($email) { return true; } -// CSRF Token generieren -function generateCSRFToken() { - if (!isset($_SESSION['csrf_token'])) { - $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); +// CSRF Token generieren (wird in functions.php verwendet) +// Hinweis: Diese Funktion existiert auch in functions.php - hier nur als Fallback +if (!function_exists('generateCSRFToken')) { + function generateCSRFToken() { + if (!isset($_SESSION['csrf_token'])) { + $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); + } + return $_SESSION['csrf_token']; } - return $_SESSION['csrf_token']; } // CSRF Token validieren -function validateCSRFToken($token) { - return isset($_SESSION['csrf_token']) && hash_equals($_SESSION['csrf_token'], $token); +if (!function_exists('validateCSRFToken')) { + function validateCSRFToken($token) { + return isset($_SESSION['csrf_token']) && hash_equals($_SESSION['csrf_token'], $token); + } } -?> \ No newline at end of file + +/** + * Hilfsfunktion zum Abrufen der Konfiguration als Array + * Kompatibilität mit contact-handler.php + * + * @param string|null $key Optional: einzelner Schlüssel + * @return mixed Konfigurationsarray oder einzelner Wert + */ +function getHexaHostConfig($key = null) { + $config = [ + // SMTP Server-Einstellungen + 'smtp_host' => SMTP_HOST, + 'smtp_port' => SMTP_PORT, + 'smtp_username' => SMTP_USERNAME, + 'smtp_password' => SMTP_PASSWORD, + 'smtp_encryption' => 'tls', + + // Absender/Empfänger + 'from_email' => SMTP_FROM_EMAIL, + 'from_name' => 'HexaHost.de Kontaktformular', + 'to_email' => SMTP_TO_EMAIL, + 'to_name' => 'HexaHost Support', + + // Sicherheit + 'max_requests_per_hour' => MAX_REQUESTS_PER_HOUR, + 'honeypot_field' => 'website', + + // Debug + 'debug_mode' => DEBUG_MODE, + 'log_errors' => LOG_EMAILS, + ]; + + if ($key === null) { + return $config; + } + + return $config[$key] ?? null; +} +?> \ No newline at end of file