Added domain delete; small epp fix

This commit is contained in:
Pinga 2023-12-06 12:20:37 +02:00
parent 4fd278faa7
commit c970ff646d
3 changed files with 310 additions and 16 deletions

View file

@ -1513,9 +1513,312 @@ class DomainsController extends Controller
}
}
public function deleteDomain(Request $request, Response $response)
public function deleteDomain(Request $request, Response $response, $args)
{
return view($response,'admin/domains/deleteDomain.twig');
// if ($request->getMethod() === 'POST') {
$db = $this->container->get('db');
// Get the current URI
$uri = $request->getUri()->getPath();
if ($args) {
$domain = $db->selectRow('SELECT id, name, tldid, registrant, crdate, exdate, update, clid, crid, upid, trdate, trstatus, reid, redate, acid, acdate, rgpstatus, addPeriod, autoRenewPeriod, renewPeriod, renewedDate, transferPeriod FROM domain WHERE name = ?',
[ $args ]);
$domainName = $domain['name'];
$domain_id = $domain['id'];
$tldid = $domain['tldid'];
$registrant = $domain['registrant'];
$crdate = $domain['crdate'];
$exdate = $domain['exdate'];
$update = $domain['update'];
$registrar_id_domain = $domain['clid'];
$crid = $domain['crid'];
$upid = $domain['upid'];
$trdate = $domain['trdate'];
$trstatus = $domain['trstatus'];
$reid = $domain['reid'];
$redate = $domain['redate'];
$acid = $domain['acid'];
$acdate = $domain['acdate'];
$rgpstatus = $domain['rgpstatus'];
$addPeriod = $domain['addPeriod'];
$autoRenewPeriod = $domain['autoRenewPeriod'];
$renewPeriod = $domain['renewPeriod'];
$renewedDate = $domain['renewedDate'];
$transferPeriod = $domain['transferPeriod'];
list($label, $domain_extension) = explode('.', $domainName, 2);
$result = $db->select('SELECT id, tld FROM domain_tld');
foreach ($result as $row) {
if ('.' . strtoupper($domain_extension) === strtoupper($row['tld'])) {
$tld_id = $row['id'];
break;
}
}
$result = $db->selectRow('SELECT registrar_id FROM registrar_users WHERE user_id = ?', [$_SESSION['auth_user_id']]);
if ($_SESSION["auth_roles"] != 0) {
$clid = $result['registrar_id'];
} else {
$clid = $registrar_id_domain;
}
$results = $db->select(
'SELECT status FROM domain_status WHERE domain_id = ?',
[ $domain_id ]
);
foreach ($results as $row) {
$status = $row['status'];
if (preg_match('/.*(UpdateProhibited|DeleteProhibited)$/', $status) || preg_match('/^pending/', $status)) {
$this->container->get('flash')->addMessage('error', 'It has a status that does not allow renew, first change the status');
return $response->withHeader('Location', '/domains')->withStatus(302);
}
}
$grace_period = 30;
$db->delete(
'domain_status',
[
'domain_id' => $domain_id
]
);
$db->exec(
'UPDATE domain SET rgpstatus = ?, delTime = DATE_ADD(CURRENT_TIMESTAMP(3), INTERVAL ? DAY) WHERE id = ?',
['redemptionPeriod', $grace_period, $domain_id]
);
$db->insert(
'domain_status',
[
'domain_id' => $domain_id,
'authinfo' => 'pendingDelete'
]
);
if ($rgpstatus) {
if ($rgpstatus === 'addPeriod') {
$addPeriod_id = $db->selectValue(
'SELECT id FROM domain WHERE id = ? AND (CURRENT_TIMESTAMP(3) < DATE_ADD(crdate, INTERVAL 5 DAY)) LIMIT 1',
[
$domain_id
]
);
if ($addPeriod_id) {
$priceColumn = "m" . $addPeriod;
$price = $db->selectValue(
'SELECT ' . $db->quoteIdentifier($priceColumn) . ' FROM domain_price WHERE tldid = ? AND command = "create" LIMIT 1',
[$tld_id]
);
if (!$price) {
$this->container->get('flash')->addMessage('error', 'The price, period and currency for such TLD are not declared');
return $response->withHeader('Location', '/domains')->withStatus(302);
}
$db->exec(
'UPDATE registrar SET accountBalance = accountBalance + ? WHERE id = ?',
[$price, $clid]
);
$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(
'INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP(3), ?, ?)',
[$clid, $description, $price]
);
$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(
'domain_host_map',
[
'host_id' => $host_id
]
);
}
// Delete domain related records
$db->delete(
'domain_contact_map',
[
'domain_id' => $domain_id
]
);
$db->delete(
'domain_host_map',
[
'domain_id' => $domain_id
]
);
$db->delete(
'domain_authInfo',
[
'domain_id' => $domain_id
]
);
$db->delete(
'domain_status',
[
'domain_id' => $domain_id
]
);
$db->delete(
'host',
[
'domain_id' => $domain_id
]
);
$db->delete(
'secdns',
[
'domain_id' => $domain_id
]
);
$db->delete(
'domain',
[
'id' => $domain_id
]
);
$curdate_id = $db->selectValue(
'SELECT id FROM statistics WHERE date = CURDATE()'
);
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') {
$autoRenewPeriod_id = $db->selectValue(
'SELECT id FROM domain WHERE id = ? AND (CURRENT_TIMESTAMP(3) < DATE_ADD(renewedDate, INTERVAL 45 DAY)) LIMIT 1',
[
$domain_id
]
);
if ($autoRenewPeriod_id) {
$priceColumn = "m" . $autoRenewPeriod;
$price = $db->selectValue(
'SELECT ' . $db->quoteIdentifier($priceColumn) . ' FROM domain_price WHERE tldid = ? AND command = "renew" LIMIT 1',
[$tld_id]
);
if (!$price) {
$this->container->get('flash')->addMessage('error', 'The price, period and currency for such TLD are not declared');
return $response->withHeader('Location', '/domains')->withStatus(302);
}
$db->exec(
'UPDATE registrar SET accountBalance = accountBalance + ? WHERE id = ?',
[$price, $clid]
);
$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";
$db->exec(
'INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP(3), ?, ?)',
[$clid, $description, $price]
);
}
} elseif ($rgpstatus === 'renewPeriod') {
$renewPeriod_id = $db->selectValue(
'SELECT id FROM domain WHERE id = ? AND (CURRENT_TIMESTAMP(3) < DATE_ADD(renewedDate, INTERVAL 5 DAY)) LIMIT 1',
[
$domain_id
]
);
if ($renewPeriod_id) {
$priceColumn = "m" . $renewPeriod;
$price = $db->selectValue(
'SELECT ' . $db->quoteIdentifier($priceColumn) . ' FROM domain_price WHERE tldid = ? AND command = "renew" LIMIT 1',
[$tld_id]
);
if (!$price) {
$this->container->get('flash')->addMessage('error', 'The price, period and currency for such TLD are not declared');
return $response->withHeader('Location', '/domains')->withStatus(302);
}
$db->exec(
'UPDATE registrar SET accountBalance = accountBalance + ? WHERE id = ?',
[$price, $clid]
);
$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";
$db->exec(
'INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP(3), ?, ?)',
[$clid, $description, $price]
);
}
} elseif ($rgpstatus === 'transferPeriod') {
$transferPeriod_id = $db->selectValue(
'SELECT id FROM domain WHERE id = ? AND (CURRENT_TIMESTAMP(3) < DATE_ADD(trdate, INTERVAL 5 DAY)) LIMIT 1',
[
$domain_id
]
);
if ($transferPeriod_id) {
$priceColumn = "m" . $transferPeriod;
$price = $db->selectValue(
'SELECT ' . $db->quoteIdentifier($priceColumn) . ' FROM domain_price WHERE tldid = ? AND command = "renew" LIMIT 1',
[$tld_id]
);
if (!$price) {
$this->container->get('flash')->addMessage('error', 'The price, period and currency for such TLD are not declared');
return $response->withHeader('Location', '/domains')->withStatus(302);
}
$db->exec(
'UPDATE registrar SET accountBalance = accountBalance + ? WHERE id = ?',
[$price, $clid]
);
$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";
$db->exec(
'INSERT INTO payment_history (registrar_id, date, description, amount) VALUES(?, CURRENT_TIMESTAMP(3), ?, ?)',
[$clid, $description, $price]
);
}
}
}
$this->container->get('flash')->addMessage('success', 'Domain ' . $domainName . ' deleted successfully');
return $response->withHeader('Location', '/domains')->withStatus(302);
} else {
// Redirect to the domains view
return $response->withHeader('Location', '/domains')->withStatus(302);
}
//}
}
public function listTransfers(Request $request, Response $response)

