mirror of
https://github.com/getnamingo/registry.git
synced 2025-06-29 23:53:17 +02:00
EPP server updates
This commit is contained in:
parent
d981b17c28
commit
1f782958a3
1 changed files with 80 additions and 2 deletions
82
epp/epp.php
82
epp/epp.php
|
@ -16,7 +16,19 @@ $db = new PDO('mysql:host=localhost;dbname=epp', 'username', 'password');
|
|||
$server = new Server('0.0.0.0', 700);
|
||||
|
||||
$server->handle(function (Connection $conn) use ($table, $db) {
|
||||
$data = $conn->recv();
|
||||
$lengthData = $conn->recv(4);
|
||||
if ($lengthData === false || strlen($lengthData) !== 4) {
|
||||
sendEppError($conn, 2100, 'Framing error');
|
||||
return;
|
||||
}
|
||||
|
||||
$length = unpack('N', $lengthData)[1];
|
||||
$data = $conn->recv($length - 4);
|
||||
|
||||
if ($data === false || strlen($data) !== $length - 4) {
|
||||
sendEppError($conn, 2100, 'Framing error');
|
||||
return;
|
||||
}
|
||||
$xml = simplexml_load_string($data);
|
||||
|
||||
if ($xml === false) {
|
||||
|
@ -52,6 +64,12 @@ $server->handle(function (Connection $conn) use ($table, $db) {
|
|||
sendEppError($conn, 2202, 'Authorization error');
|
||||
return;
|
||||
}
|
||||
|
||||
// Parsing a contact:create command
|
||||
if ($xml->getName() == 'epp' && isset($xml->command->{'create'}->{'contact:create'})) {
|
||||
processContactCreate($conn, $db, $xml);
|
||||
return;
|
||||
}
|
||||
|
||||
// Parsing a domain:check command
|
||||
if ($xml->getName() == 'epp' && isset($xml->command->{'check'}->{'domain:check'})) {
|
||||
|
@ -64,6 +82,63 @@ $server->handle(function (Connection $conn) use ($table, $db) {
|
|||
|
||||
$server->start();
|
||||
|
||||
function processContactCreate($conn, $db, $xml) {
|
||||
if (!isset($xml->command->create->{'contact:create'})) {
|
||||
sendEppError($conn, 2005, 'Syntax error');
|
||||
return;
|
||||
}
|
||||
|
||||
$contactCreate = $xml->command->create->{'contact:create'};
|
||||
$contactID = (string) $contactCreate->{'contact:id'};
|
||||
$postalInfo = $contactCreate->{'contact:postalInfo'};
|
||||
$email = (string) $contactCreate->{'contact:email'};
|
||||
$voice = (string) $contactCreate->{'contact:voice'};
|
||||
$fax = (string) $contactCreate->{'contact:fax'};
|
||||
$password = (string) $contactCreate->{'contact:authInfo'}->{'contact:pw'};
|
||||
|
||||
$name = (string) $postalInfo->{'contact:name'};
|
||||
$org = (string) $postalInfo->{'contact:org'};
|
||||
$addr = $postalInfo->{'contact:addr'};
|
||||
$street = (string) $addr->{'contact:street'};
|
||||
$city = (string) $addr->{'contact:city'};
|
||||
$sp = (string) $addr->{'contact:sp'};
|
||||
$pc = (string) $addr->{'contact:pc'};
|
||||
$cc = (string) $addr->{'contact:cc'};
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare("INSERT INTO contacts (id, name, org, street, city, state_province, postal_code, country_code, email, voice, fax, password) VALUES (:id, :name, :org, :street, :city, :sp, :pc, :cc, :email, :voice, :fax, :password)");
|
||||
$stmt->execute([
|
||||
'id' => $contactID,
|
||||
'name' => $name,
|
||||
'org' => $org,
|
||||
'street' => $street,
|
||||
'city' => $city,
|
||||
'sp' => $sp,
|
||||
'pc' => $pc,
|
||||
'cc' => $cc,
|
||||
'email' => $email,
|
||||
'voice' => $voice,
|
||||
'fax' => $fax,
|
||||
'password' => password_hash($password, PASSWORD_DEFAULT)
|
||||
]);
|
||||
|
||||
$response = <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<response>
|
||||
<result code="1000">
|
||||
<msg>Contact created successfully</msg>
|
||||
</result>
|
||||
</response>
|
||||
</epp>
|
||||
XML;
|
||||
|
||||
$conn->send($response);
|
||||
} catch (PDOException $e) {
|
||||
sendEppError($conn, 2400, 'Database error');
|
||||
}
|
||||
}
|
||||
|
||||
function processDomainCheck($conn, $db, $xml) {
|
||||
$domains = $xml->command->{'check'}->{'domain:check'}->children('domain', true);
|
||||
$response = '<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"><response><result code="1000"><msg>Command completed successfully</msg></result><resData><domain:chkData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">';
|
||||
|
@ -76,7 +151,10 @@ function processDomainCheck($conn, $db, $xml) {
|
|||
}
|
||||
|
||||
$response .= '</domain:chkData></resData></response></epp>';
|
||||
$conn->send($response);
|
||||
$length = strlen($response) + 4; // Total length including the 4-byte header
|
||||
$lengthData = pack('N', $length); // Pack the length into 4 bytes
|
||||
|
||||
$conn->send($lengthData . $response);
|
||||
}
|
||||
|
||||
function checkLogin($db, $clID, $pw) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue