-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNSResolver.php
More file actions
76 lines (68 loc) · 2.13 KB
/
DNSResolver.php
File metadata and controls
76 lines (68 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
require_once '../app/require.php';
$api = new APIController;
function dns_resolver($domain, $recordType = 'A') {
$dnsRecords = dns_get_record($domain, $recordType);
if ($dnsRecords === false) {
return ['error' => 'An error occurred while trying to retrieve DNS records.'];
}
if (count($dnsRecords) == 0) {
return ['error' => 'No records found for the specified domain and record type.'];
}
$result = [];
foreach ($dnsRecords as $record) {
if (isset($record['ip'])) {
$result[] = ['type' => $record['type'], 'ip' => $record['ip']];
} elseif (isset($record['target'])) {
$result[] = ['type' => $record['type'], 'target' => $record['target']];
}
}
return $result;
}
// start key
if (isset($_GET['key']))
{
$statusCheck = $api->CheckKey($_GET['key'], $_SERVER['REQUEST_URI']);
// start statusCheck
if ($statusCheck === "valid")
{
// start domain check
if (isset($_GET['domain']))
{
$domain = $_GET['domain'];
$recordType = $_GET['record_type'] ?? 'A';
$response = dns_resolver($domain, $recordType);
// start json check
if (isset($_GET['json']))
{
header("Content-Type: application/json");
$api->QueryLog($domain, "DNSResolver", $_GET['key']);
echo json_encode($response, JSON_PRETTY_PRINT);
}
else {
foreach ($response as $result) {
echo $result['type'] . ': ' . ($result['ip'] ?? $result['target']) . "\n";
}
$api->QueryLog($domain, "DNSResolver", $_GET['key']);
}
// end json check
}
else {
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
header("Content-Type: application/json");
echo json_encode(["error" => "Missing 'domain' parameter"]);
}
// end domain check
}
else {
echo $statusCheck;
}
}
else {
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
header("Content-Type: application/json");
echo json_encode(["error" => "Missing 'key' parameter"]);
}
?>