Reserved names now appear as such in all checks

This commit is contained in:
Pinga 2023-11-27 13:00:51 +02:00
parent 4d3ee365a1
commit 3c6504ef9e
5 changed files with 84 additions and 23 deletions

View file

@ -22,6 +22,13 @@ class DomainsController extends Controller
$domainName = $data['domain_name'] ?? null; $domainName = $data['domain_name'] ?? null;
if ($domainName) { if ($domainName) {
$domainParts = explode('.', $domainName);
if (count($domainParts) > 2) {
// Remove the leftmost part (subdomain)
array_shift($domainParts);
}
$domainModel = new Domain($this->container->get('db')); $domainModel = new Domain($this->container->get('db'));
$availability = $domainModel->getDomainByName($domainName); $availability = $domainModel->getDomainByName($domainName);
@ -35,11 +42,19 @@ class DomainsController extends Controller
$status = $invalid_label; $status = $invalid_label;
$isAvailable = 0; $isAvailable = 0;
} else { } else {
$isAvailable = $availability; // If the domain is not taken, check if it's reserved
$status = null; if ($availability === '1') {
$domain_already_reserved = $this->container->get('db')->selectRow('SELECT id,type FROM reserved_domain_names WHERE name = ? LIMIT 1',[$domainParts[0]]);
// Check if the domain is unavailable if ($domain_already_reserved) {
if ($availability === '0') { $isAvailable = 0;
$status = ucfirst($domain_already_reserved['type']);
} else {
$isAvailable = $availability;
$status = $availability === '0' ? 'In use' : null;
}
} else {
$isAvailable = $availability;
$status = 'In use'; $status = 'In use';
} }
} }

View file

@ -74,6 +74,17 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) use ($c, $pdo)
$server->close($fd); $server->close($fd);
return; return;
} }
// Check if domain is reserved
$stmtReserved = $pdo->prepare("SELECT id FROM reserved_domain_names WHERE name = ? LIMIT 1");
$stmtReserved->execute([$parts[0]]);
$domain_already_reserved = $stmtReserved->fetchColumn();
if ($domain_already_reserved) {
$server->send($fd, "Domain name is reserved or restricted");
$server->close($fd);
return;
}
// Fetch the IDN regex for the given TLD // Fetch the IDN regex for the given TLD
$stmtRegex = $pdo->prepare("SELECT idn_table FROM domain_tld WHERE tld = :tld"); $stmtRegex = $pdo->prepare("SELECT idn_table FROM domain_tld WHERE tld = :tld");

View file

@ -34,7 +34,7 @@ function processContactCheck($conn, $db, $xml, $trans) {
$ids[] = $entry; $ids[] = $entry;
} }
$svTRID = generateSvTRID(); $svTRID = generateSvTRID();
$response = [ $response = [
'command' => 'check_contact', 'command' => 'check_contact',
@ -64,10 +64,10 @@ function processHostCheck($conn, $db, $xml, $trans) {
$host = (string)$host; $host = (string)$host;
// Validation for host name // 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 (!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, $db, 2005, 'Invalid host name', $clTRID, $trans); sendEppError($conn, $db, 2005, 'Invalid host name', $clTRID, $trans);
return; return;
} }
$stmt = $db->prepare("SELECT 1 FROM host WHERE name = :name"); $stmt = $db->prepare("SELECT 1 FROM host WHERE name = :name");
$stmt->execute(['name' => $host]); $stmt->execute(['name' => $host]);
@ -112,29 +112,41 @@ function processDomainCheck($conn, $db, $xml, $trans) {
$names = []; $names = [];
foreach ($domains as $domain) { foreach ($domains as $domain) {
$domainName = (string) $domain; $domainName = (string) $domain;
// Check if the domain is already taken
$stmt = $db->prepare("SELECT name FROM domain WHERE name = :domainName"); $stmt = $db->prepare("SELECT name FROM domain WHERE name = :domainName");
$stmt->bindParam(':domainName', $domainName, PDO::PARAM_STR); $stmt->bindParam(':domainName', $domainName, PDO::PARAM_STR);
$stmt->execute(); $stmt->execute();
$availability = $stmt->fetchColumn(); $taken = $stmt->fetchColumn();
$availability = $taken ? '0' : '1';
// Convert the DB result into a boolean '0' or '1'
$availability = $availability ? '0' : '1'; // Initialize a new domain entry with the domain name
$invalid_label = validate_label($domainName, $db);
// Initialize a new domain entry with the domain name and its availability
$domainEntry = [$domainName]; $domainEntry = [$domainName];
// Check if the domain is Invalid if ($availability === '0') {
if ($invalid_label) { // Domain is taken
$domainEntry[] = 0; // Set status to unavailable $domainEntry[] = 0; // Set status to unavailable
$domainEntry[] = $invalid_label; $domainEntry[] = 'In use';
} else { } else {
$domainEntry[] = $availability; // Check if the domain is reserved
$stmt = $db->prepare("SELECT type FROM reserved_domain_names WHERE name = :domainName LIMIT 1");
$stmt->bindParam(':domainName', $domainName, PDO::PARAM_STR);
$stmt->execute();
$reserved = $stmt->fetchColumn();
// Check if the domain is unavailable if ($reserved) {
if ($availability === '0') { $domainEntry[] = 0; // Set status to unavailable
$domainEntry[] = 'In use'; $domainEntry[] = ucfirst($reserved); // Capitalize the first letter
} else {
$invalid_label = validate_label($domainName, $db);
// Check if the domain is Invalid
if ($invalid_label) {
$domainEntry[] = 0; // Set status to unavailable
$domainEntry[] = ucfirst($invalid_label); // Capitalize the first letter
} else {
$domainEntry[] = 1; // Domain is available
}
} }
} }

View file

@ -175,6 +175,18 @@ function handleDomainQuery($request, $response, $pdo, $domainName, $c) {
return; return;
} }
// Check if domain is reserved
$stmtReserved = $pdo->prepare("SELECT id FROM reserved_domain_names WHERE name = ? LIMIT 1");
$stmtReserved->execute([$parts[0]]);
$domain_already_reserved = $stmtReserved->fetchColumn();
if ($domain_already_reserved) {
$response->header('Content-Type', 'application/json');
$response->status(400); // Bad Request
$response->end(json_encode(['error' => 'Domain name is reserved or restricted']));
return;
}
// Fetch the IDN regex for the given TLD // Fetch the IDN regex for the given TLD
$stmtRegex = $pdo->prepare("SELECT idn_table FROM domain_tld WHERE tld = :tld"); $stmtRegex = $pdo->prepare("SELECT idn_table FROM domain_tld WHERE tld = :tld");
$stmtRegex->bindParam(':tld', $tld, PDO::PARAM_STR); $stmtRegex->bindParam(':tld', $tld, PDO::PARAM_STR);

View file

@ -307,6 +307,17 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) use ($c, $pdo)
$server->close($fd); $server->close($fd);
return; return;
} }
// Check if domain is reserved
$stmtReserved = $pdo->prepare("SELECT id FROM reserved_domain_names WHERE name = ? LIMIT 1");
$stmtReserved->execute([$parts[0]]);
$domain_already_reserved = $stmtReserved->fetchColumn();
if ($domain_already_reserved) {
$server->send($fd, "Domain name is reserved or restricted");
$server->close($fd);
return;
}
// Fetch the IDN regex for the given TLD // Fetch the IDN regex for the given TLD
$stmtRegex = $pdo->prepare("SELECT idn_table FROM domain_tld WHERE tld = :tld"); $stmtRegex = $pdo->prepare("SELECT idn_table FROM domain_tld WHERE tld = :tld");