Added launch phase extension in domain check

This commit is contained in:
Pinga 2023-12-17 07:16:20 +02:00
parent 61be823185
commit eab0e93417
3 changed files with 245 additions and 73 deletions

View file

@ -644,6 +644,58 @@ class EppWriter {
$this->_preamble($writer, $resp);
if ($this->epp_success($resp['resultCode'])) {
// Begin the extension part if any of the extensions are present
if (isset($resp['launchCheck'])) {
$writer->startElement('extension');
// Handle claims
if ($resp['launchCheckType'] === 'claims') {
$writer->startElement('launch:chkData');
$writer->writeAttribute('xmlns:launch', 'urn:ietf:params:xml:ns:launch-1.0');
// launch:phase
$writer->writeElement('launch:phase', 'claims');
foreach ($resp['names'] as $names) {
$writer->startElement('launch:cd');
$writer->startElement('launch:name');
$writer->writeAttribute('exists', $names[1]);
$writer->text($names[0]);
$writer->endElement(); // End of 'launch:name'
if (isset($names[2])) {
$writer->startElement('launch:claimKey');
$writer->writeAttribute('exists', $names[1]);
$writer->text($names[2]);
$writer->endElement(); // End of 'launch:claimKey'
}
$writer->endElement(); // End of 'launch:cd'
}
$writer->endElement(); // End of 'launch:chkData'
} else if ($resp['launchCheckType'] === 'trademark') {
$writer->startElement('launch:chkData');
$writer->writeAttribute('xmlns:launch', 'urn:ietf:params:xml:ns:launch-1.0');
foreach ($resp['names'] as $names) {
$writer->startElement('launch:cd');
$writer->startElement('launch:name');
$writer->writeAttribute('exists', $names[1]);
$writer->text($names[0]);
$writer->endElement(); // End of 'launch:name'
if (isset($names[2])) {
$writer->startElement('launch:claimKey');
$writer->writeAttribute('exists', $names[1]);
$writer->text($names[2]);
$writer->endElement(); // End of 'launch:claimKey'
}
$writer->endElement(); // End of 'launch:cd'
}
$writer->endElement(); // End of 'launch:chkData'
}
$writer->endElement(); // End of 'extension'
} else {
$writer->startElement('resData');
$writer->startElement('domain:chkData');
$writer->writeAttribute('xmlns:domain', 'urn:ietf:params:xml:ns:domain-1.0');
@ -662,6 +714,7 @@ class EppWriter {
$writer->endElement(); // End of 'domain:chkData'
$writer->endElement(); // End of 'resData'
}
}
$this->_postamble($writer, $resp);
}

View file

@ -109,6 +109,62 @@ function processDomainCheck($conn, $db, $xml, $trans) {
$domains = $xml->command->check->children('urn:ietf:params:xml:ns:domain-1.0')->check->name;
$clTRID = (string) $xml->command->clTRID;
$extensionNode = $xml->command->extension;
if (isset($extensionNode)) {
$launch_check = $xml->xpath('//launch:check')[0] ?? null;
}
if (isset($launch_check)) {
// Extract the 'type' attribute from <launch:check>
$launchCheckType = (string) $xml->xpath('//launch:check/@type')[0];
// Extract <launch:phase>
$launchPhaseText = (string) $xml->xpath('//launch:phase')[0];
if ($launchCheckType === 'claims' || $launchCheckType === 'trademark') {
// Check if the domain has claims
$names = [];
foreach ($domains as $domain) {
$domainName = (string) $domain;
// Initialize a new domain entry with the domain name
$domainEntry = [$domainName];
$parts = extractDomainAndTLD($domainName);
$label = $parts['domain'];
$stmt = $db->prepare("SELECT claim_key FROM tmch_claims WHERE domain_label = :domainName LIMIT 1");
$stmt->bindParam(':domainName', $label, PDO::PARAM_STR);
$stmt->execute();
$claim_key = $stmt->fetchColumn();
if ($claim_key) {
$domainEntry[] = 1;
$domainEntry[] = $claim_key;
} else {
$domainEntry[] = 0;
}
// Append this domain entry to names
$names[] = $domainEntry;
}
$svTRID = generateSvTRID();
$response = [
'command' => 'check_domain',
'resultCode' => 1000,
'lang' => 'en-US',
'message' => 'Command completed successfully',
'names' => $names,
'launchCheck' => 1,
'launchCheckType' => 'claims',
'clTRID' => $clTRID,
'svTRID' => $svTRID,
];
} else if ($launchCheckType === 'avail') {
if ($launchPhaseText === 'custom') {
$launchPhaseName = (string) $xml->xpath('//launch:phase/@name')[0];
$names = [];
foreach ($domains as $domain) {
$domainName = (string) $domain;
@ -167,6 +223,68 @@ function processDomainCheck($conn, $db, $xml, $trans) {
'clTRID' => $clTRID,
'svTRID' => $svTRID,
];
}
}
} else {
$names = [];
foreach ($domains as $domain) {
$domainName = (string) $domain;
// Check if the domain is already taken
$stmt = $db->prepare("SELECT name FROM domain WHERE name = :domainName");
$stmt->bindParam(':domainName', $domainName, PDO::PARAM_STR);
$stmt->execute();
$taken = $stmt->fetchColumn();
$availability = $taken ? '0' : '1';
// Initialize a new domain entry with the domain name
$domainEntry = [$domainName];
if ($availability === '0') {
// Domain is taken
$domainEntry[] = 0; // Set status to unavailable
$domainEntry[] = 'In use';
} else {
// Check if the domain is reserved
$parts = extractDomainAndTLD($domainName);
$label = $parts['domain'];
$stmt = $db->prepare("SELECT type FROM reserved_domain_names WHERE name = :domainName LIMIT 1");
$stmt->bindParam(':domainName', $label, PDO::PARAM_STR);
$stmt->execute();
$reserved = $stmt->fetchColumn();
if ($reserved) {
$domainEntry[] = 0; // Set status to unavailable
$domainEntry[] = ucfirst($reserved); // Capitalize the first letter
} else {
$invalid_label = validate_label($domainName, $db);
// Check if the domain is Invalid
if ($invalid_label) {
$domainEntry[] = 0; // Set status to unavailable
$domainEntry[] = ucfirst($invalid_label); // Capitalize the first letter
} else {
$domainEntry[] = 1; // Domain is available
}
}
}
// Append this domain entry to names
$names[] = $domainEntry;
}
$svTRID = generateSvTRID();
$response = [
'command' => 'check_domain',
'resultCode' => 1000,
'lang' => 'en-US',
'message' => 'Command completed successfully',
'names' => $names,
'clTRID' => $clTRID,
'svTRID' => $svTRID,
];
}
$epp = new EPP\EppWriter();
$xml = $epp->epp_writer($response);

View file

@ -108,6 +108,7 @@ $server->handle(function (Connection $conn) use ($table, $pool, $c, $log, $permi
$xml->registerXPathNamespace('host', 'urn:ietf:params:xml:ns:host-1.0');
$xml->registerXPathNamespace('rgp', 'urn:ietf:params:xml:ns:rgp-1.0');
$xml->registerXPathNamespace('secDNS', 'urn:ietf:params:xml:ns:secDNS-1.1');
$xml->registerXPathNamespace('launch', 'urn:ietf:params:xml:ns:launch-1.0');
if ($xml === false) {
sendEppError($conn, $pdo, 2001, 'Invalid XML');