mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-03 08:11:49 +02:00
Big EPP update; check commands now work
This commit is contained in:
parent
67877c55ac
commit
10f7b2b664
5 changed files with 509 additions and 364 deletions
|
@ -815,7 +815,10 @@ class EppWriter {
|
|||
$writer->writeAttribute('xsi:schemaLocation', 'urn:ietf:params:xml:ns:host-1.0 host-1.0.xsd');
|
||||
foreach ($resp['names'] as $n) {
|
||||
$writer->startElement('host:cd');
|
||||
$writer->writeElement('host:name', $n[0], ['avail' => $n[1]]);
|
||||
$writer->startElement('host:name');
|
||||
$writer->writeAttribute('avail', $n[1]);
|
||||
$writer->text($n[0]);
|
||||
$writer->endElement();
|
||||
if (isset($n[2])) {
|
||||
$writer->writeElement('host:reason', $n[2]);
|
||||
}
|
||||
|
@ -917,4 +920,3 @@ class EppWriter {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
148
epp/epp-check.php
Normal file
148
epp/epp-check.php
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
|
||||
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) {
|
||||
$contactID = (string)$contactID;
|
||||
|
||||
$stmt = $db->prepare("SELECT 1 FROM contact WHERE identifier = :id");
|
||||
$stmt->execute(['id' => $contactID]);
|
||||
|
||||
$results[$contactID] = $stmt->fetch() ? '0' : '1'; // 0 if exists, 1 if not
|
||||
}
|
||||
|
||||
$ids = [];
|
||||
foreach ($results as $id => $available) {
|
||||
$invalid_identifier = validate_identifier($contactID);
|
||||
$entry = [$id];
|
||||
|
||||
// Check if the contact ID is Invalid
|
||||
if ($invalid_identifier) {
|
||||
$entry[] = 0; // Set status to unavailable
|
||||
$entry[] = $invalid_identifier;
|
||||
} else {
|
||||
$entry[] = $available;
|
||||
|
||||
// Check if the contact is unavailable
|
||||
if (!$available) {
|
||||
$entry[] = "In use";
|
||||
}
|
||||
}
|
||||
|
||||
$ids[] = $entry;
|
||||
}
|
||||
|
||||
$response = [
|
||||
'command' => 'check_contact',
|
||||
'resultCode' => 1000,
|
||||
'lang' => 'en-US',
|
||||
'message' => 'Command completed successfully',
|
||||
'ids' => $ids,
|
||||
'clTRID' => $clTRID,
|
||||
'svTRID' => generateSvTRID(),
|
||||
];
|
||||
|
||||
$epp = new EPP\EppWriter();
|
||||
$xml = $epp->epp_writer($response);
|
||||
sendEppResponse($conn, $xml);
|
||||
}
|
||||
|
||||
function processHostCheck($conn, $db, $xml) {
|
||||
$hosts = $xml->command->check->children('urn:ietf:params:xml:ns:host-1.0')->check->{'name'};
|
||||
$clTRID = (string) $xml->command->clTRID;
|
||||
|
||||
$results = [];
|
||||
foreach ($hosts as $host) {
|
||||
$host = (string)$host;
|
||||
|
||||
// Validation for host name
|
||||
if (!preg_match('/^([A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9]){0,1}\\.){1,125}[A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9])$/i', $host) && strlen($host) > 254) {
|
||||
sendEppError($conn, 2005, 'Invalid host name');
|
||||
return;
|
||||
}
|
||||
|
||||
$stmt = $db->prepare("SELECT 1 FROM host WHERE name = :name");
|
||||
$stmt->execute(['name' => $host]);
|
||||
|
||||
$results[$host] = $stmt->fetch() ? '0' : '1'; // 0 if exists, 1 if not
|
||||
}
|
||||
|
||||
$names = [];
|
||||
foreach ($results as $id => $available) {
|
||||
$entry = [$id, $available];
|
||||
// Check if the host is unavailable
|
||||
if (!$available) {
|
||||
$entry[] = "In use";
|
||||
}
|
||||
$names[] = $entry;
|
||||
}
|
||||
|
||||
$response = [
|
||||
'command' => 'check_host',
|
||||
'resultCode' => 1000,
|
||||
'lang' => 'en-US',
|
||||
'message' => 'Command completed successfully',
|
||||
'names' => $names,
|
||||
'clTRID' => $clTRID,
|
||||
'svTRID' => generateSvTRID(),
|
||||
];
|
||||
|
||||
$epp = new EPP\EppWriter();
|
||||
$xml = $epp->epp_writer($response);
|
||||
sendEppResponse($conn, $xml);
|
||||
}
|
||||
|
||||
function processDomainCheck($conn, $db, $xml) {
|
||||
$domains = $xml->command->check->children('urn:ietf:params:xml:ns:domain-1.0')->check->name;
|
||||
$clTRID = (string) $xml->command->clTRID;
|
||||
|
||||
$names = [];
|
||||
foreach ($domains as $domain) {
|
||||
$domainName = (string) $domain;
|
||||
$stmt = $db->prepare("SELECT name FROM domain WHERE name = :domainName");
|
||||
$stmt->bindParam(':domainName', $domainName, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
$availability = $stmt->fetchColumn();
|
||||
|
||||
// Convert the DB result into a boolean '0' or '1'
|
||||
$availability = $availability ? '0' : '1';
|
||||
|
||||
$invalid_label = validate_label($domainName, $db);
|
||||
|
||||
// Initialize a new domain entry with the domain name and its availability
|
||||
$domainEntry = [$domainName];
|
||||
|
||||
// Check if the domain is Invalid
|
||||
if ($invalid_label) {
|
||||
$domainEntry[] = 0; // Set status to unavailable
|
||||
$domainEntry[] = $invalid_label;
|
||||
} else {
|
||||
$domainEntry[] = $availability;
|
||||
|
||||
// Check if the domain is unavailable
|
||||
if ($availability === '0') {
|
||||
$domainEntry[] = 'In use';
|
||||
}
|
||||
}
|
||||
|
||||
// Append this domain entry to names
|
||||
$names[] = $domainEntry;
|
||||
}
|
||||
|
||||
$response = [
|
||||
'command' => 'check_domain',
|
||||
'resultCode' => 1000,
|
||||
'lang' => 'en-US',
|
||||
'message' => 'Command completed successfully',
|
||||
'names' => $names,
|
||||
'clTRID' => $clTRID,
|
||||
'svTRID' => generateSvTRID(),
|
||||
];
|
||||
|
||||
$epp = new EPP\EppWriter();
|
||||
$xml = $epp->epp_writer($response);
|
||||
sendEppResponse($conn, $xml);
|
||||
}
|
176
epp/epp-info.php
Normal file
176
epp/epp-info.php
Normal file
|
@ -0,0 +1,176 @@
|
|||
<?php
|
||||
|
||||
function processContactInfo($conn, $db, $xml) {
|
||||
$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) {
|
||||
sendEppError($conn, 2005, 'Invalid contact ID');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare("SELECT * FROM contact WHERE id = :id");
|
||||
$stmt->execute(['id' => $contactID]);
|
||||
|
||||
$contact = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$contact) {
|
||||
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']];
|
||||
}
|
||||
|
||||
// Fetch postal_info
|
||||
$stmt = $db->prepare("SELECT * FROM contact_postalInfo WHERE contact_id = :id");
|
||||
$stmt->execute(['id' => $contactID]);
|
||||
$postals = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$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' => getRegistrarClid($db, $contact['clid']),
|
||||
'crID' => getRegistrarClid($db, $contact['crid']),
|
||||
'crDate' => $contact['crdate'],
|
||||
'upID' => getRegistrarClid($db, $contact['upid']),
|
||||
'upDate' => $contact['update'],
|
||||
'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');
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
sendEppError($conn, 2005, 'Invalid domain name');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare("SELECT * FROM domain WHERE name = :name");
|
||||
$stmt->execute(['name' => $domainName]);
|
||||
|
||||
$domain = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$domain) {
|
||||
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);
|
||||
|
||||
$transformedContacts = [];
|
||||
foreach ($contacts as $contact) {
|
||||
$transformedContacts[] = [$contact['type'], getContactIdentifier($db, $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);
|
||||
|
||||
$transformedHosts = [];
|
||||
foreach ($hosts as $host) {
|
||||
$transformedHosts[] = [getHost($db, $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' => getRegistrarClid($db, $domain['clid']),
|
||||
'crID' => getRegistrarClid($db, $domain['crid']),
|
||||
'crDate' => $domain['crdate'],
|
||||
'upID' => getRegistrarClid($db, $domain['upid']),
|
||||
'upDate' => $domain['update'],
|
||||
'exDate' => $domain['exdate'],
|
||||
'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');
|
||||
}
|
||||
}
|
376
epp/epp.php
376
epp/epp.php
|
@ -4,6 +4,9 @@
|
|||
global $c;
|
||||
$c = require_once 'config.php';
|
||||
require_once 'EppWriter.php';
|
||||
require_once 'helpers.php';
|
||||
require_once 'epp-check.php';
|
||||
require_once 'epp-info.php';
|
||||
|
||||
use Swoole\Coroutine\Server;
|
||||
use Swoole\Coroutine\Server\Connection;
|
||||
|
@ -183,6 +186,17 @@ $server->handle(function (Connection $conn) use ($table, $db) {
|
|||
processDomainInfo($conn, $db, $xml);
|
||||
break;
|
||||
}
|
||||
|
||||
case isset($xml->command->check) && isset($xml->command->check->children('urn:ietf:params:xml:ns:host-1.0')->check):
|
||||
{
|
||||
$data = $table->get($connId);
|
||||
if (!$data || $data['logged_in'] !== 1) {
|
||||
sendEppError($conn, 2202, 'Authorization error');
|
||||
$conn->close();
|
||||
}
|
||||
processHostCheck($conn, $db, $xml);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
|
@ -201,179 +215,6 @@ 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 getRegistrarClid(PDO $db, $id) {
|
||||
$stmt = $db->prepare("SELECT clid FROM registrar WHERE id = :id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
return $result['clid'] ?? null; // Return the clid if found, otherwise return null
|
||||
}
|
||||
|
||||
function getContactIdentifier(PDO $db, $id) {
|
||||
$stmt = $db->prepare("SELECT identifier FROM contact WHERE id = :id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
return $result['identifier'] ?? null; // Return the identifier if found, otherwise return null
|
||||
}
|
||||
|
||||
function getHost(PDO $db, $id) {
|
||||
$stmt = $db->prepare("SELECT name FROM host WHERE id = :id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
return $result['name'] ?? null; // Return the name if found, otherwise return null
|
||||
}
|
||||
|
||||
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) {
|
||||
$contactID = (string)$contactID;
|
||||
|
||||
// Validation for contact ID
|
||||
if (!ctype_alnum($contactID) || strlen($contactID) > 255) {
|
||||
sendEppError($conn, 2005, 'Invalid contact ID');
|
||||
return;
|
||||
}
|
||||
|
||||
$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
|
||||
}
|
||||
|
||||
$ids = [];
|
||||
foreach ($results as $id => $available) {
|
||||
$entry = [$id, $available];
|
||||
// Check if the contact is unavailable
|
||||
if (!$available) {
|
||||
$entry[] = "Contact ID already registered";
|
||||
}
|
||||
$ids[] = $entry;
|
||||
}
|
||||
|
||||
$response = [
|
||||
'command' => 'check_contact',
|
||||
'resultCode' => 1000,
|
||||
'lang' => 'en-US',
|
||||
'message' => 'Command completed successfully',
|
||||
'ids' => $ids,
|
||||
'clTRID' => $clTRID,
|
||||
'svTRID' => generateSvTRID(),
|
||||
];
|
||||
|
||||
$epp = new EPP\EppWriter();
|
||||
$xml = $epp->epp_writer($response);
|
||||
sendEppResponse($conn, $xml);
|
||||
}
|
||||
|
||||
function processContactInfo($conn, $db, $xml) {
|
||||
$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) {
|
||||
sendEppError($conn, 2005, 'Invalid contact ID');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare("SELECT * FROM contact WHERE id = :id");
|
||||
$stmt->execute(['id' => $contactID]);
|
||||
|
||||
$contact = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$contact) {
|
||||
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']];
|
||||
}
|
||||
|
||||
// Fetch postal_info
|
||||
$stmt = $db->prepare("SELECT * FROM contact_postalInfo WHERE contact_id = :id");
|
||||
$stmt->execute(['id' => $contactID]);
|
||||
$postals = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$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' => getRegistrarClid($db, $contact['clid']),
|
||||
'crID' => getRegistrarClid($db, $contact['crid']),
|
||||
'crDate' => $contact['crdate'],
|
||||
'upID' => getRegistrarClid($db, $contact['upid']),
|
||||
'upDate' => $contact['update'],
|
||||
'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');
|
||||
}
|
||||
}
|
||||
|
||||
function processContactCreate($conn, $db, $xml) {
|
||||
if (!isset($xml->command->create->{'contact:create'})) {
|
||||
sendEppError($conn, 2005, 'Syntax error');
|
||||
|
@ -432,193 +273,4 @@ XML;
|
|||
} catch (PDOException $e) {
|
||||
sendEppError($conn, 2400, 'Database error');
|
||||
}
|
||||
}
|
||||
|
||||
function processDomainCheck($conn, $db, $xml) {
|
||||
$domains = $xml->command->check->children('urn:ietf:params:xml:ns:domain-1.0')->check->name;
|
||||
$clTRID = (string) $xml->command->clTRID;
|
||||
|
||||
$names = [];
|
||||
foreach ($domains as $domain) {
|
||||
$domainName = (string) $domain;
|
||||
$availability = $db->query("SELECT name FROM domain WHERE name = '$domainName'")->fetchColumn();
|
||||
|
||||
// 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 = [
|
||||
'command' => 'check_domain',
|
||||
'resultCode' => 1000,
|
||||
'lang' => 'en-US',
|
||||
'message' => 'Command completed successfully',
|
||||
'names' => $names,
|
||||
'clTRID' => $clTRID,
|
||||
'svTRID' => generateSvTRID(),
|
||||
];
|
||||
|
||||
$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)) {
|
||||
sendEppError($conn, 2005, 'Invalid domain name');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare("SELECT * FROM domain WHERE name = :name");
|
||||
$stmt->execute(['name' => $domainName]);
|
||||
|
||||
$domain = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$domain) {
|
||||
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);
|
||||
|
||||
$transformedContacts = [];
|
||||
foreach ($contacts as $contact) {
|
||||
$transformedContacts[] = [$contact['type'], getContactIdentifier($db, $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);
|
||||
|
||||
$transformedHosts = [];
|
||||
foreach ($hosts as $host) {
|
||||
$transformedHosts[] = [getHost($db, $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' => getRegistrarClid($db, $domain['clid']),
|
||||
'crID' => getRegistrarClid($db, $domain['crid']),
|
||||
'crDate' => $domain['crdate'],
|
||||
'upID' => getRegistrarClid($db, $domain['upid']),
|
||||
'upDate' => $domain['update'],
|
||||
'exDate' => $domain['exdate'],
|
||||
'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');
|
||||
}
|
||||
}
|
||||
|
||||
function checkLogin($db, $clID, $pw) {
|
||||
$stmt = $db->prepare("SELECT pw FROM registrar WHERE clid = :username");
|
||||
$stmt->execute(['username' => $clID]);
|
||||
$hashedPassword = $stmt->fetchColumn();
|
||||
|
||||
return password_verify($pw, $hashedPassword);
|
||||
}
|
||||
|
||||
function sendGreeting($conn) {
|
||||
global $c;
|
||||
$currentDate = gmdate('Y-m-d\TH:i:s\Z');
|
||||
|
||||
$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) {
|
||||
$errorResponse = <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<response>
|
||||
<result code="$code">
|
||||
<msg>$msg</msg>
|
||||
</result>
|
||||
</response>
|
||||
</epp>
|
||||
XML;
|
||||
sendEppResponse($conn, $errorResponse);
|
||||
}
|
167
epp/helpers.php
Normal file
167
epp/helpers.php
Normal file
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
|
||||
function checkLogin($db, $clID, $pw) {
|
||||
$stmt = $db->prepare("SELECT pw FROM registrar WHERE clid = :username");
|
||||
$stmt->execute(['username' => $clID]);
|
||||
$hashedPassword = $stmt->fetchColumn();
|
||||
|
||||
return password_verify($pw, $hashedPassword);
|
||||
}
|
||||
|
||||
function sendGreeting($conn) {
|
||||
global $c;
|
||||
$currentDate = gmdate('Y-m-d\TH:i:s\Z');
|
||||
|
||||
$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) {
|
||||
$errorResponse = <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<response>
|
||||
<result code="$code">
|
||||
<msg>$msg</msg>
|
||||
</result>
|
||||
</response>
|
||||
</epp>
|
||||
XML;
|
||||
sendEppResponse($conn, $errorResponse);
|
||||
}
|
||||
|
||||
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 getRegistrarClid(PDO $db, $id) {
|
||||
$stmt = $db->prepare("SELECT clid FROM registrar WHERE id = :id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
return $result['clid'] ?? null; // Return the clid if found, otherwise return null
|
||||
}
|
||||
|
||||
function getContactIdentifier(PDO $db, $id) {
|
||||
$stmt = $db->prepare("SELECT identifier FROM contact WHERE id = :id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
return $result['identifier'] ?? null; // Return the identifier if found, otherwise return null
|
||||
}
|
||||
|
||||
function getHost(PDO $db, $id) {
|
||||
$stmt = $db->prepare("SELECT name FROM host WHERE id = :id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
return $result['name'] ?? null; // Return the name if found, otherwise return null
|
||||
}
|
||||
|
||||
function validate_identifier($identifier) {
|
||||
if (!$identifier) {
|
||||
return 'Abstract client and object identifier type minLength value=3';
|
||||
}
|
||||
|
||||
if (strlen($identifier) < 3) {
|
||||
return 'Abstract client and object identifier type minLength value=3';
|
||||
}
|
||||
|
||||
if (strlen($identifier) > 16) {
|
||||
return 'Abstract client and object identifier type maxLength value=16';
|
||||
}
|
||||
|
||||
if (preg_match('/[^A-Z0-9\-]/', $identifier)) {
|
||||
return 'The ID of the contact must contain letters (A-Z) (ASCII) hyphen (-), and digits (0-9). Registry assigns each registrar a unique prefix with which that registrar must create contact IDs.';
|
||||
}
|
||||
}
|
||||
|
||||
function validate_label($label, $pdo) {
|
||||
if (!$label) {
|
||||
return 'You must enter a domain name';
|
||||
}
|
||||
if (strlen($label) > 63) {
|
||||
return 'Total lenght of your domain must be less then 63 characters';
|
||||
}
|
||||
if (strlen($label) < 2) {
|
||||
return 'Total lenght of your domain must be greater then 2 characters';
|
||||
}
|
||||
if (preg_match("/(^-|^\.|-\.|\.-|--|\.\.|-$|\.$)/", $label)) {
|
||||
return 'Invalid domain name format, cannot begin or end with a hyphen (-)';
|
||||
}
|
||||
|
||||
// Extract TLD from the domain and prepend a dot
|
||||
$parts = explode('.', $label);
|
||||
$tld = "." . end($parts);
|
||||
|
||||
// Check if the TLD exists in the domain_tld table
|
||||
$stmtTLD = $pdo->prepare("SELECT COUNT(*) FROM domain_tld WHERE tld = :tld");
|
||||
$stmtTLD->bindParam(':tld', $tld, PDO::PARAM_STR);
|
||||
$stmtTLD->execute();
|
||||
$tldExists = $stmtTLD->fetchColumn();
|
||||
|
||||
if (!$tldExists) {
|
||||
return 'TLD not supported by the system';
|
||||
}
|
||||
|
||||
// Fetch the IDN regex for the given TLD
|
||||
$stmtRegex = $pdo->prepare("SELECT idn_table FROM domain_tld WHERE tld = :tld");
|
||||
$stmtRegex->bindParam(':tld', $tld, PDO::PARAM_STR);
|
||||
$stmtRegex->execute();
|
||||
$idnRegex = $stmtRegex->fetchColumn();
|
||||
|
||||
if (!$idnRegex) {
|
||||
return 'Failed to fetch domain IDN table';
|
||||
}
|
||||
|
||||
// Check for invalid characters using fetched regex
|
||||
if (!preg_match($idnRegex, $label)) {
|
||||
$server->send($fd, "Domain name invalid format");
|
||||
return 'Invalid domain name format, please review registry policy about accepted labels';
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue