Added launch phase delete for EPP

This commit is contained in:
Pinga 2023-12-20 20:39:36 +02:00
parent de119b013f
commit 7e34dd7501
5 changed files with 196 additions and 169 deletions

View file

@ -1324,36 +1324,7 @@ class ApplicationsController extends Controller
try { try {
$db->beginTransaction(); $db->beginTransaction();
$hostIds = $db->select(
'SELECT id FROM host WHERE domain_id = ?',
[$domain_id]
);
foreach ($hostIds as $host) {
$host_id = $host['id'];
// Delete operations
$db->delete(
'host_addr',
[
'host_id' => $host_id
]
);
$db->delete(
'host_status',
[
'host_id' => $host_id
]
);
$db->delete(
'application_host_map',
[
'host_id' => $host_id
]
);
}
// Delete domain related records // Delete domain related records
$db->delete( $db->delete(
'application_contact_map', 'application_contact_map',

View file

@ -577,6 +577,7 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans) {
$extensionNode = $xml->command->extension; $extensionNode = $xml->command->extension;
if (isset($extensionNode)) { if (isset($extensionNode)) {
$fee_create = $xml->xpath('//fee:create')[0] ?? null; $fee_create = $xml->xpath('//fee:create')[0] ?? null;
$launch_create = $xml->xpath('//launch:create')[0] ?? null;
} }
$parts = extractDomainAndTLD($domainName); $parts = extractDomainAndTLD($domainName);

View file

@ -169,6 +169,11 @@ function processDomainDelete($conn, $db, $xml, $clid, $database_type, $trans) {
$domainName = $xml->command->delete->children('urn:ietf:params:xml:ns:domain-1.0')->delete->name; $domainName = $xml->command->delete->children('urn:ietf:params:xml:ns:domain-1.0')->delete->name;
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$extensionNode = $xml->command->extension;
if (isset($extensionNode)) {
$launch_delete = $xml->xpath('//launch:delete')[0] ?? null;
}
if (!$domainName) { if (!$domainName) {
sendEppError($conn, $db, 2003, 'Please specify the domain name that will be deleted', $clTRID, $trans); sendEppError($conn, $db, 2003, 'Please specify the domain name that will be deleted', $clTRID, $trans);
return; return;
@ -181,7 +186,11 @@ function processDomainDelete($conn, $db, $xml, $clid, $database_type, $trans) {
return; return;
} }
$stmt = $db->prepare("SELECT id, tldid, registrant, crdate, exdate, clid, crid, upid, trdate, trstatus, reid, redate, acid, acdate, rgpstatus, addPeriod, autoRenewPeriod, renewPeriod, renewedDate, transferPeriod FROM domain WHERE name = :name LIMIT 1"); if (isset($launch_delete)) {
$stmt = $db->prepare("SELECT id, tldid, registrant, crdate, exdate, clid, crid, upid, trdate, trstatus, reid, redate, acid, acdate, rgpstatus, addPeriod, autoRenewPeriod, renewPeriod, renewedDate, transferPeriod FROM application WHERE name = :name LIMIT 1");
} else {
$stmt = $db->prepare("SELECT id, tldid, registrant, crdate, exdate, clid, crid, upid, trdate, trstatus, reid, redate, acid, acdate, rgpstatus, addPeriod, autoRenewPeriod, renewPeriod, renewedDate, transferPeriod FROM domain WHERE name = :name LIMIT 1");
}
$stmt->execute([':name' => $domainName]); $stmt->execute([':name' => $domainName]);
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
@ -222,144 +231,135 @@ function processDomainDelete($conn, $db, $xml, $clid, $database_type, $trans) {
return; return;
} }
$stmt = $db->prepare("SELECT status FROM domain_status WHERE domain_id = :domain_id"); if (!isset($launch_delete)) {
$stmt->execute([':domain_id' => $domain_id]); $stmt = $db->prepare("SELECT status FROM domain_status WHERE domain_id = :domain_id");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $stmt->execute([':domain_id' => $domain_id]);
$status = $row['status']; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if (preg_match('/.*(UpdateProhibited|DeleteProhibited)$/', $status) || preg_match('/^pending/', $status)) { $status = $row['status'];
sendEppError($conn, $db, 2304, 'The domain name has a status that does not allow deletion', $clTRID, $trans); if (preg_match('/.*(UpdateProhibited|DeleteProhibited)$/', $status) || preg_match('/^pending/', $status)) {
return; sendEppError($conn, $db, 2304, 'The domain name has a status that does not allow deletion', $clTRID, $trans);
return;
}
} }
} }
$grace_period = 30; if (isset($launch_delete)) {
$phaseType = (string) $launch_delete->children('urn:ietf:params:xml:ns:launch-1.0')->phase;
// DELETE FROM domain_status $applicationID = (string) $launch_delete->children('urn:ietf:params:xml:ns:launch-1.0')->applicationID;
$stmt = $db->prepare("DELETE FROM domain_status WHERE domain_id = ?");
$stmt->execute([$domain_id]);
// UPDATE domain
$stmt = $db->prepare("UPDATE domain SET rgpstatus = 'redemptionPeriod', delTime = DATE_ADD(CURRENT_TIMESTAMP(3), INTERVAL ? DAY) WHERE id = ?");
$stmt->execute([$grace_period, $domain_id]);
// INSERT INTO domain_status
$stmt = $db->prepare("INSERT INTO domain_status (domain_id, status) VALUES(?, 'pendingDelete')");
$stmt->execute([$domain_id]);
if ($rgpstatus) {
if ($rgpstatus === 'addPeriod') {
$stmt = $db->prepare("SELECT id FROM domain WHERE id = ? AND (CURRENT_TIMESTAMP(3) < DATE_ADD(crdate, INTERVAL 5 DAY)) LIMIT 1");
$stmt->execute([$domain_id]);
$addPeriod_id = $stmt->fetchColumn();
if ($addPeriod_id) {
$returnValue = getDomainPrice($db, $domainName, $tldid, $addPeriod, 'create');
$price = $returnValue['price'];
if (!isset($price)) { $stmt = $db->prepare("SELECT id FROM application WHERE name = ? AND phase_type = ? AND application_id = ? LIMIT 1");
sendEppError($conn, $db, 2400, 'The price, period and currency for such TLD are not declared', $clTRID, $trans); $stmt->execute([$domainName, $phaseType, $applicationID]);
return; $result = $stmt->fetch(PDO::FETCH_ASSOC);
}
// Update registrar if (!$result) {
$stmt = $db->prepare("UPDATE registrar SET accountBalance = (accountBalance + ?) WHERE id = ?"); sendEppError($conn, $db, 2306, "Please verify the launch phase and/or the application ID", $clTRID, $trans);
$stmt->execute([$price, $clid]); return;
}
// Insert into payment_history // Delete application related records
$description = "domain name is deleted by the registrar during grace addPeriod, the registry provides a credit for the cost of the registration domain $domainName for period $addPeriod MONTH"; $db->exec("DELETE FROM application_contact_map WHERE domain_id = $domain_id");
$stmt = $db->prepare("INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP(3), ?, ?)"); $db->exec("DELETE FROM application_host_map WHERE domain_id = $domain_id");
$stmt->execute([$clid, $description, $price]); $db->exec("DELETE FROM application_status WHERE domain_id = $domain_id");
// Fetch host ids $stmt = $db->prepare("DELETE FROM application WHERE id = ?");
$stmt = $db->prepare("SELECT id FROM host WHERE domain_id = ?"); $stmt->execute([$domain_id]);
$stmt->execute([$domain_id]);
while ($host_id = $stmt->fetchColumn()) { if ($stmt->errorCode() != "00000") {
$db->exec("DELETE FROM host_addr WHERE host_id = $host_id"); sendEppError($conn, $db, 2400, 'The application has not been deleted, it has something to do with other objects', $clTRID, $trans);
$db->exec("DELETE FROM host_status WHERE host_id = $host_id"); return;
$db->exec("DELETE FROM domain_host_map WHERE host_id = $host_id"); }
}
// Delete domain related records
$db->exec("DELETE FROM domain_contact_map WHERE domain_id = $domain_id");
$db->exec("DELETE FROM domain_host_map WHERE domain_id = $domain_id");
$db->exec("DELETE FROM domain_authInfo WHERE domain_id = $domain_id");
$db->exec("DELETE FROM domain_status WHERE domain_id = $domain_id");
$db->exec("DELETE FROM secdns WHERE domain_id = $domain_id");
$db->exec("DELETE FROM host WHERE domain_id = $domain_id");
$stmt = $db->prepare("DELETE FROM domain WHERE id = ?");
$stmt->execute([$domain_id]);
if ($stmt->errorCode() != "00000") {
sendEppError($conn, $db, 2400, 'The domain name has not been deleted, it has something to do with other objects', $clTRID, $trans);
return;
}
// Handle statistics
$curdate_id = $db->query("SELECT id FROM statistics WHERE date = CURDATE()")->fetchColumn();
if (!$curdate_id) {
$db->exec("INSERT IGNORE INTO statistics (date) VALUES(CURDATE())");
}
$db->exec("UPDATE statistics SET deleted_domains = deleted_domains + 1 WHERE date = CURDATE()"); $svTRID = generateSvTRID();
} $response = [
} elseif ($rgpstatus === 'autoRenewPeriod') { 'command' => 'delete_domain',
$stmt = $db->prepare("SELECT id FROM domain WHERE id = ? AND (CURRENT_TIMESTAMP(3) < DATE_ADD(renewedDate, INTERVAL 45 DAY)) LIMIT 1"); 'resultCode' => 1000,
$stmt->execute([$domain_id]); 'lang' => 'en-US',
$autoRenewPeriod_id = $stmt->fetchColumn(); 'message' => 'Command completed successfully',
'clTRID' => $clTRID,
'svTRID' => $svTRID,
];
if ($autoRenewPeriod_id) { } else {
$returnValue = getDomainPrice($db, $domainName, $tldid, $autoRenewPeriod, 'renew'); $grace_period = 30;
$price = $returnValue['price'];
if (!isset($price)) { // DELETE FROM domain_status
sendEppError($conn, $db, 2400, 'The price, period and currency for such TLD are not declared', $clTRID, $trans); $stmt = $db->prepare("DELETE FROM domain_status WHERE domain_id = ?");
return; $stmt->execute([$domain_id]);
// UPDATE domain
$stmt = $db->prepare("UPDATE domain SET rgpstatus = 'redemptionPeriod', delTime = DATE_ADD(CURRENT_TIMESTAMP(3), INTERVAL ? DAY) WHERE id = ?");
$stmt->execute([$grace_period, $domain_id]);
// INSERT INTO domain_status
$stmt = $db->prepare("INSERT INTO domain_status (domain_id, status) VALUES(?, 'pendingDelete')");
$stmt->execute([$domain_id]);
if ($rgpstatus) {
if ($rgpstatus === 'addPeriod') {
$stmt = $db->prepare("SELECT id FROM domain WHERE id = ? AND (CURRENT_TIMESTAMP(3) < DATE_ADD(crdate, INTERVAL 5 DAY)) LIMIT 1");
$stmt->execute([$domain_id]);
$addPeriod_id = $stmt->fetchColumn();
if ($addPeriod_id) {
$returnValue = getDomainPrice($db, $domainName, $tldid, $addPeriod, 'create');
$price = $returnValue['price'];
if (!isset($price)) {
sendEppError($conn, $db, 2400, 'The price, period and currency for such TLD are not declared', $clTRID, $trans);
return;
}
// Update registrar
$stmt = $db->prepare("UPDATE registrar SET accountBalance = (accountBalance + ?) WHERE id = ?");
$stmt->execute([$price, $clid]);
// Insert into payment_history
$description = "domain name is deleted by the registrar during grace addPeriod, the registry provides a credit for the cost of the registration domain $domainName for period $addPeriod MONTH";
$stmt = $db->prepare("INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP(3), ?, ?)");
$stmt->execute([$clid, $description, $price]);
// Fetch host ids
$stmt = $db->prepare("SELECT id FROM host WHERE domain_id = ?");
$stmt->execute([$domain_id]);
while ($host_id = $stmt->fetchColumn()) {
$db->exec("DELETE FROM host_addr WHERE host_id = $host_id");
$db->exec("DELETE FROM host_status WHERE host_id = $host_id");
$db->exec("DELETE FROM domain_host_map WHERE host_id = $host_id");
}
// Delete domain related records
$db->exec("DELETE FROM domain_contact_map WHERE domain_id = $domain_id");
$db->exec("DELETE FROM domain_host_map WHERE domain_id = $domain_id");
$db->exec("DELETE FROM domain_authInfo WHERE domain_id = $domain_id");
$db->exec("DELETE FROM domain_status WHERE domain_id = $domain_id");
$db->exec("DELETE FROM secdns WHERE domain_id = $domain_id");
$db->exec("DELETE FROM host WHERE domain_id = $domain_id");
$stmt = $db->prepare("DELETE FROM domain WHERE id = ?");
$stmt->execute([$domain_id]);
if ($stmt->errorCode() != "00000") {
sendEppError($conn, $db, 2400, 'The domain name has not been deleted, it has something to do with other objects', $clTRID, $trans);
return;
}
// Handle statistics
$curdate_id = $db->query("SELECT id FROM statistics WHERE date = CURDATE()")->fetchColumn();
if (!$curdate_id) {
$db->exec("INSERT IGNORE INTO statistics (date) VALUES(CURDATE())");
}
$db->exec("UPDATE statistics SET deleted_domains = deleted_domains + 1 WHERE date = CURDATE()");
} }
} elseif ($rgpstatus === 'autoRenewPeriod') {
$stmt = $db->prepare("SELECT id FROM domain WHERE id = ? AND (CURRENT_TIMESTAMP(3) < DATE_ADD(renewedDate, INTERVAL 45 DAY)) LIMIT 1");
$stmt->execute([$domain_id]);
$autoRenewPeriod_id = $stmt->fetchColumn();
// Update registrar if ($autoRenewPeriod_id) {
$stmt = $db->prepare("UPDATE registrar SET accountBalance = (accountBalance + ?) WHERE id = ?"); $returnValue = getDomainPrice($db, $domainName, $tldid, $autoRenewPeriod, 'renew');
$stmt->execute([$price, $clid]);
// Insert into payment_history
$description = "domain name is deleted by the registrar during grace autoRenewPeriod, the registry provides a credit for the cost of the renewal domain $domainName for period $autoRenewPeriod MONTH";
$stmt = $db->prepare("INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP(3), ?, ?)");
$stmt->execute([$clid, $description, $price]);
}
} elseif ($rgpstatus === 'renewPeriod') {
$stmt = $db->prepare("SELECT id FROM domain WHERE id = ? AND (CURRENT_TIMESTAMP(3) < DATE_ADD(renewedDate, INTERVAL 5 DAY)) LIMIT 1");
$stmt->execute([$domain_id]);
$renewPeriod_id = $stmt->fetchColumn();
if ($renewPeriod_id) {
$returnValue = getDomainPrice($db, $domainName, $tldid, $renewPeriod, 'renew');
$price = $returnValue['price'];
if (!isset($price)) {
sendEppError($conn, $db, 2400, 'The price, period and currency for such TLD are not declared', $clTRID, $trans);
return;
}
// Update registrar
$stmt = $db->prepare("UPDATE registrar SET accountBalance = (accountBalance + ?) WHERE id = ?");
$stmt->execute([$price, $clid]);
// Insert into payment_history
$description = "domain name is deleted by the registrar during grace renewPeriod, the registry provides a credit for the cost of the renewal domain $domainName for period $renewPeriod MONTH";
$stmt = $db->prepare("INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP(3), ?, ?)");
$stmt->execute([$clid, $description, $price]);
}
} elseif ($rgpstatus === 'transferPeriod') {
$stmt = $db->prepare("SELECT id FROM domain WHERE id = ? AND (CURRENT_TIMESTAMP(3) < DATE_ADD(trdate, INTERVAL 5 DAY)) LIMIT 1");
$stmt->execute([$domain_id]);
$transferPeriod_id = $stmt->fetchColumn();
if ($transferPeriod_id) {
// Return money if a transfer was also a renew
if ($transferPeriod > 0) {
$returnValue = getDomainPrice($db, $domainName, $tldid, $transferPeriod, 'renew');
$price = $returnValue['price']; $price = $returnValue['price'];
if (!isset($price)) { if (!isset($price)) {
@ -372,23 +372,72 @@ function processDomainDelete($conn, $db, $xml, $clid, $database_type, $trans) {
$stmt->execute([$price, $clid]); $stmt->execute([$price, $clid]);
// Insert into payment_history // Insert into payment_history
$description = "domain name is deleted by the registrar during grace transferPeriod, the registry provides a credit for the cost of the transfer domain $domainName for period $transferPeriod MONTH"; $description = "domain name is deleted by the registrar during grace autoRenewPeriod, the registry provides a credit for the cost of the renewal domain $domainName for period $autoRenewPeriod MONTH";
$stmt = $db->prepare("INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP(3), ?, ?)"); $stmt = $db->prepare("INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP(3), ?, ?)");
$stmt->execute([$clid, $description, $price]); $stmt->execute([$clid, $description, $price]);
} }
} } elseif ($rgpstatus === 'renewPeriod') {
} $stmt = $db->prepare("SELECT id FROM domain WHERE id = ? AND (CURRENT_TIMESTAMP(3) < DATE_ADD(renewedDate, INTERVAL 5 DAY)) LIMIT 1");
} $stmt->execute([$domain_id]);
$renewPeriod_id = $stmt->fetchColumn();
$svTRID = generateSvTRID(); if ($renewPeriod_id) {
$response = [ $returnValue = getDomainPrice($db, $domainName, $tldid, $renewPeriod, 'renew');
'command' => 'delete_domain', $price = $returnValue['price'];
'resultCode' => 1001,
'lang' => 'en-US', if (!isset($price)) {
'message' => 'Command completed successfully; action pending', sendEppError($conn, $db, 2400, 'The price, period and currency for such TLD are not declared', $clTRID, $trans);
'clTRID' => $clTRID, return;
'svTRID' => $svTRID, }
];
// Update registrar
$stmt = $db->prepare("UPDATE registrar SET accountBalance = (accountBalance + ?) WHERE id = ?");
$stmt->execute([$price, $clid]);
// Insert into payment_history
$description = "domain name is deleted by the registrar during grace renewPeriod, the registry provides a credit for the cost of the renewal domain $domainName for period $renewPeriod MONTH";
$stmt = $db->prepare("INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP(3), ?, ?)");
$stmt->execute([$clid, $description, $price]);
}
} elseif ($rgpstatus === 'transferPeriod') {
$stmt = $db->prepare("SELECT id FROM domain WHERE id = ? AND (CURRENT_TIMESTAMP(3) < DATE_ADD(trdate, INTERVAL 5 DAY)) LIMIT 1");
$stmt->execute([$domain_id]);
$transferPeriod_id = $stmt->fetchColumn();
if ($transferPeriod_id) {
// Return money if a transfer was also a renew
if ($transferPeriod > 0) {
$returnValue = getDomainPrice($db, $domainName, $tldid, $transferPeriod, 'renew');
$price = $returnValue['price'];
if (!isset($price)) {
sendEppError($conn, $db, 2400, 'The price, period and currency for such TLD are not declared', $clTRID, $trans);
return;
}
// Update registrar
$stmt = $db->prepare("UPDATE registrar SET accountBalance = (accountBalance + ?) WHERE id = ?");
$stmt->execute([$price, $clid]);
// Insert into payment_history
$description = "domain name is deleted by the registrar during grace transferPeriod, the registry provides a credit for the cost of the transfer domain $domainName for period $transferPeriod MONTH";
$stmt = $db->prepare("INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP(3), ?, ?)");
$stmt->execute([$clid, $description, $price]);
}
}
}
}
$svTRID = generateSvTRID();
$response = [
'command' => 'delete_domain',
'resultCode' => 1001,
'lang' => 'en-US',
'message' => 'Command completed successfully; action pending',
'clTRID' => $clTRID,
'svTRID' => $svTRID,
];
}
$epp = new EPP\EppWriter(); $epp = new EPP\EppWriter();
$xml = $epp->epp_writer($response); $xml = $epp->epp_writer($response);

View file

@ -171,6 +171,11 @@ function processHostInfo($conn, $db, $xml, $trans) {
function processDomainInfo($conn, $db, $xml, $trans) { function processDomainInfo($conn, $db, $xml, $trans) {
$domainName = $xml->command->info->children('urn:ietf:params:xml:ns:domain-1.0')->info->name; $domainName = $xml->command->info->children('urn:ietf:params:xml:ns:domain-1.0')->info->name;
$clTRID = (string) $xml->command->clTRID; $clTRID = (string) $xml->command->clTRID;
$extensionNode = $xml->command->extension;
if (isset($extensionNode)) {
$launch_info = $xml->xpath('//launch:info')[0] ?? null;
}
$result = $xml->xpath('//domain:authInfo/domain:pw[1]'); $result = $xml->xpath('//domain:authInfo/domain:pw[1]');
if (!empty($result)) { if (!empty($result)) {

View file

@ -931,6 +931,7 @@ function processDomainUpdate($conn, $db, $xml, $clid, $database_type, $trans) {
if (isset($extensionNode)) { if (isset($extensionNode)) {
$rgp_update = $xml->xpath('//rgp:update')[0] ?? null; $rgp_update = $xml->xpath('//rgp:update')[0] ?? null;
$secdns_update = $xml->xpath('//secDNS:update')[0] ?? null; $secdns_update = $xml->xpath('//secDNS:update')[0] ?? null;
$launch_update = $xml->xpath('//launch:update')[0] ?? null;
} }
if ($domainRem === null && $domainAdd === null && $domainChg === null && $extensionNode === null) { if ($domainRem === null && $domainAdd === null && $domainChg === null && $extensionNode === null) {