diff --git a/cp/app/Controllers/DomainsController.php b/cp/app/Controllers/DomainsController.php index a10baa4..62c05b0 100644 --- a/cp/app/Controllers/DomainsController.php +++ b/cp/app/Controllers/DomainsController.php @@ -610,7 +610,7 @@ class DomainsController extends Controller } else { $currentDateTime = new \DateTime(); $host_date = $currentDateTime->format('Y-m-d H:i:s.v'); - $host_id = $db->insert( + $db->insert( 'host', [ 'name' => $nameserver, @@ -620,6 +620,7 @@ class DomainsController extends Controller 'crdate' => $host_date ] ); + $host_id = $db->getlastInsertId(); $db->insert( 'domain_host_map', @@ -882,6 +883,10 @@ class DomainsController extends Controller JOIN contact c ON dcm.contact_id = c.id WHERE dcm.domain_id = ?'; $domainContacts = $db->select($domainContactsQuery, [$domain['id']]); + + $csrfTokenName = $this->container->get('csrf')->getTokenName(); + $csrfTokenValue = $this->container->get('csrf')->getTokenValue(); + return view($response,'admin/domains/updateDomain.twig', [ 'domain' => $domain, @@ -892,7 +897,9 @@ class DomainsController extends Controller 'domainHosts' => $domainHosts, 'domainContacts' => $domainContacts, 'registrar' => $registrars, - 'currentUri' => $uri + 'currentUri' => $uri, + 'csrfTokenName' => $csrfTokenName, + 'csrfTokenValue' => $csrfTokenValue ]); } else { // Domain does not exist, redirect to the domains view @@ -1214,7 +1221,7 @@ class DomainsController extends Controller } else { $currentDateTime = new \DateTime(); $host_date = $currentDateTime->format('Y-m-d H:i:s.v'); - $host_id = $db->insert( + $db->insert( 'host', [ 'name' => $nameserver, @@ -1224,6 +1231,7 @@ class DomainsController extends Controller 'crdate' => $host_date ] ); + $host_id = $db->getlastInsertId(); $db->insert( 'domain_host_map', @@ -1307,6 +1315,55 @@ class DomainsController extends Controller } } + public function domainDeleteHost(Request $request, Response $response) + { + $db = $this->container->get('db'); + $data = $request->getParsedBody(); + $uri = $request->getUri()->getPath(); + + if ($data['nameserver']) { + $host_id = $db->selectValue('SELECT id FROM host WHERE name = ?', + [ $data['nameserver'] ]); + $domain_id = $db->selectValue('SELECT domain_id FROM domain_host_map WHERE host_id = ?', + [ $host_id ]); + $domainName = $db->selectValue('SELECT name FROM domain WHERE id = ?', + [ $domain_id ]); + $db->delete( + 'domain_host_map', + [ + 'host_id' => $host_id, + 'domain_id' => $domain_id + ] + ); + + $this->container->get('flash')->addMessage('success', 'Host ' . $data['nameserver'] . ' 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 8162c7c..39f46a4 100644 --- a/cp/bootstrap/app.php +++ b/cp/bootstrap/app.php @@ -210,6 +210,9 @@ $csrfMiddleware = function ($request, $handler) use ($container) { if ($path && $path === '/webauthn/login/verify') { return $handler->handle($request); } + if ($path && $path === '/domain/deletehost') { + 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 8d51128..a73fe28 100644 --- a/cp/resources/views/admin/domains/updateDomain.twig +++ b/cp/resources/views/admin/domains/updateDomain.twig @@ -104,10 +104,10 @@ {% for host in domainHosts %}
- -
- -
+
+ + +
{% endfor %} @@ -228,6 +228,31 @@