RST improvements

This commit is contained in:
Pinga 2025-05-05 15:37:12 +03:00
parent d755704917
commit 6528ad6530
4 changed files with 86 additions and 141 deletions

View file

@ -268,8 +268,11 @@ function validate_label($domain, $db) {
}
} else {
// Prevent consecutive or invalid hyphen usage
if (preg_match('/--|\.\./', $label)) {
return 'Domain labels cannot contain consecutive dashes (--) or dots (..)';
if ($label !== $labels[0] && preg_match('/\.\./', $label)) {
return 'Domain labels cannot contain consecutive dots (..)';
}
if (preg_match('/^..--/', $label)) {
return 'Domain labels cannot have double hyphens at position 3 and 4';
}
}
}

View file

@ -429,7 +429,7 @@ function processHostCreate($conn, $db, $xml, $clid, $database_type, $trans) {
$hostName = strtolower($hostName);
$host_addr_list = $xml->xpath('//addr');
$host_addr_list = $xml->xpath('//host:addr');
if (count($host_addr_list) > 13) {
sendEppError($conn, $db, 2306, 'No more than 13 host:addr are allowed', $clTRID, $trans);
return;
@ -1379,38 +1379,8 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans, $m
]);
}
} else {
$internal_host = false;
$stmt = $db->prepare("SELECT tld FROM domain_tld");
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$tld = strtoupper($row['tld']);
$tld = str_replace('.', '\\.', $tld); // Escape the dot for regex pattern matching
if (preg_match("/$tld$/i", $hostObj)) {
$internal_host = true;
break;
}
}
$stmt->closeCursor();
if ($internal_host) {
if (preg_match("/\.$domainName$/i", $hostObj)) {
$stmt = $db->prepare("INSERT INTO host (name,domain_id,clid,crid,crdate) VALUES(?, ?, ?, ?, CURRENT_TIMESTAMP(3))");
$stmt->execute([$hostObj, $domain_id, $clid, $clid]);
$host_id = $db->lastInsertId();
$stmt = $db->prepare("INSERT INTO application_host_map (domain_id,host_id) VALUES(?, ?)");
$stmt->execute([$domain_id, $host_id]);
}
} else {
$stmt = $db->prepare("INSERT INTO host (name,clid,crid,crdate) VALUES(?, ?, ?, CURRENT_TIMESTAMP(3))");
$stmt->execute([$hostObj, $clid, $clid]);
$host_id = $db->lastInsertId();
$stmt = $db->prepare("INSERT INTO application_host_map (domain_id,host_id) VALUES(?, ?)");
$stmt->execute([$domain_id, $host_id]);
}
sendEppError($conn, $db, 2303, "Host object $hostObj does not exist", $clTRID, $trans);
return;
}
}
}
@ -1451,31 +1421,40 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans, $m
]);
}
} else {
// Insert a new host
$tlds = $db->query("SELECT tld FROM domain_tld")->fetchAll(PDO::FETCH_COLUMN);
$internal_host = false;
foreach ($tlds as $tld) {
if (str_ends_with(strtolower($hostName), strtolower($tld))) {
$internal_host = true;
break;
}
}
if ($internal_host) {
$stmt = $db->prepare("INSERT INTO host (name, domain_id, clid, crid, crdate) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP(3))");
$stmt->execute([$hostName, $domain_id, $clid, $clid]);
$host_id = $db->lastInsertId();
// Map the new host to the domain
$stmt = $db->prepare("INSERT INTO application_host_map (domain_id, host_id) VALUES (?, ?)");
$stmt->execute([$domain_id, $host_id]);
// Process and insert host addresses
foreach ($node->xpath('./domain:hostAddr') as $nodeAddr) {
$hostAddr = (string)$nodeAddr;
$addr_type = (string)($nodeAddr->attributes()->ip ?? 'v4');
// Normalize the address
if ($addr_type === 'v6') {
$hostAddr = normalize_v6_address($hostAddr);
} else {
$hostAddr = normalize_v4_address($hostAddr);
}
// Insert the address into host_addr table
$stmt = $db->prepare("INSERT INTO host_addr (host_id, addr, ip) VALUES (?, ?, ?)");
$stmt->execute([$host_id, $hostAddr, $addr_type]);
}
} else {
sendEppError($conn, $db, 2303, "Host attribute $hostName does not exist", $clTRID, $trans);
return;
}
}
}
}

View file

