mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-14 16:46:59 +02:00
Hostnames can now be deleted; fixes
This commit is contained in:
parent
42fd21e7a5
commit
fb19e13297
4 changed files with 94 additions and 8 deletions
|
@ -610,7 +610,7 @@ class DomainsController extends Controller
|
||||||
} else {
|
} else {
|
||||||
$currentDateTime = new \DateTime();
|
$currentDateTime = new \DateTime();
|
||||||
$host_date = $currentDateTime->format('Y-m-d H:i:s.v');
|
$host_date = $currentDateTime->format('Y-m-d H:i:s.v');
|
||||||
$host_id = $db->insert(
|
$db->insert(
|
||||||
'host',
|
'host',
|
||||||
[
|
[
|
||||||
'name' => $nameserver,
|
'name' => $nameserver,
|
||||||
|
@ -620,6 +620,7 @@ class DomainsController extends Controller
|
||||||
'crdate' => $host_date
|
'crdate' => $host_date
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
$host_id = $db->getlastInsertId();
|
||||||
|
|
||||||
$db->insert(
|
$db->insert(
|
||||||
'domain_host_map',
|
'domain_host_map',
|
||||||
|
@ -883,6 +884,10 @@ class DomainsController extends Controller
|
||||||
WHERE dcm.domain_id = ?';
|
WHERE dcm.domain_id = ?';
|
||||||
$domainContacts = $db->select($domainContactsQuery, [$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', [
|
return view($response,'admin/domains/updateDomain.twig', [
|
||||||
'domain' => $domain,
|
'domain' => $domain,
|
||||||
'domainStatus' => $domainStatus,
|
'domainStatus' => $domainStatus,
|
||||||
|
@ -892,7 +897,9 @@ class DomainsController extends Controller
|
||||||
'domainHosts' => $domainHosts,
|
'domainHosts' => $domainHosts,
|
||||||
'domainContacts' => $domainContacts,
|
'domainContacts' => $domainContacts,
|
||||||
'registrar' => $registrars,
|
'registrar' => $registrars,
|
||||||
'currentUri' => $uri
|
'currentUri' => $uri,
|
||||||
|
'csrfTokenName' => $csrfTokenName,
|
||||||
|
'csrfTokenValue' => $csrfTokenValue
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
// Domain does not exist, redirect to the domains view
|
// Domain does not exist, redirect to the domains view
|
||||||
|
@ -1214,7 +1221,7 @@ class DomainsController extends Controller
|
||||||
} else {
|
} else {
|
||||||
$currentDateTime = new \DateTime();
|
$currentDateTime = new \DateTime();
|
||||||
$host_date = $currentDateTime->format('Y-m-d H:i:s.v');
|
$host_date = $currentDateTime->format('Y-m-d H:i:s.v');
|
||||||
$host_id = $db->insert(
|
$db->insert(
|
||||||
'host',
|
'host',
|
||||||
[
|
[
|
||||||
'name' => $nameserver,
|
'name' => $nameserver,
|
||||||
|
@ -1224,6 +1231,7 @@ class DomainsController extends Controller
|
||||||
'crdate' => $host_date
|
'crdate' => $host_date
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
$host_id = $db->getlastInsertId();
|
||||||
|
|
||||||
$db->insert(
|
$db->insert(
|
||||||
'domain_host_map',
|
'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)
|
public function renewDomain(Request $request, Response $response, $args)
|
||||||
{
|
{
|
||||||
if ($request->getMethod() === 'POST') {
|
if ($request->getMethod() === 'POST') {
|
||||||
|
|
|
@ -210,6 +210,9 @@ $csrfMiddleware = function ($request, $handler) use ($container) {
|
||||||
if ($path && $path === '/webauthn/login/verify') {
|
if ($path && $path === '/webauthn/login/verify') {
|
||||||
return $handler->handle($request);
|
return $handler->handle($request);
|
||||||
}
|
}
|
||||||
|
if ($path && $path === '/domain/deletehost') {
|
||||||
|
return $handler->handle($request);
|
||||||
|
}
|
||||||
|
|
||||||
// If not skipped, apply the CSRF Guard
|
// If not skipped, apply the CSRF Guard
|
||||||
return $csrf->process($request, $handler);
|
return $csrf->process($request, $handler);
|
||||||
|
|
|
@ -104,9 +104,9 @@
|
||||||
<label class="form-label">{{ __('Nameservers') }} <button type="button" id="addNameserver" class="btn btn-success btn-sm mb-2">+</button> <button type="button" id="removeNameserver" class="btn btn-danger btn-sm mb-2">-</button></label>
|
<label class="form-label">{{ __('Nameservers') }} <button type="button" id="addNameserver" class="btn btn-success btn-sm mb-2">+</button> <button type="button" id="removeNameserver" class="btn btn-danger btn-sm mb-2">-</button></label>
|
||||||
{% for host in domainHosts %}
|
{% for host in domainHosts %}
|
||||||
<div class="nameserver-group mb-1 row">
|
<div class="nameserver-group mb-1 row">
|
||||||
<!-- Nameserver -->
|
<div class="input-group mb-1">
|
||||||
<div class="col-md-12">
|
<input type="text" class="form-control" placeholder="{{ __('Nameserver') }} {{ loop.index }}" value="{{ host.name }}" autocapitalize="none" disabled>
|
||||||
<input type="text" class="form-control mb-1" placeholder="{{ __('Nameserver') }} {{ loop.index }}" name="nameserver[]" value="{{ host.name }}" autocapitalize="none">
|
<button type="button" class="btn btn-secondary btn-icon" onclick="sendRequest('{{ host.name }}')" title="Delete nameserver"><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 d="M10 10l4 4m0 -4l-4 4" /><path d="M12 3c7.2 0 9 1.8 9 9s-1.8 9 -9 9s-9 -1.8 -9 -9s1.8 -9 9 -9z" /></svg></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -228,6 +228,31 @@
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
|
var csrfTokenName = "{{ csrfTokenName }}";
|
||||||
|
var csrfTokenValue = "{{ csrfTokenValue }}";
|
||||||
|
|
||||||
|
function sendRequest(nameserver) {
|
||||||
|
var formData = new FormData();
|
||||||
|
formData.append('nameserver', nameserver);
|
||||||
|
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('POST', '/domain/deletehost');
|
||||||
|
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() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
|
||||||
const addNameserverBtn = document.getElementById('addNameserver');
|
const addNameserverBtn = document.getElementById('addNameserver');
|
||||||
|
@ -265,7 +290,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
|
||||||
// Remove nameserver group
|
// Remove nameserver group
|
||||||
removeNameserverBtn.addEventListener('click', function() {
|
removeNameserverBtn.addEventListener('click', function() {
|
||||||
if (nameserverCount > 2) {
|
if (nameserverCount > {{ domainHosts|length }}) {
|
||||||
const lastGroup = nameserverFields.querySelector('.nameserver-group:last-child');
|
const lastGroup = nameserverFields.querySelector('.nameserver-group:last-child');
|
||||||
if (lastGroup) {
|
if (lastGroup) {
|
||||||
nameserverFields.removeChild(lastGroup);
|
nameserverFields.removeChild(lastGroup);
|
||||||
|
|
|
@ -44,6 +44,7 @@ $app->group('', function ($route) {
|
||||||
$route->get('/domain/view/{domain}', DomainsController::class . ':viewDomain')->setName('viewDomain');
|
$route->get('/domain/view/{domain}', DomainsController::class . ':viewDomain')->setName('viewDomain');
|
||||||
$route->get('/domain/update/{domain}', DomainsController::class . ':updateDomain')->setName('updateDomain');
|
$route->get('/domain/update/{domain}', DomainsController::class . ':updateDomain')->setName('updateDomain');
|
||||||
$route->post('/domain/update', DomainsController::class . ':updateDomainProcess')->setName('updateDomainProcess');
|
$route->post('/domain/update', DomainsController::class . ':updateDomainProcess')->setName('updateDomainProcess');
|
||||||
|
$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/renew/{domain}', DomainsController::class . ':renewDomain')->setName('renewDomain');
|
||||||
$route->map(['GET', 'POST'], '/domain/delete/{domain}', DomainsController::class . ':deleteDomain')->setName('deleteDomain');
|
$route->map(['GET', 'POST'], '/domain/delete/{domain}', DomainsController::class . ':deleteDomain')->setName('deleteDomain');
|
||||||
$route->map(['GET', 'POST'], '/domain/restore/{domain}', DomainsController::class . ':restoreDomain')->setName('restoreDomain');
|
$route->map(['GET', 'POST'], '/domain/restore/{domain}', DomainsController::class . ':restoreDomain')->setName('restoreDomain');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue