Refactored EPP for high load

This commit is contained in:
Pinga 2023-12-02 12:31:10 +02:00
parent eebf61ca56
commit 54c84943a0
2 changed files with 425 additions and 401 deletions

View file

@ -1,6 +1,6 @@
<?php <?php
require_once '../vendor/autoload.php'; require_once __DIR__ . '/../vendor/autoload.php';
use Monolog\Logger; use Monolog\Logger;
use Monolog\Handler\StreamHandler; use Monolog\Handler\StreamHandler;
@ -135,21 +135,21 @@ function generateSvTRID() {
return $svTRID; return $svTRID;
} }
function getRegistrarClid(PDO $db, $id) { function getRegistrarClid(Swoole\Database\PDOProxy $db, $id) {
$stmt = $db->prepare("SELECT clid FROM registrar WHERE id = :id"); $stmt = $db->prepare("SELECT clid FROM registrar WHERE id = :id");
$stmt->execute([':id' => $id]); $stmt->execute([':id' => $id]);
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result['clid'] ?? null; // Return the clid if found, otherwise return null return $result['clid'] ?? null; // Return the clid if found, otherwise return null
} }
function getContactIdentifier(PDO $db, $id) { function getContactIdentifier(Swoole\Database\PDOProxy $db, $id) {
$stmt = $db->prepare("SELECT identifier FROM contact WHERE id = :id"); $stmt = $db->prepare("SELECT identifier FROM contact WHERE id = :id");
$stmt->execute([':id' => $id]); $stmt->execute([':id' => $id]);
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result['identifier'] ?? null; // Return the identifier if found, otherwise return null return $result['identifier'] ?? null; // Return the identifier if found, otherwise return null
} }
function getHost(PDO $db, $id) { function getHost(Swoole\Database\PDOProxy $db, $id) {
$stmt = $db->prepare("SELECT name FROM host WHERE id = :id"); $stmt = $db->prepare("SELECT name FROM host WHERE id = :id");
$stmt->execute([':id' => $id]); $stmt->execute([':id' => $id]);
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
@ -320,7 +320,7 @@ function updateTransaction($db, $cmd, $obj_type, $obj_id, $code, $msg, $svTRID,
return true; return true;
} }
function getClid(PDO $db, string $clid): ?int { function getClid(Swoole\Database\PDOProxy $db, string $clid): ?int {
$stmt = $db->prepare("SELECT id FROM registrar WHERE clid = :clid LIMIT 1"); $stmt = $db->prepare("SELECT id FROM registrar WHERE clid = :clid LIMIT 1");
$stmt->bindParam(':clid', $clid, PDO::PARAM_STR); $stmt->bindParam(':clid', $clid, PDO::PARAM_STR);
$stmt->execute(); $stmt->execute();

View file

@ -25,9 +25,17 @@ $table->column('clid', Table::TYPE_STRING, 64);
$table->column('logged_in', Table::TYPE_INT, 1); $table->column('logged_in', Table::TYPE_INT, 1);
$table->create(); $table->create();
$dsn = "{$c['db_type']}:host={$c['db_host']};dbname={$c['db_database']};port={$c['db_port']}"; // Initialize the PDO connection pool
$db = new PDO($dsn, $c['db_username'], $c['db_password']); $pool = new Swoole\Database\PDOPool(
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); (new Swoole\Database\PDOConfig())
->withDriver($c['db_type'])
->withHost($c['db_host'])
->withPort($c['db_port'])
->withDbName($c['db_database'])
->withUsername($c['db_username'])
->withPassword($c['db_password'])
->withCharset('utf8mb4')
);
Swoole\Runtime::enableCoroutine(); Swoole\Runtime::enableCoroutine();
$server = new Server($c['epp_host'], $c['epp_port']); $server = new Server($c['epp_host'], $c['epp_port']);
@ -51,74 +59,96 @@ $server->set([
'ssl_protocols' => SWOOLE_SSL_TLSv1_2 | SWOOLE_SSL_TLSv1_3, 'ssl_protocols' => SWOOLE_SSL_TLSv1_2 | SWOOLE_SSL_TLSv1_3,
'ssl_ciphers' => 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES256-GCM-SHA384', 'ssl_ciphers' => 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES256-GCM-SHA384',
]); ]);
$log->info('server started.'); $log->info('Namingo EPP server started');
$server->handle(function (Connection $conn) use ($table, $db, $c, $log) { $server->handle(function (Connection $conn) use ($table, $pool, $c, $log) {
$log->info('new client connected'); $log->info('new client connected');
sendGreeting($conn); sendGreeting($conn);
while (true) { while (true) {
$data = $conn->recv(); try {
$connId = spl_object_id($conn); // Get a PDO connection from the pool
$pdo = $pool->get();
$data = $conn->recv();
$connId = spl_object_id($conn);
if ($data === false || strlen($data) < 4) { if ($data === false || strlen($data) < 4) {
sendEppError($conn, $db, 2100, 'Data reception error'); sendEppError($conn, $pdo, 2000, 'Data reception error');
break; break;
} }
$length = unpack('N', substr($data, 0, 4))[1]; $length = unpack('N', substr($data, 0, 4))[1];
$xmlData = substr($data, 4, $length - 4); $xmlData = substr($data, 4, $length - 4);
// If you're using PHP < 8.0 // If you're using PHP < 8.0
libxml_disable_entity_loader(true); libxml_disable_entity_loader(true);
libxml_use_internal_errors(true); libxml_use_internal_errors(true);
$xml = simplexml_load_string($xmlData); $xml = simplexml_load_string($xmlData);
$xml->registerXPathNamespace('e', 'urn:ietf:params:xml:ns:epp-1.0'); $xml->registerXPathNamespace('e', 'urn:ietf:params:xml:ns:epp-1.0');
$xml->registerXPathNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $xml->registerXPathNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$xml->registerXPathNamespace('domain', 'urn:ietf:params:xml:ns:domain-1.0'); $xml->registerXPathNamespace('domain', 'urn:ietf:params:xml:ns:domain-1.0');
$xml->registerXPathNamespace('contact', 'urn:ietf:params:xml:ns:contact-1.0'); $xml->registerXPathNamespace('contact', 'urn:ietf:params:xml:ns:contact-1.0');
$xml->registerXPathNamespace('host', 'urn:ietf:params:xml:ns:host-1.0'); $xml->registerXPathNamespace('host', 'urn:ietf:params:xml:ns:host-1.0');
$xml->registerXPathNamespace('rgp', 'urn:ietf:params:xml:ns:rgp-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('secDNS', 'urn:ietf:params:xml:ns:secDNS-1.1');
if ($xml === false) { if ($xml === false) {
sendEppError($conn, $db, 2001, 'Invalid XML'); sendEppError($conn, $pdo, 2001, 'Invalid XML');
break; break;
} }
if ($xml->getName() != 'epp') { if ($xml->getName() != 'epp') {
continue; // Skip this iteration if not an EPP command continue; // Skip this iteration if not an EPP command
} }
switch (true) { switch (true) {
case isset($xml->command->login): case isset($xml->command->login):
{ {
$clID = (string) $xml->command->login->clID; $clID = (string) $xml->command->login->clID;
$pw = (string) $xml->command->login->pw; $pw = (string) $xml->command->login->pw;
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $clID); $clid = getClid($pdo, $clID);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (checkLogin($db, $clID, $pw)) { if (checkLogin($pdo, $clID, $pw)) {
if (isset($xml->command->login->newPW)) { if (isset($xml->command->login->newPW)) {
$newPW = (string) $xml->command->login->newPW; $newPW = (string) $xml->command->login->newPW;
$options = [ $options = [
'memory_cost' => 1024 * 128, 'memory_cost' => 1024 * 128,
'time_cost' => 6, 'time_cost' => 6,
'threads' => 4, 'threads' => 4,
]; ];
$hashedPassword = password_hash($newPW, PASSWORD_ARGON2ID, $options); $hashedPassword = password_hash($newPW, PASSWORD_ARGON2ID, $options);
try { try {
$stmt = $db->prepare("UPDATE registrar SET pw = :newPW WHERE clid = :clID"); $stmt = $pdo->prepare("UPDATE registrar SET pw = :newPW WHERE clid = :clID");
$stmt->bindParam(':newPW', $hashedPassword); $stmt->bindParam(':newPW', $hashedPassword);
$stmt->bindParam(':clID', $clID); $stmt->bindParam(':clID', $clID);
$stmt->execute(); $stmt->execute();
} catch (PDOException $e) { } catch (PDOException $e) {
sendEppError($conn, $db, 2400, 'Password could not be changed', $clTRID); sendEppError($conn, $pdo, 2400, 'Password could not be changed', $clTRID);
}
$svTRID = generateSvTRID();
$response = [
'command' => 'login',
'resultCode' => 1000,
'lang' => 'en-US',
'clTRID' => $clTRID,
'svTRID' => $svTRID,
'msg' => 'Password changed successfully. Session will be terminated'
];
$epp = new EPP\EppWriter();
$xml = $epp->epp_writer($response);
updateTransaction($pdo, 'login', null, null, 1000, 'Password changed successfully. Session will be terminated', $svTRID, $xml, $trans);
sendEppResponse($conn, $xml);
$conn->close();
break;
} }
$table->set($connId, ['clid' => $clID, 'logged_in' => 1]);
$svTRID = generateSvTRID(); $svTRID = generateSvTRID();
$response = [ $response = [
'command' => 'login', 'command' => 'login',
@ -126,22 +156,30 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
'lang' => 'en-US', 'lang' => 'en-US',
'clTRID' => $clTRID, 'clTRID' => $clTRID,
'svTRID' => $svTRID, 'svTRID' => $svTRID,
'msg' => 'Password changed successfully. Session will be terminated'
]; ];
$epp = new EPP\EppWriter(); $epp = new EPP\EppWriter();
$xml = $epp->epp_writer($response); $xml = $epp->epp_writer($response);
updateTransaction($db, 'login', null, null, 1000, 'Password changed successfully. Session will be terminated', $svTRID, $xml, $trans); updateTransaction($pdo, 'login', null, null, 1000, 'Command completed successfully', $svTRID, $xml, $trans);
sendEppResponse($conn, $xml); sendEppResponse($conn, $xml);
$conn->close(); } else {
break; sendEppError($conn, $pdo, 2200, 'Authentication error', $clTRID);
} }
break;
}
$table->set($connId, ['clid' => $clID, 'logged_in' => 1]); case isset($xml->command->logout):
{
$data = $table->get($connId);
$clid = getClid($pdo, $clID);
$table->del($connId);
$clTRID = (string) $xml->command->clTRID;
$xmlString = $xml->asXML();
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
$svTRID = generateSvTRID(); $svTRID = generateSvTRID();
$response = [ $response = [
'command' => 'login', 'command' => 'logout',
'resultCode' => 1000, 'resultCode' => 1500,
'lang' => 'en-US', 'lang' => 'en-US',
'clTRID' => $clTRID, 'clTRID' => $clTRID,
'svTRID' => $svTRID, 'svTRID' => $svTRID,
@ -149,359 +187,345 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
$epp = new EPP\EppWriter(); $epp = new EPP\EppWriter();
$xml = $epp->epp_writer($response); $xml = $epp->epp_writer($response);
updateTransaction($db, 'login', null, null, 1000, 'Command completed successfully', $svTRID, $xml, $trans); updateTransaction($pdo, 'logout', null, null, 1500, 'Command completed successfully; ending session', $svTRID, $xml, $trans);
sendEppResponse($conn, $xml); sendEppResponse($conn, $xml);
} else {
sendEppError($conn, $db, 2200, 'Authentication error', $clTRID);
}
break;
}
case isset($xml->command->logout):
{
$data = $table->get($connId);
$clid = getClid($db, $clID);
$table->del($connId);
$clTRID = (string) $xml->command->clTRID;
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$svTRID = generateSvTRID();
$response = [
'command' => 'logout',
'resultCode' => 1500,
'lang' => 'en-US',
'clTRID' => $clTRID,
'svTRID' => $svTRID,
];
$epp = new EPP\EppWriter();
$xml = $epp->epp_writer($response);
updateTransaction($db, 'logout', null, null, 1500, 'Command completed successfully; ending session', $svTRID, $xml, $trans);
sendEppResponse($conn, $xml);
$conn->close();
break;
}
case isset($xml->hello):
{
sendGreeting($conn);
break;
}
case isset($xml->command->poll):
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
break;
} }
processPoll($conn, $db, $xml, $data['clid'], $trans);
break;
}
case isset($xml->command->check) && isset($xml->command->check->children('urn:ietf:params:xml:ns:contact-1.0')->check): case isset($xml->hello):
{ {
$data = $table->get($connId); sendGreeting($conn);
$clTRID = (string) $xml->command->clTRID; break;
$clid = getClid($db, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
$conn->close();
} }
processContactCheck($conn, $db, $xml, $trans);
break;
}
case isset($xml->command->create) && isset($xml->command->create->children('urn:ietf:params:xml:ns:contact-1.0')->create): case isset($xml->command->poll):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processPoll($conn, $pdo, $xml, $data['clid'], $trans);
break;
} }
processContactCreate($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
case isset($xml->command->info) && isset($xml->command->info->children('urn:ietf:params:xml:ns:contact-1.0')->info): case isset($xml->command->check) && isset($xml->command->check->children('urn:ietf:params:xml:ns:contact-1.0')->check):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processContactCheck($conn, $pdo, $xml, $trans);
break;
} }
processContactInfo($conn, $db, $xml, $trans);
break;
}
case isset($xml->command->update) && isset($xml->command->update->children('urn:ietf:params:xml:ns:contact-1.0')->update): case isset($xml->command->create) && isset($xml->command->create->children('urn:ietf:params:xml:ns:contact-1.0')->create):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processContactCreate($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
} }
processContactUpdate($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
case isset($xml->command->delete) && isset($xml->command->delete->children('urn:ietf:params:xml:ns:contact-1.0')->delete): case isset($xml->command->info) && isset($xml->command->info->children('urn:ietf:params:xml:ns:contact-1.0')->info):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processContactInfo($conn, $pdo, $xml, $trans);
break;
} }
processContactDelete($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
case isset($xml->command->transfer) && isset($xml->command->transfer->children('urn:ietf:params:xml:ns:contact-1.0')->transfer): case isset($xml->command->update) && isset($xml->command->update->children('urn:ietf:params:xml:ns:contact-1.0')->update):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processContactUpdate($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
} }
processContactTransfer($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
case isset($xml->command->check) && isset($xml->command->check->children('urn:ietf:params:xml:ns:domain-1.0')->check): case isset($xml->command->delete) && isset($xml->command->delete->children('urn:ietf:params:xml:ns:contact-1.0')->delete):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processContactDelete($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
} }
processDomainCheck($conn, $db, $xml, $trans);
break;
}
case isset($xml->command->info) && isset($xml->command->info->children('urn:ietf:params:xml:ns:domain-1.0')->info): case isset($xml->command->transfer) && isset($xml->command->transfer->children('urn:ietf:params:xml:ns:contact-1.0')->transfer):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processContactTransfer($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
} }
processDomainInfo($conn, $db, $xml, $trans);
break;
}
case isset($xml->command->update) && isset($xml->command->update->children('urn:ietf:params:xml:ns:domain-1.0')->update): case isset($xml->command->check) && isset($xml->command->check->children('urn:ietf:params:xml:ns:domain-1.0')->check):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processDomainCheck($conn, $pdo, $xml, $trans);
break;
} }
processDomainUpdate($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
case isset($xml->command->create) && isset($xml->command->create->children('urn:ietf:params:xml:ns:domain-1.0')->create): case isset($xml->command->info) && isset($xml->command->info->children('urn:ietf:params:xml:ns:domain-1.0')->info):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processDomainInfo($conn, $pdo, $xml, $trans);
break;
} }
processDomainCreate($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
case isset($xml->command->delete) && isset($xml->command->delete->children('urn:ietf:params:xml:ns:domain-1.0')->delete): case isset($xml->command->update) && isset($xml->command->update->children('urn:ietf:params:xml:ns:domain-1.0')->update):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processDomainUpdate($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
} }
processDomainDelete($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
case isset($xml->command->transfer) && isset($xml->command->transfer->children('urn:ietf:params:xml:ns:domain-1.0')->transfer): case isset($xml->command->create) && isset($xml->command->create->children('urn:ietf:params:xml:ns:domain-1.0')->create):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processDomainCreate($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
} }
processDomainTransfer($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
case isset($xml->command->check) && isset($xml->command->check->children('urn:ietf:params:xml:ns:host-1.0')->check): case isset($xml->command->delete) && isset($xml->command->delete->children('urn:ietf:params:xml:ns:domain-1.0')->delete):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processDomainDelete($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
} }
processHostCheck($conn, $db, $xml, $trans);
break;
}
case isset($xml->command->create) && isset($xml->command->create->children('urn:ietf:params:xml:ns:host-1.0')->create): case isset($xml->command->transfer) && isset($xml->command->transfer->children('urn:ietf:params:xml:ns:domain-1.0')->transfer):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processDomainTransfer($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
} }
processHostCreate($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
case isset($xml->command->info) && isset($xml->command->info->children('urn:ietf:params:xml:ns:host-1.0')->info): case isset($xml->command->check) && isset($xml->command->check->children('urn:ietf:params:xml:ns:host-1.0')->check):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processHostCheck($conn, $pdo, $xml, $trans);
break;
} }
processHostInfo($conn, $db, $xml, $trans);
break;
}
case isset($xml->command->update) && isset($xml->command->update->children('urn:ietf:params:xml:ns:host-1.0')->update): case isset($xml->command->create) && isset($xml->command->create->children('urn:ietf:params:xml:ns:host-1.0')->create):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processHostCreate($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
} }
processHostUpdate($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
case isset($xml->command->delete) && isset($xml->command->delete->children('urn:ietf:params:xml:ns:host-1.0')->delete): case isset($xml->command->info) && isset($xml->command->info->children('urn:ietf:params:xml:ns:host-1.0')->info):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processHostInfo($conn, $pdo, $xml, $trans);
break;
} }
processHostDelete($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
case isset($xml->command->info) && isset($xml->command->info->children('https://namingo.org/epp/funds-1.0')->info): case isset($xml->command->update) && isset($xml->command->update->children('urn:ietf:params:xml:ns:host-1.0')->update):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processHostUpdate($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
} }
processFundsInfo($conn, $db, $xml, $data['clid'], $trans);
break;
}
case isset($xml->command->renew) && isset($xml->command->renew->children('urn:ietf:params:xml:ns:domain-1.0')->renew): case isset($xml->command->delete) && isset($xml->command->delete->children('urn:ietf:params:xml:ns:host-1.0')->delete):
{ {
$data = $table->get($connId); $data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']); $clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML(); $xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString); $trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) { if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID); sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close(); $conn->close();
}
processHostDelete($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
} }
processDomainRenew($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
default: case isset($xml->command->info) && isset($xml->command->info->children('https://namingo.org/epp/funds-1.0')->info):
{ {
sendEppError($conn, $db, 2102, 'Unrecognized command'); $data = $table->get($connId);
break; $clTRID = (string) $xml->command->clTRID;
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processFundsInfo($conn, $pdo, $xml, $data['clid'], $trans);
break;
}
case isset($xml->command->renew) && isset($xml->command->renew->children('urn:ietf:params:xml:ns:domain-1.0')->renew):
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processDomainRenew($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
default:
{
sendEppError($conn, $pdo, 2000, 'Unrecognized command');
break;
}
} }
} catch (PDOException $e) {
// Handle database exceptions
$log->error('Database error: ' . $e->getMessage());
sendEppError($conn, $pdo, 2500, 'Error connecting to the EPP database');
$conn->close();
} catch (Throwable $e) {
// Catch any other exceptions or errors
$log->error('Error: ' . $e->getMessage());
sendEppError($conn, $pdo, 2500, 'General error');
$conn->close();
} finally {
// Return the connection to the pool
$pool->put($pdo);
} }
} }
sendEppError($conn, $db, 2100, 'Unknown command'); sendEppError($conn, $pdo, 2000, 'Unrecognized command');
$log->info('client disconnected'); $log->info('client disconnected');
$conn->close();
}); });
$log->info('Namingo EPP server started');
Swoole\Coroutine::create(function () use ($server) { Swoole\Coroutine::create(function () use ($server) {
$server->start(); $server->start();
}); });