@ -1686,57 +1686,9 @@ function processDomainUpdate($conn, $db, $xml, $clid, $database_type, $trans) {
$stmt->execute([$logMessage, $contextData]);
}
} else {
$tlds = $db->query("SELECT tld FROM domain_tld")->fetchAll(PDO::FETCH_COLUMN);
$internal_host = false;
foreach ($tlds as $tld) {
if (str_ends_with(strtolower($hostObj), strtolower($tld))) {
$internal_host = true;
break;
}
}
if ($internal_host) {
if (preg_match("/\.$domainName$/i", $hostObj)) {
$sth = $db->prepare("INSERT INTO host (name,domain_id,clid,crid,crdate) VALUES(?, ?, ?, ?, CURRENT_TIMESTAMP(3))");
if (!$sth->execute([$hostObj, $domain_id, $clid, $clid])) {
sendEppError($conn, $db, 2400, 'Database error', $clTRID, $trans);
sendEppError($conn, $db, 2303, "Host object $hostObj does not exist", $clTRID, $trans);
return;
}
$host_id = $db->lastInsertId();
$sth = $db->prepare("INSERT INTO domain_host_map (domain_id,host_id) VALUES(?, ?)");
if (!$sth->execute([$domain_id, $host_id])) {
sendEppError($conn, $db, 2400, 'Database error', $clTRID, $trans);
return;
}
$sth = $db->prepare("UPDATE domain SET upid = ?, lastupdate = CURRENT_TIMESTAMP(3) WHERE id = ?");
if (!$sth->execute([$clid, $domain_id])) {
sendEppError($conn, $db, 2400, 'Database error', $clTRID, $trans);
return;
}
}
} else {
$sth = $db->prepare("INSERT INTO host (name,clid,crid,crdate) VALUES(?, ?, ?, CURRENT_TIMESTAMP(3))");
if (!$sth->execute([$hostObj, $clid, $clid])) {
sendEppError($conn, $db, 2400, 'Database error', $clTRID, $trans);
return;
}
$host_id = $db->lastInsertId();
$sth = $db->prepare("INSERT INTO domain_host_map (domain_id,host_id) VALUES(?, ?)");
if (!$sth->execute([$domain_id, $host_id])) {
sendEppError($conn, $db, 2400, 'Database error', $clTRID, $trans);
return;
}
$sth = $db->prepare("UPDATE domain SET upid = ?, lastupdate = CURRENT_TIMESTAMP(3) WHERE id = ?");
if (!$sth->execute([$clid, $domain_id])) {
sendEppError($conn, $db, 2400, 'Database error', $clTRID, $trans);
return;
}
}
}
}
foreach ($hostAttr_list as $node) {
@ -1784,30 +1736,34 @@ function processDomainUpdate($conn, $db, $xml, $clid, $database_type, $trans) {
}
}
} else {
// Insert into the host table
$tlds = $db->query("SELECT tld FROM domain_tld")->fetchAll(PDO::FETCH_COLUMN);
$internal_host = false;
foreach ($tlds as $tld) {
if (str_ends_with(strtolower($hostName), strtolower($tld))) {
$internal_host = true;
break;
}
}
if ($internal_host) {
$sth = $db->prepare("INSERT INTO host (name,domain_id,clid,crid,crdate) VALUES(?, ?, ?, ?, CURRENT_TIMESTAMP(3))");
$sth->execute([$hostName, $domain_id, $clid, $clid]) or die($sth->errorInfo()[2]);
$host_id = $db->lastInsertId();
// Insert into the domain_host_map table
$sth = $db->prepare("INSERT INTO domain_host_map (domain_id,host_id) VALUES(?, ?)");
$sth->execute([$domain_id, $host_id]) or die($sth->errorInfo()[2]);
// Iterate over the hostAddr_list
$hostAddr_list = $node->xpath('domain:hostAddr');
foreach ($hostAddr_list as $node) {
$hostAddr = (string)$node;
$addr_type = isset($node['ip']) ? (string)$node['ip'] : 'v4';
// Normalize
if ($addr_type == 'v6') {
$hostAddr = _normalise_v6_address($hostAddr); // PHP function to normalize IPv6
} else {
$hostAddr = _normalise_v4_address($hostAddr); // PHP function to normalize IPv4
}
// Insert into the host_addr table
$sth = $db->prepare("INSERT INTO host_addr (host_id,addr,ip) VALUES(?, ?, ?)");
$sth->execute([$host_id, $hostAddr, $addr_type]) or die($sth->errorInfo()[2]);
}
@ -1817,6 +1773,10 @@ function processDomainUpdate($conn, $db, $xml, $clid, $database_type, $trans) {
sendEppError($conn, $db, 2400, 'Database error', $clTRID, $trans);
return;
}
} else {
sendEppError($conn, $db, 2303, "Host attribute $hostName does not exist", $clTRID, $trans);
return;
}
}
}
}

View file

@ -273,8 +273,11 @@ function validate_label($domain, $pdo) {
}
} else {
// Prevent consecutive or invalid hyphen usage
if (preg_match('/--|\.\./', $label)) {
return 'Domain labels cannot contain consecutive dashes (--) or dots (..)';
if ($label !== $labels[0] && preg_match('/\.\./', $label)) {
return 'Domain labels cannot contain consecutive dots (..)';
}
if (preg_match('/^..--/', $label)) {
return 'Domain labels cannot have double hyphens at position 3 and 4';
}
}
}