From 66a67ca7cf03c7aca3d98d7c9231198ede9f10a0 Mon Sep 17 00:00:00 2001 From: Kitteh Date: Thu, 13 May 2021 06:28:51 +0100 Subject: [PATCH] Add the ability to create new Transit engines. --- src/allPages.ts | 2 + src/pages/NewEngines/NewTransitEngine.ts | 70 ++++++++++++++++++++++++ src/pages/NewSecretsEngine.ts | 7 +++ src/translations/en.js | 8 +++ 4 files changed, 87 insertions(+) create mode 100644 src/pages/NewEngines/NewTransitEngine.ts diff --git a/src/allPages.ts b/src/allPages.ts index bec37ab..dc94bb4 100644 --- a/src/allPages.ts +++ b/src/allPages.ts @@ -11,6 +11,7 @@ import { NewKVEnginePage } from "./pages/NewEngines/NewKVEngine"; import { NewSecretsEnginePage } from "./pages/NewSecretsEngine"; import { NewTOTPEnginePage } from "./pages/NewEngines/NewTOTPEngine"; import { NewTOTPPage } from "./pages/TOTP/NewTOTP"; +import { NewTransitEnginePage } from "./pages/NewEngines/NewTransitEngine"; import { Page } from "./types/Page"; import { PwGenPage } from "./pages/PwGen"; import { SetLanguagePage } from "./pages/SetLanguage"; @@ -51,4 +52,5 @@ export const allPages: pagesList = { NEW_SECRETS_ENGINE: new NewSecretsEnginePage(), NEW_KV_ENGINE: new NewKVEnginePage(), NEW_TOTP_ENGINE: new NewTOTPEnginePage(), + NEW_TRANSIT_ENGINE: new NewTransitEnginePage(), }; diff --git a/src/pages/NewEngines/NewTransitEngine.ts b/src/pages/NewEngines/NewTransitEngine.ts new file mode 100644 index 0000000..26e810b --- /dev/null +++ b/src/pages/NewEngines/NewTransitEngine.ts @@ -0,0 +1,70 @@ +import { Margin } from "../../elements/Margin"; +import { Page } from "../../types/Page"; +import { changePage, setErrorText, setPageContent } from "../../pageUtils"; +import { makeElement } from "../../htmlUtils"; +import { newMount } from "../../api/sys/newMount"; +import { pageState } from "../../globalPageState"; +import i18next from "i18next"; + +export class NewTransitEnginePage extends Page { + constructor() { + super(); + } + async render(): Promise { + const newEngineForm = makeElement({ + tag: "form", + children: [ + Margin( + makeElement({ + tag: "input", + class: ["uk-input", "uk-form-width-medium"], + attributes: { + required: "true", + type: "text", + placeholder: i18next.t("new_transit_engine_name_input"), + name: "name", + }, + }), + ), + makeElement({ + tag: "p", + id: "errorText", + class: "uk-text-danger", + }), + makeElement({ + tag: "button", + class: ["uk-button", "uk-button-primary"], + text: i18next.t("new_transit_engine_create_btn"), + attributes: { + type: "submit", + }, + }), + ], + }) as HTMLFormElement; + + setPageContent(newEngineForm); + + newEngineForm.addEventListener("submit", async function (e) { + e.preventDefault(); + const formData = new FormData(newEngineForm); + + const name = formData.get("name") as string; + + try { + await newMount({ + name: name, + type: "transit", + }); + pageState.currentMountType = "transit"; + pageState.currentBaseMount = name + "/"; + await changePage("TRANSIT_VIEW"); + } catch (e) { + const error = e as Error; + setErrorText(error.message); + } + }); + } + get name(): string { + return i18next.t("new_transit_engine_title"); + } +} diff --git a/src/pages/NewSecretsEngine.ts b/src/pages/NewSecretsEngine.ts index 340f49a..99a9884 100644 --- a/src/pages/NewSecretsEngine.ts +++ b/src/pages/NewSecretsEngine.ts @@ -30,6 +30,13 @@ export class NewSecretsEnginePage extends Page { void changePage("NEW_TOTP_ENGINE"); }, }), + Tile({ + title: i18next.t("new_secrets_engine_transit_title"), + description: i18next.t("new_secrets_engine_transit_description"), + onclick: () => { + void changePage("NEW_TRANSIT_ENGINE"); + }, + }), ], }), ); diff --git a/src/translations/en.js b/src/translations/en.js index 0ed5d5e..e645de5 100644 --- a/src/translations/en.js +++ b/src/translations/en.js @@ -45,6 +45,9 @@ module.exports = { new_secrets_engine_kv_description: "For storing key/value mapped secrets.", new_secrets_engine_totp_title: "TOTP", new_secrets_engine_totp_description: "For handing Time-based One Time Pass (TOTP) codes.", + new_secrets_engine_transit_title: "Transit", + new_secrets_engine_transit_description: + "For doing encryption/decryption without storing the data.", // New KV Engine Page new_kv_engine_title: "New Key/Value Engine", @@ -58,6 +61,11 @@ module.exports = { new_totp_engine_name_input: "Name", new_totp_engine_create_btn: "Create", + // New Transit Engine Page + new_transit_engine_title: "New Transit Engine", + new_transit_engine_name_input: "Name", + new_transit_engine_create_btn: "Create", + // Unseal Page unseal_vault_text: "Unseal the Vault", submit_key_btn: "Submit Key",