Compare commits

...

6 Commits

Author SHA1 Message Date
f3bc9a27ae s11 2026-03-02 20:28:18 +05:30
8d4cdcf601 add CORS 2026-01-27 13:52:31 +05:30
0e265ed859 add CORS 2026-01-27 13:48:57 +05:30
30503e398d add CORS 2026-01-27 13:03:04 +05:30
70e1f85971 add CORS 2026-01-27 12:56:41 +05:30
deeecc6f9c add CORS 2026-01-27 12:52:02 +05:30
3 changed files with 100 additions and 26 deletions

View File

@@ -6,7 +6,7 @@
$API_HEADERS = [ $API_HEADERS = [
'Content-Type: application/json; charset=utf-8', 'Content-Type: application/json; charset=utf-8',
'Access-Control-Allow-Origin: *', 'Access-Control-Allow-Origin: *',
'Access-Control-Allow-Methods: GET, POST, OPTIONS', 'Access-Control-Allow-Methods: POST, OPTIONS',
'Access-Control-Allow-Headers: Content-Type, Authorization', 'Access-Control-Allow-Headers: Content-Type, Authorization',
'X-Powered-By: SiliconPin Tools' 'X-Powered-By: SiliconPin Tools'
]; ];
@@ -14,9 +14,20 @@ $API_HEADERS = [
/** /**
* Apply headers helper * Apply headers helper
*/ */
function applyApiHeaders(array $headers) function applyApiHeaders(array $headers): void
{ {
foreach ($headers as $header) { foreach ($headers as $header) {
header($header); header($header);
} }
} }
/**
* Handle CORS preflight globally
*/
function handleCorsPreflight(): void
{
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit;
}
}

View File

@@ -1,20 +1,8 @@
<?php <?php
header('Content-Type: application/json; charset=utf-8'); require_once __DIR__ . '/../.hta_config/conf.php';
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
header('X-Powered-By: SiliconPin Tools');
/**
* DNS A Record Lookup API
* Endpoint: /dns-tools-get-a-record
* Method: POST
* Content-Type: application/json
*/
// ------------------------------- applyApiHeaders($API_HEADERS);
// Response headers handleCorsPreflight();
// -------------------------------
header('Content-Type: application/json; charset=utf-8');
// ------------------------------- // -------------------------------
// Allow only POST // Allow only POST
@@ -34,7 +22,21 @@ if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
$rawInput = file_get_contents('php://input'); $rawInput = file_get_contents('php://input');
$data = json_decode($rawInput, true); $data = json_decode($rawInput, true);
$domain = $data['domain'] ?? ''; if (!is_array($data)) {
http_response_code(400);
echo json_encode([
'success' => false,
'message' => 'Invalid JSON payload'
]);
exit;
}
// -------------------------------
// Normalize domain
// -------------------------------
$domain = trim($data['domain'] ?? '');
$domain = preg_replace('#^https?://#', '', $domain);
$domain = preg_replace('#/.*$#', '', $domain);
// ------------------------------- // -------------------------------
// Domain validation // Domain validation
@@ -57,15 +59,47 @@ if (!$domain || !validateDomain($domain)) {
} }
// ------------------------------- // -------------------------------
// DNS lookup (NO shell_exec) // 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 = 'hosting-default';
// -------------------------------
// 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'])
];
} }
} }
} }
@@ -73,12 +107,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;
} }
@@ -86,5 +120,8 @@ if (empty($ips)) {
echo json_encode([ echo json_encode([
'success' => true, 'success' => true,
'domain' => $domain, 'domain' => $domain,
'ips' => $ips 'record_count' => count($result),
'lookup_time_ms' => $lookupTimeMs,
'resolver' => $resolver,
'records' => $result
]); ]);

View File

@@ -0,0 +1,26 @@
<?php
// stream.php
header("Content-Type: text/event-stream");
header("Cache-Control: no-cache");
header("Access-Control-Allow-Origin: *");
$siteId = file_get_contents("current_site.txt");
for ($i = 1; $i <= 5; $i++) {
echo "data: " . json_encode([
"type" => "update",
"message" => "Crawling page $i..."
]) . "\n\n";
ob_flush();
flush();
sleep(1);
}
echo "data: " . json_encode([
"type" => "complete",
"site_id" => trim($siteId)
]) . "\n\n";
ob_flush();
flush();