From c62cd89771983ef337e38c483f20f25a2e9a84e9 Mon Sep 17 00:00:00 2001 From: ChaotiCryptidz Date: Thu, 6 Jan 2022 18:53:38 +0000 Subject: [PATCH] initial work on moving to a real page router --- package.json | 7 +- src/allPages.ts | 242 +++++++++--------- src/api/kv/createOrUpdateSecret.ts | 5 +- src/api/kv/deleteSecret.ts | 34 +-- src/api/kv/getSecret.ts | 10 +- src/api/kv/getSecrets.ts | 5 +- src/api/sys/getMounts.ts | 12 + src/main.tsx | 117 ++++++--- src/pageUtils.ts | 17 +- src/translations/en.js | 1 + src/types/DefaultPageProps.ts | 6 + src/ui/elements/NavBar.tsx | 25 +- src/ui/elements/PageTitle.tsx | 9 + src/ui/pages/Access/AccessHome.tsx | 3 +- src/ui/pages/Home.tsx | 149 ++++++----- src/ui/pages/Login.tsx | 70 ++--- src/ui/pages/Me.tsx | 123 +++++---- src/ui/pages/Policies/PoliciesHome.tsx | 3 +- src/ui/pages/Policies/PolicyView.tsx | 3 +- src/ui/pages/PwGen.tsx | 110 ++++---- src/ui/pages/Secrets/DeleteSecretsEngine.tsx | 52 ++-- .../pages/Secrets/KeyValue/KeyValueDelete.tsx | 78 +++--- src/ui/pages/Secrets/KeyValue/KeyValueNew.tsx | 13 +- .../pages/Secrets/KeyValue/KeyValueSecret.tsx | 169 ++++++------ .../Secrets/KeyValue/KeyValueSecretsEdit.tsx | 68 ++--- .../Secrets/KeyValue/KeyValueVersions.tsx | 55 ---- .../pages/Secrets/KeyValue/KeyValueView.tsx | 103 ++++---- .../pages/Secrets/KeyValue/splitKVMount.tsx | 10 + .../pages/Secrets/NewEngines/NewKVEngine.tsx | 82 +++--- .../Secrets/NewEngines/NewTOTPEngine.tsx | 58 ++--- .../Secrets/NewEngines/NewTransitEngine.tsx | 58 ++--- src/ui/pages/Secrets/NewSecretsEngine.tsx | 30 +-- src/ui/pages/Secrets/SecretTitleElement.tsx | 88 +++---- src/ui/pages/Secrets/SecretsHome.tsx | 129 +++++----- src/ui/pages/Secrets/TOTP/TOTPDelete.tsx | 43 ++-- src/ui/pages/Secrets/TOTP/TOTPNew.tsx | 39 +-- src/ui/pages/Secrets/TOTP/TOTPView.tsx | 130 ++++++---- .../pages/Secrets/Transit/NewTransitKey.tsx | 12 +- .../pages/Secrets/Transit/TransitDecrypt.tsx | 12 +- .../pages/Secrets/Transit/TransitEncrypt.tsx | 12 +- .../pages/Secrets/Transit/TransitRewrap.tsx | 12 +- src/ui/pages/Secrets/Transit/TransitView.tsx | 6 +- .../Secrets/Transit/TransitViewSecret.tsx | 6 +- src/ui/pages/SetLanguage.tsx | 65 ++--- src/ui/pages/SetVaultURL.tsx | 27 +- src/ui/pages/Unseal.tsx | 98 ++++--- webpack-dev.config.js | 2 + webpack.config.js | 2 + 48 files changed, 1201 insertions(+), 1209 deletions(-) create mode 100644 src/types/DefaultPageProps.ts create mode 100644 src/ui/elements/PageTitle.tsx delete mode 100644 src/ui/pages/Secrets/KeyValue/KeyValueVersions.tsx create mode 100644 src/ui/pages/Secrets/KeyValue/splitKVMount.tsx diff --git a/package.json b/package.json index 6a3bf8a..ff1deda 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "codejar": "^3.5.0", "core-js": "^3.20.2", "css-loader": "^6.5.1", + "css-minimizer-webpack-plugin": "^3.3.1", "date-fns": "^2.28.0", "eslint": "^8.6.0", "eslint-config-prettier": "^8.3.0", @@ -41,7 +42,9 @@ "uikit": "^3.9.4", "webpack": "^5.65.0", "webpack-cli": "^4.9.1", - "webpack-dev-server": "^4.7.2", - "css-minimizer-webpack-plugin": "^3.3.1" + "webpack-dev-server": "^4.7.2" + }, + "dependencies": { + "preact-router": "^4.0.0" } } diff --git a/src/allPages.ts b/src/allPages.ts index c404558..0f350ab 100644 --- a/src/allPages.ts +++ b/src/allPages.ts @@ -1,121 +1,121 @@ -import { PageType } from "./pagerouter/PageType"; - -import { AccessHomePage } from "./ui/pages/Access/AccessHome"; -import { AuthHomePage } from "./ui/pages/Access/Auth/AuthHome"; -import { AuthViewConfigPage } from "./ui/pages/Access/Auth/AuthViewConfig"; -import { DeleteSecretsEnginePage } from "./ui/pages/Secrets/DeleteSecretsEngine"; -import { HomePage } from "./ui/pages/Home"; -import { KeyValueDeletePage } from "./ui/pages/Secrets/KeyValue/KeyValueDelete"; -import { KeyValueNewPage } from "./ui/pages/Secrets/KeyValue/KeyValueNew"; -import { KeyValueSecretEditPage } from "./ui/pages/Secrets/KeyValue/KeyValueSecretsEdit"; -import { KeyValueSecretPage } from "./ui/pages/Secrets/KeyValue/KeyValueSecret"; -import { KeyValueVersionsPage } from "./ui/pages/Secrets/KeyValue/KeyValueVersions"; -import { KeyValueViewPage } from "./ui/pages/Secrets/KeyValue/KeyValueView"; -import { LoginPage } from "./ui/pages/Login"; -import { MePage } from "./ui/pages/Me"; -import { NewKVEnginePage } from "./ui/pages/Secrets/NewEngines/NewKVEngine"; -import { NewSecretsEnginePage } from "./ui/pages/Secrets/NewSecretsEngine"; -import { NewTOTPEnginePage } from "./ui/pages/Secrets/NewEngines/NewTOTPEngine"; -import { NewTransitEnginePage } from "./ui/pages/Secrets/NewEngines/NewTransitEngine"; -import { NewTransitKeyPage } from "./ui/pages/Secrets/Transit/NewTransitKey"; -import { Page } from "./types/Page"; -import { PoliciesHomePage } from "./ui/pages/Policies/PoliciesHome"; -import { PolicyDeletePage } from "./ui/pages/Policies/PolicyDelete"; -import { PolicyEditPage } from "./ui/pages/Policies/PolicyEdit"; -import { PolicyNewPage } from "./ui/pages/Policies/PolicyNew"; -import { PolicyViewPage } from "./ui/pages/Policies/PolicyView"; -import { PwGenPage } from "./ui/pages/PwGen"; -import { SecretsHomePage } from "./ui/pages/Secrets/SecretsHome"; -import { SetLanguagePage } from "./ui/pages/SetLanguage"; -import { SetVaultURLPage } from "./ui/pages/SetVaultURL"; -import { TOTPDeletePage } from "./ui/pages/Secrets/TOTP/TOTPDelete"; -import { TOTPNewPage } from "./ui/pages/Secrets/TOTP/TOTPNew"; -import { TOTPViewPage } from "./ui/pages/Secrets/TOTP/TOTPView"; -import { TransitDecryptPage } from "./ui/pages/Secrets/Transit/TransitDecrypt"; -import { TransitEncryptPage } from "./ui/pages/Secrets/Transit/TransitEncrypt"; -import { TransitRewrapPage } from "./ui/pages/Secrets/Transit/TransitRewrap"; -import { TransitViewPage } from "./ui/pages/Secrets/Transit/TransitView"; -import { TransitViewSecretPage } from "./ui/pages/Secrets/Transit/TransitViewSecret"; -import { UnsealPage } from "./ui/pages/Unseal"; -import { UserPassUserDeletePage } from "./ui/pages/Access/Auth/userpass/UserPassUserDelete"; -import { UserPassUserEditPage } from "./ui/pages/Access/Auth/userpass/UserPassUserEdit"; -import { UserPassUserNewPage } from "./ui/pages/Access/Auth/userpass/UserPassUserNew"; -import { UserPassUserViewPage } from "./ui/pages/Access/Auth/userpass/UserPassUserView"; -import { UserPassUsersListPage } from "./ui/pages/Access/Auth/userpass/UserPassUsersList"; -import { getObjectKeys } from "./utils"; - -type pagesList = { - [key: string]: Page; -}; - -export const allPages: pagesList = { - HOME: new HomePage(), - LOGIN: new LoginPage(), - SET_VAULT_URL: new SetVaultURLPage(), - UNSEAL: new UnsealPage(), - SET_LANGUAGE: new SetLanguagePage(), - ME: new MePage(), - PW_GEN: new PwGenPage(), - - POLICIES_HOME: new PoliciesHomePage(), - POLICY_VIEW: new PolicyViewPage(), - POLICY_NEW: new PolicyNewPage(), - POLICY_EDIT: new PolicyEditPage(), - POLICY_DELETE: new PolicyDeletePage(), - - ACCESS_HOME: new AccessHomePage(), - - AUTH_HOME: new AuthHomePage(), - AUTH_VIEW_CONFIG: new AuthViewConfigPage(), - - USERPASS_USERS_LIST: new UserPassUsersListPage(), - USERPASS_USER_VIEW: new UserPassUserViewPage(), - USERPASS_USER_EDIT: new UserPassUserEditPage(), - USERPASS_USER_NEW: new UserPassUserNewPage(), - USERPASS_USER_DELETE: new UserPassUserDeletePage(), - - SECRETS_HOME: new SecretsHomePage(), - - TOTP_VIEW: new TOTPViewPage(), - TOTP_NEW: new TOTPNewPage(), - TOTP_DELETE: new TOTPDeletePage(), - - TRANSIT_VIEW: new TransitViewPage(), - TRANSIT_NEW_KEY: new NewTransitKeyPage(), - TRANSIT_VIEW_SECRET: new TransitViewSecretPage(), - TRANSIT_ENCRYPT: new TransitEncryptPage(), - TRANSIT_DECRYPT: new TransitDecryptPage(), - TRANSIT_REWRAP: new TransitRewrapPage(), - - KEY_VALUE_VIEW: new KeyValueViewPage(), - KEY_VALUE_SECRET: new KeyValueSecretPage(), - KEY_VALUE_VERSIONS: new KeyValueVersionsPage(), - KEY_VALUE_NEW_SECRET: new KeyValueNewPage(), - KEY_VALUE_DELETE: new KeyValueDeletePage(), - KEY_VALUE_SECRET_EDIT: new KeyValueSecretEditPage(), - - DELETE_SECRET_ENGINE: new DeleteSecretsEnginePage(), - - NEW_SECRETS_ENGINE: new NewSecretsEnginePage(), - NEW_KV_ENGINE: new NewKVEnginePage(), - NEW_TOTP_ENGINE: new NewTOTPEnginePage(), - NEW_TRANSIT_ENGINE: new NewTransitEnginePage(), -}; - -// This should implement all o PageListType -class PageList { - constructor(pages: pagesList) { - this.pages = pages; - } - - private pages: pagesList; - - async getPageIDs(): Promise { - return getObjectKeys(this.pages); - } - async getPage(pageID: string): Promise { - return this.pages[pageID]; - } -} - -export const pageList = new PageList(allPages); +//import { PageType } from "./pagerouter/PageType"; +// +//import { AccessHomePage } from "./ui/pages/Access/AccessHome"; +//import { AuthHomePage } from "./ui/pages/Access/Auth/AuthHome"; +//import { AuthViewConfigPage } from "./ui/pages/Access/Auth/AuthViewConfig"; +//import { DeleteSecretsEnginePage } from "./ui/pages/Secrets/DeleteSecretsEngine"; +//import { HomePage } from "./ui/pages/Home"; +//import { KeyValueDeletePage } from "./ui/pages/Secrets/KeyValue/KeyValueDelete"; +//import { KeyValueNewPage } from "./ui/pages/Secrets/KeyValue/KeyValueNew"; +//import { KeyValueSecretEditPage } from "./ui/pages/Secrets/KeyValue/KeyValueSecretsEdit"; +//import { KeyValueSecretPage } from "./ui/pages/Secrets/KeyValue/KeyValueSecret"; +//import { KeyValueVersionsPage } from "./ui/pages/Secrets/KeyValue/KeyValueVersions"; +//import { KeyValueViewPage } from "./ui/pages/Secrets/KeyValue/KeyValueView"; +//import { LoginPage } from "./ui/pages/Login"; +//import { MePage } from "./ui/pages/Me"; +//import { NewKVEnginePage } from "./ui/pages/Secrets/NewEngines/NewKVEngine"; +//import { NewSecretsEnginePage } from "./ui/pages/Secrets/NewSecretsEngine"; +//import { NewTOTPEnginePage } from "./ui/pages/Secrets/NewEngines/NewTOTPEngine"; +//import { NewTransitEnginePage } from "./ui/pages/Secrets/NewEngines/NewTransitEngine"; +//import { NewTransitKeyPage } from "./ui/pages/Secrets/Transit/NewTransitKey"; +//import { Page } from "./types/Page"; +//import { PoliciesHomePage } from "./ui/pages/Policies/PoliciesHome"; +//import { PolicyDeletePage } from "./ui/pages/Policies/PolicyDelete"; +//import { PolicyEditPage } from "./ui/pages/Policies/PolicyEdit"; +//import { PolicyNewPage } from "./ui/pages/Policies/PolicyNew"; +//import { PolicyViewPage } from "./ui/pages/Policies/PolicyView"; +//import { PwGenPage } from "./ui/pages/PwGen"; +//import { SecretsHomePage } from "./ui/pages/Secrets/SecretsHome"; +//import { SetLanguagePage } from "./ui/pages/SetLanguage"; +//import { SetVaultURLPage } from "./ui/pages/SetVaultURL"; +//import { TOTPDeletePage } from "./ui/pages/Secrets/TOTP/TOTPDelete"; +//import { TOTPNewPage } from "./ui/pages/Secrets/TOTP/TOTPNew"; +//import { TOTPViewPage } from "./ui/pages/Secrets/TOTP/TOTPView"; +//import { TransitDecryptPage } from "./ui/pages/Secrets/Transit/TransitDecrypt"; +//import { TransitEncryptPage } from "./ui/pages/Secrets/Transit/TransitEncrypt"; +//import { TransitRewrapPage } from "./ui/pages/Secrets/Transit/TransitRewrap"; +//import { TransitViewPage } from "./ui/pages/Secrets/Transit/TransitView"; +//import { TransitViewSecretPage } from "./ui/pages/Secrets/Transit/TransitViewSecret"; +//import { UnsealPage } from "./ui/pages/Unseal"; +//import { UserPassUserDeletePage } from "./ui/pages/Access/Auth/userpass/UserPassUserDelete"; +//import { UserPassUserEditPage } from "./ui/pages/Access/Auth/userpass/UserPassUserEdit"; +//import { UserPassUserNewPage } from "./ui/pages/Access/Auth/userpass/UserPassUserNew"; +//import { UserPassUserViewPage } from "./ui/pages/Access/Auth/userpass/UserPassUserView"; +//import { UserPassUsersListPage } from "./ui/pages/Access/Auth/userpass/UserPassUsersList"; +//import { getObjectKeys } from "./utils"; +// +//type pagesList = { +// [key: string]: Page; +//}; +// +//export const allPages: pagesList = { +// HOME: new HomePage(), +// LOGIN: new LoginPage(), +// SET_VAULT_URL: new SetVaultURLPage(), +// UNSEAL: new UnsealPage(), +// SET_LANGUAGE: new SetLanguagePage(), +// ME: new MePage(), +// PW_GEN: new PwGenPage(), +// +// POLICIES_HOME: new PoliciesHomePage(), +// POLICY_VIEW: new PolicyViewPage(), +// POLICY_NEW: new PolicyNewPage(), +// POLICY_EDIT: new PolicyEditPage(), +// POLICY_DELETE: new PolicyDeletePage(), +// +// ACCESS_HOME: new AccessHomePage(), +// +// AUTH_HOME: new AuthHomePage(), +// AUTH_VIEW_CONFIG: new AuthViewConfigPage(), +// +// USERPASS_USERS_LIST: new UserPassUsersListPage(), +// USERPASS_USER_VIEW: new UserPassUserViewPage(), +// USERPASS_USER_EDIT: new UserPassUserEditPage(), +// USERPASS_USER_NEW: new UserPassUserNewPage(), +// USERPASS_USER_DELETE: new UserPassUserDeletePage(), +// +// SECRETS_HOME: new SecretsHomePage(), +// +// TOTP_VIEW: new TOTPViewPage(), +// TOTP_NEW: new TOTPNewPage(), +// TOTP_DELETE: new TOTPDeletePage(), +// +// TRANSIT_VIEW: new TransitViewPage(), +// TRANSIT_NEW_KEY: new NewTransitKeyPage(), +// TRANSIT_VIEW_SECRET: new TransitViewSecretPage(), +// TRANSIT_ENCRYPT: new TransitEncryptPage(), +// TRANSIT_DECRYPT: new TransitDecryptPage(), +// TRANSIT_REWRAP: new TransitRewrapPage(), +// +// KEY_VALUE_VIEW: new KeyValueViewPage(), +// KEY_VALUE_SECRET: new KeyValueSecretPage(), +// KEY_VALUE_VERSIONS: new KeyValueVersionsPage(), +// KEY_VALUE_NEW_SECRET: new KeyValueNewPage(), +// KEY_VALUE_DELETE: new KeyValueDeletePage(), +// KEY_VALUE_SECRET_EDIT: new KeyValueSecretEditPage(), +// +// DELETE_SECRET_ENGINE: new DeleteSecretsEnginePage(), +// +// NEW_SECRETS_ENGINE: new NewSecretsEnginePage(), +// NEW_KV_ENGINE: new NewKVEnginePage(), +// NEW_TOTP_ENGINE: new NewTOTPEnginePage(), +// NEW_TRANSIT_ENGINE: new NewTransitEnginePage(), +//}; +// +//// This should implement all o PageListType +//class PageList { +// constructor(pages: pagesList) { +// this.pages = pages; +// } +// +// private pages: pagesList; +// +// async getPageIDs(): Promise { +// return getObjectKeys(this.pages); +// } +// async getPage(pageID: string): Promise { +// return this.pages[pageID]; +// } +//} +// +//export const pageList = new PageList(allPages); diff --git a/src/api/kv/createOrUpdateSecret.ts b/src/api/kv/createOrUpdateSecret.ts index 2d532cd..437be70 100644 --- a/src/api/kv/createOrUpdateSecret.ts +++ b/src/api/kv/createOrUpdateSecret.ts @@ -1,9 +1,9 @@ import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils"; import { removeDoubleSlash } from "../../utils"; +import { getMount } from "../sys/getMounts"; export async function createOrUpdateSecret( baseMount: string, - secretMountType: string, secretPath: string[], name: string, data: Record, @@ -11,7 +11,8 @@ export async function createOrUpdateSecret( let secretURL = ""; let APIData = {}; - if (secretMountType == "kv-v2") { + const mountInfo = await getMount(baseMount); + if (mountInfo.options.version == "2") { secretURL = `/v1/${baseMount}/data/${secretPath.join("/")}/${name}`; APIData = { data: data }; } else { diff --git a/src/api/kv/deleteSecret.ts b/src/api/kv/deleteSecret.ts index 6435fb5..3b69fe4 100644 --- a/src/api/kv/deleteSecret.ts +++ b/src/api/kv/deleteSecret.ts @@ -1,40 +1,26 @@ import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils"; import { removeDoubleSlash } from "../../utils"; +import { getMount } from "../sys/getMounts"; export async function deleteSecret( baseMount: string, - secretMountType: string, secretPath: string[], name: string, - version: string | null = null, ): Promise { let secretURL = ""; - let request; - if (secretMountType == "kv-v2" && version != null) { - secretURL = `/v1/${baseMount}/delete/${secretPath.join("")}/${name}`; - secretURL = removeDoubleSlash(secretURL).replace(/\/$/, ""); - request = new Request(appendAPIURL(secretURL), { - method: "POST", - headers: { - ...getHeaders(), - "Content-Type": "application/json", - }, - body: version != null ? JSON.stringify({ versions: [version] }) : "{}", - }); + const mountInfo = await getMount(baseMount); + if (mountInfo.options.version == "2") { + secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}/${name}`; } else { - if (secretMountType == "kv-v2") { - secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}/${name}`; - } else { - secretURL = `/v1/${baseMount}/${secretPath.join("")}/${name}`; - } - secretURL = removeDoubleSlash(secretURL).replace(/\/$/, ""); - request = new Request(appendAPIURL(secretURL), { - method: "DELETE", - headers: getHeaders(), - }); + secretURL = `/v1/${baseMount}/${secretPath.join("")}/${name}`; } + secretURL = removeDoubleSlash(secretURL).replace(/\/$/, ""); + request = new Request(appendAPIURL(secretURL), { + method: "DELETE", + headers: getHeaders(), + }); const resp = await fetch(request); await checkResponse(resp); } diff --git a/src/api/kv/getSecret.ts b/src/api/kv/getSecret.ts index 04f64ca..156bd66 100644 --- a/src/api/kv/getSecret.ts +++ b/src/api/kv/getSecret.ts @@ -1,4 +1,5 @@ import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils"; +import { getMount } from "../sys/getMounts"; export async function getSecretKV1( baseMount: string, @@ -21,12 +22,10 @@ export async function getSecretKV2( baseMount: string, secretPath: string[], name: string, - version: string | null = null, ): Promise> { let secretURL = ""; secretURL = `/v1/${baseMount}/data/${secretPath.join("")}/${name}`; - if (version != null) secretURL += `?version=${version}`; const request = new Request(appendAPIURL(secretURL), { headers: getHeaders(), @@ -41,13 +40,12 @@ export async function getSecretKV2( export async function getSecret( baseMount: string, - secretMountType: string, secretPath: string[], name: string, - version: string | null = null, ): Promise> { - if (secretMountType == "kv-v2") { - return await getSecretKV2(baseMount, secretPath, name, version); + const mountInfo = await getMount(baseMount); + if (mountInfo.options.version == "2") { + return await getSecretKV2(baseMount, secretPath, name); } else { return await getSecretKV1(baseMount, secretPath, name); } diff --git a/src/api/kv/getSecrets.ts b/src/api/kv/getSecrets.ts index 66e00fd..b19dd7f 100644 --- a/src/api/kv/getSecrets.ts +++ b/src/api/kv/getSecrets.ts @@ -2,10 +2,13 @@ import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils"; export async function getSecrets( baseMount: string, - secretMountType: string, secretPath: string[], ): Promise { let secretURL = ""; + + // TODO: FIX THIS + let secretMountType = "kv-v2" + if (secretMountType == "kv-v2") { secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}?list=true`; } else { diff --git a/src/api/sys/getMounts.ts b/src/api/sys/getMounts.ts index 53a8277..5923710 100644 --- a/src/api/sys/getMounts.ts +++ b/src/api/sys/getMounts.ts @@ -21,3 +21,15 @@ export async function getMounts(): Promise { const data = (await resp.json()) as { data: { secret: MountsType } }; return data.data.secret; } + +export async function getMount(mountName: string): Promise { + const request = new Request(appendAPIURL("/v1/sys/internal/ui/mounts/" + mountName), { + headers: getHeaders(), + }); + const resp = await fetch(request); + await checkResponse(resp); + + const data = (await resp.json()) as { data: MountType }; + return data.data; +} + diff --git a/src/main.tsx b/src/main.tsx index b8e5145..64b21ae 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -25,59 +25,110 @@ import translations from "./translations/index.mjs"; import { PageRouter } from "./pagerouter/PageRouter"; import { formatDistance } from "./formatDistance"; import { getSealStatus } from "./api/sys/getSealStatus"; -import { pageList } from "./allPages"; +//import { pageList } from "./allPages"; import { pageState } from "./globalPageState"; import { playground } from "./playground"; -import { reloadNavBar } from "./ui/elements/NavBar"; -import { render } from "preact"; +import { NavBar } from "./ui/elements/NavBar"; +import { render, Component } from "preact"; import i18next from "i18next"; +import Router from 'preact-router'; +import { Home } from "./ui/pages/Home"; +import { Me } from "./ui/pages/Me"; +import { Login } from "./ui/pages/Login"; +import { PasswordGenerator } from "./ui/pages/PwGen"; +import { SetVaultURL } from "./ui/pages/SetVaultURL"; +import { Unseal } from "./ui/pages/Unseal"; +import { SetLanguage } from "./ui/pages/SetLanguage"; +import { Secrets } from "./ui/pages/Secrets/SecretsHome"; +import { TOTPView } from "./ui/pages/Secrets/TOTP/TOTPView"; +import { TOTPNew } from "./ui/pages/Secrets/TOTP/TOTPNew"; +import { TOTPDelete } from "./ui/pages/Secrets/TOTP/TOTPDelete"; +import { NewSecretsEngine } from "./ui/pages/Secrets/NewSecretsEngine"; +import { NewKVEngine } from "./ui/pages/Secrets/NewEngines/NewKVEngine"; +import { NewTOTPEngine } from "./ui/pages/Secrets/NewEngines/NewTOTPEngine"; +import { NewTransitEngine } from "./ui/pages/Secrets/NewEngines/NewTransitEngine"; +import { DeleteSecretsEngine } from "./ui/pages/Secrets/DeleteSecretsEngine"; +import { KeyValueView } from "./ui/pages/Secrets/KeyValue/KeyValueView"; +import { KeyValueSecret } from "./ui/pages/Secrets/KeyValue/KeyValueSecret"; +import { KeyValueSecretEdit } from "./ui/pages/Secrets/KeyValue/KeyValueSecretsEdit"; +import { KeyValueDelete } from "./ui/pages/Secrets/KeyValue/KeyValueDelete"; async function onLoad(): Promise { + const Main = () => ( + + + + + + + + + + + + + + + + + + + + + + + + + + +

