'Allgemeine Anfrage', 'vpc-anfrage' => 'Virtual Private Container Anfrage', 'vps-anfrage' => 'Virtual Private Server Anfrage', 'mail-gateway-anfrage' => 'Mail Gateway Anfrage', 'webhosting-anfrage' => 'Webhosting Anfrage', 'support' => 'Technischer Support', 'beratung' => 'Persönliche Beratung', 'migration' => 'Migration/Umzug', 'sonstiges' => 'Sonstige Anfrage' ]; // CSRF-Token validieren und invalidieren (verhindert Replay-Attacks) function validateCSRFToken($token) { if (isset($_SESSION['csrf_token']) && hash_equals($_SESSION['csrf_token'], $token)) { // Token nach erfolgreicher Validierung invalidieren unset($_SESSION['csrf_token']); return true; } return false; } // CORS Headers für AJAX-Requests (nur eigene Domains erlauben) $allowed_origins = getAllowedOrigins(); $origin = $_SERVER['HTTP_ORIGIN'] ?? ''; if (in_array($origin, $allowed_origins)) { header('Access-Control-Allow-Origin: ' . $origin); } header('Access-Control-Allow-Methods: POST'); header('Access-Control-Allow-Headers: Content-Type'); header('Content-Type: application/json; charset=utf-8'); // Nur POST-Requests erlauben if ($_SERVER['REQUEST_METHOD'] !== 'POST') { http_response_code(405); echo json_encode(['success' => false, 'message' => 'Method not allowed']); exit; } // Rate Limiting function checkRateLimit($ip) { global $config; $cache_file = sys_get_temp_dir() . '/hexahost_contact_' . md5($ip) . '.txt'; $current_time = time(); if (file_exists($cache_file)) { $data = json_decode(file_get_contents($cache_file), true); if ($data && isset($data['requests'])) { // Entferne alte Einträge (älter als 1 Stunde) $data['requests'] = array_filter($data['requests'], function($timestamp) use ($current_time) { return ($current_time - $timestamp) < 3600; }); if (count($data['requests']) >= $config['max_requests_per_hour']) { return false; } } } // Füge aktuellen Request hinzu $data = isset($data) ? $data : ['requests' => []]; $data['requests'][] = $current_time; file_put_contents($cache_file, json_encode($data)); return true; } // Honeypot Check function checkHoneypot($data) { global $config; $honeypot_field = $config['honeypot_field']; // Das Honeypot-Feld sollte leer sein (verstecktes Feld) if (!empty($data[$honeypot_field])) { return false; } return true; } // E-Mail-Validierung function validateEmail($email) { return filter_var($email, FILTER_VALIDATE_EMAIL) !== false; } // Input-Sanitization function sanitizeInput($input) { return htmlspecialchars(strip_tags(trim($input)), ENT_QUOTES, 'UTF-8'); } // Sichere IP-Adressen-Erkennung (auch hinter Proxies/Cloudflare) function getClientIP() { $ip_keys = [ 'HTTP_CF_CONNECTING_IP', // Cloudflare 'HTTP_X_FORWARDED_FOR', // Proxy 'HTTP_X_REAL_IP', // Nginx Proxy 'REMOTE_ADDR' // Standard ]; foreach ($ip_keys as $key) { if (!empty($_SERVER[$key])) { // Bei X-Forwarded-For kann eine Liste von IPs kommen $ip = explode(',', $_SERVER[$key])[0]; $ip = trim($ip); // Validiere IP-Format if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { return $ip; } } } // Fallback auf REMOTE_ADDR (auch private IPs für lokale Entwicklung) return $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0'; } // SMTP E-Mail-Versand mit PHPMailer function sendEmail($data) { global $config; // PHPMailer laden (falls verfügbar) if (!class_exists('PHPMailer\PHPMailer\PHPMailer')) { // Fallback: Native PHP mail() Funktion return sendEmailNative($data); } try { $mail = new PHPMailer\PHPMailer\PHPMailer(true); // Server-Einstellungen $mail->isSMTP(); $mail->Host = $config['smtp_host']; $mail->SMTPAuth = true; $mail->Username = $config['smtp_username']; $mail->Password = $config['smtp_password']; $mail->SMTPSecure = $config['smtp_encryption']; $mail->Port = $config['smtp_port']; $mail->CharSet = 'UTF-8'; // Absender $mail->setFrom($config['from_email'], $config['from_name']); $mail->addReplyTo($data['email'], $data['firstName'] . ' ' . $data['lastName']); // Empfänger $mail->addAddress($config['to_email'], $config['to_name']); // Betreff (nutzt zentrale SUBJECT_MAP Konstante) $subject = SUBJECT_MAP[$data['subject']] ?? 'Neue Kontaktanfrage'; $mail->Subject = '[HexaHost.de] ' . $subject; // HTML E-Mail-Inhalt $html_content = generateEmailHTML($data); $mail->isHTML(true); $mail->Body = $html_content; $mail->AltBody = generateEmailText($data); // Anti-Spam Headers $mail->addCustomHeader('X-Mailer', 'HexaHost Contact Form'); $mail->addCustomHeader('X-Priority', '3'); $mail->addCustomHeader('X-MSMail-Priority', 'Normal'); $mail->addCustomHeader('Importance', 'Normal'); $mail->addCustomHeader('X-Report-Abuse', 'Please report abuse here: abuse@hexahost.de'); // DKIM, SPF, DMARC werden über DNS konfiguriert $mail->send(); return true; } catch (Exception $e) { error_log('HexaHost Contact Form Error: ' . $e->getMessage()); return false; } } // Fallback: Native PHP mail() Funktion function sendEmailNative($data) { global $config; // Betreff (nutzt zentrale SUBJECT_MAP Konstante) $subject = SUBJECT_MAP[$data['subject']] ?? 'Neue Kontaktanfrage'; $subject = '[HexaHost.de] ' . $subject; // Headers für Spam-Schutz $headers = [ 'From: ' . $config['from_name'] . ' <' . $config['from_email'] . '>', 'Reply-To: ' . $data['firstName'] . ' ' . $data['lastName'] . ' <' . $data['email'] . '>', 'MIME-Version: 1.0', 'Content-Type: text/html; charset=UTF-8', 'X-Mailer: HexaHost Contact Form', 'X-Priority: 3', 'X-MSMail-Priority: Normal', 'Importance: Normal', 'X-Report-Abuse: Please report abuse here: abuse@hexahost.de' ]; $message = generateEmailHTML($data); return mail($config['to_email'], $subject, $message, implode("\r\n", $headers)); } // HTML E-Mail-Template function generateEmailHTML($data) { // Betreff (nutzt zentrale SUBJECT_MAP Konstante) $subject_text = SUBJECT_MAP[$data['subject']] ?? 'Neue Kontaktanfrage'; $html = '
HexaHost.de Kontaktformular