diff --git a/src/api/kv/createOrUpdateSecret.ts b/src/api/kv/createOrUpdateSecret.ts index 437be70..f2cf946 100644 --- a/src/api/kv/createOrUpdateSecret.ts +++ b/src/api/kv/createOrUpdateSecret.ts @@ -1,6 +1,6 @@ import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils"; -import { removeDoubleSlash } from "../../utils"; import { getMount } from "../sys/getMounts"; +import { removeDoubleSlash } from "../../utils"; export async function createOrUpdateSecret( baseMount: string, diff --git a/src/api/kv/deleteSecret.ts b/src/api/kv/deleteSecret.ts index 540b3eb..9c450a1 100644 --- a/src/api/kv/deleteSecret.ts +++ b/src/api/kv/deleteSecret.ts @@ -1,6 +1,6 @@ import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils"; -import { removeDoubleSlash } from "../../utils"; import { getMount } from "../sys/getMounts"; +import { removeDoubleSlash } from "../../utils"; export async function deleteSecret( baseMount: string, diff --git a/src/api/kv/getSecrets.ts b/src/api/kv/getSecrets.ts index c7da108..d51f98f 100644 --- a/src/api/kv/getSecrets.ts +++ b/src/api/kv/getSecrets.ts @@ -1,13 +1,10 @@ import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils"; -export async function getSecrets( - baseMount: string, - secretPath: string[], -): Promise { +export async function getSecrets(baseMount: string, secretPath: string[]): Promise { let secretURL = ""; // TODO: FIX THIS - let secretMountType = "kv-v2" + const secretMountType = "kv-v2"; if (secretMountType == "kv-v2") { secretURL = `/v1/${baseMount}/metadata/${secretPath.join("/")}?list=true`; diff --git a/src/api/sys/getMounts.ts b/src/api/sys/getMounts.ts index 5923710..1589e55 100644 --- a/src/api/sys/getMounts.ts +++ b/src/api/sys/getMounts.ts @@ -29,7 +29,6 @@ export async function getMount(mountName: string): Promise { const resp = await fetch(request); await checkResponse(resp); - const data = (await resp.json()) as { data: MountType }; + const data = (await resp.json()) as { data: MountType }; return data.data; } - diff --git a/src/main.tsx b/src/main.tsx index 71450b6..ed315b2 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -12,8 +12,8 @@ UIkit.use(Icons); import Prism from "prismjs"; // Don't Sort These! -import "prismjs/components/prism-json"; import "prismjs/components/prism-hcl"; +import "prismjs/components/prism-json"; Prism.highlightAll(); /* eslint-enable */ @@ -26,35 +26,35 @@ import { PageRouter } from "./pagerouter/PageRouter"; import { formatDistance } from "./formatDistance"; import { getSealStatus } from "./api/sys/getSealStatus"; //import { pageList } from "./allPages"; -import { pageState } from "./globalPageState"; -import { playground } from "./playground"; -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 { Component, render } from "preact"; import { DeleteSecretsEngine } from "./ui/pages/Secrets/DeleteSecretsEngine"; -import { KeyValueView } from "./ui/pages/Secrets/KeyValue/KeyValueView"; +import { Home } from "./ui/pages/Home"; +import { KeyValueDelete } from "./ui/pages/Secrets/KeyValue/KeyValueDelete"; import { KeyValueSecret } from "./ui/pages/Secrets/KeyValue/KeyValueSecret"; import { KeyValueSecretEdit } from "./ui/pages/Secrets/KeyValue/KeyValueSecretsEdit"; -import { KeyValueDelete } from "./ui/pages/Secrets/KeyValue/KeyValueDelete"; +import { KeyValueView } from "./ui/pages/Secrets/KeyValue/KeyValueView"; +import { Login } from "./ui/pages/Login"; +import { Me } from "./ui/pages/Me"; +import { NavBar } from "./ui/elements/NavBar"; +import { NewKVEngine } from "./ui/pages/Secrets/NewEngines/NewKVEngine"; +import { NewSecretsEngine } from "./ui/pages/Secrets/NewSecretsEngine"; +import { NewTOTPEngine } from "./ui/pages/Secrets/NewEngines/NewTOTPEngine"; +import { NewTransitEngine } from "./ui/pages/Secrets/NewEngines/NewTransitEngine"; +import { NewTransitKey } from "./ui/pages/Secrets/Transit/NewTransitKey"; +import { PasswordGenerator } from "./ui/pages/PwGen"; +import { Secrets } from "./ui/pages/Secrets/SecretsHome"; +import { SetLanguage } from "./ui/pages/SetLanguage"; +import { SetVaultURL } from "./ui/pages/SetVaultURL"; +import { TOTPDelete } from "./ui/pages/Secrets/TOTP/TOTPDelete"; +import { TOTPNew } from "./ui/pages/Secrets/TOTP/TOTPNew"; +import { TOTPView } from "./ui/pages/Secrets/TOTP/TOTPView"; import { TransitView } from "./ui/pages/Secrets/Transit/TransitView"; import { TransitViewSecret } from "./ui/pages/Secrets/Transit/TransitViewSecret"; -import { NewTransitKey } from "./ui/pages/Secrets/Transit/NewTransitKey"; +import { Unseal } from "./ui/pages/Unseal"; +import { pageState } from "./globalPageState"; +import { playground } from "./playground"; +import Router from "preact-router"; +import i18next from "i18next"; async function onLoad(): Promise { const Main = () => ( @@ -88,9 +88,9 @@ async function onLoad(): Promise { - -

PAGE NOT YET IMPLEMENTED

- +
+

PAGE NOT YET IMPLEMENTED

+
); diff --git a/src/pageUtils.ts b/src/pageUtils.ts index 77358ba..eb26c8f 100644 --- a/src/pageUtils.ts +++ b/src/pageUtils.ts @@ -2,10 +2,10 @@ import { PageRouter } from "./pagerouter/PageRouter"; import { PageState } from "./state/PageState"; import { getSealStatus } from "./api/sys/getSealStatus"; import { lookupSelf } from "./api/sys/lookupSelf"; +import { route } from "preact-router"; import ClipboardJS from "clipboard"; import UIkit from "uikit"; import i18next from "i18next"; -import { route } from "preact-router"; async function prePageChecksReal(state: PageState) { if (state.language.length == 0) { diff --git a/src/pagerouter/PageListType.ts b/src/pagerouter/PageListType.ts index 7057156..1ebb54a 100644 --- a/src/pagerouter/PageListType.ts +++ b/src/pagerouter/PageListType.ts @@ -3,4 +3,4 @@ import { PageType } from "./PageType"; export type PageListType = { getPageIDs(): Promise; getPage(pageID: string): Promise; -} \ No newline at end of file +}; diff --git a/src/pagerouter/PageRouter.ts b/src/pagerouter/PageRouter.ts index 0260601..f5d3dc2 100644 --- a/src/pagerouter/PageRouter.ts +++ b/src/pagerouter/PageRouter.ts @@ -1,5 +1,5 @@ -import { PageType } from "./PageType"; import { PageListType } from "./PageListType"; +import { PageType } from "./PageType"; const PageDoesNotExistError = new Error("Page does not exist."); const PageHasNotBeenSetError = new Error("Page has not been set."); @@ -9,20 +9,18 @@ export type Options = { state: unknown; pageContentElement: HTMLElement; pageTitleElement: HTMLElement; - resetElementContent?: Boolean; + resetElementContent?: boolean; onPageChange: () => void; -} +}; export class PageRouter { - constructor( - options: Options - ) { + constructor(options: Options) { this.pageList = options.pageList; this.state = options.state; this.pageContentElement = options.pageContentElement; this.pageTitleElement = options.pageTitleElement; this.resetElementContent = (options.resetElementContent || true) == true; - this.onPageChange = (options.onPageChange); + this.onPageChange = options.onPageChange; } public onPageChange: () => void; @@ -31,7 +29,7 @@ export class PageRouter { private currentPageID: string; private currentPage: PageType; - private resetElementContent: Boolean; + private resetElementContent: boolean; public state: unknown; public pageContentElement: HTMLElement; @@ -87,11 +85,7 @@ export class PageRouter { this.pageContentElement.innerHTML = ""; this.pageTitleElement.innerHTML = ""; } - await Promise.all([ - this.currentPage.renderPageTitle(), - this.currentPage.render(), - ]) -; + await Promise.all([this.currentPage.renderPageTitle(), this.currentPage.render()]); } public async refresh(): Promise { diff --git a/src/pagerouter/PageType.ts b/src/pagerouter/PageType.ts index feb0d7c..f3331e9 100644 --- a/src/pagerouter/PageType.ts +++ b/src/pagerouter/PageType.ts @@ -6,4 +6,4 @@ export type PageType = { goBack(): Promise; cleanup(): Promise; setRouterAndState(router: PageRouter, state: unknown): Promise; -} \ No newline at end of file +}; diff --git a/src/state/PageState.ts b/src/state/PageState.ts index 4c9bd63..e2c1c38 100644 --- a/src/state/PageState.ts +++ b/src/state/PageState.ts @@ -4,8 +4,8 @@ export class PageState { constructor() { const params = new URLSearchParams(window.location.search); if (params.has("reset")) this.storage.clear(); - if (params.has("state")) { - console.log("state owo") + if (params.has("state")) { + console.log("state owo"); this.loadState(JSON.parse(params.get("state"))); } @@ -20,29 +20,28 @@ export class PageState { dumpState(): { [key: string]: unknown } { return { - "baseMount": this.baseMount, - "secretPath": this.secretPath, - "secretVersion": this.secretVersion, - "secretItem": this.secretItem, - "secretMountType": this.secretMountType, - "policyItem": this.policyItem, - "authPath": this.authPath, - "userPassUser": this.userPassUser, - "currentPage": this.currentPage, - } + baseMount: this.baseMount, + secretPath: this.secretPath, + secretVersion: this.secretVersion, + secretItem: this.secretItem, + secretMountType: this.secretMountType, + policyItem: this.policyItem, + authPath: this.authPath, + userPassUser: this.userPassUser, + currentPage: this.currentPage, + }; } loadState(newState: { [key: string]: unknown }) { - console.log(newState) - for (let prop in newState) { - console.log("WANTS", prop) + console.log(newState); + for (const prop in newState) { + console.log("WANTS", prop); if (prop in this) { console.log("HAS", prop.toString()); // @ts-ignore - this[prop] = newState[prop]; + this[prop] = newState[prop]; } - } - + } } // NOTE: When a item in the page state isn't a string (e.g it is a array or object), diff --git a/src/translations/de.js b/src/translations/de.js index b8cb055..4015859 100644 --- a/src/translations/de.js +++ b/src/translations/de.js @@ -147,7 +147,8 @@ module.exports = { "Bei cubbyhole, können secrets gespeichert werden, solange dein Token gültig ist. Sobald der Token nicht mehr gültig ist, werden die Secrets gelöscht und können daher auch nur mit dem jetzigen Token gültig ist.", kv_view_new_btn: "Neu", kv_view_delete_btn: "Löschen", - kv_view_none_here_text: "Es scheint so als hättest du noch keine Secrets hier. Möchtest du eins erstellen?", + kv_view_none_here_text: + "Es scheint so als hättest du noch keine Secrets hier. Möchtest du eins erstellen?", // TOTP View Page totp_view_title: "TOTP", @@ -320,4 +321,4 @@ module.exports = { policy_delete_text: "Sicher das diese Richtlinie gelöscht werden soll? Diese Aktion kann nicht rückgängig gemacht werden und könnte die Berechtigungen der Benutzer stören.", policy_delete_btn: "Richtlinie Löschen", -}; \ No newline at end of file +}; diff --git a/src/types/DefaultPageProps.ts b/src/types/DefaultPageProps.ts index a1476fd..a2d6342 100644 --- a/src/types/DefaultPageProps.ts +++ b/src/types/DefaultPageProps.ts @@ -1,6 +1,6 @@ import { PageState } from "../state/PageState"; export type DefaultPageProps = { - state: PageState; - matches?: {[key: string]: string} -}; \ No newline at end of file + state: PageState; + matches?: { [key: string]: string }; +}; diff --git a/src/types/Page.tsx b/src/types/Page.tsx index 7f6f45e..f248eae 100644 --- a/src/types/Page.tsx +++ b/src/types/Page.tsx @@ -1,7 +1,7 @@ -import { render } from "preact"; +import { CopyStateLinkButton } from "../ui/elements/CopyStateLinkButton"; import { PageRouter } from "../pagerouter/PageRouter"; import { PageState } from "../state/PageState"; -import { CopyStateLinkButton } from "../ui/elements/CopyStateLinkButton"; +import { render } from "preact"; export class Page { constructor() { @@ -18,8 +18,8 @@ export class Page { async renderPageTitle(): Promise { render( <> - {this.name} - + {this.name} + , this.router.pageTitleElement, ); diff --git a/src/ui/elements/CopyStateLinkButton.tsx b/src/ui/elements/CopyStateLinkButton.tsx index c259f9a..66b8a63 100644 --- a/src/ui/elements/CopyStateLinkButton.tsx +++ b/src/ui/elements/CopyStateLinkButton.tsx @@ -1,33 +1,33 @@ import { Component, JSX, createRef } from "preact"; +import { PageState } from "../../state/PageState"; import { addClipboardNotifications } from "../../pageUtils"; import ClipboardJS from "clipboard"; -import { PageState } from "../../state/PageState"; export type CopyStateLinkButtonProps = { - state: PageState; + state: PageState; }; export class CopyStateLinkButton extends Component { - buttonRef = createRef(); + buttonRef = createRef(); - componentDidMount(): void { - const clipboard = new ClipboardJS(this.buttonRef.current); - addClipboardNotifications(clipboard, 600); - } + componentDidMount(): void { + const clipboard = new ClipboardJS(this.buttonRef.current); + addClipboardNotifications(clipboard, 600); + } - render(): JSX.Element { - const newURL = new URL(window.location.toString()); - newURL.searchParams.set("state", JSON.stringify(this.props.state.dumpState())); + render(): JSX.Element { + const newURL = new URL(window.location.toString()); + newURL.searchParams.set("state", JSON.stringify(this.props.state.dumpState())); - return ( - - ); - } + return ( + + ); + } } diff --git a/src/ui/elements/NavBar.tsx b/src/ui/elements/NavBar.tsx index 838ce73..231b263 100644 --- a/src/ui/elements/NavBar.tsx +++ b/src/ui/elements/NavBar.tsx @@ -1,8 +1,7 @@ import { JSX, render } from "preact"; import { PageRouter } from "../../pagerouter/PageRouter"; -import i18next from "i18next"; import { getCurrentUrl, route } from "preact-router"; - +import i18next from "i18next"; export function NavBar(): JSX.Element { return ( @@ -10,14 +9,12 @@ export function NavBar(): JSX.Element { ); -} \ No newline at end of file +} diff --git a/src/ui/elements/PageTitle.tsx b/src/ui/elements/PageTitle.tsx index 947155d..2eef571 100644 --- a/src/ui/elements/PageTitle.tsx +++ b/src/ui/elements/PageTitle.tsx @@ -1,9 +1,13 @@ import { JSX } from "preact"; export type PageTitleProps = { - title: string; + title: string; }; export function PageTitle(props: PageTitleProps): JSX.Element { - return

{props.title}

; + return ( +

+ {props.title} +

+ ); } diff --git a/src/ui/pages/Access/AccessHome.tsx b/src/ui/pages/Access/AccessHome.tsx index fe20881..73a868b 100644 --- a/src/ui/pages/Access/AccessHome.tsx +++ b/src/ui/pages/Access/AccessHome.tsx @@ -1,10 +1,10 @@ import { Grid, GridSizes } from "../../elements/Grid"; import { Page } from "../../../types/Page"; +import { PageState } from "../../../state/PageState"; import { Tile } from "../../elements/Tile"; import { notImplemented, prePageChecks } from "../../../pageUtils"; import { render } from "preact"; import i18next from "i18next"; -import { PageState } from "../../../state/PageState"; export class AccessHomePage extends Page { constructor() { diff --git a/src/ui/pages/Home.tsx b/src/ui/pages/Home.tsx index 7ca06ce..73b66b9 100644 --- a/src/ui/pages/Home.tsx +++ b/src/ui/pages/Home.tsx @@ -1,31 +1,31 @@ +import { Component, JSX, render } from "preact"; import { Grid, GridSizes } from "../elements/Grid"; import { Margin } from "../elements/Margin"; import { Page } from "../../types/Page"; +import { PageState } from "../../state/PageState"; +import { PageTitle } from "../elements/PageTitle"; import { Tile } from "../elements/Tile"; import { TokenInfo } from "../../api/types/token"; import { getCapabilitiesPath } from "../../api/sys/getCapabilities"; import { lookupSelf } from "../../api/sys/lookupSelf"; import { prePageChecks, setErrorText } from "../../pageUtils"; -import { Component, JSX, render } from "preact"; -import i18next from "i18next"; -import { PageState } from "../../state/PageState"; import { route } from "preact-router"; -import { PageTitle } from "../elements/PageTitle"; +import i18next from "i18next"; type HomeProps = { state: PageState; -} +}; type HomeState = { selfTokenInfo: TokenInfo; authCaps: string[]; policiesCaps: string[]; -} +}; export class Home extends Component { async componentDidMount() { if (!(await prePageChecks(this.props.state))) return; - + let selfTokenInfo: TokenInfo; try { selfTokenInfo = await lookupSelf(); @@ -34,7 +34,7 @@ export class Home extends Component { setErrorText(error.message); if (error.message == "permission denied") { this.props.state.token = ""; - route('/login', true); + route("/login", true); return; } } @@ -47,63 +47,63 @@ export class Home extends Component { selfTokenInfo: selfTokenInfo, authCaps: authCaps, policiesCaps: policiesCaps, - }) + }); } render(): JSX.Element { - return this.state.selfTokenInfo && ( - <> - -
- - - - { - route("/secrets"); - }} - /> - { - route("/access"); - }} - /> - { - route("/policies"); - }} - /> - - -
- + return ( + this.state.selfTokenInfo && ( + <> + +
+
    +
  • + {i18next.t("home_vaulturl_text", { text: this.props.state.apiURL })} +
  • +
  • + {i18next.t("home_password_generator_btn")} +
  • +
  • + + {i18next.t("home_your_token_expires_in", { + date: new Date(this.state.selfTokenInfo.expire_time), + })} + +
  • +
+ + + { + route("/secrets"); + }} + /> + { + route("/access"); + }} + /> + { + route("/policies"); + }} + /> + + +
+ + ) ); } diff --git a/src/ui/pages/Login.tsx b/src/ui/pages/Login.tsx index 61fc1db..dfdeedc 100644 --- a/src/ui/pages/Login.tsx +++ b/src/ui/pages/Login.tsx @@ -1,18 +1,18 @@ import { Component, JSX, render } from "preact"; +import { DefaultPageProps } from "../../types/DefaultPageProps"; import { Form } from "../elements/Form"; import { Margin } from "../elements/Margin"; import { MarginInline } from "../elements/MarginInline"; import { Page } from "../../types/Page"; +import { PageState } from "../../state/PageState"; +import { PageTitle } from "../elements/PageTitle"; import { lookupSelf } from "../../api/sys/lookupSelf"; +import { route } from "preact-router"; import { setErrorText } from "../../pageUtils"; import { usernameLogin } from "../../api/auth/usernameLogin"; import i18next from "i18next"; -import { route } from "preact-router"; -import { PageTitle } from "../elements/PageTitle"; -import { DefaultPageProps } from "../../types/DefaultPageProps"; -import { PageState } from "../../state/PageState"; -export class TokenLoginForm extends Component<{state: PageState}, unknown> { +export class TokenLoginForm extends Component<{ state: PageState }, unknown> { constructor() { super(); } @@ -58,7 +58,7 @@ export class TokenLoginForm extends Component<{state: PageState}, unknown> { } } -export class UsernameLoginForm extends Component<{state: PageState}, unknown> { +export class UsernameLoginForm extends Component<{ state: PageState }, unknown> { constructor() { super(); } diff --git a/src/ui/pages/Me.tsx b/src/ui/pages/Me.tsx index 409cf03..86680fd 100644 --- a/src/ui/pages/Me.tsx +++ b/src/ui/pages/Me.tsx @@ -1,13 +1,13 @@ import { Component, JSX, createRef } from "preact"; +import { DefaultPageProps } from "../../types/DefaultPageProps"; +import { PageTitle } from "../elements/PageTitle"; import { addClipboardNotifications, prePageChecks, setErrorText } from "../../pageUtils"; import { getCapsPath } from "../../api/sys/getCapabilities"; import { renewSelf } from "../../api/sys/renewSelf"; +import { route } from "preact-router"; import { sealVault } from "../../api/sys/sealVault"; import ClipboardJS from "clipboard"; import i18next from "i18next"; -import { DefaultPageProps } from "../../types/DefaultPageProps"; -import { route } from "preact-router"; -import { PageTitle } from "../elements/PageTitle"; export class CopyLink extends Component<{ text: string; data: string }, unknown> { linkRef = createRef(); @@ -29,10 +29,10 @@ export class CopyLink extends Component<{ text: string; data: string }, unknown> type MeState = { loaded: boolean; canSealVault: boolean; -} +}; export class Me extends Component { - defaultState = { loaded: false, canSealVault: false } + defaultState = { loaded: false, canSealVault: false }; constructor() { super(); this.state = this.defaultState; @@ -58,62 +58,60 @@ export class Me extends Component { } render(): JSX.Element { - return this.state.loaded && ( - <> - - + + ) ); } diff --git a/src/ui/pages/Policies/PoliciesHome.tsx b/src/ui/pages/Policies/PoliciesHome.tsx index 45e0a85..4e2dbd6 100644 --- a/src/ui/pages/Policies/PoliciesHome.tsx +++ b/src/ui/pages/Policies/PoliciesHome.tsx @@ -1,10 +1,10 @@ import { Margin } from "../../elements/Margin"; import { Page } from "../../../types/Page"; +import { PageState } from "../../../state/PageState"; import { getPolicies } from "../../../api/sys/policies/getPolicies"; import { prePageChecks } from "../../../pageUtils"; import { render } from "preact"; import i18next from "i18next"; -import { PageState } from "../../../state/PageState"; export class PoliciesHomePage extends Page { constructor() { diff --git a/src/ui/pages/Policies/PolicyView.tsx b/src/ui/pages/Policies/PolicyView.tsx index cad7965..bdd77d2 100644 --- a/src/ui/pages/Policies/PolicyView.tsx +++ b/src/ui/pages/Policies/PolicyView.tsx @@ -1,11 +1,11 @@ import { CodeBlock } from "../../elements/CodeBlock"; import { Margin } from "../../elements/Margin"; import { Page } from "../../../types/Page"; +import { PageState } from "../../../state/PageState"; import { getPolicy } from "../../../api/sys/policies/getPolicy"; import { prePageChecks } from "../../../pageUtils"; import { render } from "preact"; import i18next from "i18next"; -import { PageState } from "../../../state/PageState"; export class PolicyViewPage extends Page { constructor() { diff --git a/src/ui/pages/PwGen.tsx b/src/ui/pages/PwGen.tsx index be3b913..ce8090d 100644 --- a/src/ui/pages/PwGen.tsx +++ b/src/ui/pages/PwGen.tsx @@ -1,9 +1,9 @@ import { Component, JSX, createRef, render } from "preact"; import { CopyableInputBox } from "../elements/CopyableInputBox"; -import { PageTitle } from "../elements/PageTitle"; import { Form } from "../elements/Form"; import { Margin } from "../elements/Margin"; import { Page } from "../../types/Page"; +import { PageTitle } from "../elements/PageTitle"; import i18next from "i18next"; const passwordLengthMin = 1; @@ -140,4 +140,4 @@ export class PasswordGenerator extends Component<{}, PasswordGeneratorState> { ); } -} \ No newline at end of file +} diff --git a/src/ui/pages/Secrets/DeleteSecretsEngine.tsx b/src/ui/pages/Secrets/DeleteSecretsEngine.tsx index 81c120e..9f17e5e 100644 --- a/src/ui/pages/Secrets/DeleteSecretsEngine.tsx +++ b/src/ui/pages/Secrets/DeleteSecretsEngine.tsx @@ -1,20 +1,21 @@ +import { Component, render } from "preact"; +import { DefaultPageProps } from "../../../types/DefaultPageProps"; import { Form } from "../../elements/Form"; import { MarginInline } from "../../elements/MarginInline"; import { Page } from "../../../types/Page"; +import { PageTitle } from "../../elements/PageTitle"; import { deleteMount } from "../../../api/sys/deleteMount"; -import { Component, render } from "preact"; +import { route } from "preact-router"; import { setErrorText } from "../../../pageUtils"; import i18next from "i18next"; -import { DefaultPageProps } from "../../../types/DefaultPageProps"; -import { PageTitle } from "../../elements/PageTitle"; -import { route } from "preact-router"; export class DeleteSecretsEngine extends Component { render() { - return ( <> - +
{ await this.onSubmit(); diff --git a/src/ui/pages/Secrets/KeyValue/KeyValueDelete.tsx b/src/ui/pages/Secrets/KeyValue/KeyValueDelete.tsx index ab03b36..9df08fc 100644 --- a/src/ui/pages/Secrets/KeyValue/KeyValueDelete.tsx +++ b/src/ui/pages/Secrets/KeyValue/KeyValueDelete.tsx @@ -1,9 +1,9 @@ +import { Component, render } from "preact"; +import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { Page } from "../../../../types/Page"; import { SecretTitleElement } from "../SecretTitleElement"; import { deleteSecret } from "../../../../api/kv/deleteSecret"; -import { Component, render } from "preact"; import i18next from "i18next"; -import { DefaultPageProps } from "../../../../types/DefaultPageProps"; export class KeyValueDelete extends Component { render() { @@ -25,11 +25,7 @@ export class KeyValueDelete extends Component { - ); } } diff --git a/src/ui/pages/Secrets/KeyValue/KeyValueNew.tsx b/src/ui/pages/Secrets/KeyValue/KeyValueNew.tsx index 74078c5..7caa02e 100644 --- a/src/ui/pages/Secrets/KeyValue/KeyValueNew.tsx +++ b/src/ui/pages/Secrets/KeyValue/KeyValueNew.tsx @@ -1,20 +1,20 @@ +import { Component, render } from "preact"; +import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { Form } from "../../../elements/Form"; import { Margin } from "../../../elements/Margin"; import { SecretTitleElement } from "../SecretTitleElement"; import { createOrUpdateSecret } from "../../../../api/kv/createOrUpdateSecret"; -import { Component, render } from "preact"; +import { kvViewURL } from "../../pageLinks"; +import { route } from "preact-router"; import { setErrorText } from "../../../../pageUtils"; import i18next from "i18next"; -import { DefaultPageProps } from "../../../../types/DefaultPageProps"; -import { route } from "preact-router"; -import { kvViewURL } from "../../pageLinks"; export class KeyValueNewPage extends Component { - render(){ + render() { const baseMount = this.props.matches["baseMount"]; const secretPath = (this.props.matches["secretPath"] || "").split("/"); - return( + return ( <> { secretPath={secretPath} suffix={i18next.t("kv_sec_edit_suffix")} /> -
- await this.newKVSecretHandleForm(formData, baseMount, secretPath)}> - - - -

- -

-
+
+
+ await this.newKVSecretHandleForm(formData, baseMount, secretPath) + } + > + + + +

+ +

+
); } - async newKVSecretHandleForm(formData: FormData, baseMount: string, secretPath: string[]): Promise { + async newKVSecretHandleForm( + formData: FormData, + baseMount: string, + secretPath: string[], + ): Promise { const path = formData.get("path") as string; // TODO: check only do this on kv v1 - let keyData = { "key": "value" }; + const keyData = { key: "value" }; try { - await createOrUpdateSecret( - baseMount, - secretPath, - path, - keyData, - ); - route(kvViewURL(baseMount, secretPath, path)) + await createOrUpdateSecret(baseMount, secretPath, path, keyData); + route(kvViewURL(baseMount, secretPath, path)); } catch (e: unknown) { const error = e as Error; setErrorText(error.message); diff --git a/src/ui/pages/Secrets/KeyValue/KeyValueSecret.tsx b/src/ui/pages/Secrets/KeyValue/KeyValueSecret.tsx index 0ba152c..46877a1 100644 --- a/src/ui/pages/Secrets/KeyValue/KeyValueSecret.tsx +++ b/src/ui/pages/Secrets/KeyValue/KeyValueSecret.tsx @@ -1,15 +1,15 @@ import { CodeBlock } from "../../../elements/CodeBlock"; import { Component, JSX, render } from "preact"; import { CopyableInputBox } from "../../../elements/CopyableInputBox"; +import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { Grid, GridSizes } from "../../../elements/Grid"; import { SecretTitleElement } from "../SecretTitleElement"; import { getCapabilities } from "../../../../api/sys/getCapabilities"; import { getSecret } from "../../../../api/kv/getSecret"; +import { kvDeleteURL, kvEditURL } from "../../pageLinks"; +import { route } from "preact-router"; import { sortedObjectMap } from "../../../../utils"; import i18next from "i18next"; -import { DefaultPageProps } from "../../../../types/DefaultPageProps"; -import { route } from "preact-router"; -import { kvDeleteURL, kvEditURL } from "../../pageLinks"; export type KVSecretViewProps = { kvData: Record; @@ -48,7 +48,7 @@ type KeyValueSecretState = { secretItem: string; caps: string[]; secretInfo: Record; -} +}; export class KeyValueSecret extends Component { async componentDidMount() { @@ -56,30 +56,25 @@ export class KeyValueSecret extends Component e + "/"); + const secretPathAPI = secretPath.map((e) => e + "/"); // TODO: this is a big hacky, fix when redo how api arguments work - secretPathAPI[secretPathAPI.length - 1] = String(secretPathAPI[secretPathAPI.length - 1]).replace("/", "").toString(); + secretPathAPI[secretPathAPI.length - 1] = String(secretPathAPI[secretPathAPI.length - 1]) + .replace("/", "") + .toString(); - const secretInfo = await getSecret( - baseMount, - secretPathAPI, - secretItem, - ); + const secretInfo = await getSecret(baseMount, secretPathAPI, secretItem); this.setState({ baseMount, secretPath, secretItem, caps, - secretInfo - }) - + secretInfo, + }); } render() { - if (!this.state.baseMount) return; + if (!this.state.baseMount) return; return ( <> @@ -92,23 +87,25 @@ export class KeyValueSecret extends Component

- { - this.state.caps.includes("delete") && ( - - ) - } + {this.state.caps.includes("delete") && ( + + )} {this.state.caps.includes("update") && (

- ); } } diff --git a/src/ui/pages/Secrets/KeyValue/KeyValueSecretsEdit.tsx b/src/ui/pages/Secrets/KeyValue/KeyValueSecretsEdit.tsx index fda20f0..f298b4a 100644 --- a/src/ui/pages/Secrets/KeyValue/KeyValueSecretsEdit.tsx +++ b/src/ui/pages/Secrets/KeyValue/KeyValueSecretsEdit.tsx @@ -1,5 +1,6 @@ import { CodeEditor } from "../../../elements/CodeEditor"; import { Component, JSX, render } from "preact"; +import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { Page } from "../../../../types/Page"; import { SecretTitleElement } from "../SecretTitleElement"; import { createOrUpdateSecret } from "../../../../api/kv/createOrUpdateSecret"; @@ -7,7 +8,6 @@ import { getSecret } from "../../../../api/kv/getSecret"; import { setErrorText } from "../../../../pageUtils"; import { sortedObjectMap, verifyJSONString } from "../../../../utils"; import i18next from "i18next"; -import { DefaultPageProps } from "../../../../types/DefaultPageProps"; export type KVEditProps = { baseMount: string; @@ -17,13 +17,13 @@ export type KVEditProps = { type KVEditState = | { - dataLoaded: false; - } + dataLoaded: false; + } | { - dataLoaded: true; - kvData: Record; - code: string; - }; + dataLoaded: true; + kvData: Record; + code: string; + }; export class KVEditor extends Component { constructor() { diff --git a/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx b/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx index 74af41a..8dd13d7 100644 --- a/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx +++ b/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx @@ -1,16 +1,15 @@ -import { Component, createRef, JSX, render } from "preact"; +import { CapabilitiesType, getCapabilitiesPath } from "../../../../api/sys/getCapabilities"; +import { Component, JSX, createRef, render } from "preact"; +import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { DoesNotExistError } from "../../../../types/internalErrors"; import { Page } from "../../../../types/Page"; import { SecretTitleElement } from "../SecretTitleElement"; -import { CapabilitiesType, getCapabilitiesPath } from "../../../../api/sys/getCapabilities"; -import { getSecrets } from "../../../../api/kv/getSecrets"; -import { setErrorText } from "../../../../pageUtils"; -import i18next from "i18next"; -import { DefaultPageProps } from "../../../../types/DefaultPageProps"; -import { route } from "preact-router"; import { delSecretsEngineURL, kvListURL, kvNewURL, kvViewURL } from "../../pageLinks"; import { getMount } from "../../../../api/sys/getMounts"; - +import { getSecrets } from "../../../../api/kv/getSecrets"; +import { route } from "preact-router"; +import { setErrorText } from "../../../../pageUtils"; +import i18next from "i18next"; export type KVKeysListProps = DefaultPageProps & { baseMount: string; @@ -28,11 +27,16 @@ function SecretsList(baseMount: string, secretPath: string[], secrets: string[])
  • { - console.log(baseMount, secretPath, secret) + console.log(baseMount, secretPath, secret); if (secret.endsWith("/")) { - route(kvListURL(baseMount, [...secretPath, secret.replace("/", "")].filter((e)=>e.length > 0))) + route( + kvListURL( + baseMount, + [...secretPath, secret.replace("/", "")].filter((e) => e.length > 0), + ), + ); } else { - route(kvViewURL(baseMount, secretPath, secret)) + route(kvViewURL(baseMount, secretPath, secret)); } }} > @@ -54,10 +58,7 @@ export class KVKeysList extends Component { async loadData(): Promise { try { - const keys = await getSecrets( - this.props.baseMount, - this.props.secretPath, - ); + const keys = await getSecrets(this.props.baseMount, this.props.secretPath); this.setState({ dataLoaded: true, keys: keys, @@ -142,7 +143,7 @@ type KeyValueViewState = { pathCaps: string[]; mountCaps: string[]; mountType: string; -} +}; export class KeyValueView extends Component { async componentDidMount() { @@ -181,7 +182,7 @@ export class KeyValueView extends Component - , + + , ); } diff --git a/src/ui/pages/Secrets/NewEngines/NewTransitEngine.tsx b/src/ui/pages/Secrets/NewEngines/NewTransitEngine.tsx index d7d3ad4..6ad9a58 100644 --- a/src/ui/pages/Secrets/NewEngines/NewTransitEngine.tsx +++ b/src/ui/pages/Secrets/NewEngines/NewTransitEngine.tsx @@ -1,13 +1,13 @@ +import { Component, render } from "preact"; import { Form } from "../../../elements/Form"; import { Margin } from "../../../elements/Margin"; import { MarginInline } from "../../../elements/MarginInline"; import { Page } from "../../../../types/Page"; +import { PageTitle } from "../../../elements/PageTitle"; import { newMount } from "../../../../api/sys/newMount"; -import { Component, render } from "preact"; +import { route } from "preact-router"; import { setErrorText } from "../../../../pageUtils"; import i18next from "i18next"; -import { PageTitle } from "../../../elements/PageTitle"; -import { route } from "preact-router"; export class NewTransitEngine extends Component { render() { @@ -30,7 +30,8 @@ export class NewTransitEngine extends Component { {i18next.t("new_transit_engine_create_btn")} - , + + , ); } @@ -43,7 +44,7 @@ export class NewTransitEngine extends Component { name: name, type: "transit", }); - route("/secrets/transit/list/" + name + "/") + route("/secrets/transit/list/" + name + "/"); } catch (e) { const error = e as Error; setErrorText(error.message); diff --git a/src/ui/pages/Secrets/NewSecretsEngine.tsx b/src/ui/pages/Secrets/NewSecretsEngine.tsx index dab8622..da8b985 100644 --- a/src/ui/pages/Secrets/NewSecretsEngine.tsx +++ b/src/ui/pages/Secrets/NewSecretsEngine.tsx @@ -1,39 +1,39 @@ +import { Component, render } from "preact"; import { Grid, GridSizes } from "../../elements/Grid"; import { Page } from "../../../types/Page"; -import { Tile } from "../../elements/Tile"; -import { Component, render } from "preact"; -import i18next from "i18next"; -import { route } from "preact-router"; import { PageTitle } from "../../elements/PageTitle"; +import { Tile } from "../../elements/Tile"; +import { route } from "preact-router"; +import i18next from "i18next"; export class NewSecretsEngine extends Component { render() { return ( <> - - - { - route("/secrets/new_secrets_engine/kv") - }} - /> - { - route("/secrets/new_secrets_engine/totp") - }} - /> - { - route("/secrets/new_secrets_engine/transit") - }} - /> - + + + { + route("/secrets/new_secrets_engine/kv"); + }} + /> + { + route("/secrets/new_secrets_engine/totp"); + }} + /> + { + route("/secrets/new_secrets_engine/transit"); + }} + /> + ); } diff --git a/src/ui/pages/Secrets/SecretTitleElement.tsx b/src/ui/pages/Secrets/SecretTitleElement.tsx index 8ad27e3..2b5e040 100644 --- a/src/ui/pages/Secrets/SecretTitleElement.tsx +++ b/src/ui/pages/Secrets/SecretTitleElement.tsx @@ -1,6 +1,6 @@ -import { route } from "preact-router"; import { JSX } from "preact/jsx-runtime"; import { kvListURL } from "../pageLinks"; +import { route } from "preact-router"; type SecretTitleElementProps = { type: string; @@ -17,7 +17,6 @@ export function SecretTitleElement(props: SecretTitleElementProps): JSX.Element const baseMount = props.baseMount; const secretPath = props.secretPath || []; - return (

    @@ -30,24 +29,29 @@ export function SecretTitleElement(props: SecretTitleElementProps): JSX.Element {"/ "} - + {baseMount + "/ "} {...secretPath.map((secretPath, index, secretPaths) => { // TODO: find where a '' is returned so dont need this if (secretPath.length < 1) return; - return { - - if (type == "kv") { - let secretPath = secretPaths.slice(0, index + 1); - route(kvListURL(baseMount, secretPath)) - } - }} - > - {secretPath + "/" + " "} - + return ( + { + if (type == "kv") { + const secretPath = secretPaths.slice(0, index + 1); + route(kvListURL(baseMount, secretPath)); + } + }} + > + {secretPath + "/" + " "} + + ); })} {item.length != 0 && {item}} {suffix.length != 0 && {suffix}} diff --git a/src/ui/pages/Secrets/SecretsHome.tsx b/src/ui/pages/Secrets/SecretsHome.tsx index 6c51deb..a0fc0e8 100644 --- a/src/ui/pages/Secrets/SecretsHome.tsx +++ b/src/ui/pages/Secrets/SecretsHome.tsx @@ -1,14 +1,14 @@ import { Component, JSX, render } from "preact"; +import { DefaultPageProps } from "../../../types/DefaultPageProps"; import { MountType, getMounts } from "../../../api/sys/getMounts"; import { Page } from "../../../types/Page"; +import { PageState } from "../../../state/PageState"; +import { PageTitle } from "../../elements/PageTitle"; import { getCapsPath } from "../../../api/sys/getCapabilities"; import { prePageChecks } from "../../../pageUtils"; +import { route } from "preact-router"; import { sortedObjectMap } from "../../../utils"; import i18next from "i18next"; -import { PageState } from "../../../state/PageState"; -import { DefaultPageProps } from "../../../types/DefaultPageProps"; -import { route } from "preact-router"; -import { PageTitle } from "../../elements/PageTitle"; const supportedMountTypes = ["kv", "totp", "transit", "cubbyhole"]; @@ -46,21 +46,19 @@ function MountLink(props: MountLinkProps): JSX.Element { mountPathType = "kv"; } - let link = "/secrets/" + mountPathType + "/list/" + baseMount; + const link = "/secrets/" + mountPathType + "/list/" + baseMount; return (
  • - - {linkText} - + {linkText}
  • ); } type SecretsState = { - mountsMap: Map; + mountsMap: Map; capabilities: string[]; -} +}; export class Secrets extends Component { async componentDidMount() { @@ -72,44 +70,48 @@ export class Secrets extends Component { const mountsMap = sortedObjectMap(mounts); this.setState({ capabilities: mountsCapabilities, - mountsMap: mountsMap as Map - }) + mountsMap: mountsMap as Map, + }); } - render() { - return this.state.mountsMap && ( - <> - -
    + return ( + this.state.mountsMap && ( + <> +
    -

    - {this.state.capabilities.includes("sudo") && this.state.capabilities.includes("create") && ( - - )} -

    +
    +

    + {this.state.capabilities.includes("sudo") && + this.state.capabilities.includes("create") && ( + + )} +

    +
    +
    +
      + {Array.from(this.state.mountsMap).map((args: [string, MountType]) => { + const baseMount = args[0]; + const mount = args[1]; + console.log(baseMount, mount); + if (isSupportedMount(mount)) { + return ( + + ); + } + })} +
    +
    -
    -
      - {Array.from(this.state.mountsMap).map((args: [string, MountType]) => { - const baseMount = args[0]; - const mount = args[1]; - console.log(baseMount, mount) - if (isSupportedMount(mount)) { - return ; - } - })} -
    -
    -
    - + + ) ); } } diff --git a/src/ui/pages/Secrets/TOTP/TOTPDelete.tsx b/src/ui/pages/Secrets/TOTP/TOTPDelete.tsx index 9b4c542..5b54ef9 100644 --- a/src/ui/pages/Secrets/TOTP/TOTPDelete.tsx +++ b/src/ui/pages/Secrets/TOTP/TOTPDelete.tsx @@ -1,11 +1,11 @@ +import { Component, render } from "preact"; +import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { Page } from "../../../../types/Page"; import { SecretTitleElement } from "../SecretTitleElement"; import { deleteTOTP } from "../../../../api/totp/deleteTOTP"; -import { Component, render } from "preact"; -import i18next from "i18next"; -import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { route } from "preact-router"; import { totpListURL } from "../../pageLinks"; +import i18next from "i18next"; export class TOTPDelete extends Component { render() { @@ -22,8 +22,8 @@ export class TOTPDelete extends Component {
    - ); } } diff --git a/src/ui/pages/Secrets/TOTP/TOTPNew.tsx b/src/ui/pages/Secrets/TOTP/TOTPNew.tsx index 3f77b68..c611eed 100644 --- a/src/ui/pages/Secrets/TOTP/TOTPNew.tsx +++ b/src/ui/pages/Secrets/TOTP/TOTPNew.tsx @@ -1,4 +1,5 @@ import { Component, JSX, createRef, render } from "preact"; +import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { Form } from "../../../elements/Form"; import { Margin } from "../../../elements/Margin"; import { MarginInline } from "../../../elements/MarginInline"; @@ -6,10 +7,9 @@ import { Page } from "../../../../types/Page"; import { QRScanner } from "../../../elements/QRScanner"; import { SecretTitleElement } from "../SecretTitleElement"; import { addNewTOTP } from "../../../../api/totp/addNewTOTP"; +import { route } from "preact-router"; import { setErrorText } from "../../../../pageUtils"; import i18next from "i18next"; -import { route } from "preact-router"; -import { DefaultPageProps } from "../../../../types/DefaultPageProps"; function replaceAll(str: string, replace: string, replaceWith: string): string { return str.replace(new RegExp(replace, "g"), replaceWith); @@ -41,7 +41,7 @@ export class TOTPNewForm extends Component<{ baseMount: string }, { qrMode: bool try { await addNewTOTP(this.props.baseMount, parms); - route("/secrets/totp/list/" + this.props.baseMount) + route("/secrets/totp/list/" + this.props.baseMount); } catch (e: unknown) { const error = e as Error; setErrorText(`API Error: ${error.message}`); @@ -124,7 +124,11 @@ export class TOTPNew extends Component { const baseMount = this.props.matches["baseMount"]; return ( <> - + ); diff --git a/src/ui/pages/Secrets/TOTP/TOTPView.tsx b/src/ui/pages/Secrets/TOTP/TOTPView.tsx index 44b8c09..73156a2 100644 --- a/src/ui/pages/Secrets/TOTP/TOTPView.tsx +++ b/src/ui/pages/Secrets/TOTP/TOTPView.tsx @@ -1,28 +1,31 @@ +import { + CapabilitiesType, + getCapabilitiesPath, + getCapsPath, +} from "../../../../api/sys/getCapabilities"; import { Component, JSX, render } from "preact"; import { CopyableInputBox } from "../../../elements/CopyableInputBox"; +import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { DoesNotExistError } from "../../../../types/internalErrors"; import { Grid, GridSizes } from "../../../elements/Grid"; import { MarginInline } from "../../../elements/MarginInline"; import { Page } from "../../../../types/Page"; import { SecretTitleElement } from "../SecretTitleElement"; -import { CapabilitiesType, getCapabilitiesPath, getCapsPath } from "../../../../api/sys/getCapabilities"; +import { delSecretsEngineURL, totpNewURL } from "../../pageLinks"; import { getTOTPCode } from "../../../../api/totp/getTOTPCode"; import { getTOTPKeys } from "../../../../api/totp/getTOTPKeys"; import { removeDoubleSlash } from "../../../../utils"; +import { route } from "preact-router"; import { setErrorText } from "../../../../pageUtils"; import i18next from "i18next"; -import { DefaultPageProps } from "../../../../types/DefaultPageProps"; -import { route } from "preact-router"; -import { delSecretsEngineURL, totpNewURL } from "../../pageLinks"; type TOTPGridItemProps = { - baseMount: string; totpKey: string; canDelete: boolean; -} + baseMount: string; + totpKey: string; + canDelete: boolean; +}; -export class RefreshingTOTPGridItem extends Component< - TOTPGridItemProps, - { totpValue: string } -> { +export class RefreshingTOTPGridItem extends Component { constructor() { super(); this.state = { totpValue: "" }; @@ -73,7 +76,7 @@ export class RefreshingTOTPGridItem extends Component< type TOTPViewState = { capabilities?: CapabilitiesType; totpItems: TOTPGridItemProps[]; -} +}; export class TOTPView extends Component { constructor() { @@ -85,7 +88,7 @@ export class TOTPView extends Component { refresher: number; async componentDidMount() { - var baseMount = this.props.matches["baseMount"]; + const baseMount = this.props.matches["baseMount"]; const mountsPath = "/sys/mounts/" + baseMount; const caps = await getCapabilitiesPath([mountsPath, baseMount]); @@ -95,9 +98,7 @@ export class TOTPView extends Component { try { totpItems = await Promise.all( Array.from(await getTOTPKeys(baseMount)).map(async (key) => { - const totpCaps = await getCapsPath( - removeDoubleSlash(baseMount + "/code/" + key), - ); + const totpCaps = await getCapsPath(removeDoubleSlash(baseMount + "/code/" + key)); if (totpCaps.includes("read")) { return { baseMount: baseMount, @@ -116,13 +117,13 @@ export class TOTPView extends Component { this.setState({ capabilities: caps, - totpItems: totpItems + totpItems: totpItems, }); } render() { if (!this.state.capabilities) return; - var baseMount = this.props.matches["baseMount"]; + const baseMount = this.props.matches["baseMount"]; const mountsPath = "/sys/mounts/" + baseMount; const mountCaps = this.state.capabilities[mountsPath]; @@ -130,50 +131,49 @@ export class TOTPView extends Component { return ( <> - -
    -

    - {totpCaps.includes("create") && ( - - )} - {mountCaps.includes("delete") && ( - - )} -

    -
    - { - (() => { + +
    +

    + {totpCaps.includes("create") && ( + + )} + {mountCaps.includes("delete") && ( + + )} +

    +
    + {(() => { if (this.state.totpItems.length == 0) { return

    {i18next.t("totp_view_empty")}

    ; } else { return this.state.totpItems.map((totpItem) => { - return - }) + return ( + + ); + }); } - })() - } + })()} +
    -
    - ); } } diff --git a/src/ui/pages/Secrets/Transit/NewTransitKey.tsx b/src/ui/pages/Secrets/Transit/NewTransitKey.tsx index c487f3f..d8a46ff 100644 --- a/src/ui/pages/Secrets/Transit/NewTransitKey.tsx +++ b/src/ui/pages/Secrets/Transit/NewTransitKey.tsx @@ -1,14 +1,14 @@ +import { Component } from "preact"; +import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { Form } from "../../../elements/Form"; import { Margin } from "../../../elements/Margin"; import { MarginInline } from "../../../elements/MarginInline"; import { SecretTitleElement } from "../SecretTitleElement"; import { newTransitKey } from "../../../../api/transit/newTransitKey"; -import { Component } from "preact"; -import { setErrorText } from "../../../../pageUtils"; -import i18next from "i18next"; -import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { route } from "preact-router"; +import { setErrorText } from "../../../../pageUtils"; import { transitViewSecretURL } from "../../pageLinks"; +import i18next from "i18next"; export class NewTransitKey extends Component { constructor() { @@ -65,7 +65,6 @@ export class NewTransitKey extends Component { - ); } @@ -80,7 +79,7 @@ export class NewTransitKey extends Component { name: name, type: type, }); - route(transitViewSecretURL(baseMount, name)) + route(transitViewSecretURL(baseMount, name)); } catch (e) { const error = e as Error; setErrorText(error.message); diff --git a/src/ui/pages/Secrets/Transit/TransitView.tsx b/src/ui/pages/Secrets/Transit/TransitView.tsx index 25f83a8..bfcce97 100644 --- a/src/ui/pages/Secrets/Transit/TransitView.tsx +++ b/src/ui/pages/Secrets/Transit/TransitView.tsx @@ -1,11 +1,11 @@ -import { Component, JSX, render } from "preact"; -import { SecretTitleElement } from "../SecretTitleElement"; import { CapabilitiesType, getCapabilitiesPath } from "../../../../api/sys/getCapabilities"; -import { getTransitKeys } from "../../../../api/transit/getTransitKeys"; -import i18next from "i18next"; -import { route } from "preact-router"; +import { Component, JSX, render } from "preact"; import { DefaultPageProps } from "../../../../types/DefaultPageProps"; +import { SecretTitleElement } from "../SecretTitleElement"; import { delSecretsEngineURL, transitNewSecretURL, transitViewSecretURL } from "../../pageLinks"; +import { getTransitKeys } from "../../../../api/transit/getTransitKeys"; +import { route } from "preact-router"; +import i18next from "i18next"; type TransitViewListState = { contentLoaded: boolean; @@ -58,7 +58,7 @@ export class TransitViewListItem extends Component<{ baseMount: string }, Transi
  • { - route(transitViewSecretURL(this.props.baseMount, key)) + route(transitViewSecretURL(this.props.baseMount, key)); }} > {key} @@ -70,13 +70,13 @@ export class TransitViewListItem extends Component<{ baseMount: string }, Transi } } -export class TransitView extends Component { +export class TransitView extends Component { async componentDidMount() { const baseMount = this.props.matches["baseMount"]; const mountsPath = "/sys/mounts/" + baseMount; - + const caps = await getCapabilitiesPath([mountsPath, baseMount]); - this.setState({caps}) + this.setState({ caps }); } render() { @@ -105,7 +105,7 @@ export class TransitView extends Component { - route(delSecretsEngineURL(baseMount)) + route(delSecretsEngineURL(baseMount)); }} > {i18next.t("transit_view_delete_btn")} diff --git a/src/ui/pages/Secrets/Transit/TransitViewSecret.tsx b/src/ui/pages/Secrets/Transit/TransitViewSecret.tsx index cdcf978..979ba15 100644 --- a/src/ui/pages/Secrets/Transit/TransitViewSecret.tsx +++ b/src/ui/pages/Secrets/Transit/TransitViewSecret.tsx @@ -1,19 +1,19 @@ +import { Component, render } from "preact"; +import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { Grid, GridSizes } from "../../../elements/Grid"; import { Page } from "../../../../types/Page"; import { SecretTitleElement } from "../SecretTitleElement"; import { Tile } from "../../../elements/Tile"; -import { getTransitKey } from "../../../../api/transit/getTransitKey"; -import { Component, render } from "preact"; -import i18next from "i18next"; -import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { TransitKeyType } from "../../../../api/types/transit"; +import { getTransitKey } from "../../../../api/transit/getTransitKey"; +import i18next from "i18next"; -export class TransitViewSecret extends Component { +export class TransitViewSecret extends Component { async componentDidMount() { const baseMount = this.props.matches["baseMount"]; const secretItem = this.props.matches["secretItem"]; const transitKey = await getTransitKey(baseMount, secretItem); - this.setState({transitKey}); + this.setState({ transitKey }); } render() { @@ -21,7 +21,6 @@ export class TransitViewSecret extends Component diff --git a/src/ui/pages/SetLanguage.tsx b/src/ui/pages/SetLanguage.tsx index 3218702..dcc04d5 100644 --- a/src/ui/pages/SetLanguage.tsx +++ b/src/ui/pages/SetLanguage.tsx @@ -2,14 +2,14 @@ import translations from "../../translations/index.mjs"; // ts-unignore +import { Component } from "preact"; +import { DefaultPageProps } from "../../types/DefaultPageProps.js"; import { Form } from "../elements/Form"; import { Margin } from "../elements/Margin"; import { MarginInline } from "../elements/MarginInline"; -import { Component } from "preact"; -import i18next from "i18next"; -import { route } from "preact-router"; import { PageTitle } from "../elements/PageTitle"; -import { DefaultPageProps } from "../../types/DefaultPageProps.js"; +import { route } from "preact-router"; +import i18next from "i18next"; const languageIDs = Object.getOwnPropertyNames(translations); @@ -40,7 +40,6 @@ export class SetLanguage extends Component { ); - } async onSubmit(data: FormData): Promise { diff --git a/src/ui/pages/SetVaultURL.tsx b/src/ui/pages/SetVaultURL.tsx index eb0dc94..7b7e558 100644 --- a/src/ui/pages/SetVaultURL.tsx +++ b/src/ui/pages/SetVaultURL.tsx @@ -1,33 +1,33 @@ +import { Component, render } from "preact"; +import { DefaultPageProps } from "../../types/DefaultPageProps"; import { Form } from "../elements/Form"; import { Margin } from "../elements/Margin"; import { Page } from "../../types/Page"; -import { Component, render } from "preact"; -import { DefaultPageProps } from "../../types/DefaultPageProps"; -import { route } from "preact-router"; import { PageTitle } from "../elements/PageTitle"; +import { route } from "preact-router"; export class SetVaultURL extends Component { render() { return ( <> - -
    this.onSubmit(data)}> - - - -

    - - - -

    + +
    this.onSubmit(data)}> + + + +

    + + + +

    ); } @@ -35,11 +35,11 @@ export class SetVaultURL extends Component { async onSubmit(data: FormData): Promise { // TODO: check if vault is actually working here. this.props.state.apiURL = data.get("vaultURL") as string; - route("/") + route("/"); } get name(): string { - // TODO: + // TODO: return "Set Vault URL"; } } diff --git a/src/ui/pages/Unseal.tsx b/src/ui/pages/Unseal.tsx index d5f531a..1ca963a 100644 --- a/src/ui/pages/Unseal.tsx +++ b/src/ui/pages/Unseal.tsx @@ -5,13 +5,13 @@ import { Page } from "../../types/Page"; import { QRScanner } from "../elements/QRScanner"; import { getSealStatus } from "../../api/sys/getSealStatus"; +import { DefaultPageProps } from "../../types/DefaultPageProps"; +import { PageTitle } from "../elements/PageTitle"; +import { route } from "preact-router"; 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", @@ -146,4 +146,4 @@ export class Unseal extends Component { ); } -} \ No newline at end of file +} diff --git a/src/ui/pages/pageLinks.tsx b/src/ui/pages/pageLinks.tsx index 34fb319..47123e2 100644 --- a/src/ui/pages/pageLinks.tsx +++ b/src/ui/pages/pageLinks.tsx @@ -1,55 +1,54 @@ // Delete Secret Engine export function delSecretsEngineURL(baseMount: string): string { - return `/secrets/delete_engine/${baseMount}`; + return `/secrets/delete_engine/${baseMount}`; } // Secrets / Key Value export function kvNewURL(baseMount: string, secretPath?: string[]): string { - return `/secrets/kv/new/${baseMount}` + secretPath ? `/${secretPath.join("/")}` : ""; + return `/secrets/kv/new/${baseMount}` + secretPath ? `/${secretPath.join("/")}` : ""; } export function kvDeleteURL(baseMount: string, secretPath: string[], secret: string): string { - return `/secrets/kv/delete/${secret}/${baseMount}/${secretPath.join("/")}`; + return `/secrets/kv/delete/${secret}/${baseMount}/${secretPath.join("/")}`; } export function kvEditURL(baseMount: string, secretPath: string[], secret: string): string { - return `/secrets/kv/edit/${secret}/${baseMount}/${secretPath.join("/")}`; + return `/secrets/kv/edit/${secret}/${baseMount}/${secretPath.join("/")}`; } export function kvViewURL(baseMount: string, secretPath: string[], secret: string): string { - return `/secrets/kv/view/${secret}/${baseMount}/${secretPath.join("/")}`; + return `/secrets/kv/view/${secret}/${baseMount}/${secretPath.join("/")}`; } export function kvListURL(baseMount: string, secretPath: string[]): string { - console.log(baseMount, secretPath); - return `/secrets/kv/list/${baseMount}/${secretPath.join("/")}`; + console.log(baseMount, secretPath); + return `/secrets/kv/list/${baseMount}/${secretPath.join("/")}`; } // Secrets / TOTP export function totpNewURL(baseMount: string): string { - return `/secrets/totp/new/${baseMount}`; + return `/secrets/totp/new/${baseMount}`; } export function totpListURL(baseMount: string): string { - return `/secrets/totp/list/${baseMount}`; + return `/secrets/totp/list/${baseMount}`; } export function totpDeleteURL(baseMount: string, secret: string): string { - return `/secrets/totp/delete/${baseMount}/${secret}`; + return `/secrets/totp/delete/${baseMount}/${secret}`; } // Secrets / Transit export function transitNewSecretURL(baseMount: string): string { - return `/secrets/transit/new/${baseMount}`; + return `/secrets/transit/new/${baseMount}`; } export function transitViewSecretURL(baseMount: string, secret: string): string { - return `/secrets/transit/view/${baseMount}/${secret}`; + return `/secrets/transit/view/${baseMount}/${secret}`; } - //