From 9a45cdab9e7486b36d09b7161e081dfc5dc7e5b5 Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Fri, 15 Dec 2023 08:21:11 +0200 Subject: [PATCH] Domain update improvements, dnssec records can be deleted now --- cp/app/Controllers/DomainsController.php | 48 +++++++++++ cp/bootstrap/app.php | 3 + .../views/admin/domains/updateDomain.twig | 82 ++++++++++++++++--- cp/routes/web.php | 1 + 4 files changed, 121 insertions(+), 13 deletions(-) diff --git a/cp/app/Controllers/DomainsController.php b/cp/app/Controllers/DomainsController.php index 138b710..a7d7aab 100644 --- a/cp/app/Controllers/DomainsController.php +++ b/cp/app/Controllers/DomainsController.php @@ -1433,6 +1433,54 @@ class DomainsController extends Controller } } + public function domainDeleteSecdns(Request $request, Response $response) + { + $db = $this->container->get('db'); + $data = $request->getParsedBody(); + $uri = $request->getUri()->getPath(); + + if ($data['record']) { + $record = filter_var($data['record'], FILTER_SANITIZE_NUMBER_INT); + $domain_id = filter_var($data['domain_id'], FILTER_SANITIZE_NUMBER_INT); + + $domainName = $db->selectValue('SELECT name FROM domain WHERE id = ?', + [ $domain_id ]); + $db->delete( + 'secdns', + [ + 'id' => $record, + 'domain_id' => $domain_id + ] + ); + + $this->container->get('flash')->addMessage('success', 'Record has been removed from domain successfully'); + + $jsonData = json_encode([ + 'success' => true, + 'redirect' => '/domain/update/'.$domainName + ]); + + $response = new \Nyholm\Psr7\Response( + 200, // Status code + ['Content-Type' => 'application/json'], // Headers + $jsonData // Body + ); + + return $response; + } else { + $jsonData = json_encode([ + 'success' => false, + 'error' => 'An error occurred while processing your request.' + ]); + + return new \Nyholm\Psr7\Response( + 400, + ['Content-Type' => 'application/json'], + $jsonData + ); + } + } + public function renewDomain(Request $request, Response $response, $args) { if ($request->getMethod() === 'POST') { diff --git a/cp/bootstrap/app.php b/cp/bootstrap/app.php index 39f46a4..27b00d5 100644 --- a/cp/bootstrap/app.php +++ b/cp/bootstrap/app.php @@ -213,6 +213,9 @@ $csrfMiddleware = function ($request, $handler) use ($container) { if ($path && $path === '/domain/deletehost') { return $handler->handle($request); } + if ($path && $path === '/domain/deletesecdns') { + return $handler->handle($request); + } // If not skipped, apply the CSRF Guard return $csrf->process($request, $handler); diff --git a/cp/resources/views/admin/domains/updateDomain.twig b/cp/resources/views/admin/domains/updateDomain.twig index a73fe28..46715df 100644 --- a/cp/resources/views/admin/domains/updateDomain.twig +++ b/cp/resources/views/admin/domains/updateDomain.twig @@ -126,22 +126,55 @@
- {% for row in domainSecdns %} - - {% for key, value in row %} - {% if key not in ['id', 'domain_id', 'maxsiglife'] %} - + + + {% set dsDataExists = false %} + {% set keyDataExists = false %} + + {% for row in domainSecdns %} + {% if row.interface == 'dsData' %} + {% set dsDataExists = true %} + {% elseif row.interface == 'keyData' %} + {% set keyDataExists = true %} + {% endif %} + {% endfor %} + + + {% if dsDataExists %} + + + + {% endif %} - {% endfor %} - - - {% for key, value in row %} - {% if key not in ['id', 'domain_id', 'maxsiglife'] %} - + + + {% if keyDataExists %} + + + + {% endif %} + + + + + {% for row in domainSecdns %} + + {% if row.interface == 'dsData' %} + + + + + {% elseif row.interface == 'keyData' %} + + + + + {% endif %} + + {% endfor %} - - {% endfor %} +
{{ key }}
KeytagAlgorithmDigest TypeDigest
{{ value }}FlagsProtocolKeydata AlgorithmPublic Key 
{{ row.keytag }}{{ row.alg }}{{ row.digesttype }}{{ row.digest }}{{ row.flags }}{{ row.protocol }}{{ row.keydata_alg }}{{ row.pubkey }}
@@ -253,6 +286,29 @@ function sendRequest(nameserver) { xhr.send(formData); } +function sendSecRequest(record,domain_id) { + var formData = new FormData(); + formData.append('record', record); + formData.append('domain_id', domain_id); + + var xhr = new XMLHttpRequest(); + xhr.open('POST', '/domain/deletesecdns'); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + var response = JSON.parse(xhr.responseText); + if (xhr.status == 200 && response.success) { + // Redirect to the provided URL + window.location.href = response.redirect; + } else { + // Handle error + console.error('Error: ' + response.error); + alert('Error: ' + response.error); // Display error message to the user + } + } + }; + xhr.send(formData); +} + document.addEventListener("DOMContentLoaded", function() { const addNameserverBtn = document.getElementById('addNameserver'); diff --git a/cp/routes/web.php b/cp/routes/web.php index c06e25c..8a49ec5 100644 --- a/cp/routes/web.php +++ b/cp/routes/web.php @@ -44,6 +44,7 @@ $app->group('', function ($route) { $route->get('/domain/view/{domain}', DomainsController::class . ':viewDomain')->setName('viewDomain'); $route->get('/domain/update/{domain}', DomainsController::class . ':updateDomain')->setName('updateDomain'); $route->post('/domain/update', DomainsController::class . ':updateDomainProcess')->setName('updateDomainProcess'); + $route->post('/domain/deletesecdns', DomainsController::class . ':domainDeleteSecdns')->setName('domainDeleteSecdns'); $route->post('/domain/deletehost', DomainsController::class . ':domainDeleteHost')->setName('domainDeleteHost'); $route->map(['GET', 'POST'], '/domain/renew/{domain}', DomainsController::class . ':renewDomain')->setName('renewDomain'); $route->map(['GET', 'POST'], '/domain/delete/{domain}', DomainsController::class . ':deleteDomain')->setName('deleteDomain');