PAGE NOT YET IMPLEMENTED

+ +
+ ); render( <> - , - this.router.pageContentElement, - ); - } + + - async renderPageTitle(): Promise { - render(, this.router.pageTitleElement); + ); } get name(): string { diff --git a/src/ui/pages/Secrets/Transit/NewTransitKey.tsx b/src/ui/pages/Secrets/Transit/NewTransitKey.tsx index d71149f..291ec6c 100644 --- a/src/ui/pages/Secrets/Transit/NewTransitKey.tsx +++ b/src/ui/pages/Secrets/Transit/NewTransitKey.tsx @@ -76,12 +76,12 @@ export class NewTransitKeyPage extends Page { } } - async renderPageTitle(): Promise { - render( - , - this.router.pageTitleElement, - ); - } + //async renderPageTitle(): Promise { + // render( + // , + // this.router.pageTitleElement, + // ); + //} get name(): string { return i18next.t("transit_new_key_title"); diff --git a/src/ui/pages/Secrets/Transit/TransitDecrypt.tsx b/src/ui/pages/Secrets/Transit/TransitDecrypt.tsx index 0f04a1f..013365e 100644 --- a/src/ui/pages/Secrets/Transit/TransitDecrypt.tsx +++ b/src/ui/pages/Secrets/Transit/TransitDecrypt.tsx @@ -82,12 +82,12 @@ export class TransitDecryptPage extends Page { } } - async renderPageTitle(): Promise { - render( - , - this.router.pageTitleElement, - ); - } + //async renderPageTitle(): Promise { + // render( + // , + // this.router.pageTitleElement, + // ); + //} get name(): string { return i18next.t("transit_decrypt_title"); diff --git a/src/ui/pages/Secrets/Transit/TransitEncrypt.tsx b/src/ui/pages/Secrets/Transit/TransitEncrypt.tsx index d434a04..138ed36 100644 --- a/src/ui/pages/Secrets/Transit/TransitEncrypt.tsx +++ b/src/ui/pages/Secrets/Transit/TransitEncrypt.tsx @@ -79,12 +79,12 @@ export class TransitEncryptPage extends Page { } } - async renderPageTitle(): Promise { - render( - , - this.router.pageTitleElement, - ); - } + //async renderPageTitle(): Promise { + // render( + // , + // this.router.pageTitleElement, + // ); + //} get name(): string { return i18next.t("transit_encrypt_title"); diff --git a/src/ui/pages/Secrets/Transit/TransitRewrap.tsx b/src/ui/pages/Secrets/Transit/TransitRewrap.tsx index faae513..fce2ac5 100644 --- a/src/ui/pages/Secrets/Transit/TransitRewrap.tsx +++ b/src/ui/pages/Secrets/Transit/TransitRewrap.tsx @@ -94,12 +94,12 @@ export class TransitRewrapPage extends Page { } } - async renderPageTitle(): Promise { - render( - , - this.router.pageTitleElement, - ); - } + //async renderPageTitle(): Promise { + // render( + // , + // this.router.pageTitleElement, + // ); + //} get name(): string { return i18next.t("transit_rewrap_title"); diff --git a/src/ui/pages/Secrets/Transit/TransitView.tsx b/src/ui/pages/Secrets/Transit/TransitView.tsx index f5e56e7..a4e0b2a 100644 --- a/src/ui/pages/Secrets/Transit/TransitView.tsx +++ b/src/ui/pages/Secrets/Transit/TransitView.tsx @@ -116,9 +116,9 @@ export class TransitViewPage extends Page { ); } - async renderPageTitle(): Promise { - render(, this.router.pageTitleElement); - } + //async renderPageTitle(): Promise { + // render(, this.router.pageTitleElement); + //} get name(): string { return i18next.t("transit_view_title"); diff --git a/src/ui/pages/Secrets/Transit/TransitViewSecret.tsx b/src/ui/pages/Secrets/Transit/TransitViewSecret.tsx index dce33a9..266a8bc 100644 --- a/src/ui/pages/Secrets/Transit/TransitViewSecret.tsx +++ b/src/ui/pages/Secrets/Transit/TransitViewSecret.tsx @@ -52,9 +52,9 @@ export class TransitViewSecretPage extends Page { ); } - async renderPageTitle(): Promise { - render(, this.router.pageTitleElement); - } + //async renderPageTitle(): Promise { + // render(, this.router.pageTitleElement); + //} get name(): string { return i18next.t("transit_view_secret_title"); diff --git a/src/ui/pages/SetLanguage.tsx b/src/ui/pages/SetLanguage.tsx index e95dc66..3218702 100644 --- a/src/ui/pages/SetLanguage.tsx +++ b/src/ui/pages/SetLanguage.tsx @@ -5,51 +5,52 @@ import translations from "../../translations/index.mjs"; import { Form } from "../elements/Form"; import { Margin } from "../elements/Margin"; import { MarginInline } from "../elements/MarginInline"; -import { Page } from "../../types/Page"; -import { reloadNavBar } from "../elements/NavBar"; -import { render } from "preact"; +import { Component } from "preact"; import i18next from "i18next"; +import { route } from "preact-router"; +import { PageTitle } from "../elements/PageTitle"; +import { DefaultPageProps } from "../../types/DefaultPageProps.js"; const languageIDs = Object.getOwnPropertyNames(translations); -export class SetLanguagePage extends Page { +export class SetLanguage extends Component { constructor() { super(); } - async render(): Promise { - render( -
this.onSubmit(data)}> - - - -

