From 012f859c09943540500e7bf5c98bbd5fca1ec87e Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Wed, 9 Aug 2023 13:20:45 +0300 Subject: [PATCH] Even more epp server updates --- epp/EppWriter.php | 50 +++++++++++++-------- epp/epp.php | 110 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 120 insertions(+), 40 deletions(-) diff --git a/epp/EppWriter.php b/epp/EppWriter.php index 73a08b3..a26daec 100644 --- a/epp/EppWriter.php +++ b/epp/EppWriter.php @@ -635,7 +635,10 @@ class EppWriter { $writer->writeAttribute('xsi:schemaLocation', 'urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd'); foreach ($resp['names'] as $names) { $writer->startElement('domain:cd'); - $writer->writeElement('domain:name', $names[0], ['avail' => $names[1]]); + $writer->startElement('domain:name'); + $writer->writeAttribute('avail', $names[1]); + $writer->text($names[0]); + $writer->endElement(); // End of 'domain:name' if (isset($names[2])) { $writer->writeElement('domain:reason', $names[2]); } @@ -676,7 +679,7 @@ class EppWriter { $writer->writeAttribute('xsi:schemaLocation', 'urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd'); $writer->writeElement('domain:name', $resp['name']); $writer->writeElement('domain:roid', $resp['roid']); - foreach ($resp['status'] as $s) { + foreach ($resp['status'] as $s) { if (isset($s[1]) && isset($s[2])) { $writer->writeElement('domain:status', $s[2], ['s' => $s[0], 'lang' => $s[1]]); } else { @@ -690,20 +693,25 @@ class EppWriter { $writer->writeElement('domain:registrant', $resp['registrant']); } foreach ($resp['contact'] as $t) { - $writer->writeElement('domain:contact', $t[1], ['type' => $t[0]]); + $writer->startElement('domain:contact'); + $writer->writeAttribute('type', $t[0]); + $writer->text($t[1]); + $writer->endElement(); } - if ($resp['return_ns']) { + if (isset($resp['hostObj']) && is_array($resp['hostObj'])) { $writer->startElement('domain:ns'); - foreach ($resp['hostObj'] as $n) { - $writer->writeElement('domain:hostObj', $n); + foreach ($resp['hostObj'] as $host) { + $writer->writeElement('domain:hostObj', (string)$host[0]); } $writer->endElement(); // End of 'domain:ns' } - if ($resp['return_host']) { - foreach ($resp['host'] as $h) { - $writer->writeElement('domain:host', $h); + if (isset($resp['return_host'])) { + if ($resp['return_host']) { + foreach ($resp['host'] as $h) { + $writer->writeElement('domain:host', $h); + } } - } + } $writer->writeElement('domain:clID', $resp['clID']); if (isset($resp['crID'])) { $writer->writeElement('domain:crID', $resp['crID']); @@ -737,15 +745,19 @@ class EppWriter { $writer->endElement(); // End of 'resData' // Handling the extension part - $writer->startElement('extension'); - $writer->startElement('rgp:infData'); - $writer->writeAttribute('xmlns:rgp', 'urn:ietf:params:xml:ns:rgp-1.0'); - $writer->writeAttribute('xsi:schemaLocation', 'urn:ietf:params:xml:ns:rgp-1.0 rgp-1.0.xsd'); - $writer->startElement('rgp:rgpStatus'); - $writer->writeAttribute('s', $resp['rgpstatus']); - $writer->endElement(); // End of 'rgp:rgpStatus' - $writer->endElement(); // End of 'rgp:infData' - $writer->endElement(); // End of 'extension' + // Check if the 'rgpstatus' key is set in $resp + if (isset($resp['rgpstatus'])) { + // Handling the extension part + $writer->startElement('extension'); + $writer->startElement('rgp:infData'); + $writer->writeAttribute('xmlns:rgp', 'urn:ietf:params:xml:ns:rgp-1.0'); + $writer->writeAttribute('xsi:schemaLocation', 'urn:ietf:params:xml:ns:rgp-1.0 rgp-1.0.xsd'); + $writer->startElement('rgp:rgpStatus'); + $writer->writeAttribute('s', $resp['rgpstatus']); + $writer->endElement(); // End of 'rgp:rgpStatus' + $writer->endElement(); // End of 'rgp:infData' + $writer->endElement(); // End of 'extension' + } } $this->_postamble($writer, $resp); diff --git a/epp/epp.php b/epp/epp.php index cb65c61..3bcdd54 100644 --- a/epp/epp.php +++ b/epp/epp.php @@ -403,24 +403,46 @@ XML; function processDomainCheck($conn, $db, $xml) { $domains = $xml->command->check->children('urn:ietf:params:xml:ns:domain-1.0')->check->name; - $response = 'Command completed successfully'; + $clTRID = (string) $xml->command->clTRID; + $names = []; foreach ($domains as $domain) { $domainName = (string) $domain; $availability = $db->query("SELECT name FROM domain WHERE name = '$domainName'")->fetchColumn(); - $availString = $availability ? 'available' : 'unavailable'; - $response .= "$domainName"; + + // Convert the DB result into a boolean '0' or '1' + $availability = $availability ? '0' : '1'; + + // Initialize a new domain entry with the domain name and its availability + $domainEntry = [$domainName, $availability]; + + // If there's a reason for unavailability, add it to the domain entry + if ($availability === '0') { + $domainEntry[] = 'Domain is already registered'; + } + + // Append this domain entry to names + $names[] = $domainEntry; } - $response .= ''; - $length = strlen($response) + 4; // Total length including the 4-byte header - $lengthData = pack('N', $length); // Pack the length into 4 bytes + $response = [ + 'command' => 'check_domain', + 'resultCode' => 1000, + 'lang' => 'en-US', + 'message' => 'Command completed successfully', + 'names' => $names, + 'clTRID' => $clTRID, + 'svTRID' => generateSvTRID(), + ]; - $conn->send($lengthData . $response); + $epp = new EPP\EppWriter(); + $xml = $epp->epp_writer($response); + sendEppResponse($conn, $xml); } function processDomainInfo($conn, $db, $xml) { $domainName = $xml->command->info->children('urn:ietf:params:xml:ns:domain-1.0')->info->name; + $clTRID = (string) $xml->command->clTRID; // Validation for domain name if (!filter_var($domainName, FILTER_VALIDATE_DOMAIN)) { @@ -438,22 +460,68 @@ function processDomainInfo($conn, $db, $xml) { sendEppError($conn, 2303, 'Object does not exist'); return; } + + // Fetch contacts + $stmt = $db->prepare("SELECT * FROM domain_contact_map WHERE domain_id = :id"); + $stmt->execute(['id' => $domain['id']]); + $contacts = $stmt->fetchAll(PDO::FETCH_ASSOC); - $response = << - - - - Domain information retrieved successfully - - - - -XML; - $length = strlen($response) + 4; // Total length including the 4-byte header - $lengthData = pack('N', $length); // Pack the length into 4 bytes + $transformedContacts = []; + foreach ($contacts as $contact) { + $transformedContacts[] = [$contact['type'], $contact['contact_id']]; + } + + // Fetch hosts + $stmt = $db->prepare("SELECT * FROM domain_host_map WHERE domain_id = :id"); + $stmt->execute(['id' => $domain['id']]); + $hosts = $stmt->fetchAll(PDO::FETCH_ASSOC); - $conn->send($lengthData . $response); + $transformedHosts = []; + foreach ($hosts as $host) { + $transformedHosts[] = [$host['host_id']]; + } + + // Fetch authInfo + $stmt = $db->prepare("SELECT * FROM domain_authInfo WHERE domain_id = :id"); + $stmt->execute(['id' => $domain['id']]); + $authInfo = $stmt->fetch(PDO::FETCH_ASSOC); + + // Fetch status + $stmt = $db->prepare("SELECT * FROM domain_status WHERE domain_id = :id"); + $stmt->execute(['id' => $domain['id']]); + $statuses = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $statusArray = []; + foreach($statuses as $status) { + $statusArray[] = [$status['status']]; + } + + $response = [ + 'command' => 'info_domain', + 'clTRID' => $clTRID, + 'svTRID' => generateSvTRID(), + 'resultCode' => 1000, + 'msg' => 'Command completed successfully', + 'name' => $domain['name'], + 'roid' => $domain['id'], + 'status' => $statusArray, + 'registrant' => $domain['registrant'], + 'contact' => $transformedContacts, + 'hostObj' => $transformedHosts, + 'clID' => $domain['clid'], + 'crID' => $domain['crid'], + 'crDate' => $domain['crdate'], + 'upID' => $domain['upid'], + 'upDate' => $domain['update'], + 'trDate' => $domain['trdate'], + 'authInfo' => 'valid', + 'authInfo_type' => $authInfo['authtype'], + 'authInfo_val' => $authInfo['authinfo'] + ]; + + $epp = new EPP\EppWriter(); + $xml = $epp->epp_writer($response); + sendEppResponse($conn, $xml); } catch (PDOException $e) { sendEppError($conn, 2400, 'Database error'); }