diff --git a/cp/app/Controllers/SystemController.php b/cp/app/Controllers/SystemController.php index 0025797..26c7c58 100644 --- a/cp/app/Controllers/SystemController.php +++ b/cp/app/Controllers/SystemController.php @@ -7,6 +7,7 @@ use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Container\ContainerInterface; use Respect\Validation\Validator as v; use League\ISO3166\ISO3166; +use Ramsey\Uuid\Uuid; class SystemController extends Controller { @@ -1306,27 +1307,93 @@ class SystemController extends Controller 'currentUri' => $uri ]); } - + + public function generateTokens(Request $request, Response $response) + { + if ($_SESSION["auth_roles"] != 0) { + return $response->withHeader('Location', '/dashboard')->withStatus(302); + } + + $db = $this->container->get('db'); + + try { + $currentDateTime = new \DateTime(); + $crdate = $currentDateTime->format('Y-m-d H:i:s.v'); // Current timestamp + + $db->beginTransaction(); + + for ($i = 0; $i < 10; $i++) { + $uuid = Uuid::uuid4()->toString(); + + $db->insert('allocation_tokens', [ + 'token' => $uuid, + 'domain_name' => null, + 'tokenStatus' => 'new', + 'tokenType' => 'simple', + 'crdate' => $crdate + ]); + } + + $db->commit(); + + $this->container->get('flash')->addMessage('success', '10 tokens successfully created'); + return $response->withHeader('Location', '/registry/tokens')->withStatus(302); + } catch (Exception $e) { + $db->rollBack(); + $this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage()); + return $response->withHeader('Location', '/registry/tokens')->withStatus(302); + } + } + public function manageTokens(Request $request, Response $response) { if ($_SESSION["auth_roles"] != 0) { return $response->withHeader('Location', '/dashboard')->withStatus(302); } - if ($request->getMethod() === 'POST') { - return $response->withHeader('Location', '/dashboard')->withStatus(302); - } - - $db = $this->container->get('db'); $uri = $request->getUri()->getPath(); - $tokens = $db->select("SELECT * FROM allocation_tokens"); return view($response,'admin/system/manageTokens.twig', [ - 'tokens' => $tokens, 'currentUri' => $uri ]); } - + + public function deleteToken(Request $request, Response $response, $args) + { + if ($_SESSION["auth_roles"] != 0) { + return $response->withHeader('Location', '/dashboard')->withStatus(302); + } + + // if ($request->getMethod() === 'POST') { + $db = $this->container->get('db'); + // Get the current URI + $uri = $request->getUri()->getPath(); + + if ($args) { + $args = trim($args); + + if (!preg_match('/^[a-zA-Z0-9\-]+$/', $args)) { + $this->container->get('flash')->addMessage('error', 'Invalid token format'); + return $response->withHeader('Location', '/registry/tokens')->withStatus(302); + } + + $db->delete( + 'allocation_tokens', + [ + 'token' => $args + ] + ); + + $this->container->get('flash')->addMessage('success', 'Token ' . $args . ' deleted successfully'); + return $response->withHeader('Location', '/registry/tokens')->withStatus(302); + } else { + // Redirect to the tokens view + return $response->withHeader('Location', '/registry/tokens')->withStatus(302); + } + + //} + } + public function managePromo(Request $request, Response $response) { if ($_SESSION["auth_roles"] != 0) { diff --git a/cp/lang/ar_SA/messages.po b/cp/lang/ar_SA/messages.po index 6dd6605..f6708e8 100644 --- a/cp/lang/ar_SA/messages.po +++ b/cp/lang/ar_SA/messages.po @@ -1698,3 +1698,15 @@ msgstr "تصدير جدول IDN" msgid "Published" msgstr "منشور" + +msgid "Manage Allocation Tokens" +msgstr "إدارة رموز التخصيص" + +msgid "Generate 10 Tokens" +msgstr "إنشاء 10 رموز" + +msgid "Token" +msgstr "رمز" + +msgid "Are you sure you want to delete this token?" +msgstr "هل أنت متأكد أنك تريد حذف هذا الرمز؟" \ No newline at end of file diff --git a/cp/lang/en_US/messages.po b/cp/lang/en_US/messages.po index bcab02d..6d7333d 100644 --- a/cp/lang/en_US/messages.po +++ b/cp/lang/en_US/messages.po @@ -1700,4 +1700,16 @@ msgid "Export IDN Table" msgstr "Export IDN Table" msgid "Published" -msgstr "Published" \ No newline at end of file +msgstr "Published" + +msgid "Manage Allocation Tokens" +msgstr "Manage Allocation Tokens" + +msgid "Generate 10 Tokens" +msgstr "Generate 10 Tokens" + +msgid "Token" +msgstr "Token" + +msgid "Are you sure you want to delete this token?" +msgstr "Are you sure you want to delete this token?" \ No newline at end of file diff --git a/cp/lang/es_ES/messages.po b/cp/lang/es_ES/messages.po index 495954b..de6cf98 100644 --- a/cp/lang/es_ES/messages.po +++ b/cp/lang/es_ES/messages.po @@ -1701,3 +1701,15 @@ msgstr "Exportar tabla IDN" msgid "Published" msgstr "Publicado" + +msgid "Manage Allocation Tokens" +msgstr "Gestionar los tokens de asignación" + +msgid "Generate 10 Tokens" +msgstr "Generar 10 tokens" + +msgid "Token" +msgstr "Token" + +msgid "Are you sure you want to delete this token?" +msgstr "¿Está seguro de que desea eliminar este token?" \ No newline at end of file diff --git a/cp/lang/fr_FR/messages.po b/cp/lang/fr_FR/messages.po index 18da4c1..51451bf 100644 --- a/cp/lang/fr_FR/messages.po +++ b/cp/lang/fr_FR/messages.po @@ -1701,3 +1701,15 @@ msgstr "Exporter le tableau IDN" msgid "Published" msgstr "Publié" + +msgid "Manage Allocation Tokens" +msgstr "Gérer les jetons d’allocation" + +msgid "Generate 10 Tokens" +msgstr "Générer 10 jetons" + +msgid "Token" +msgstr "Jeton" + +msgid "Are you sure you want to delete this token?" +msgstr "Êtes-vous sûr de vouloir supprimer ce jeton ?" \ No newline at end of file diff --git a/cp/lang/jp_JP/messages.po b/cp/lang/jp_JP/messages.po index 0034064..368682a 100644 --- a/cp/lang/jp_JP/messages.po +++ b/cp/lang/jp_JP/messages.po @@ -1701,3 +1701,15 @@ msgstr "IDNテーブルをエクスポート" msgid "Published" msgstr "公開済み" + +msgid "Manage Allocation Tokens" +msgstr "割り当てトークンの管理" + +msgid "Generate 10 Tokens" +msgstr "トークンを10個生成" + +msgid "Token" +msgstr "トークン" + +msgid "Are you sure you want to delete this token?" +msgstr "このトークンを削除してもよろしいですか?" \ No newline at end of file diff --git a/cp/lang/messages_template.po b/cp/lang/messages_template.po index b7385b2..0850308 100644 --- a/cp/lang/messages_template.po +++ b/cp/lang/messages_template.po @@ -1701,3 +1701,15 @@ msgstr "" msgid "Published" msgstr "" + +msgid "Manage Allocation Tokens" +msgstr "" + +msgid "Generate 10 Tokens" +msgstr "" + +msgid "Token" +msgstr "" + +msgid "Are you sure you want to delete this token?" +msgstr "" \ No newline at end of file diff --git a/cp/lang/pt_PT/messages.po b/cp/lang/pt_PT/messages.po index 073460c..aeb115d 100644 --- a/cp/lang/pt_PT/messages.po +++ b/cp/lang/pt_PT/messages.po @@ -1701,3 +1701,15 @@ msgstr "Exportar tabela IDN" msgid "Published" msgstr "Publicado" + +msgid "Manage Allocation Tokens" +msgstr "Gerenciar tokens de alocação" + +msgid "Generate 10 Tokens" +msgstr "Gerar 10 tokens" + +msgid "Token" +msgstr "Token" + +msgid "Are you sure you want to delete this token?" +msgstr "Tem certeza de que deseja excluir este token?" \ No newline at end of file diff --git a/cp/lang/uk_UA/messages.po b/cp/lang/uk_UA/messages.po index 0bb2427..ba10c9e 100644 --- a/cp/lang/uk_UA/messages.po +++ b/cp/lang/uk_UA/messages.po @@ -1701,3 +1701,15 @@ msgstr "Експортувати таблицю IDN" msgid "Published" msgstr "Опубліковано" + +msgid "Manage Allocation Tokens" +msgstr "Керування токенами розподілу" + +msgid "Generate 10 Tokens" +msgstr "Створити 10 токенів" + +msgid "Token" +msgstr "Токен" + +msgid "Are you sure you want to delete this token?" +msgstr "Ви впевнені, що хочете видалити цей токен?" \ No newline at end of file diff --git a/cp/resources/views/admin/system/manageTokens.twig b/cp/resources/views/admin/system/manageTokens.twig index d9f8197..205d738 100644 --- a/cp/resources/views/admin/system/manageTokens.twig +++ b/cp/resources/views/admin/system/manageTokens.twig @@ -17,6 +17,18 @@ {{ __('Manage Allocation Tokens') }} + +
+
+ + + {{ __('Generate 10 Tokens') }} + + + + +
+
@@ -24,61 +36,28 @@
- {% include 'partials/flash.twig' %}
-
- {{ csrf.field | raw }} -
- - - - - - - - - - - - - - - - - {% if tokens is not empty %} - {% for token in tokens %} - - - - - - - - - - - - - {% endfor %} - {% else %} - - - - {% endif %} - -
{{ __('Token') }}{{ __('Domain') }}{{ __('Type') }}{{ __('Status') }}{{ __('Registrars') }}{{ __('TLDs') }}{{ __('Actions') }}{{ __('Premiums') }}{{ __('Discounts') }}
{{ token.token }}{{ token.domain_name }}{{ token.tokenType is empty ? 'Default' : token.tokenType }}{{ token.tokenStatus is empty ? 'OK' : token.tokenStatus }}{{ token.registrars is empty ? 'All' : token.registrars }}{{ token.tlds is empty ? 'All' : token.tlds }}{{ token.eppActions is empty ? 'All' : token.eppActions }}{{ token.reducePremium is empty ? 'N/A' : token.reducePremium }}{{ token.reduceYears is empty ? 'N/A' : token.reduceYears }} - Edit -
No tokens found.
+
+
+
+ + + + +
+
+ {{ __('Search') }}: +
+ +
+
+
+
+
+
+
diff --git a/cp/resources/views/layouts/app.twig b/cp/resources/views/layouts/app.twig index 948d8d6..d755770 100644 --- a/cp/resources/views/layouts/app.twig +++ b/cp/resources/views/layouts/app.twig @@ -7,7 +7,7 @@ {% block title %}{% endblock %} | Namingo -{% if route_is('domains') or route_is('applications') or route_is('contacts') or route_is('hosts') or route_is('epphistory') or is_current_url('registrars') or route_is('transactions') or route_is('overview') or route_is('reports') or route_is('transfers') or route_is('users') or is_current_url('ticketview') or route_is('poll') or route_is('log') or route_is('invoices') or route_is('registry/tlds') or route_is('profile') %}{% include 'partials/css-tables.twig' %}{% else %}{% include 'partials/css.twig' %}{% endif %} +{% if route_is('domains') or route_is('applications') or route_is('contacts') or route_is('hosts') or route_is('epphistory') or is_current_url('registrars') or route_is('transactions') or route_is('overview') or route_is('reports') or route_is('transfers') or route_is('users') or is_current_url('ticketview') or route_is('poll') or route_is('log') or route_is('invoices') or route_is('registry/tlds') or route_is('profile') or route_is('registry/tokens') %}{% include 'partials/css-tables.twig' %}{% else %}{% include 'partials/css.twig' %}{% endif %}
@@ -308,6 +308,8 @@ {% include 'partials/js-server.twig' %} {% elseif route_is('deposit') %} {% include 'partials/js-server.twig' %} +{% elseif route_is('registry/tokens') %} + {% include 'partials/js-tokens.twig' %} {% else %} {% include 'partials/js.twig' %} {% endif %} diff --git a/cp/resources/views/partials/js-tokens.twig b/cp/resources/views/partials/js-tokens.twig new file mode 100644 index 0000000..f037a54 --- /dev/null +++ b/cp/resources/views/partials/js-tokens.twig @@ -0,0 +1,155 @@ + + + + + + + \ No newline at end of file diff --git a/cp/routes/web.php b/cp/routes/web.php index 146fac5..0d879b3 100644 --- a/cp/routes/web.php +++ b/cp/routes/web.php @@ -139,7 +139,9 @@ $app->group('', function ($route) { $route->map(['GET', 'POST'], '/registry/tld/{tld}', SystemController::class . ':manageTld')->setName('manageTld'); $route->get('/registry/tlds', SystemController::class .':listTlds')->setName('listTlds'); $route->map(['GET', 'POST'], '/registry/reserved', SystemController::class .':manageReserved')->setName('manageReserved'); - $route->map(['GET', 'POST'], '/registry/tokens', SystemController::class .':manageTokens')->setName('manageTokens'); + $route->get('/registry/tokens', SystemController::class .':manageTokens')->setName('manageTokens'); + $route->get('/registry/tokens/generate', SystemController::class .':generateTokens')->setName('generateTokens'); + $route->map(['GET', 'POST'], '/registry/tokens/delete/{token}', SystemController::class . ':deleteToken')->setName('deleteToken'); $route->post('/registry/promotions', SystemController::class . ':managePromo')->setName('managePromo'); $route->post('/registry/phases', SystemController::class . ':managePhases')->setName('managePhases'); $route->get('/registry/idnexport/{script}', SystemController::class .':idnexport')->setName('idnexport');