Further fixes and optimizations to EPP

This commit is contained in:
Pinga 2024-11-27 16:28:23 +02:00
parent cd265c92f0
commit d312db4f14
5 changed files with 25 additions and 21 deletions

View file

@ -76,7 +76,7 @@ function processHostCheck($conn, $db, $xml, $trans) {
$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) {
if (!validateHostName($host)) {
sendEppError($conn, $db, 2005, 'Invalid host name', $clTRID, $trans);
return;
}

View file

@ -392,7 +392,7 @@ function processHostCreate($conn, $db, $xml, $clid, $database_type, $trans) {
$hostName = $xml->command->create->children('urn:ietf:params:xml:ns:host-1.0')->create->name;
$clTRID = (string) $xml->command->clTRID;
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', $hostName) && strlen($hostName) < 254) {
if (validateHostName($hostName)) {
$host_id_already_exist = $db->query("SELECT id FROM host WHERE name = '$hostName' LIMIT 1")->fetchColumn();
if ($host_id_already_exist) {
sendEppError($conn, $db, 2302, 'host:name already exists', $clTRID, $trans);

View file

@ -98,6 +98,12 @@ function processHostDelete($conn, $db, $xml, $clid, $database_type, $trans) {
return;
}
// Validation for host name
if (!validateHostName($hostName)) {
sendEppError($conn, $db, 2005, 'Invalid host name', $clTRID, $trans);
return;
}
$query = "SELECT id, clid FROM host WHERE name = :name LIMIT 1";
$stmt = $db->prepare($query);
$stmt->execute([':name' => $hostName]);

View file

@ -103,13 +103,13 @@ function processHostInfo($conn, $db, $xml, $trans) {
sendEppError($conn, $db, 2003, 'Specify your host name', $clTRID, $trans);
return;
}
// 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', $hostName) && strlen($hostName) > 254) {
if (!validateHostName($hostName)) {
sendEppError($conn, $db, 2005, 'Invalid host name', $clTRID, $trans);
return;
}
try {
$stmt = $db->prepare("SELECT * FROM host WHERE name = :name");
$stmt->execute(['name' => $hostName]);

View file

@ -828,9 +828,7 @@ function processHostUpdate($conn, $db, $xml, $clid, $database_type, $trans) {
if (isset($hostChg)) {
$chg_name = $xml->xpath('//host:name[1]')[0];
$pattern = '/^([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';
if (preg_match($pattern, $chg_name) && strlen($chg_name) < 254) {
if (validateHostName($chg_name)) {
$stmt = $db->prepare("SELECT id FROM host WHERE name = ? LIMIT 1");
$stmt->execute([$chg_name]);
$chg_name_id = $stmt->fetchColumn();
@ -926,19 +924,19 @@ function processHostUpdate($conn, $db, $xml, $clid, $database_type, $trans) {
$addr = normalize_v4_address($addr);
}
try {
$stmt = $db->prepare("INSERT INTO host_addr (host_id,addr,ip) VALUES(?,?,?)");
$stmt->execute([$hostId, $addr, $addr_type]);
} catch (PDOException $e) {
if ($database_type === 'mysql' && $e->errorInfo[1] == 1062) {
// Duplicate entry error for MySQL. Silently ignore.
} elseif ($database_type === 'pgsql' && $e->errorInfo[1] == 23505) {
// Duplicate entry error for PostgreSQL. Silently ignore.
} else {
sendEppError($conn, $db, 2400, 'Database error', $clTRID, $trans);
return;
try {
$stmt = $db->prepare("INSERT INTO host_addr (host_id,addr,ip) VALUES(?,?,?)");
$stmt->execute([$hostId, $addr, $addr_type]);
} catch (PDOException $e) {
if ($database_type === 'mysql' && $e->errorInfo[1] == 1062) {
// Duplicate entry error for MySQL. Silently ignore.
} elseif ($database_type === 'pgsql' && $e->errorInfo[1] == 23505) {
// Duplicate entry error for PostgreSQL. Silently ignore.
} else {
sendEppError($conn, $db, 2400, 'Database error', $clTRID, $trans);
return;
}
}
}
}
@ -1195,7 +1193,7 @@ function processDomainUpdate($conn, $db, $xml, $clid, $database_type, $trans) {
}
// Additional checks related to domain TLDs and existing records
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', $hostObj) && strlen($hostObj) < 254) {
if (validateHostName($hostObj)) {
$stmt = $db->prepare("SELECT tld FROM domain_tld");
$stmt->execute();
$tlds = $stmt->fetchAll(PDO::FETCH_COLUMN);