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') }} + +