mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-06 09:35:03 +02:00
And one more epp update
This commit is contained in:
parent
8719aad491
commit
0719adc3dc
2 changed files with 123 additions and 47 deletions
|
@ -7,13 +7,6 @@ use XMLWriter;
|
|||
class EppWriter {
|
||||
|
||||
// Properties
|
||||
private $EPP_VERSIONS = ['1.0'];
|
||||
private $EPP_LANGUAGES = ['en-US', 'ua'];
|
||||
private $EPP_OBJECTS = [
|
||||
'contact' => 'urn:ietf:params:xml:ns:contact-1.0',
|
||||
'domain' => 'urn:ietf:params:xml:ns:domain-1.0',
|
||||
'host' => 'urn:ietf:params:xml:ns:host-1.0',
|
||||
];
|
||||
private $command_handler_map = [
|
||||
'greeting' => '_greeting',
|
||||
'login' => '_common',
|
||||
|
@ -257,23 +250,93 @@ class EppWriter {
|
|||
|
||||
private function _greeting($writer, $resp) {
|
||||
$writer->startElement('greeting');
|
||||
|
||||
// Server ID and Server Date
|
||||
$writer->writeElement('svID', $resp['svID']);
|
||||
$writer->writeElement('svDate', date('c')); // Using PHP's date function with 'c' format as a placeholder for EPP date
|
||||
$writer->writeElement('svDate', $resp['svDate']);
|
||||
|
||||
// Services
|
||||
$writer->startElement('svcMenu');
|
||||
|
||||
foreach ($this->EPP_VERSIONS as $ver) {
|
||||
$writer->writeElement('version', $ver);
|
||||
}
|
||||
|
||||
foreach ($this->EPP_LANGUAGES as $lang) {
|
||||
$writer->writeElement('lang', $lang);
|
||||
$writer->writeElement('version', $resp['version']);
|
||||
|
||||
// Check if 'lang' is an array and handle accordingly
|
||||
if (is_array($resp['lang'])) {
|
||||
foreach ($resp['lang'] as $language) {
|
||||
$writer->writeElement('lang', $language);
|
||||
}
|
||||
} else {
|
||||
$writer->writeElement('lang', $resp['lang']);
|
||||
}
|
||||
|
||||
foreach ($this->EPP_OBJECTS as $obj => $uri) {
|
||||
$writer->writeElement('objURI', $uri);
|
||||
foreach ($resp['services'] as $service) {
|
||||
$writer->writeElement('objURI', $service);
|
||||
}
|
||||
|
||||
// Optional extensions
|
||||
if (isset($resp['extensions'])) {
|
||||
$writer->startElement('svcExtension');
|
||||
foreach ($resp['extensions'] as $extension) {
|
||||
$writer->writeElement('extURI', $extension);
|
||||
}
|
||||
$writer->endElement(); // End of 'svcExtension'
|
||||
}
|
||||
|
||||
$writer->endElement(); // End of 'svcMenu'
|
||||
|
||||
// Optional Data Collection Policy (dcp)
|
||||
if (isset($resp['dcp'])) {
|
||||
$writer->startElement('dcp');
|
||||
|
||||
// Handle the access element
|
||||
if (isset($resp['dcp']['access'])) {
|
||||
$writer->startElement('access');
|
||||
foreach ($resp['dcp']['access'] as $accessType) {
|
||||
$writer->startElement($accessType);
|
||||
$writer->endElement();
|
||||
}
|
||||
$writer->endElement(); // End of 'access'
|
||||
}
|
||||
|
||||
// Handle the statement element
|
||||
if (isset($resp['dcp']['statement'])) {
|
||||
$writer->startElement('statement');
|
||||
|
||||
// Handle purpose
|
||||
if (isset($resp['dcp']['statement']['purpose'])) {
|
||||
$writer->startElement('purpose');
|
||||
foreach ($resp['dcp']['statement']['purpose'] as $purposeType) {
|
||||
$writer->startElement($purposeType);
|
||||
$writer->endElement();
|
||||
}
|
||||
$writer->endElement(); // End of 'purpose'
|
||||
}
|
||||
|
||||
// Handle recipient
|
||||
if (isset($resp['dcp']['statement']['recipient'])) {
|
||||
$writer->startElement('recipient');
|
||||
foreach ($resp['dcp']['statement']['recipient'] as $recipientType) {
|
||||
$writer->startElement($recipientType);
|
||||
$writer->endElement();
|
||||
}
|
||||
$writer->endElement(); // End of 'recipient'
|
||||
}
|
||||
|
||||
// Handle retention
|
||||
if (isset($resp['dcp']['statement']['retention'])) {
|
||||
$writer->startElement('retention');
|
||||
foreach ($resp['dcp']['statement']['retention'] as $retentionType) {
|
||||
$writer->startElement($retentionType);
|
||||
$writer->endElement();
|
||||
}
|
||||
$writer->endElement(); // End of 'retention'
|
||||
}
|
||||
|
||||
$writer->endElement(); // End of 'statement'
|
||||
}
|
||||
|
||||
$writer->endElement(); // End of 'dcp'
|
||||
}
|
||||
|
||||
$writer->endElement(); // End of 'greeting'
|
||||
}
|
||||
|
||||
|
|
73
epp/epp.php
73
epp/epp.php
|
@ -69,7 +69,7 @@ $server->handle(function (Connection $conn) use ($table, $db) {
|
|||
{
|
||||
$clID = (string) $xml->command->login->clID;
|
||||
$pw = (string) $xml->command->login->pw;
|
||||
$clTRID = (string) $xml->command->clTRID;
|
||||
$clTRID = (string) $xml->command->clTRID;
|
||||
|
||||
if (checkLogin($db, $clID, $pw)) {
|
||||
$table->set($connId, ['clid' => $clID, 'logged_in' => 1]);
|
||||
|
@ -110,6 +110,12 @@ $server->handle(function (Connection $conn) use ($table, $db) {
|
|||
$conn->close();
|
||||
break;
|
||||
}
|
||||
|
||||
case isset($xml->hello):
|
||||
{
|
||||
sendGreeting($conn);
|
||||
break;
|
||||
}
|
||||
|
||||
case isset($xml->command->check) && isset($xml->command->check->children('urn:ietf:params:xml:ns:contact-1.0')->check):
|
||||
{
|
||||
|
@ -462,36 +468,43 @@ function checkLogin($db, $clID, $pw) {
|
|||
}
|
||||
|
||||
function sendGreeting($conn) {
|
||||
global $c;
|
||||
global $c;
|
||||
$currentDate = gmdate('Y-m-d\TH:i:s\Z');
|
||||
$greetingXml = <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<greeting>
|
||||
<svID>{$c['epp_greeting']}</svID>
|
||||
<svDate>$currentDate</svDate>
|
||||
<svcMenu>
|
||||
<version>1.0</version>
|
||||
<lang>en</lang>
|
||||
<objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
|
||||
<objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
|
||||
<!-- Add other namespaces as supported -->
|
||||
</svcMenu>
|
||||
<!-- Optional: extensions you support -->
|
||||
<dcp>
|
||||
<access><all/></access>
|
||||
<statement>
|
||||
<purpose><admin/><prov/></purpose>
|
||||
<recipient><ours/><public/><same/></recipient>
|
||||
<retention><stated/></retention>
|
||||
</statement>
|
||||
</dcp>
|
||||
</greeting>
|
||||
</epp>
|
||||
XML;
|
||||
$length = strlen($greetingXml) + 4; // Total length including the 4-byte header
|
||||
$lengthData = pack('N', $length); // Pack the length into 4 bytes
|
||||
$conn->send($lengthData . $greetingXml);
|
||||
|
||||
$response = [
|
||||
'command' => 'greeting',
|
||||
'svID' => $c['epp_greeting'],
|
||||
'svDate' => $currentDate,
|
||||
'version' => '1.0',
|
||||
'lang' => 'en',
|
||||
'services' => [
|
||||
'urn:ietf:params:xml:ns:domain-1.0',
|
||||
'urn:ietf:params:xml:ns:contact-1.0',
|
||||
'urn:ietf:params:xml:ns:host-1.0'
|
||||
],
|
||||
'extensions' => [
|
||||
'http://www.namingo.org/epp/nBalance-1.0',
|
||||
'http://www.namingo.org/epp/nIdent-1.0',
|
||||
'urn:ietf:params:xml:ns:secDNS-1.1',
|
||||
'urn:ietf:params:xml:ns:rgp-1.0',
|
||||
'urn:ietf:params:xml:ns:launch-1.0',
|
||||
'urn:ietf:params:xml:ns:idn-1.0',
|
||||
'urn:ietf:params:xml:ns:epp:fee-1.0',
|
||||
'urn:ar:params:xml:ns:price-1.1'
|
||||
],
|
||||
'dcp' => [ // Data Collection Policy (optional)
|
||||
'access' => ['all'],
|
||||
'statement' => [
|
||||
'purpose' => ['admin', 'prov'],
|
||||
'recipient' => ['ours'],
|
||||
'retention' => ['stated']
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$epp = new EPP\EppWriter();
|
||||
$xml = $epp->epp_writer($response);
|
||||
sendEppResponse($conn, $xml);
|
||||
}
|
||||
|
||||
function sendEppError($conn, $code, $msg) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue