Added EPP domain delete

This commit is contained in:
Pinga 2023-08-20 17:47:00 +03:00
parent 6824dc5b2c
commit 56f07f7391
2 changed files with 247 additions and 10 deletions

View file

@ -156,6 +156,232 @@ function processHostDelete($conn, $db, $xml, $clid, $database_type) {
'svTRID' => generateSvTRID(),
];
$epp = new EPP\EppWriter();
$xml = $epp->epp_writer($response);
sendEppResponse($conn, $xml);
}
function processDomainDelete($conn, $db, $xml, $clid, $database_type) {
$domainName = $xml->command->delete->children('urn:ietf:params:xml:ns:domain-1.0')->delete->name;
$clTRID = (string) $xml->command->clTRID;
if (!$domainName) {
sendEppError($conn, 2003, 'Required parameter missing');
return;
}
$stmt = $db->prepare("SELECT id, tldid, registrant, crdate, exdate, `update`, 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]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$result) {
sendEppError($conn, 2303, 'Object does not exist');
return;
}
$domain_id = $result['id'];
$tldid = $result['tldid'];
$registrant = $result['registrant'];
$crdate = $result['crdate'];
$exdate = $result['exdate'];
$update = $result['update'];
$registrar_id_domain = $result['clid'];
$crid = $result['crid'];
$upid = $result['upid'];
$trdate = $result['trdate'];
$trstatus = $result['trstatus'];
$reid = $result['reid'];
$redate = $result['redate'];
$acid = $result['acid'];
$acdate = $result['acdate'];
$rgpstatus = $result['rgpstatus'];
$addPeriod = $result['addPeriod'];
$autoRenewPeriod = $result['autoRenewPeriod'];
$renewPeriod = $result['renewPeriod'];
$renewedDate = $result['renewedDate'];
$transferPeriod = $result['transferPeriod'];
$stmt = $db->prepare("SELECT id FROM registrar WHERE clid = :clid LIMIT 1");
$stmt->bindParam(':clid', $clid, PDO::PARAM_STR);
$stmt->execute();
$clid = $stmt->fetch(PDO::FETCH_ASSOC);
$clid = $clid['id'];
if ($clid != $registrar_id_domain) {
sendEppError($conn, 2201, 'Authorization error');
return;
}
$stmt = $db->prepare("SELECT status FROM domain_status WHERE domain_id = :domain_id");
$stmt->execute([':domain_id' => $domain_id]);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$status = $row['status'];
if (preg_match('/.*(UpdateProhibited|DeleteProhibited)$/', $status) || preg_match('/^pending/', $status)) {
sendEppError($conn, 2304, 'Object status prohibits operation');
return;
}
}
$grace_period = 30;
// DELETE FROM `domain_status`
$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, 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 < DATE_ADD(crdate, INTERVAL 5 DAY)) LIMIT 1");
$stmt->execute([$domain_id]);
$addPeriod_id = $stmt->fetchColumn();
if ($addPeriod_id) {
$stmt = $db->prepare("SELECT m$addPeriod FROM domain_price WHERE tldid = ? AND command = 'create' LIMIT 1");
$stmt->execute([$tldid]);
$price = $stmt->fetchColumn();
if (!isset($price)) {
sendEppError($conn, 2400, 'Command failed');
return;
}
// Update registrar
$stmt = $db->prepare("UPDATE registrar SET accountBalance = (accountBalance + ?) WHERE id = ?");
$stmt->execute([$price, $registrar_id]);
// 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 $name for period $addPeriod MONTH";
$stmt = $db->prepare("INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP, ?, ?)");
$stmt->execute([$registrar_id, $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 host WHERE domain_id = $domain_id");
$stmt = $db->prepare("DELETE FROM domain WHERE id = ?");
$stmt->execute([$domain_id]);
if ($stmt->errorCode() != "00000") {
sendEppError($conn, 2400, 'Command failed');
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 < DATE_ADD(renewedDate, INTERVAL 45 DAY)) LIMIT 1");
$stmt->execute([$domain_id]);
$autoRenewPeriod_id = $stmt->fetchColumn();
if ($autoRenewPeriod_id) {
$stmt = $db->prepare("SELECT m$autoRenewPeriod FROM domain_price WHERE tldid = ? AND command = 'renew' LIMIT 1");
$stmt->execute([$tldid]);
$price = $stmt->fetchColumn();
if (!isset($price)) {
sendEppError($conn, 2400, 'Command failed');
return;
}
// Update registrar
$stmt = $db->prepare("UPDATE registrar SET accountBalance = (accountBalance + ?) WHERE id = ?");
$stmt->execute([$price, $registrar_id]);
// 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 $name for period $autoRenewPeriod MONTH";
$stmt = $db->prepare("INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP, ?, ?)");
$stmt->execute([$registrar_id, $description, $price]);
}
} elseif ($rgpstatus === 'renewPeriod') {
$stmt = $db->prepare("SELECT id FROM domain WHERE id = ? AND (CURRENT_TIMESTAMP < DATE_ADD(renewedDate, INTERVAL 5 DAY)) LIMIT 1");
$stmt->execute([$domain_id]);
$renewPeriod_id = $stmt->fetchColumn();
if ($renewPeriod_id) {
$stmt = $db->prepare("SELECT m$renewPeriod FROM domain_price WHERE tldid = ? AND command = 'renew' LIMIT 1");
$stmt->execute([$tldid]);
$price = $stmt->fetchColumn();
if (!isset($price)) {
sendEppError($conn, 2400, 'Command failed');
return;
}
// Update registrar
$stmt = $db->prepare("UPDATE registrar SET accountBalance = (accountBalance + ?) WHERE id = ?");
$stmt->execute([$price, $registrar_id]);
// 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 $name for period $renewPeriod MONTH";
$stmt = $db->prepare("INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP, ?, ?)");
$stmt->execute([$registrar_id, $description, $price]);
}
} elseif ($rgpstatus === 'transferPeriod') {
$stmt = $db->prepare("SELECT id FROM domain WHERE id = ? AND (CURRENT_TIMESTAMP < 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) {
$stmt = $db->prepare("SELECT m$transferPeriod FROM domain_price WHERE tldid = ? AND command = 'renew' LIMIT 1");
$stmt->execute([$tldid]);
$price = $stmt->fetchColumn();
if (!isset($price)) {
sendEppError($conn, 2400, 'Command failed');
return;
}
// Update registrar
$stmt = $db->prepare("UPDATE registrar SET accountBalance = (accountBalance + ?) WHERE id = ?");
$stmt->execute([$price, $registrar_id]);
// 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 $name for period $transferPeriod MONTH";
$stmt = $db->prepare("INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP, ?, ?)");
$stmt->execute([$registrar_id, $description, $price]);
}
}
}
}
$response = [
'command' => 'delete_domain',
'resultCode' => 1001,
'lang' => 'en-US',
'message' => 'Command completed successfully; action pending',
'clTRID' => $clTRID,
'svTRID' => generateSvTRID(),
];
$epp = new EPP\EppWriter();
$xml = $epp->epp_writer($response);
sendEppResponse($conn, $xml);