- - - -

, - this.router.pageContentElement, + render() { + return ( + <> + +
this.onSubmit(data)}> + + + +

+ + + +

+ ); + } async onSubmit(data: FormData): Promise { const language = data.get("language") as string; - this.state.language = language; + this.props.state.language = language; const t = await i18next.changeLanguage(language); - this.state.pageDirection = t("language_direction"); - reloadNavBar(this.router); - await this.router.changePage("HOME"); - } - - get name(): string { - return i18next.t("set_language_title"); + this.props.state.pageDirection = t("language_direction"); + // TODO: make navbar somethingy + //reloadNavBar(this.router); + route("/"); } } diff --git a/src/ui/pages/SetVaultURL.tsx b/src/ui/pages/SetVaultURL.tsx index c28938f..eb0dc94 100644 --- a/src/ui/pages/SetVaultURL.tsx +++ b/src/ui/pages/SetVaultURL.tsx @@ -1,14 +1,16 @@ import { Form } from "../elements/Form"; import { Margin } from "../elements/Margin"; import { Page } from "../../types/Page"; -import { render } from "preact"; +import { Component, render } from "preact"; +import { DefaultPageProps } from "../../types/DefaultPageProps"; +import { route } from "preact-router"; +import { PageTitle } from "../elements/PageTitle"; -export class SetVaultURLPage extends Page { - constructor() { - super(); - } - async render(): Promise { - render( +export class SetVaultURL extends Component { + render() { + return ( + <> +
this.onSubmit(data)}> -
, - - this.router.pageContentElement, + + ); } async onSubmit(data: FormData): Promise { - this.state.apiURL = data.get("vaultURL") as string; - await this.router.changePage("HOME"); + // TODO: check if vault is actually working here. + this.props.state.apiURL = data.get("vaultURL") as string; + route("/") } get name(): string { + // TODO: return "Set Vault URL"; } } diff --git a/src/ui/pages/Unseal.tsx b/src/ui/pages/Unseal.tsx index b68093e..d5f531a 100644 --- a/src/ui/pages/Unseal.tsx +++ b/src/ui/pages/Unseal.tsx @@ -9,6 +9,9 @@ import { setErrorText } from "../../pageUtils"; import { submitUnsealKey } from "../../api/sys/submitUnsealKey"; import { toStr } from "../../utils"; import i18next from "i18next"; +import { DefaultPageProps } from "../../types/DefaultPageProps"; +import { PageTitle } from "../elements/PageTitle"; +import { route } from "preact-router"; const UnsealInputModes = { FORM_INPUT: "FORM_INPUT", @@ -50,7 +53,7 @@ type UnsealPageState = { keys_needed: number; }; -export class UnsealPageElement extends Component<{ page: Page }, UnsealPageState> { +export class Unseal extends Component { constructor() { super(); this.state = { @@ -79,7 +82,7 @@ export class UnsealPageElement extends Component<{ page: Page }, UnsealPageState keys_needed: data.t, }); if (!data.sealed) { - void this.props.page.router.changePage("HOME"); + route("/"); } }); } @@ -97,61 +100,50 @@ export class UnsealPageElement extends Component<{ page: Page }, UnsealPageState render(): JSX.Element { return ( -
- + <> + +
+ -

+

-

- {i18next.t("unseal_keys_progress", { - progress: toStr(this.state.keys_submitted), - keys_needed: toStr(this.state.keys_needed), - })} -

+

+ {i18next.t("unseal_keys_progress", { + progress: toStr(this.state.keys_submitted), + keys_needed: toStr(this.state.keys_needed), + })} +

- {this.state.mode == UnsealInputModes.FORM_INPUT && ( - this.submitKey(code)} /> - )} + {this.state.mode == UnsealInputModes.FORM_INPUT && ( + this.submitKey(code)} /> + )} - {this.state.mode == UnsealInputModes.QR_INPUT && ( - this.submitKey(code)} /> - )} + {this.state.mode == UnsealInputModes.QR_INPUT && ( + this.submitKey(code)} /> + )} - -
+ +
+ ); } -} - -export class UnsealPage extends Page { - constructor() { - super(); - } - - async render(): Promise { - render(, this.router.pageContentElement); - } - - get name(): string { - return i18next.t("unseal_vault_text"); - } -} +} \ No newline at end of file diff --git a/webpack-dev.config.js b/webpack-dev.config.js index ce8cb6e..f5b9c0d 100644 --- a/webpack-dev.config.js +++ b/webpack-dev.config.js @@ -16,6 +16,7 @@ module.exports = { output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js', + publicPath: '/', }, stats: { colors: true, @@ -31,6 +32,7 @@ module.exports = { ], devServer: { open: process.env.BROWSER, + historyApiFallback: true, }, resolve: { modules: ['node_modules'], diff --git a/webpack.config.js b/webpack.config.js index 64f9ee1..2c78c97 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -41,6 +41,7 @@ module.exports = { output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js', + publicPath: '/', }, stats: { colors: true, @@ -56,6 +57,7 @@ module.exports = { ], devServer: { open: process.env.BROWSER || "microsoft-edge-dev", + historyApiFallback: true, }, resolve: { modules: ['node_modules'],