Update file inclusion paths in multiple PHP files: Adjusted paths to use the new backend directory structure, ensuring consistent access to functions and configuration files across the application.
This commit is contained in:
175
backend/api/dns-propagation.php
Normal file
175
backend/api/dns-propagation.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
/**
|
||||
* HexaDNS - DNS Propagation Check API
|
||||
*
|
||||
* Prüft DNS-Records bei verschiedenen öffentlichen DNS-Servern
|
||||
*
|
||||
* Verwendung: GET /api/dns-propagation.php?domain=example.com&type=A
|
||||
*/
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: GET, OPTIONS');
|
||||
header('Access-Control-Allow-Headers: Content-Type');
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Öffentliche DNS-Server für Propagation-Check
|
||||
$dnsServers = [
|
||||
['name' => 'Google', 'ip' => '8.8.8.8', 'location' => 'Global'],
|
||||
['name' => 'Google Secondary', 'ip' => '8.8.4.4', 'location' => 'Global'],
|
||||
['name' => 'Cloudflare', 'ip' => '1.1.1.1', 'location' => 'Global'],
|
||||
['name' => 'Cloudflare Secondary', 'ip' => '1.0.0.1', 'location' => 'Global'],
|
||||
['name' => 'Quad9', 'ip' => '9.9.9.9', 'location' => 'Global'],
|
||||
['name' => 'OpenDNS', 'ip' => '208.67.222.222', 'location' => 'USA'],
|
||||
['name' => 'Comodo', 'ip' => '8.26.56.26', 'location' => 'USA'],
|
||||
['name' => 'Level3', 'ip' => '4.2.2.1', 'location' => 'USA'],
|
||||
];
|
||||
|
||||
$domain = isset($_GET['domain']) ? trim($_GET['domain']) : '';
|
||||
$type = isset($_GET['type']) ? strtoupper(trim($_GET['type'])) : 'A';
|
||||
|
||||
if (empty($domain)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'Domain-Parameter fehlt']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!preg_match('/^[a-zA-Z0-9][a-zA-Z0-9\-\.]*\.[a-zA-Z]{2,}$/', $domain)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'Ungültiges Domain-Format']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Erlaubte Record-Typen
|
||||
$allowedTypes = ['A', 'AAAA', 'MX', 'NS', 'TXT', 'CNAME'];
|
||||
if (!in_array($type, $allowedTypes)) {
|
||||
$type = 'A';
|
||||
}
|
||||
|
||||
$results = [];
|
||||
$startTime = microtime(true);
|
||||
|
||||
foreach ($dnsServers as $server) {
|
||||
$serverResult = [
|
||||
'server' => $server['name'],
|
||||
'ip' => $server['ip'],
|
||||
'location' => $server['location'],
|
||||
'records' => [],
|
||||
'status' => 'success',
|
||||
'response_time' => 0
|
||||
];
|
||||
|
||||
$queryStart = microtime(true);
|
||||
|
||||
// DNS-Abfrage mit spezifischem Server via dig (falls verfügbar) oder dns_get_record
|
||||
$records = queryDnsServer($domain, $type, $server['ip']);
|
||||
|
||||
$serverResult['response_time'] = round((microtime(true) - $queryStart) * 1000, 2);
|
||||
$serverResult['records'] = $records;
|
||||
|
||||
if (empty($records)) {
|
||||
$serverResult['status'] = 'no_records';
|
||||
}
|
||||
|
||||
$results[] = $serverResult;
|
||||
}
|
||||
|
||||
$totalTime = round((microtime(true) - $startTime) * 1000, 2);
|
||||
|
||||
// Propagation-Status berechnen
|
||||
$propagationStatus = calculatePropagationStatus($results);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'domain' => $domain,
|
||||
'record_type' => $type,
|
||||
'propagation_status' => $propagationStatus,
|
||||
'total_time_ms' => $totalTime,
|
||||
'timestamp' => date('Y-m-d H:i:s'),
|
||||
'servers' => $results
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
|
||||
/**
|
||||
* DNS-Abfrage bei spezifischem Server
|
||||
*/
|
||||
function queryDnsServer(string $domain, string $type, string $server): array {
|
||||
$records = [];
|
||||
|
||||
// Versuche zuerst dig zu verwenden (genauer)
|
||||
$digResult = @shell_exec("dig @{$server} {$domain} {$type} +short +time=2 +tries=1 2>/dev/null");
|
||||
|
||||
if ($digResult !== null && trim($digResult) !== '') {
|
||||
$lines = array_filter(explode("\n", trim($digResult)));
|
||||
foreach ($lines as $line) {
|
||||
$records[] = trim($line);
|
||||
}
|
||||
return $records;
|
||||
}
|
||||
|
||||
// Fallback auf PHP dns_get_record (verwendet System-DNS)
|
||||
$dnsType = constant('DNS_' . $type);
|
||||
$result = @dns_get_record($domain, $dnsType);
|
||||
|
||||
if ($result) {
|
||||
foreach ($result as $record) {
|
||||
switch ($type) {
|
||||
case 'A':
|
||||
$records[] = $record['ip'] ?? '';
|
||||
break;
|
||||
case 'AAAA':
|
||||
$records[] = $record['ipv6'] ?? '';
|
||||
break;
|
||||
case 'MX':
|
||||
$records[] = ($record['pri'] ?? '') . ' ' . ($record['target'] ?? '');
|
||||
break;
|
||||
case 'NS':
|
||||
case 'CNAME':
|
||||
$records[] = $record['target'] ?? '';
|
||||
break;
|
||||
case 'TXT':
|
||||
$records[] = $record['txt'] ?? '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_filter($records);
|
||||
}
|
||||
|
||||
/**
|
||||
* Berechnet den Propagation-Status
|
||||
*/
|
||||
function calculatePropagationStatus(array $results): array {
|
||||
$totalServers = count($results);
|
||||
$serversWithRecords = 0;
|
||||
$allRecords = [];
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (!empty($result['records'])) {
|
||||
$serversWithRecords++;
|
||||
foreach ($result['records'] as $record) {
|
||||
$allRecords[] = $record;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Einzigartige Records
|
||||
$uniqueRecords = array_unique($allRecords);
|
||||
|
||||
// Konsistenz prüfen (haben alle Server die gleichen Records?)
|
||||
$isConsistent = count($uniqueRecords) <= 1 || $serversWithRecords === 0;
|
||||
|
||||
$percentage = $totalServers > 0 ? round(($serversWithRecords / $totalServers) * 100) : 0;
|
||||
|
||||
return [
|
||||
'percentage' => $percentage,
|
||||
'servers_responding' => $serversWithRecords,
|
||||
'total_servers' => $totalServers,
|
||||
'is_consistent' => $isConsistent,
|
||||
'unique_values' => array_values($uniqueRecords)
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user