-
Notifications
You must be signed in to change notification settings - Fork 1
/
check.php
93 lines (73 loc) · 2.45 KB
/
check.php
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
// ==========================================
// Start editing below: Add your WHOIS and RDAP server hostnames here
// ==========================================
// WHOIS server
$whoisServer = 'whois.example.com';
// RDAP server
$rdap_url = 'rdap.example.com';
// ==========================================
// Stop editing above: No further modifications are necessary
// ==========================================
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['error' => 'Invalid request method.']);
exit;
}
$domain = $_POST['domain'];
$type = $_POST['type'];
$rdapServer = 'https://' . $rdap_url . '/domain/';
$sanitized_domain = filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
// Check if the domain is in Unicode and convert it to Punycode
if (mb_check_encoding($domain, 'UTF-8') && !filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) {
$punycodeDomain = idn_to_ascii($domain, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46);
if ($punycodeDomain !== false) {
$domain = $punycodeDomain;
} else {
echo json_encode(['error' => 'Invalid domain.']);
exit;
}
}
$sanitized_domain = filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
if ($sanitized_domain) {
$domain = $sanitized_domain;
} else {
echo json_encode(['error' => 'Invalid domain.']);
exit;
}
$sanitized_type = filter_var($type, FILTER_SANITIZE_STRING);
if ($sanitized_type === 'whois' || $sanitized_type === 'rdap') {
$type = $sanitized_type;
} else {
echo json_encode(['error' => 'Invalid input.']);
exit;
}
if ($type === 'whois') {
$output = '';
$socket = fsockopen($whoisServer, 43, $errno, $errstr, 30);
if (!$socket) {
echo json_encode(['error' => "Error fetching WHOIS data."]);
exit;
}
fwrite($socket, $domain . "\r\n");
while (!feof($socket)) {
$output .= fgets($socket);
}
fclose($socket);
} elseif ($type === 'rdap') {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $rdapServer . $domain);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
if (curl_errno($ch)) {
echo json_encode(['error' => 'cURL error: ' . curl_error($ch)]);
curl_close($ch);
exit;
}
curl_close($ch);
if (!$output) {
echo json_encode(['error' => 'Error fetching RDAP data.']);
exit;
}
}
echo $output;