From 8719aad491fab264e10e625b7ecec6b8448ebf5f Mon Sep 17 00:00:00 2001
From: Pinga <121483313+getpinga@users.noreply.github.com>
Date: Wed, 9 Aug 2023 11:40:36 +0300
Subject: [PATCH] Another big epp update
---
epp/EppWriter.php | 20 +++--
epp/epp.php | 201 +++++++++++++++++++++++++++++-----------------
2 files changed, 140 insertions(+), 81 deletions(-)
diff --git a/epp/EppWriter.php b/epp/EppWriter.php
index 58195c3..a82ff5a 100644
--- a/epp/EppWriter.php
+++ b/epp/EppWriter.php
@@ -394,14 +394,18 @@ class EppWriter {
$writer->writeAttribute('xmlns:contact', 'urn:ietf:params:xml:ns:contact-1.0');
$writer->writeAttribute('xsi:schemaLocation', 'urn:ietf:params:xml:ns:contact-1.0 contact-1.0.xsd');
- foreach ($resp['ids'] as $ids) {
- $writer->startElement('contact:cd');
- $writer->writeElement('contact:id', $ids[0], ['avail' => $ids[1]]);
- if (isset($ids[2])) {
- $writer->writeElement('contact:reason', $ids[2]);
- }
- $writer->endElement(); // End of 'contact:cd'
- }
+ foreach ($resp['ids'] as $ids) {
+ $writer->startElement('contact:cd');
+ $writer->startElement('contact:id');
+ $writer->writeAttribute('avail', $ids[1]);
+ $writer->text($ids[0]);
+ $writer->endElement(); // End of 'contact:id'
+
+ if (isset($ids[2])) {
+ $writer->writeElement('contact:reason', $ids[2]);
+ }
+ $writer->endElement(); // End of 'contact:cd'
+ }
$writer->endElement(); // End of 'contact:chkData'
$writer->endElement(); // End of 'resData'
diff --git a/epp/epp.php b/epp/epp.php
index 30a7b64..702991f 100644
--- a/epp/epp.php
+++ b/epp/epp.php
@@ -3,6 +3,7 @@
//require 'vendor/autoload.php';
global $c;
$c = require 'config.php';
+require_once 'EppWriter.php';
use Swoole\Coroutine\Server;
use Swoole\Coroutine\Server\Connection;
@@ -68,26 +69,22 @@ $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;
if (checkLogin($db, $clID, $pw)) {
$table->set($connId, ['clid' => $clID, 'logged_in' => 1]);
- $eppLoginResponse = '
-
-
-
- Login successful
-
-
- ABC-12345
- SRV-54321
-
-
- ';
+ $response = [
+ 'command' => 'login',
+ 'resultCode' => 1000,
+ 'lang' => 'en-US',
+ 'message' => 'Login successful',
+ 'clTRID' => $clTRID,
+ 'svTRID' => generateSvTRID(),
+ ];
- $length = strlen($eppLoginResponse) + 4; // Total length including the 4-byte header
- $lengthData = pack('N', $length); // Pack the length into 4 bytes
-
- $conn->send($lengthData . $eppLoginResponse);
+ $epp = new EPP\EppWriter();
+ $xml = $epp->epp_writer($response);
+ sendEppResponse($conn, $xml);
} else {
sendEppError($conn, 2200, 'Authentication error');
}
@@ -97,23 +94,19 @@ $server->handle(function (Connection $conn) use ($table, $db) {
case isset($xml->command->logout):
{
$table->del($connId);
- $eppLogoutResponse = '
-
-
-
- Logout successful
-
-
- ABC-12345
- SRV-54321
-
-
- ';
+ $clTRID = (string) $xml->command->clTRID;
+
+ $response = [
+ 'command' => 'logout',
+ 'resultCode' => 1500,
+ 'lang' => 'en-US',
+ 'clTRID' => $clTRID,
+ 'svTRID' => generateSvTRID(),
+ ];
- $length = strlen($eppLogoutResponse) + 4; // Total length including the 4-byte header
- $lengthData = pack('N', $length); // Pack the length into 4 bytes
-
- $conn->send($lengthData . $eppLogoutResponse);
+ $epp = new EPP\EppWriter();
+ $xml = $epp->epp_writer($response);
+ sendEppResponse($conn, $xml);
$conn->close();
break;
}
@@ -190,8 +183,29 @@ Swoole\Coroutine::create(function () use ($server) {
$server->start();
});
+function sendEppResponse($conn, $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 generateSvTRID($prefix = "Namingo") {
+ // Get current timestamp
+ $timestamp = time();
+
+ // Generate a random 5-character alphanumeric string
+ $randomString = bin2hex(random_bytes(5));
+
+ // Combine the prefix, timestamp, and random string to form the svTRID
+ $svTRID = "{$prefix}-{$timestamp}-{$randomString}";
+
+ return $svTRID;
+}
+
function processContactCheck($conn, $db, $xml) {
$contactIDs = $xml->command->check->children('urn:ietf:params:xml:ns:contact-1.0')->check->{'id'};
+ $clTRID = (string) $xml->command->clTRID;
$results = [];
foreach ($contactIDs as $contactID) {
@@ -203,41 +217,40 @@ function processContactCheck($conn, $db, $xml) {
return;
}
- $stmt = $db->prepare("SELECT 1 FROM contacts WHERE id = :id");
+ $stmt = $db->prepare("SELECT 1 FROM contact WHERE id = :id");
$stmt->execute(['id' => $contactID]);
$results[$contactID] = $stmt->fetch() ? '0' : '1'; // 0 if exists, 1 if not
}
- $checkResults = '';
+ $ids = [];
foreach ($results as $id => $available) {
- $checkResults .= "$id";
+ $entry = [$id, $available];
+ // Check if the contact is unavailable
+ if (!$available) {
+ $entry[] = "Contact ID already registered";
+ }
+ $ids[] = $entry;
}
- $response = <<
-
-
-
- Contact check completed
-
-
-
- $checkResults
-
-
-
-
-XML;
+ $response = [
+ 'command' => 'check_contact',
+ 'resultCode' => 1000,
+ 'lang' => 'en-US',
+ 'message' => 'Command completed successfully',
+ 'ids' => $ids,
+ 'clTRID' => $clTRID,
+ 'svTRID' => generateSvTRID(),
+ ];
- $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);
+ $epp = new EPP\EppWriter();
+ $xml = $epp->epp_writer($response);
+ sendEppResponse($conn, $xml);
}
function processContactInfo($conn, $db, $xml) {
- $contactID = (string) $xml->command->{'info'}->{'contact:info'}->{'id'};
+ $contactID = (string) $xml->command->info->children('urn:ietf:params:xml:ns:contact-1.0')->info->{'id'};
+ $clTRID = (string) $xml->command->clTRID;
// Validation for contact ID
if (!ctype_alnum($contactID) || strlen($contactID) > 255) {
@@ -246,7 +259,7 @@ function processContactInfo($conn, $db, $xml) {
}
try {
- $stmt = $db->prepare("SELECT * FROM contacts WHERE id = :id");
+ $stmt = $db->prepare("SELECT * FROM contact WHERE id = :id");
$stmt->execute(['id' => $contactID]);
$contact = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -255,23 +268,67 @@ function processContactInfo($conn, $db, $xml) {
sendEppError($conn, 2303, 'Object does not exist');
return;
}
+
+ // Fetch authInfo
+ $stmt = $db->prepare("SELECT * FROM contact_authInfo WHERE contact_id = :id");
+ $stmt->execute(['id' => $contactID]);
+ $authInfo = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ // Fetch status
+ $stmt = $db->prepare("SELECT * FROM contact_status WHERE contact_id = :id");
+ $stmt->execute(['id' => $contactID]);
+ $statuses = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+ $statusArray = [];
+ foreach($statuses as $status) {
+ $statusArray[] = [$status['status']];
+ }
- $response = <<
-
-
-
- Contact information retrieved successfully
-
-
-
-
-XML;
+ // Fetch postal_info
+ $stmt = $db->prepare("SELECT * FROM contact_postalInfo WHERE contact_id = :id");
+ $stmt->execute(['id' => $contactID]);
+ $postals = $stmt->fetchAll(PDO::FETCH_ASSOC);
- $length = strlen($response) + 4; // Total length including the 4-byte header
- $lengthData = pack('N', $length); // Pack the length into 4 bytes
+ $postalArray = [];
+ foreach ($postals as $postal) {
+ $postalType = $postal['type']; // 'int' or 'loc'
+ $postalArray[$postalType] = [
+ 'name' => $postal['name'],
+ 'org' => $postal['org'],
+ 'street' => [$postal['street1'], $postal['street2'], $postal['street3']],
+ 'city' => $postal['city'],
+ 'sp' => $postal['sp'],
+ 'pc' => $postal['pc'],
+ 'cc' => $postal['cc']
+ ];
+ }
+
+ $response = [
+ 'command' => 'info_contact',
+ 'clTRID' => $clTRID,
+ 'svTRID' => generateSvTRID(),
+ 'resultCode' => 1000,
+ 'msg' => 'Command completed successfully',
+ 'id' => $contact['id'],
+ 'roid' => $contact['identifier'],
+ 'status' => $statusArray,
+ 'postal' => $postalArray,
+ 'voice' => $contact['voice'],
+ 'fax' => $contact['fax'],
+ 'email' => $contact['email'],
+ 'clID' => $contact['clid'],
+ 'crID' => $contact['crid'],
+ 'crDate' => $contact['crdate'],
+ 'upID' => $contact['upid'],
+ 'upDate' => $contact['update'],
+ 'authInfo' => 'valid',
+ 'authInfo_type' => $authInfo['authtype'],
+ 'authInfo_val' => $authInfo['authinfo']
+ ];
- $conn->send($lengthData . $response);
+ $epp = new EPP\EppWriter();
+ $xml = $epp->epp_writer($response);
+ sendEppResponse($conn, $xml);
} catch (PDOException $e) {
sendEppError($conn, 2400, 'Database error');
@@ -448,7 +505,5 @@ function sendEppError($conn, $code, $msg) {
XML;
- $length = strlen($errorResponse) + 4; // Total length including the 4-byte header
- $lengthData = pack('N', $length); // Pack the length into 4 bytes
- $conn->send($lengthData . $errorResponse);
+ sendEppResponse($conn, $errorResponse);
}
\ No newline at end of file