This commit is contained in:
Pinga 2023-08-27 18:41:21 +03:00
parent b7065fcaa6
commit 6181ece4de
9 changed files with 84 additions and 84 deletions

View file

@ -41,7 +41,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
$server->send($fd, "Error connecting to database");
$server->close($fd);
}
// Validate and sanitize the domain name
$domain = trim($data);
if (!$domain) {
@ -57,7 +57,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
$server->send($fd, "domain name invalid format");
$server->close($fd);
}
// Extract TLD from the domain and prepend a dot
$parts = explode('.', $domain);
$tld = "." . end($parts);
@ -92,39 +92,39 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
$server->close($fd);
return;
}
// Perform the DAS lookup
try {
$query = "SELECT name FROM `registry`.`domain` WHERE `name` = :domain";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':domain', $domain, PDO::PARAM_STR);
$stmt->execute();
try {
$query = "SELECT name FROM `registry`.`domain` WHERE `name` = :domain";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':domain', $domain, PDO::PARAM_STR);
$stmt->execute();
if ($f = $stmt->fetch(PDO::FETCH_ASSOC)) {
$server->send($fd, "1");
if ($f = $stmt->fetch(PDO::FETCH_ASSOC)) {
$server->send($fd, "1");
if ($fp = @fopen("/var/log/das/das_request.log",'a')) {
$clientInfo = $server->getClientInfo($fd);
$remoteAddr = $clientInfo['remote_ip'];
fwrite($fp,date('Y-m-d H:i:s')."\t-\t".$remoteAddr."\t-\t".$domain."\n");
fclose($fp);
}
$server->close($fd);
} else {
$server->send($fd, "0");
if ($fp = @fopen("/var/log/das/das_request.log",'a')) {
$clientInfo = $server->getClientInfo($fd);
$remoteAddr = $clientInfo['remote_ip'];
fwrite($fp,date('Y-m-d H:i:s')."\t-\t".$remoteAddr."\t-\t".$domain."\n");
fclose($fp);
}
$server->close($fd);
} else {
$server->send($fd, "0");
if ($fp = @fopen("/var/log/das/das_not_found.log",'a')) {
$clientInfo = $server->getClientInfo($fd);
$remoteAddr = $clientInfo['remote_ip'];
fwrite($fp,date('Y-m-d H:i:s')."\t-\t".$remoteAddr."\t-\t".$domain."\n");
fclose($fp);
}
$server->close($fd);
}
} catch (PDOException $e) {
if ($fp = @fopen("/var/log/das/das_not_found.log",'a')) {
$clientInfo = $server->getClientInfo($fd);
$remoteAddr = $clientInfo['remote_ip'];
fwrite($fp,date('Y-m-d H:i:s')."\t-\t".$remoteAddr."\t-\t".$domain."\n");
fclose($fp);
}
$server->close($fd);
}
} catch (PDOException $e) {
$server->send($fd, "Error connecting to the das database");
$server->close($fd);
}
}
// Close the connection
$pdo = null;

View file

