Added ability to disable registrar accreditation permanently

This commit is contained in:
Pinga 2025-02-03 15:53:32 +02:00
parent 6e3a04cda4
commit aae8cad364
5 changed files with 233 additions and 1 deletions

View file

@ -1265,6 +1265,131 @@ class RegistrarsController extends Controller
}
}
public function transferRegistrar(Request $request, Response $response)
{
if ($_SESSION["auth_roles"] != 0) {
return $response->withHeader('Location', '/dashboard')->withStatus(302);
}
// Retrieve POST data
$data = $request->getParsedBody();
$db = $this->container->get('db');
if (!empty($_SESSION['registrars_to_update'])) {
$registrar = $db->selectRow('SELECT id, name, clid FROM registrar WHERE clid = ?',
[ $_SESSION['registrars_to_update'][0] ]);
$registrars = $db->select("SELECT id, clid, name FROM registrar");
} else {
$this->container->get('flash')->addMessage('error', 'No registrar specified for update');
return $response->withHeader('Location', '/registrars')->withStatus(302);
}
return view($response,'admin/registrars/transferRegistrar.twig', [
'registrars' => $registrars,
'registrar' => $registrar,
]);
}
public function transferRegistrarProcess(Request $request, Response $response)
{
if ($_SESSION["auth_roles"] != 0) {
return $response->withHeader('Location', '/dashboard')->withStatus(302);
}
if ($request->getMethod() === 'POST') {
// Retrieve POST data
$data = $request->getParsedBody();
$db = $this->container->get('db');
if (isset($data['registrar'], $_SESSION['registrars_to_update'])) {
$registrar = $db->selectRow('SELECT id, name, clid FROM registrar WHERE clid = ?',
[ $_SESSION['registrars_to_update'][0] ]);
if ((int) $data['registrar'] === (int) $registrar['id']) {
$this->container->get('flash')->addMessage('error', 'You cannot transfer registrar objects to the current registrar; please select a different registrar to proceed');
return $response->withHeader('Location', '/registrars')->withStatus(302);
}
} else {
$this->container->get('flash')->addMessage('error', 'An unexpected error occurred during the registrar transfer process. Please restart the process to ensure proper completion');
return $response->withHeader('Location', '/registrars')->withStatus(302);
}
$db->beginTransaction();
try {
$db->update(
'application',
[
'clid' => $data['registrar']
],
[
'clid' => $registrar['id']
]
);
$db->update(
'contact',
[
'clid' => $data['registrar']
],
[
'clid' => $registrar['id']
]
);
$db->update(
'domain',
[
'clid' => $data['registrar']
],
[
'clid' => $registrar['id']
]
);
$db->update(
'host',
[
'clid' => $data['registrar']
],
[
'clid' => $registrar['id']
]
);
$db->delete(
'registrar_users',
[
'registrar_id' => $registrar['id']
]
);
$db->update(
'registrar',
[
'pw' => generateAuthInfo()
],
[
'id' => $registrar['id']
]
);
$db->commit();
} catch (Exception $e) {
$db->rollBack();
$this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage());
return $response->withHeader('Location', '/registrars')->withStatus(302);
}
unset($_SESSION['registrars_to_update']);
$this->container->get('flash')->addMessage('success', 'Registrar ' . $data['name'] . ' has been disabled, and all associated objects have been successfully transferred away');
return $response->withHeader('Location', '/registrars')->withStatus(302);
} else {
// Redirect to the registrars view
unset($_SESSION['registrars_to_update']);
return $response->withHeader('Location', '/registrars')->withStatus(302);
}
}
public function impersonateRegistrar(Request $request, Response $response, $args)
{
if ($_SESSION["auth_roles"] != 0) {

View file

@ -0,0 +1,83 @@
{% extends "layouts/app.twig" %}
{% block title %}{{ __('Registrar Transfer') }}{% endblock %}
{% block content %}
<div class="page-wrapper">
<!-- Page header -->
<div class="page-header d-print-none">
<div class="container-xl">
<div class="row g-2 align-items-center">
<div class="col">
<!-- Page pre-title -->
<div class="page-pretitle">
{{ __('Overview') }}
</div>
<h2 class="page-title">
{{ __('Registrar Transfer') }}
</h2>
</div>
</div>
</div>
</div>
<!-- Page body -->
<div class="page-body">
<div class="container-xl">
<div class="col-12">
<div class="card mb-3">
<div class="card-header">
<h3 class="card-title">{{ __('Current') }} {{ __('Registrar') }} {{ registrar.name }}</h3>
<div class="card-actions">
<form action="/registrar/process" method="post">
{{ csrf.field | raw }}
<a href="/registrar/update/{{ registrar.clid }}" class="btn btn-success">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 11l-4 4l4 4m-4 -4h11a4 4 0 0 0 0 -8h-1" /></svg>
{{ __('Back') }}
</a>
<button type="submit" class="btn btn-danger">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9.615 20h-2.615a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8" /><path d="M14 19l2 2l4 -4" /><path d="M9 8h4" /><path d="M9 12h2" /></svg>
{{ __('Transfer Registrar') }}
</button>
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
{% if registrars %}
<div class="mb-3">
<label for="registrarDropdown" class="form-label required">{{ __('Gaining Registrar') }}</label>
<select id="registrarDropdown" name="registrar" class="form-select">
{% for registrar in registrars %}
<option value="{{ registrar.id }}">{{ registrar.name }}</option>
{% endfor %}
</select>
</div>
{% endif %}
<div class="alert alert-danger shadow-sm border-danger" role="alert">
<h2 class="alert-heading fw-bold text-danger">
⚠️ {{ __('Final Confirmation Required') }}
</h2>
<p class="fs-5">
{{ __('This action will') }} <strong class="text-warning">{{ __('initiate the transfer') }}</strong> {{ __('of all
registrar-related objects to another accredited registrar.') }}
</p>
<p class="fs-5 text-danger">
<strong>{{ __('The current registrar will be permanently closed') }}</strong> {{ __('after the transfer is complete.') }}
</p>
<hr class="my-3 border-danger">
<p class="fs-6 text-muted">
{{ __('Please') }} <strong class="text-danger">{{ __('proceed with extreme caution') }}</strong> {{ __('as this action is') }}
<u>{{ __('irreversible') }}</u>.
</p>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
{% include 'partials/footer.twig' %}
</div>
{% endblock %}

View file

@ -483,6 +483,28 @@
</div>
</div>
</form>
<div class="col-lg-4 offset-lg-8 col-md-6 offset-md-6 col-12">
<div class="card bg-danger text-white">
<div class="card-stamp">
<div class="card-stamp-icon bg-white text-danger">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><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" /><path d="M12 8v4" /><path d="M12 16h.01" /></svg>
</div>
</div>
<div class="card-body">
<h3 class="card-title">{{ __('Registrar Accreditation Transfer') }}</h3>
<p>
{{ __('This action will initiate the transfer of all registrar-related objects to another accredited registrar.
The current registrar will be') }} <strong>{{ __('permanently closed') }}</strong> {{ __('after the transfer is complete.
Please proceed with caution as this action is irreversible.') }}
</p>
<a href="/registrar/transfer" class="btn btn-warning">
{{ __('Initiate Transfer') }}
</a>
</div>
</div>
</div>
</div>
</div>
</div>

View file

@ -147,7 +147,7 @@
</a>
</div>
</li>
{% if roles == 0 %}<li {{ is_current_url('registrars') or is_current_url('listUsers') or is_current_url('createUser') or is_current_url('registrarcreate') or 'registrar/' in currentUri ? 'class="nav-item dropdown active"' : 'class="nav-item dropdown"' }}>
{% if roles == 0 %}<li {{ is_current_url('registrars') or is_current_url('listUsers') or is_current_url('transferRegistrar') or is_current_url('createUser') or is_current_url('registrarcreate') or 'registrar/' in currentUri ? 'class="nav-item dropdown active"' : 'class="nav-item dropdown"' }}>
<a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown" data-bs-auto-close="outside" role="button" aria-expanded="false">
<span class="nav-link-icon d-md-none d-lg-inline-block"><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="M12 13a3 3 0 1 0 0 -6a3 3 0 0 0 0 6z"></path><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"></path><path d="M6 20.05v-.05a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v.05"></path></svg>
</span>

View file

@ -96,6 +96,8 @@ $app->group('', function ($route) {
$route->get('/registrar', RegistrarsController::class .':registrar')->setName('registrar');
$route->map(['GET', 'POST'], '/registrar/edit', RegistrarsController::class .':editRegistrar')->setName('editRegistrar');
$route->get('/registrar/check', RegistrarsController::class . ':oteCheck')->setName('oteCheck');
$route->map(['GET', 'POST'], '/registrar/transfer', RegistrarsController::class . ':transferRegistrar')->setName('transferRegistrar');
$route->map(['GET', 'POST'], '/registrar/process', RegistrarsController::class . ':transferRegistrarProcess')->setName('transferRegistrarProcess');
$route->get('/registrar/impersonate/{registrar}', RegistrarsController::class . ':impersonateRegistrar')->setName('impersonateRegistrar');
$route->get('/leave_impersonation', RegistrarsController::class . ':leave_impersonation')->setName('leave_impersonation');