add CORS
This commit is contained in:
@@ -1,10 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../.hta_config/conf.php';
|
require_once __DIR__ . '/../.hta_config/conf.php';
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------
|
|
||||||
// Apply headers + CORS
|
|
||||||
// -------------------------------
|
|
||||||
applyApiHeaders($API_HEADERS);
|
applyApiHeaders($API_HEADERS);
|
||||||
handleCorsPreflight();
|
handleCorsPreflight();
|
||||||
|
|
||||||
@@ -36,11 +32,9 @@ if (!is_array($data)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
// Extract + normalize domain
|
// Normalize domain
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
$domain = trim($data['domain'] ?? '');
|
$domain = trim($data['domain'] ?? '');
|
||||||
|
|
||||||
// Remove protocol if user sends URL
|
|
||||||
$domain = preg_replace('#^https?://#', '', $domain);
|
$domain = preg_replace('#^https?://#', '', $domain);
|
||||||
$domain = preg_replace('#/.*$#', '', $domain);
|
$domain = preg_replace('#/.*$#', '', $domain);
|
||||||
|
|
||||||
@@ -65,15 +59,54 @@ if (!$domain || !validateDomain($domain)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
// DNS A record lookup
|
// DNS lookup with timing
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
|
$startTime = microtime(true);
|
||||||
$records = dns_get_record($domain, DNS_A);
|
$records = dns_get_record($domain, DNS_A);
|
||||||
$ips = [];
|
$lookupTimeMs = round((microtime(true) - $startTime) * 1000, 2);
|
||||||
|
|
||||||
|
// -------------------------------
|
||||||
|
// Resolver info
|
||||||
|
// -------------------------------
|
||||||
|
$resolver = 'system';
|
||||||
|
$resolvConf = '/etc/resolv.conf';
|
||||||
|
if (is_readable($resolvConf)) {
|
||||||
|
$content = file_get_contents($resolvConf);
|
||||||
|
if (preg_match('/nameserver\s+([^\s]+)/', $content, $m)) {
|
||||||
|
$resolver = $m[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------
|
||||||
|
// Provider detection (heuristic)
|
||||||
|
// -------------------------------
|
||||||
|
function detectProvider(string $ip): string
|
||||||
|
{
|
||||||
|
if (preg_match('/^(104\.|172\.6[4-7]\.)/', $ip)) {
|
||||||
|
return 'Cloudflare';
|
||||||
|
}
|
||||||
|
if (preg_match('/^(13\.|15\.|52\.|54\.)/', $ip)) {
|
||||||
|
return 'AWS';
|
||||||
|
}
|
||||||
|
if (preg_match('/^(34\.|35\.)/', $ip)) {
|
||||||
|
return 'Google Cloud';
|
||||||
|
}
|
||||||
|
return 'Unknown';
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------
|
||||||
|
// Build records
|
||||||
|
// -------------------------------
|
||||||
|
$result = [];
|
||||||
|
|
||||||
if ($records !== false) {
|
if ($records !== false) {
|
||||||
foreach ($records as $record) {
|
foreach ($records as $record) {
|
||||||
if (!empty($record['ip'])) {
|
if (!empty($record['ip'])) {
|
||||||
$ips[] = $record['ip'];
|
$result[] = [
|
||||||
|
'ip' => $record['ip'],
|
||||||
|
'ttl' => $record['ttl'] ?? null,
|
||||||
|
'provider' => detectProvider($record['ip'])
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,12 +114,12 @@ if ($records !== false) {
|
|||||||
// -------------------------------
|
// -------------------------------
|
||||||
// Response
|
// Response
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
if (empty($ips)) {
|
if (empty($result)) {
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'domain' => $domain,
|
'domain' => $domain,
|
||||||
'message' => 'No A records found',
|
'message' => 'No A records found',
|
||||||
'ips' => []
|
'records' => []
|
||||||
]);
|
]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@@ -94,5 +127,8 @@ if (empty($ips)) {
|
|||||||
echo json_encode([
|
echo json_encode([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'domain' => $domain,
|
'domain' => $domain,
|
||||||
'ips' => array_values(array_unique($ips))
|
'record_count' => count($result),
|
||||||
|
'lookup_time_ms' => $lookupTimeMs,
|
||||||
|
'resolver' => $resolver,
|
||||||
|
'records' => $result
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user