mirror of
https://git.hexahost.dev/smueller/HexaHost-Frontend.git
synced 2026-06-02 17:08:43 +00:00
181 lines
4.8 KiB
PHP
181 lines
4.8 KiB
PHP
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../includes/api-helpers.php';
|
|
|
|
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;
|
|
}
|
|
|
|
if (!checkApiRateLimit('dns-propagation')) {
|
|
rejectApiRateLimit();
|
|
}
|
|
|
|
|
|
$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 = getValidatedDomainParam();
|
|
$type = isset($_GET['type']) ? strtoupper(trim($_GET['type'])) : 'A';
|
|
|
|
if ($domain === null) {
|
|
http_response_code(400);
|
|
echo json_encode(['error' => empty($_GET['domain']) ? 'Domain-Parameter fehlt' : 'Ungültiges Domain-Format']);
|
|
exit;
|
|
}
|
|
|
|
|
|
$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);
|
|
|
|
|
|
$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);
|
|
|
|
|
|
$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);
|
|
|
|
|
|
|
|
|
|
function queryDnsServer(string $domain, string $type, string $server): array {
|
|
$records = [];
|
|
|
|
|
|
$digResult = @shell_exec(
|
|
'dig @' . escapeshellarg($server) . ' '
|
|
. escapeshellarg($domain) . ' '
|
|
. escapeshellarg($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;
|
|
}
|
|
|
|
|
|
$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);
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$uniqueRecords = array_unique($allRecords);
|
|
|
|
|
|
$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)
|
|
];
|
|
}
|