// NO OUTPUT BEFORE HEADERS if (!ob_get_level()) { ob_start(); } /** * DNS Management Page * Klanten kunnen hier DNS records beheren via NameSilo */ session_name('CUSTOMER_PORTAL_SESSION'); ini_set('session.cookie_path', '/'); ini_set('session.cookie_httponly', '1'); ini_set('session.cookie_secure', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? '1' : '0'); session_start(); require_once __DIR__ . '/inc/base.php'; // Check if customer is logged in if (!isset($_SESSION['customer_logged_in']) || $_SESSION['customer_logged_in'] !== true) { header('Location: /customer_portal/login.php?redirect=' . urlencode(customer_portal_safe_redirect_target($_SERVER['REQUEST_URI'] ?? '/customer_portal/dns.php'))); exit; } $customer_info = $_SESSION['customer_info'] ?? null; $customer_id = $customer_info['id'] ?? null; $domain = $_GET['domain'] ?? ''; if (!$customer_id) { header('Location: /customer_portal/dashboard.php'); exit; } // Verify domain belongs to customer $domain_belongs_to_customer = false; $customer_domains = []; try { // Get from itlive_portal $conn_portal = @new mysqli('localhost', 'root', '', 'itlive_portal'); if ($conn_portal && $conn_portal->connect_error) { $conn_portal = @new mysqli('localhost', 'root', 'root', 'itlive_portal'); } if ($conn_portal && $conn_portal->connect_error) { $conn_portal = @new mysqli('localhost', 'cyberpanel', 'OAmPGf6r10dTYR', 'itlive_portal'); } if ($conn_portal && !$conn_portal->connect_error) { $stmt = $conn_portal->prepare(" SELECT DISTINCT JSON_EXTRACT(o.order_data, '$.domain') as domain FROM orders o WHERE o.customer_id = ? AND JSON_EXTRACT(o.order_data, '$.domain') IS NOT NULL AND JSON_EXTRACT(o.order_data, '$.domain') != 'null' AND JSON_EXTRACT(o.order_data, '$.domain') != '' "); if ($stmt) { $stmt->bind_param('i', $customer_id); $stmt->execute(); $result = $stmt->get_result(); while ($row = $result->fetch_assoc()) { if ($row['domain']) { $domainName = trim($row['domain'], '"'); if (!empty($domainName) && $domainName !== 'null') { $customer_domains[] = $domainName; if ($domain === $domainName) { $domain_belongs_to_customer = true; } } } } $stmt->close(); } $conn_portal->close(); } // Also check cyberpanel if (!$domain_belongs_to_customer && !empty($domain)) { $conn = @new mysqli('localhost', 'cyberpanel', 'OAmPGf6r10dTYR', 'cyberpanel'); if ($conn && !$conn->connect_error) { $stmt = $conn->prepare(" SELECT COUNT(*) as count FROM website_configs WHERE customer_id = ? AND domain_name = ? "); if ($stmt) { $stmt->bind_param('is', $customer_id, $domain); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc(); if ($row && $row['count'] > 0) { $domain_belongs_to_customer = true; } $stmt->close(); } $conn->close(); } } } catch (Exception $e) { error_log("DNS domain verification error: " . $e->getMessage()); } // If no domain selected, use first domain if (empty($domain) && !empty($customer_domains)) { $domain = $customer_domains[0]; $domain_belongs_to_customer = true; } // Get DNS records from NameSilo $dns_records = []; $nameservers = []; $error = null; if ($domain_belongs_to_customer && !empty($domain)) { try { $apiKey = trim(@file_get_contents('/root/.namesilo/api_key')); if ($apiKey) { // Get DNS records $url = "https://www.namesilo.com/api/dnsListRecords?version=1&type=xml&key={$apiKey}&domain={$domain}"; $response = @file_get_contents($url); if ($response) { $xml = @simplexml_load_string($response); if ($xml) { if (isset($xml->reply->code) && (string)$xml->reply->code === '300') { // Success if (isset($xml->reply->resource_record)) { foreach ($xml->reply->resource_record as $record) { $dns_records[] = [ 'record_id' => (string)$record->record_id, 'type' => (string)$record->type, 'host' => (string)$record->host, 'value' => (string)$record->value, 'ttl' => (string)$record->ttl, 'distance' => (string)($record->distance ?? '') ]; } } } else { $error = isset($xml->reply->detail) ? (string)$xml->reply->detail : 'Fout bij ophalen DNS records'; } } } // Get nameservers $url = "https://www.namesilo.com/api/getDomainInfo?version=1&type=xml&key={$apiKey}&domain={$domain}"; $response = @file_get_contents($url); if ($response) { $xml = @simplexml_load_string($response); if ($xml && isset($xml->nameservers)) { foreach ($xml->nameservers->nameserver as $ns) { $nameservers[] = (string)$ns; } } } } else { $error = 'NameSilo API key niet gevonden'; } } catch (Exception $e) { $error = 'Fout bij ophalen DNS records: ' . $e->getMessage(); error_log("DNS fetch error: " . $e->getMessage()); } } // Group records by type $records_by_type = [ 'A' => [], 'AAAA' => [], 'CNAME' => [], 'MX' => [], 'TXT' => [], 'NS' => [], 'OTHER' => [] ]; foreach ($dns_records as $record) { $type = strtoupper($record['type']); if (isset($records_by_type[$type])) { $records_by_type[$type][] = $record; } else { $records_by_type['OTHER'][] = $record; } } $is_admin_impersonating = !empty($_SESSION['admin_impersonating']); if (!function_exists('customer_portal_base')) { require_once __DIR__ . '/inc/base.php'; } $page_title = 'DNS Beheer - ' . htmlspecialchars($domain ?? 'Selecteer Domein'); $page_extra_styles = ''; if (ob_get_level()) { @ob_clean(); } include __DIR__ . '/layout-start.php'; ?>

⚙️ DNS Beheer

Beheer DNS records voor je domeinen via NameSilo