View file

@ -5,13 +5,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.6.0/jspdf.plugin.autotable.min.js"></script>
<script>
var table;
document.querySelector("#domainTable").addEventListener('click', function(e) {
if (e.target.matches('.delete-btn')) {
let id = e.target.getAttribute('data-id');
deleteRecord(id);
}
});
document.addEventListener("DOMContentLoaded", function(){
function domainLinkFormatter(cell){
var value = cell.getValue();
@ -22,7 +16,7 @@
return `
<a class="btn btn-primary btn-icon" href="domain/update/${cell.getRow().getData().name}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1"></path><path d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z"></path><path d="M16 5l3 3"></path></svg></a>
<a class="btn btn-secondary btn-icon" href="domain/renew/${cell.getRow().getData().name}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4"></path><path d="M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4"></path></svg></a>
<button class="btn btn-danger btn-icon delete-btn" data-id="${cell.getRow().getData().id}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M4 7h16"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12"></path><path d="M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path><path d="M10 12l4 4m0 -4l-4 4"></path></svg></button>
<a class="btn btn-danger btn-icon" href="domain/delete/${cell.getRow().getData().name}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M4 7h16"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12"></path><path d="M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path><path d="M10 12l4 4m0 -4l-4 4"></path></svg></a>
`;
}
@ -116,11 +110,7 @@
updateSearchTerm(searchInput.value);
});
});
function deleteRecord(id) {
console.log("Deleting record with ID: " + id);
}
function downloadCSV() {
table.download("csv", "data.csv");
}

View file

@ -173,7 +173,7 @@ function processDomainDelete($conn, $db, $xml, $clid, $database_type, $trans) {
sendEppError($conn, $db, 2003, 'Please specify the domain name that will be deleted', $clTRID, $trans);
return;
}
if ($database_type === 'mysql') {
$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");
} elseif ($database_type === 'pgsql') {
@ -285,6 +285,7 @@ function processDomainDelete($conn, $db, $xml, $clid, $database_type, $trans) {
$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 = ?");