@ -107,7 +107,7 @@ $http->start();
function handleDomainQuery($request, $response, $pdo, $domainName) {
// Extract and validate the domain name from the request
$domain = trim($domainName);
// Empty domain check
if (!$domain) {
$response->header('Content-Type', 'application/json');
@ -115,7 +115,7 @@ function handleDomainQuery($request, $response, $pdo, $domainName) {
$response->end(json_encode(['error' => 'Please enter a domain name']));
return;
}
// Check domain length
if (strlen($domain) > 68) {
$response->header('Content-Type', 'application/json');
@ -123,7 +123,7 @@ function handleDomainQuery($request, $response, $pdo, $domainName) {
$response->end(json_encode(['error' => 'Domain name is too long']));
return;
}
// Check for prohibited patterns in domain names
if (preg_match("/(^-|^\.|-\.|\.-|--|\.\.|-$|\.$)/", $domain)) {
$response->header('Content-Type', 'application/json');
@ -131,7 +131,7 @@ function handleDomainQuery($request, $response, $pdo, $domainName) {
$response->end(json_encode(['error' => 'Domain name invalid format']));
return;
}
// Extract TLD from the domain
$parts = explode('.', $domain);
$tld = "." . end($parts);
@ -148,7 +148,7 @@ function handleDomainQuery($request, $response, $pdo, $domainName) {
$response->end(json_encode(['error' => 'Invalid TLD. Please search only allowed TLDs']));
return;
}
// Fetch the IDN regex for the given TLD
$stmtRegex = $pdo->prepare("SELECT idn_table FROM domain_tld WHERE tld = :tld");
$stmtRegex->bindParam(':tld', $tld, PDO::PARAM_STR);
@ -177,21 +177,21 @@ function handleDomainQuery($request, $response, $pdo, $domainName) {
$stmt1->bindParam(':domain', $domain, PDO::PARAM_STR);
$stmt1->execute();
$domainDetails = $stmt1->fetch(PDO::FETCH_ASSOC);
// Check if the domain exists
if (!$domainDetails) {
// Domain not found, respond with a 404 error
$response->header('Content-Type', 'application/json');
$response->status(404);
$response->end(json_encode([
'errorCode' => 404,
'title' => 'Not Found',
'description' => 'The requested domain was not found in the RDAP database.',
]));
// Close the connection
$pdo = null;
return;
}
// Check if the domain exists
if (!$domainDetails) {
// Domain not found, respond with a 404 error
$response->header('Content-Type', 'application/json');
$response->status(404);
$response->end(json_encode([
'errorCode' => 404,
'title' => 'Not Found',
'description' => 'The requested domain was not found in the RDAP database.',
]));
// Close the connection
$pdo = null;
return;
}
// Query 2: Get status details
$stmt2 = $pdo->prepare("SELECT `status` FROM `domain_status` WHERE `domain_id` = :domain_id");
@ -211,12 +211,12 @@ function handleDomainQuery($request, $response, $pdo, $domainName) {
$stmt4->execute();
$registrantDetails = $stmt4->fetch(PDO::FETCH_ASSOC);
// Query 5: Get admin, billing and tech contacts
// Query 5: Get admin, billing and tech contacts
$stmtMap = $pdo->prepare("SELECT contact_id, type FROM domain_contact_map WHERE domain_id = :domain_id");
$stmtMap->bindParam(':domain_id', $domainDetails['id'], PDO::PARAM_INT);
$stmtMap->execute();
$contactMap = $stmtMap->fetchAll(PDO::FETCH_ASSOC);
$adminDetails = [];
$techDetails = [];
$billingDetails = [];
@ -251,7 +251,7 @@ function handleDomainQuery($request, $response, $pdo, $domainName) {
$stmt6->bindParam(':domain_id', $domainDetails['id'], PDO::PARAM_INT);
$stmt6->execute();
$nameservers = $stmt6->fetchAll(PDO::FETCH_ASSOC);
// Define the basic events
$events = [
['eventAction' => 'registration', 'eventDate' => $domainDetails['crdate']],
@ -350,11 +350,11 @@ function handleDomainQuery($request, $response, $pdo, $domainName) {
"This response conforms to the RDAP Operational Profile for gTLD Registries and Registrars version 1.0"
]
],
[
[
"description" => [
"For more information on domain status codes, please visit https://icann.org/epp"
],
"links" => [
"links" => [
[
"href" => "https://icann.org/epp",
"rel" => "alternate",
@ -363,11 +363,11 @@ function handleDomainQuery($request, $response, $pdo, $domainName) {
],
"title" => "Status Codes"
],
[
[
"description" => [
"URL of the ICANN RDDS Inaccuracy Complaint Form: https://icann.org/wicf"
],
"links" => [
"links" => [
[
"href" => "https://icann.org/wicf",
"rel" => "alternate",

View file

@ -41,7 +41,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
$server->send($fd, "Error connecting to database");
$server->close($fd);
}
$privacy = $c['privacy'];
// Validate and sanitize the data
@ -67,7 +67,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
if ($queryType == 'nameserver') {
// Handle nameserver query
$nameserver = $queryData;
if (!$nameserver) {
$server->send($fd, "please enter a nameserver");
$server->close($fd);
@ -76,12 +76,12 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
$server->send($fd, "nameserver is too long");
$server->close($fd);
}
if (!preg_match('/^([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,}$/', $nameserver)) {
$server->send($fd, "Nameserver contains invalid characters or is not in the correct format.");
$server->close($fd);
}
// Perform the WHOIS lookup
try {
$query = "SELECT `name`,`clid` FROM `host` WHERE `name` = :nameserver";
@ -91,7 +91,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
if ($f = $stmt->fetch(PDO::FETCH_ASSOC)) {
$res = "Server Name: ".$f['name'];
// Fetch the registrar details for this registrar using the id
$regQuery = "SELECT `id`,`name`,`iana_id`,`whois_server`,`url`,`abuse_email`,`abuse_phone` FROM `registrar` WHERE `id` = :clid";
$regStmt = $pdo->prepare($regQuery);
@ -107,7 +107,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
$res .= "\nRegistrar Abuse Contact Email: ".$registrar['abuse_email'];
$res .= "\nRegistrar Abuse Contact Phone: ".$registrar['abuse_phone'];
}
$res .= "\nURL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/";
$currentTimestamp = date('Y-m-d\TH:i:s\Z');
$res .= "\n>>> Last update of WHOIS database: {$currentTimestamp} <<<";
@ -152,17 +152,17 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
}
$server->close($fd);
}
} catch (PDOException $e) {
$server->send($fd, "Error connecting to the whois database");
$server->close($fd);
}
}
}
elseif ($queryType == 'registrar') {
// Handle registrar query
$registrar = $queryData;
if (!$registrar) {
$server->send($fd, "please enter a registrar name");
$server->close($fd);
@ -171,12 +171,12 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
$server->send($fd, "registrar name is too long");
$server->close($fd);
}
if (!preg_match('/^[a-zA-Z0-9\s\-]+$/', $registrar)) {
$server->send($fd, "Registrar name contains invalid characters.");
$server->close($fd);
}
// Perform the WHOIS lookup
try {
$query = "SELECT `id`,`name`,`iana_id`,`whois_server`,`url`,`abuse_email`,`abuse_phone` FROM `registrar` WHERE `name` = :registrar";
@ -191,7 +191,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
."\nRegistrar IANA ID: ".$f['iana_id']
."\nRegistrar Abuse Contact Email: ".$f['abuse_email']
."\nRegistrar Abuse Contact Phone: ".$f['abuse_phone'];
// Fetch the contact details for this registrar using the id
$contactQuery = "SELECT * FROM `registrar_contact` WHERE `id` = :registrar_id";
$contactStmt = $pdo->prepare($contactQuery);
@ -208,7 +208,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
$res .= "\nFax: " . $contact['fax'];
$res .= "\nPublic Email: " . $contact['email'];
}
$res .= "\nURL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/";
$currentTimestamp = date('Y-m-d\TH:i:s\Z');
$res .= "\n>>> Last update of WHOIS database: {$currentTimestamp} <<<";
@ -253,11 +253,11 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
}
$server->close($fd);
}
} catch (PDOException $e) {
$server->send($fd, "Error connecting to the whois database");
$server->close($fd);
}
}
}
else {
@ -367,7 +367,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
$stmt5->execute();
$f2 = $stmt5->fetch(PDO::FETCH_ASSOC);
if ($privacy) {
if ($privacy) {
$res .= "\nRegistry Registrant ID: REDACTED FOR PRIVACY"
."\nRegistrant Name: REDACTED FOR PRIVACY"
."\nRegistrant Organization: REDACTED FOR PRIVACY"
@ -381,7 +381,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
."\nRegistrant Phone: REDACTED FOR PRIVACY"
."\nRegistrant Fax: REDACTED FOR PRIVACY"
."\nRegistrant Email: Kindly refer to the RDDS server associated with the identified registrar in this output to obtain contact details for the Registrant, Admin, or Tech associated with the queried domain name.";
} else {
} else {
$res .= "\nRegistry Registrant ID: ".$f2['identifier']
."\nRegistrant Name: ".$f2['name']
."\nRegistrant Organization: ".$f2['org']
@ -395,7 +395,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
."\nRegistrant Phone: ".$f2['voice']
."\nRegistrant Fax: ".$f2['fax']
."\nRegistrant Email: ".$f2['email'];
}
}
$query6 = "SELECT contact.identifier,contact_postalInfo.name,contact_postalInfo.org,contact_postalInfo.street1,contact_postalInfo.street2,contact_postalInfo.street3,contact_postalInfo.city,contact_postalInfo.sp,contact_postalInfo.pc,contact_postalInfo.cc,contact.voice,contact.fax,contact.email
FROM domain_contact_map,contact,contact_postalInfo WHERE domain_contact_map.domain_id=:domain_id AND domain_contact_map.type='admin' AND domain_contact_map.contact_id=contact.id AND domain_contact_map.contact_id=contact_postalInfo.contact_id";
@ -404,7 +404,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
$stmt6->execute();
$f2 = $stmt6->fetch(PDO::FETCH_ASSOC);
if ($privacy) {
if ($privacy) {
$res .= "\nRegistry Admin ID: REDACTED FOR PRIVACY"
."\nAdmin Name: REDACTED FOR PRIVACY"
."\nAdmin Organization: REDACTED FOR PRIVACY"
@ -418,7 +418,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
."\nAdmin Phone: REDACTED FOR PRIVACY"
."\nAdmin Fax: REDACTED FOR PRIVACY"
."\nAdmin Email: Kindly refer to the RDDS server associated with the identified registrar in this output to obtain contact details for the Registrant, Admin, or Tech associated with the queried domain name.";
} else {
} else {
$res .= "\nRegistry Admin ID: ".$f2['identifier']
."\nAdmin Name: ".$f2['name']
."\nAdmin Organization: ".$f2['org']
@ -432,7 +432,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
."\nAdmin Phone: ".$f2['voice']
."\nAdmin Fax: ".$f2['fax']
."\nAdmin Email: ".$f2['email'];
}
}
$query7 = "SELECT contact.identifier,contact_postalInfo.name,contact_postalInfo.org,contact_postalInfo.street1,contact_postalInfo.street2,contact_postalInfo.street3,contact_postalInfo.city,contact_postalInfo.sp,contact_postalInfo.pc,contact_postalInfo.cc,contact.voice,contact.fax,contact.email
FROM domain_contact_map,contact,contact_postalInfo WHERE domain_contact_map.domain_id=:domain_id AND domain_contact_map.type='billing' AND domain_contact_map.contact_id=contact.id AND domain_contact_map.contact_id=contact_postalInfo.contact_id";
@ -441,7 +441,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
$stmt7->execute();
$f2 = $stmt7->fetch(PDO::FETCH_ASSOC);
if ($privacy) {
if ($privacy) {
$res .= "\nRegistry Billing ID: REDACTED FOR PRIVACY"
."\nBilling Name: REDACTED FOR PRIVACY"
."\nBilling Organization: REDACTED FOR PRIVACY"
@ -455,7 +455,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
."\nBilling Phone: REDACTED FOR PRIVACY"
."\nBilling Fax: REDACTED FOR PRIVACY"
."\nBilling Email: Kindly refer to the RDDS server associated with the identified registrar in this output to obtain contact details for the Registrant, Admin, or Tech associated with the queried domain name.";
} else {
} else {
$res .= "\nRegistry Billing ID: ".$f2['identifier']
."\nBilling Name: ".$f2['name']
."\nBilling Organization: ".$f2['org']
@ -469,7 +469,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
."\nBilling Phone: ".$f2['voice']
."\nBilling Fax: ".$f2['fax']
."\nBilling Email: ".$f2['email'];
}
}
$query8 = "SELECT contact.identifier,contact_postalInfo.name,contact_postalInfo.org,contact_postalInfo.street1,contact_postalInfo.street2,contact_postalInfo.street3,contact_postalInfo.city,contact_postalInfo.sp,contact_postalInfo.pc,contact_postalInfo.cc,contact.voice,contact.fax,contact.email
FROM domain_contact_map,contact,contact_postalInfo WHERE domain_contact_map.domain_id=:domain_id AND domain_contact_map.type='tech' AND domain_contact_map.contact_id=contact.id AND domain_contact_map.contact_id=contact_postalInfo.contact_id";
@ -478,7 +478,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
$stmt8->execute();
$f2 = $stmt8->fetch(PDO::FETCH_ASSOC);
if ($privacy) {
if ($privacy) {
$res .= "\nRegistry Tech ID: REDACTED FOR PRIVACY"
."\nTech Name: REDACTED FOR PRIVACY"
."\nTech Organization: REDACTED FOR PRIVACY"
@ -492,7 +492,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
."\nTech Phone: REDACTED FOR PRIVACY"
."\nTech Fax: REDACTED FOR PRIVACY"
."\nTech Email: Kindly refer to the RDDS server associated with the identified registrar in this output to obtain contact details for the Registrant, Admin, or Tech associated with the queried domain name.";
} else {
} else {
$res .= "\nRegistry Tech ID: ".$f2['identifier']
."\nTech Name: ".$f2['name']
."\nTech Organization: ".$f2['org']
@ -506,7 +506,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) {
."\nTech Phone: ".$f2['voice']
."\nTech Fax: ".$f2['fax']
."\nTech Email: ".$f2['email'];
}
}
$query9 = "SELECT `name` FROM `domain_host_map`,`host` WHERE `domain_host_map`.`domain_id` = :domain_id AND `domain_host_map`.`host_id` = `host`.`id`";
$stmt9 = $pdo->prepare($query9);