Added handle formatting for objects

And fixed RDAP URLs
This commit is contained in:
Pinga 2023-11-27 12:22:46 +02:00
parent 964cd8f370
commit 4d3ee365a1
6 changed files with 51 additions and 47 deletions

View file

@ -69,7 +69,7 @@ foreach ($tlds as $tld) {
foreach ($domains as $domain) { foreach ($domains as $domain) {
$xml->startElement('rdeDom:domain'); $xml->startElement('rdeDom:domain');
$xml->writeElement('rdeDom:name', $domain['name']); $xml->writeElement('rdeDom:name', $domain['name']);
$xml->writeElement('rdeDom:roid', $domain['id']); $xml->writeElement('rdeDom:roid', 'D' . $domain['id']);
$xml->writeElement('rdeDom:uName', $domain['name']); $xml->writeElement('rdeDom:uName', $domain['name']);
$xml->writeElement('rdeDom:idnTableId', 'Latn'); $xml->writeElement('rdeDom:idnTableId', 'Latn');
@ -168,7 +168,7 @@ foreach ($tlds as $tld) {
foreach ($hosts as $host) { foreach ($hosts as $host) {
$xml->startElement('rdeHost:host'); $xml->startElement('rdeHost:host');
$xml->writeElement('rdeHost:name', $host['name']); $xml->writeElement('rdeHost:name', $host['name']);
$xml->writeElement('rdeHost:roid', $host['id']); $xml->writeElement('rdeHost:roid', 'H' . $host['id']);
$xml->startElement('rdeHost:status'); $xml->startElement('rdeHost:status');
$xml->writeAttribute('s', 'ok'); $xml->writeAttribute('s', 'ok');
@ -190,7 +190,7 @@ foreach ($tlds as $tld) {
foreach ($contacts as $contact) { foreach ($contacts as $contact) {
$xml->startElement('rdeContact:contact'); $xml->startElement('rdeContact:contact');
$xml->writeElement('rdeContact:id', $contact['identifier']); $xml->writeElement('rdeContact:id', $contact['identifier']);
$xml->writeElement('rdeContact:roid', $contact['id']); $xml->writeElement('rdeContact:roid', 'C' . $contact['id']);
$xml->startElement('rdeContact:status'); $xml->startElement('rdeContact:status');
$xml->writeAttribute('s', 'ok'); $xml->writeAttribute('s', 'ok');
$xml->text('ok'); $xml->text('ok');

View file

@ -64,7 +64,7 @@ function processContactInfo($conn, $db, $xml, $trans) {
'resultCode' => 1000, 'resultCode' => 1000,
'msg' => 'Command completed successfully', 'msg' => 'Command completed successfully',
'id' => $contact['id'], 'id' => $contact['id'],
'roid' => 'C_'.$contact['identifier'], 'roid' => 'C' . $contact['identifier'],
'status' => $statusArray, 'status' => $statusArray,
'postal' => $postalArray, 'postal' => $postalArray,
'voice' => $contact['voice'], 'voice' => $contact['voice'],
@ -148,7 +148,7 @@ function processHostInfo($conn, $db, $xml, $trans) {
'resultCode' => 1000, 'resultCode' => 1000,
'msg' => 'Command completed successfully', 'msg' => 'Command completed successfully',
'name' => $host['name'], 'name' => $host['name'],
'roid' => 'H_'.$host['id'], 'roid' => 'H' . $host['id'],
'status' => $statusArray, 'status' => $statusArray,
'addr' => $addrArray, 'addr' => $addrArray,
'clID' => getRegistrarClid($db, $host['clid']), 'clID' => getRegistrarClid($db, $host['clid']),
@ -283,7 +283,7 @@ function processDomainInfo($conn, $db, $xml, $trans) {
'resultCode' => 1000, 'resultCode' => 1000,
'msg' => 'Command completed successfully', 'msg' => 'Command completed successfully',
'name' => $domain['name'], 'name' => $domain['name'],
'roid' => 'D_'.$domain['id'], 'roid' => 'D' . $domain['id'],
'status' => $statusArray, 'status' => $statusArray,
'registrant' => $domain['registrant'], 'registrant' => $domain['registrant'],
'contact' => $transformedContacts, 'contact' => $transformedContacts,

View file

@ -6,5 +6,8 @@ return [
'db_port' => 3306, 'db_port' => 3306,
'db_database' => 'your_database_name', 'db_database' => 'your_database_name',
'db_username' => 'your_username', 'db_username' => 'your_username',
'db_password' => 'your_password' 'db_password' => 'your_password',
'roid' => 'XX',
'registry_url' => 'https://example.com/rdap-terms',
'rdap_url' => 'https://rdap.example.com',
]; ];

View file

@ -4,10 +4,10 @@ if (!extension_loaded('swoole')) {
die('Swoole extension must be installed'); die('Swoole extension must be installed');
} }
function mapContactToVCard($contactDetails, $role) { function mapContactToVCard($contactDetails, $role, $c) {
return [ return [
'objectClassName' => 'entity', 'objectClassName' => 'entity',
'handle' => [$contactDetails['identifier']], 'handle' => ['C' . $contactDetails['identifier'] . '-' . $c['roid']],
'roles' => [$role], 'roles' => [$role],
'remarks' => [ 'remarks' => [
[ [
@ -96,26 +96,26 @@ $http->on('request', function ($request, $response) use ($c, $pdo) {
// Handle domain query // Handle domain query
if (preg_match('#^/domain/([^/?]+)#', $requestPath, $matches)) { if (preg_match('#^/domain/([^/?]+)#', $requestPath, $matches)) {
$domainName = $matches[1]; $domainName = $matches[1];
handleDomainQuery($request, $response, $pdo, $domainName); handleDomainQuery($request, $response, $pdo, $domainName, $c);
} }
// Handle entity (contacts) query // Handle entity (contacts) query
elseif (preg_match('#^/entity/([^/?]+)#', $requestPath, $matches)) { elseif (preg_match('#^/entity/([^/?]+)#', $requestPath, $matches)) {
$entityHandle = $matches[1]; $entityHandle = $matches[1];
handleEntityQuery($request, $response, $pdo, $entityHandle); handleEntityQuery($request, $response, $pdo, $entityHandle, $c);
} }
// Handle nameserver query // Handle nameserver query
elseif (preg_match('#^/nameserver/([^/?]+)#', $requestPath, $matches)) { elseif (preg_match('#^/nameserver/([^/?]+)#', $requestPath, $matches)) {
$nameserverHandle = $matches[1]; $nameserverHandle = $matches[1];
handleNameserverQuery($request, $response, $pdo, $nameserverHandle); handleNameserverQuery($request, $response, $pdo, $nameserverHandle, $c);
} }
// Handle help query // Handle help query
elseif ($requestPath === '/help') { elseif ($requestPath === '/help') {
handleHelpQuery($request, $response, $pdo); handleHelpQuery($request, $response, $pdo, $c);
} }
// Handle search query (e.g., search for domains by pattern) // Handle search query (e.g., search for domains by pattern)
elseif (preg_match('#^/domains\?name=([^/?]+)#', $requestPath, $matches)) { elseif (preg_match('#^/domains\?name=([^/?]+)#', $requestPath, $matches)) {
$searchPattern = $matches[1]; $searchPattern = $matches[1];
handleSearchQuery($request, $response, $pdo, $searchPattern); handleSearchQuery($request, $response, $pdo, $searchPattern, $c);
} }
else { else {
$response->header('Content-Type', 'application/json'); $response->header('Content-Type', 'application/json');
@ -130,7 +130,7 @@ $http->on('request', function ($request, $response) use ($c, $pdo) {
// Start the server // Start the server
$http->start(); $http->start();
function handleDomainQuery($request, $response, $pdo, $domainName) { function handleDomainQuery($request, $response, $pdo, $domainName, $c) {
// Extract and validate the domain name from the request // Extract and validate the domain name from the request
$domain = trim($domainName); $domain = trim($domainName);
@ -354,7 +354,7 @@ function handleDomainQuery($request, $response, $pdo, $domainName) {
"handle" => $registrarDetails['iana_id'], "handle" => $registrarDetails['iana_id'],
"links" => [ "links" => [
[ [
"href" => "https://rdap.example.com/entity/" . $registrarDetails['iana_id'], "href" => $c['rdap_url'] . "/entity/" . $registrarDetails['iana_id'],
"rel" => "self", "rel" => "self",
"type" => "application/rdap+json" "type" => "application/rdap+json"
] ]
@ -383,29 +383,29 @@ function handleDomainQuery($request, $response, $pdo, $domainName) {
], ],
], ],
[ [
mapContactToVCard($registrantDetails, 'registrant') mapContactToVCard($registrantDetails, 'registrant', $c)
], ],
array_map(function ($contact) { array_map(function ($contact) {
return mapContactToVCard($contact, 'admin'); return mapContactToVCard($contact, 'admin', $c);
}, $adminDetails), }, $adminDetails),
array_map(function ($contact) { array_map(function ($contact) {
return mapContactToVCard($contact, 'tech'); return mapContactToVCard($contact, 'tech', $c);
}, $techDetails), }, $techDetails),
array_map(function ($contact) { array_map(function ($contact) {
return mapContactToVCard($contact, 'billing'); return mapContactToVCard($contact, 'billing', $c);
}, $billingDetails) }, $billingDetails)
), ),
'events' => $events, 'events' => $events,
'handle' => $domainDetails['id'] . '', 'handle' => 'D' . $domainDetails['id'] . '-' . $c['roid'] . '',
'ldhName' => $domain, 'ldhName' => $domain,
'links' => [ 'links' => [
[ [
'href' => 'https://rdap.example.com/domain/' . $domain, 'href' => $c['rdap_url'] . '/domain/' . $domain,
'rel' => 'self', 'rel' => 'self',
'type' => 'application/rdap+json', 'type' => 'application/rdap+json',
], ],
[ [
'href' => 'https://rdap.registrar.com/domain/' . $domain, 'href' => 'https://' . $registrarDetails['rdap_server'] . '/domain/' . $domain,
'rel' => 'related', 'rel' => 'related',
'type' => 'application/rdap+json', 'type' => 'application/rdap+json',
] ]
@ -413,11 +413,11 @@ function handleDomainQuery($request, $response, $pdo, $domainName) {
'nameservers' => array_map(function ($nameserverDetails) { 'nameservers' => array_map(function ($nameserverDetails) {
return [ return [
'objectClassName' => 'nameserver', 'objectClassName' => 'nameserver',
'handle' => $nameserverDetails['host_id'] . '', 'handle' => 'H' . $nameserverDetails['host_id'] . '-' . $c['roid'] . '',
'ldhName' => $nameserverDetails['name'], 'ldhName' => $nameserverDetails['name'],
'links' => [ 'links' => [
[ [
'href' => 'https://rdap.example.com/nameserver/' . $nameserverDetails['name'], 'href' => $c['rdap_url'] . '/nameserver/' . $nameserverDetails['name'],
'rel' => 'self', 'rel' => 'self',
'type' => 'application/rdap+json', 'type' => 'application/rdap+json',
], ],
@ -450,12 +450,12 @@ function handleDomainQuery($request, $response, $pdo, $domainName) {
], ],
"links" => [ "links" => [
[ [
"href" => "https://rdap.example.com/help", "href" => $c['rdap_url'] . "/help",
"rel" => "self", "rel" => "self",
"type" => "application/rdap+json" "type" => "application/rdap+json"
], ],
[ [
"href" => "https://example.com/rdap-terms", "href" => $c['registry_url'],
"rel" => "alternate", "rel" => "alternate",
"type" => "text/html" "type" => "text/html"
], ],
@ -508,7 +508,7 @@ function handleDomainQuery($request, $response, $pdo, $domainName) {
} }
} }
function handleEntityQuery($request, $response, $pdo, $entityHandle) { function handleEntityQuery($request, $response, $pdo, $entityHandle, $c) {
// Extract and validate the entity handle from the request // Extract and validate the entity handle from the request
$entity = trim($entityHandle); $entity = trim($entityHandle);
@ -588,7 +588,7 @@ function handleEntityQuery($request, $response, $pdo, $entityHandle) {
'events' => $events, 'events' => $events,
'links' => [ 'links' => [
[ [
'href' => 'https://rdap.example.com/entity/' . $registrarDetails['iana_id'], 'href' => $c['rdap_url'] . '/entity/' . $registrarDetails['iana_id'],
'rel' => 'self', 'rel' => 'self',
'type' => 'application/rdap+json', 'type' => 'application/rdap+json',
] ]
@ -630,12 +630,12 @@ function handleEntityQuery($request, $response, $pdo, $entityHandle) {
], ],
"links" => [ "links" => [
[ [
"href" => "https://rdap.example.com/help", "href" => $c['rdap_url'] . "/help",
"rel" => "self", "rel" => "self",
"type" => "application/rdap+json" "type" => "application/rdap+json"
], ],
[ [
"href" => "https://example.com/rdap-terms", "href" => $c['registry_url'],
"rel" => "alternate", "rel" => "alternate",
"type" => "text/html" "type" => "text/html"
], ],
@ -688,7 +688,7 @@ function handleEntityQuery($request, $response, $pdo, $entityHandle) {
} }
} }
function handleNameserverQuery($request, $response, $pdo, $nameserverHandle) { function handleNameserverQuery($request, $response, $pdo, $nameserverHandle, $c) {
// Extract and validate the nameserver handle from the request // Extract and validate the nameserver handle from the request
$ns = trim($nameserverHandle); $ns = trim($nameserverHandle);
@ -835,7 +835,7 @@ function handleNameserverQuery($request, $response, $pdo, $nameserverHandle) {
"handle" => $registrarDetails['iana_id'], "handle" => $registrarDetails['iana_id'],
"links" => [ "links" => [
[ [
"href" => "https://rdap.example.com/entity/" . $registrarDetails['iana_id'], "href" => $c['rdap_url'] . "/entity/" . $registrarDetails['iana_id'],
"rel" => "self", "rel" => "self",
"type" => "application/rdap+json" "type" => "application/rdap+json"
] ]
@ -864,13 +864,13 @@ function handleNameserverQuery($request, $response, $pdo, $nameserverHandle) {
], ],
], ],
), ),
'handle' => $hostDetails['id'] . '', 'handle' => 'H' . $hostDetails['id'] . '-' . $c['roid'] . '',
'ipAddresses' => $ipAddresses, 'ipAddresses' => $ipAddresses,
'events' => $events, 'events' => $events,
'ldhName' => $hostDetails['name'], 'ldhName' => $hostDetails['name'],
'links' => [ 'links' => [
[ [
'href' => 'https://rdap.example.com/nameserver/' . $hostDetails['name'], 'href' => $c['rdap_url'] . '/nameserver/' . $hostDetails['name'],
'rel' => 'self', 'rel' => 'self',
'type' => 'application/rdap+json', 'type' => 'application/rdap+json',
] ]
@ -888,12 +888,12 @@ function handleNameserverQuery($request, $response, $pdo, $nameserverHandle) {
], ],
"links" => [ "links" => [
[ [
"href" => "https://rdap.example.com/help", "href" => $c['rdap_url'] . "/help",
"rel" => "self", "rel" => "self",
"type" => "application/rdap+json" "type" => "application/rdap+json"
], ],
[ [
"href" => "https://example.com/rdap-terms", "href" => $c['registry_url'],
"rel" => "alternate", "rel" => "alternate",
"type" => "text/html" "type" => "text/html"
], ],
@ -946,7 +946,7 @@ function handleNameserverQuery($request, $response, $pdo, $nameserverHandle) {
} }
} }
function handleHelpQuery($request, $response, $pdo) { function handleHelpQuery($request, $response, $pdo, $c) {
// Set the RDAP conformance levels // Set the RDAP conformance levels
$rdapConformance = [ $rdapConformance = [
"rdap_level_0", "rdap_level_0",
@ -971,7 +971,7 @@ function handleHelpQuery($request, $response, $pdo) {
], ],
'links' => [ 'links' => [
[ [
'href' => 'https://rdap.example.com/help', 'href' => $c['rdap_url'] . '/help',
'rel' => 'self', 'rel' => 'self',
'type' => 'application/rdap+json', 'type' => 'application/rdap+json',
], ],
@ -996,12 +996,12 @@ function handleHelpQuery($request, $response, $pdo) {
], ],
"links" => [ "links" => [
[ [
"href" => "https://rdap.example.com/help", "href" => $c['rdap_url'] . "/help",
"rel" => "self", "rel" => "self",
"type" => "application/rdap+json" "type" => "application/rdap+json"
], ],
[ [
"href" => "https://example.com/rdap-terms", "href" => $c['registry_url'],
"rel" => "alternate", "rel" => "alternate",
"type" => "text/html" "type" => "text/html"
], ],

View file

@ -7,5 +7,6 @@ return [
'db_database' => 'your_database_name', 'db_database' => 'your_database_name',
'db_username' => 'your_username', 'db_username' => 'your_username',
'db_password' => 'your_password', 'db_password' => 'your_password',
'privacy' => false 'privacy' => false,
'roid' => 'XX',
]; ];

View file

@ -358,7 +358,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) use ($c, $pdo)
$clidF = $stmt3->fetch(PDO::FETCH_ASSOC); $clidF = $stmt3->fetch(PDO::FETCH_ASSOC);
$res = "Domain Name: ".strtoupper($f['name']) $res = "Domain Name: ".strtoupper($f['name'])
."\nRegistry Domain ID: ".$f['id'] ."\nRegistry Domain ID: D".$f['id']."-".$c['roid']
."\nRegistrar WHOIS Server: ".$clidF['whois_server'] ."\nRegistrar WHOIS Server: ".$clidF['whois_server']
."\nRegistrar URL: ".$clidF['url'] ."\nRegistrar URL: ".$clidF['url']
."\nUpdated Date: ".$f['update'] ."\nUpdated Date: ".$f['update']
@ -400,7 +400,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) use ($c, $pdo)
."\nRegistrant Fax: 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."; ."\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'] $res .= "\nRegistry Registrant ID: C".$f2['identifier']."-".$c['roid']
."\nRegistrant Name: ".$f2['name'] ."\nRegistrant Name: ".$f2['name']
."\nRegistrant Organization: ".$f2['org'] ."\nRegistrant Organization: ".$f2['org']
."\nRegistrant Street: ".$f2['street1'] ."\nRegistrant Street: ".$f2['street1']
@ -437,7 +437,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) use ($c, $pdo)
."\nAdmin Fax: 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."; ."\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'] $res .= "\nRegistry Admin ID: C".$f2['identifier']."-".$c['roid']
."\nAdmin Name: ".$f2['name'] ."\nAdmin Name: ".$f2['name']
."\nAdmin Organization: ".$f2['org'] ."\nAdmin Organization: ".$f2['org']
."\nAdmin Street: ".$f2['street1'] ."\nAdmin Street: ".$f2['street1']
@ -474,7 +474,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) use ($c, $pdo)
."\nBilling Fax: 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."; ."\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'] $res .= "\nRegistry Billing ID: C".$f2['identifier']."-".$c['roid']
."\nBilling Name: ".$f2['name'] ."\nBilling Name: ".$f2['name']
."\nBilling Organization: ".$f2['org'] ."\nBilling Organization: ".$f2['org']
."\nBilling Street: ".$f2['street1'] ."\nBilling Street: ".$f2['street1']
@ -511,7 +511,7 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) use ($c, $pdo)
."\nTech Fax: 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."; ."\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'] $res .= "\nRegistry Tech ID: C".$f2['identifier']."-".$c['roid']
."\nTech Name: ".$f2['name'] ."\nTech Name: ".$f2['name']
."\nTech Organization: ".$f2['org'] ."\nTech Organization: ".$f2['org']
."\nTech Street: ".$f2['street1'] ."\nTech Street: ".$f2['street1']