View file

@ -114,7 +114,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
{
$table->del($connId);
$clTRID = (string) $xml->command->clTRID;
$response = [
'command' => 'logout',
'resultCode' => 1500,
@ -129,13 +129,13 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
$conn->close();
break;
}
case isset($xml->hello):
{
sendGreeting($conn);
break;
}
case isset($xml->command->poll):
{
$data = $table->get($connId);
@ -179,7 +179,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
processContactInfo($conn, $db, $xml);
break;
}
case isset($xml->command->delete) && isset($xml->command->delete->children('urn:ietf:params:xml:ns:contact-1.0')->delete):
{
$data = $table->get($connId);
@ -212,7 +212,18 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
processDomainInfo($conn, $db, $xml);
break;
}
case isset($xml->command->delete) && isset($xml->command->delete->children('urn:ietf:params:xml:ns:domain-1.0')->delete):
{
$data = $table->get($connId);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, 2202, 'Authorization error');
$conn->close();
}
processDomainDelete($conn, $db, $xml, $data['clid'], $c['db_type']);
break;
}
case isset($xml->command->check) && isset($xml->command->check->children('urn:ietf:params:xml:ns:host-1.0')->check):
{
$data = $table->get($connId);
@ -223,7 +234,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
processHostCheck($conn, $db, $xml);
break;
}
case isset($xml->command->create) && isset($xml->command->create->children('urn:ietf:params:xml:ns:host-1.0')->create):
{
$data = $table->get($connId);
@ -234,7 +245,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
processHostCreate($conn, $db, $xml, $data['clid'], $c['db_type']);
break;
}
case isset($xml->command->info) && isset($xml->command->info->children('urn:ietf:params:xml:ns:host-1.0')->info):
{
$data = $table->get($connId);
@ -245,7 +256,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
processHostInfo($conn, $db, $xml);
break;
}
case isset($xml->command->delete) && isset($xml->command->delete->children('urn:ietf:params:xml:ns:host-1.0')->delete):
{
$data = $table->get($connId);
@ -256,7 +267,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
processHostDelete($conn, $db, $xml, $data['clid'], $c['db_type']);
break;
}
case isset($xml->command->info) && isset($xml->command->info->children('https://namingo.org/epp/funds-1.0')->info):
{
$data = $table->get($connId);
@ -267,7 +278,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c) {
processFundsInfo($conn, $db, $xml, $data['clid']);
break;
}
case isset($xml->command->renew) && isset($xml->command->renew->children('urn:ietf:params:xml:ns:domain-1.0')->renew):
{
$data = $table->get($connId);