Add tsx syntax to TOTPNew and rename TOTP page IDs.
This commit is contained in:
parent
1ccb432cbc
commit
7568bc6d8e
6791
pnpm-lock.yaml
Normal file
6791
pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load diff
|
@ -18,7 +18,6 @@ import { MePage } from "./pages/Me";
|
||||||
import { NewKVEnginePage } from "./pages/Secrets/NewEngines/NewKVEngine";
|
import { NewKVEnginePage } from "./pages/Secrets/NewEngines/NewKVEngine";
|
||||||
import { NewSecretsEnginePage } from "./pages/Secrets/NewSecretsEngine";
|
import { NewSecretsEnginePage } from "./pages/Secrets/NewSecretsEngine";
|
||||||
import { NewTOTPEnginePage } from "./pages/Secrets/NewEngines/NewTOTPEngine";
|
import { NewTOTPEnginePage } from "./pages/Secrets/NewEngines/NewTOTPEngine";
|
||||||
import { NewTOTPPage } from "./pages/Secrets/TOTP/NewTOTP";
|
|
||||||
import { NewTransitEnginePage } from "./pages/Secrets/NewEngines/NewTransitEngine";
|
import { NewTransitEnginePage } from "./pages/Secrets/NewEngines/NewTransitEngine";
|
||||||
import { NewTransitKeyPage } from "./pages/Secrets/Transit/NewTransitKey";
|
import { NewTransitKeyPage } from "./pages/Secrets/Transit/NewTransitKey";
|
||||||
import { Page } from "./types/Page";
|
import { Page } from "./types/Page";
|
||||||
|
@ -27,6 +26,7 @@ import { SecretsHomePage } from "./pages/Secrets/SecretsHome";
|
||||||
import { SetLanguagePage } from "./pages/SetLanguage";
|
import { SetLanguagePage } from "./pages/SetLanguage";
|
||||||
import { SetVaultURLPage } from "./pages/SetVaultURL";
|
import { SetVaultURLPage } from "./pages/SetVaultURL";
|
||||||
import { TOTPDeletePage } from "./pages/Secrets/TOTP/TOTPDelete";
|
import { TOTPDeletePage } from "./pages/Secrets/TOTP/TOTPDelete";
|
||||||
|
import { TOTPNewPage } from "./pages/Secrets/TOTP/TOTPNew";
|
||||||
import { TOTPViewPage } from "./pages/Secrets/TOTP/TOTPView";
|
import { TOTPViewPage } from "./pages/Secrets/TOTP/TOTPView";
|
||||||
import { TransitDecryptPage } from "./pages/Secrets/Transit/TransitDecrypt";
|
import { TransitDecryptPage } from "./pages/Secrets/Transit/TransitDecrypt";
|
||||||
import { TransitEncryptPage } from "./pages/Secrets/Transit/TransitEncrypt";
|
import { TransitEncryptPage } from "./pages/Secrets/Transit/TransitEncrypt";
|
||||||
|
@ -57,8 +57,8 @@ export const allPages: pagesList = {
|
||||||
USERPASS_USER_NEW: new UserPassUserNewPage(),
|
USERPASS_USER_NEW: new UserPassUserNewPage(),
|
||||||
USERPASS_USER_DELETE: new UserPassUserDeletePage(),
|
USERPASS_USER_DELETE: new UserPassUserDeletePage(),
|
||||||
ME: new MePage(),
|
ME: new MePage(),
|
||||||
TOTP: new TOTPViewPage(),
|
TOTP_VIEW: new TOTPViewPage(),
|
||||||
NEW_TOTP: new NewTOTPPage(),
|
TOTP_NEW: new TOTPNewPage(),
|
||||||
TOTP_DELETE: new TOTPDeletePage(),
|
TOTP_DELETE: new TOTPDeletePage(),
|
||||||
LOGIN: new LoginPage(),
|
LOGIN: new LoginPage(),
|
||||||
SET_VAULT_URL: new SetVaultURLPage(),
|
SET_VAULT_URL: new SetVaultURLPage(),
|
||||||
|
|
|
@ -55,7 +55,7 @@ export class NewTOTPEnginePage extends Page {
|
||||||
});
|
});
|
||||||
this.state.secretMountType = "totp";
|
this.state.secretMountType = "totp";
|
||||||
this.state.baseMount = name + "/";
|
this.state.baseMount = name + "/";
|
||||||
await this.router.changePage("TOTP");
|
await this.router.changePage("TOTP_VIEW");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = e as Error;
|
const error = e as Error;
|
||||||
setErrorText(error.message);
|
setErrorText(error.message);
|
||||||
|
|
|
@ -2,9 +2,8 @@ import { PageRouter } from "z-pagerouter";
|
||||||
import { PageState } from "../../PageState";
|
import { PageState } from "../../PageState";
|
||||||
import { makeElement } from "z-makeelement";
|
import { makeElement } from "z-makeelement";
|
||||||
|
|
||||||
function currentTitleSecretText(state: PageState, suffix = ""): string {
|
function currentTitleSecretText(state: PageState): string {
|
||||||
let secretItemText = state.secretItem;
|
let secretItemText = state.secretItem;
|
||||||
secretItemText += suffix;
|
|
||||||
if (state.secretVersion !== null) secretItemText += ` (v${state.secretVersion})`;
|
if (state.secretVersion !== null) secretItemText += ` (v${state.secretVersion})`;
|
||||||
return secretItemText;
|
return secretItemText;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +24,7 @@ export async function SecretTitleElement(router: PageRouter, suffix = ""): Promi
|
||||||
if (state.secretMountType.startsWith("kv") || state.secretMountType == "cubbyhole") {
|
if (state.secretMountType.startsWith("kv") || state.secretMountType == "cubbyhole") {
|
||||||
await router.changePage("KEY_VALUE_VIEW");
|
await router.changePage("KEY_VALUE_VIEW");
|
||||||
} else if (state.secretMountType == "totp") {
|
} else if (state.secretMountType == "totp") {
|
||||||
await router.changePage("TOTP");
|
await router.changePage("TOTP_VIEW");
|
||||||
} else if (state.secretMountType == "transit") {
|
} else if (state.secretMountType == "transit") {
|
||||||
await router.changePage("TRANSIT_VIEW");
|
await router.changePage("TRANSIT_VIEW");
|
||||||
}
|
}
|
||||||
|
@ -47,7 +46,12 @@ export async function SecretTitleElement(router: PageRouter, suffix = ""): Promi
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "span",
|
tag: "span",
|
||||||
condition: state.secretItem.length != 0,
|
condition: state.secretItem.length != 0,
|
||||||
text: currentTitleSecretText(state, suffix),
|
text: currentTitleSecretText(state),
|
||||||
|
}),
|
||||||
|
makeElement({
|
||||||
|
tag: "span",
|
||||||
|
condition: suffix.length != 0,
|
||||||
|
text: suffix,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
|
@ -65,7 +65,7 @@ export class SecretsHomePage extends Page {
|
||||||
linkPage = "KEY_VALUE_VIEW";
|
linkPage = "KEY_VALUE_VIEW";
|
||||||
} else if (mount.type == "totp") {
|
} else if (mount.type == "totp") {
|
||||||
linkText = `TOTP - ${baseMount}`;
|
linkText = `TOTP - ${baseMount}`;
|
||||||
linkPage = "TOTP";
|
linkPage = "TOTP_VIEW";
|
||||||
} else if (mount.type == "transit") {
|
} else if (mount.type == "transit") {
|
||||||
linkText = `Transit - ${baseMount}`;
|
linkText = `Transit - ${baseMount}`;
|
||||||
linkPage = "TRANSIT_VIEW";
|
linkPage = "TRANSIT_VIEW";
|
||||||
|
|
|
@ -1,114 +0,0 @@
|
||||||
import { Form } from "../../../elements/Form";
|
|
||||||
import { Margin } from "../../../elements/Margin";
|
|
||||||
import { MarginInline } from "../../../elements/MarginInline";
|
|
||||||
import { Page } from "../../../types/Page";
|
|
||||||
import { SecretTitleElement } from "../SecretTitleElement";
|
|
||||||
import { addNewTOTP } from "../../../api/totp/addNewTOTP";
|
|
||||||
import { makeElement } from "z-makeelement";
|
|
||||||
import { setErrorText } from "../../../pageUtils";
|
|
||||||
import i18next from "i18next";
|
|
||||||
|
|
||||||
function replaceAll(str: string, replace: string, replaceWith: string): string {
|
|
||||||
return str.replace(new RegExp(replace, "g"), replaceWith);
|
|
||||||
}
|
|
||||||
function removeDashSpaces(str: string): string {
|
|
||||||
str = replaceAll(str, "-", "");
|
|
||||||
str = replaceAll(str, " ", "");
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class NewTOTPPage extends Page {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
async goBack(): Promise<void> {
|
|
||||||
await this.router.changePage("TOTP");
|
|
||||||
}
|
|
||||||
async render(): Promise<void> {
|
|
||||||
await this.router.setPageContent(
|
|
||||||
Form(
|
|
||||||
[
|
|
||||||
Margin(
|
|
||||||
makeElement({
|
|
||||||
tag: "input",
|
|
||||||
class: ["uk-input", "uk-form-width-medium"],
|
|
||||||
attributes: {
|
|
||||||
required: "true",
|
|
||||||
type: "text",
|
|
||||||
placeholder: i18next.t("totp_new_name_text"),
|
|
||||||
name: "name",
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
makeElement({
|
|
||||||
tag: "p",
|
|
||||||
text: i18next.t("totp_new_info"),
|
|
||||||
}),
|
|
||||||
Margin(
|
|
||||||
makeElement({
|
|
||||||
tag: "input",
|
|
||||||
class: ["uk-input", "uk-form-width-medium"],
|
|
||||||
attributes: {
|
|
||||||
type: "text",
|
|
||||||
placeholder: i18next.t("totp_new_uri_input"),
|
|
||||||
name: "uri",
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
Margin(
|
|
||||||
makeElement({
|
|
||||||
tag: "input",
|
|
||||||
class: ["uk-input", "uk-form-width-medium"],
|
|
||||||
attributes: {
|
|
||||||
type: "text",
|
|
||||||
placeholder: i18next.t("totp_new_key_input"),
|
|
||||||
name: "key",
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
makeElement({
|
|
||||||
tag: "p",
|
|
||||||
id: "errorText",
|
|
||||||
class: "uk-text-danger",
|
|
||||||
}),
|
|
||||||
MarginInline(
|
|
||||||
makeElement({
|
|
||||||
tag: "button",
|
|
||||||
class: ["uk-button", "uk-button-primary"],
|
|
||||||
text: i18next.t("totp_new_add_btn"),
|
|
||||||
attributes: {
|
|
||||||
type: "submit",
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
async (form: HTMLFormElement) => {
|
|
||||||
const formData = new FormData(form);
|
|
||||||
|
|
||||||
const parms = {
|
|
||||||
url: formData.get("uri") as string,
|
|
||||||
key: removeDashSpaces(formData.get("key") as string).toUpperCase(),
|
|
||||||
name: formData.get("name") as string,
|
|
||||||
generate: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
await addNewTOTP(this.state.baseMount, parms);
|
|
||||||
await this.router.changePage("TOTP");
|
|
||||||
} catch (e: unknown) {
|
|
||||||
const error = e as Error;
|
|
||||||
setErrorText(`API Error: ${error.message}`);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
|
||||||
return await SecretTitleElement(this.router, i18next.t("totp_new_suffix"));
|
|
||||||
}
|
|
||||||
|
|
||||||
get name(): string {
|
|
||||||
return i18next.t("totp_new_title");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,7 +15,7 @@ export class TOTPDeletePage extends Page {
|
||||||
|
|
||||||
async goBack(): Promise<void> {
|
async goBack(): Promise<void> {
|
||||||
this.state.secretItem = "";
|
this.state.secretItem = "";
|
||||||
await this.router.changePage("TOTP");
|
await this.router.changePage("TOTP_VIEW");
|
||||||
}
|
}
|
||||||
async render(): Promise<void> {
|
async render(): Promise<void> {
|
||||||
render(
|
render(
|
||||||
|
|
91
src/pages/Secrets/TOTP/TOTPNew.tsx
Normal file
91
src/pages/Secrets/TOTP/TOTPNew.tsx
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
import { Form } from "../../../elements/ReactForm";
|
||||||
|
import { Margin } from "../../../elements/ReactMargin";
|
||||||
|
import { MarginInline } from "../../../elements/ReactMarginInline";
|
||||||
|
import { Page } from "../../../types/Page";
|
||||||
|
import { SecretTitleElement } from "../SecretTitleElement";
|
||||||
|
import { addNewTOTP } from "../../../api/totp/addNewTOTP";
|
||||||
|
import { render } from "preact";
|
||||||
|
import { setErrorText } from "../../../pageUtils";
|
||||||
|
import i18next from "i18next";
|
||||||
|
|
||||||
|
function replaceAll(str: string, replace: string, replaceWith: string): string {
|
||||||
|
return str.replace(new RegExp(replace, "g"), replaceWith);
|
||||||
|
}
|
||||||
|
function removeDashSpaces(str: string): string {
|
||||||
|
str = replaceAll(str, "-", "");
|
||||||
|
str = replaceAll(str, " ", "");
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TOTPNewPage extends Page {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
async goBack(): Promise<void> {
|
||||||
|
await this.router.changePage("TOTP_VIEW");
|
||||||
|
}
|
||||||
|
async render(): Promise<void> {
|
||||||
|
render(
|
||||||
|
<Form onSubmit={(data) => this.onSubmit(data)}>
|
||||||
|
<Margin>
|
||||||
|
<input
|
||||||
|
class="uk-input uk-form-width-medium"
|
||||||
|
name="name"
|
||||||
|
type="text"
|
||||||
|
placeholder={i18next.t("totp_new_name_text")}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</Margin>
|
||||||
|
<p>{i18next.t("totp_new_info")}</p>
|
||||||
|
<Margin>
|
||||||
|
<input
|
||||||
|
class="uk-input uk-form-width-medium"
|
||||||
|
name="uri"
|
||||||
|
type="text"
|
||||||
|
placeholder={i18next.t("totp_new_uri_input")}
|
||||||
|
/>
|
||||||
|
</Margin>
|
||||||
|
<Margin>
|
||||||
|
<input
|
||||||
|
class="uk-input uk-form-width-medium"
|
||||||
|
name="key"
|
||||||
|
type="text"
|
||||||
|
placeholder={i18next.t("totp_new_key_input")}
|
||||||
|
/>
|
||||||
|
</Margin>
|
||||||
|
<p id="errorText" class="uk-text-danger" />
|
||||||
|
<MarginInline>
|
||||||
|
<button class="uk-button uk-button-primary" type="submit">
|
||||||
|
{i18next.t("totp_new_add_btn")}
|
||||||
|
</button>
|
||||||
|
</MarginInline>
|
||||||
|
</Form>,
|
||||||
|
this.router.pageContentElement,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async onSubmit(data: FormData): Promise<void> {
|
||||||
|
const parms = {
|
||||||
|
url: data.get("uri") as string,
|
||||||
|
key: removeDashSpaces(data.get("key") as string).toUpperCase(),
|
||||||
|
name: data.get("name") as string,
|
||||||
|
generate: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await addNewTOTP(this.state.baseMount, parms);
|
||||||
|
await this.router.changePage("TOTP_VIEW");
|
||||||
|
} catch (e: unknown) {
|
||||||
|
const error = e as Error;
|
||||||
|
setErrorText(`API Error: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async getPageTitle(): Promise<Element | string> {
|
||||||
|
return await SecretTitleElement(this.router, i18next.t("totp_new_suffix"));
|
||||||
|
}
|
||||||
|
|
||||||
|
get name(): string {
|
||||||
|
return i18next.t("totp_new_title");
|
||||||
|
}
|
||||||
|
}
|
|
@ -77,7 +77,7 @@ export class TOTPViewPage extends Page {
|
||||||
<button
|
<button
|
||||||
class="uk-button uk-button-primary uk-margin-bottom"
|
class="uk-button uk-button-primary uk-margin-bottom"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
await this.router.changePage("NEW_TOTP");
|
await this.router.changePage("TOTP_NEW");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{i18next.t("totp_view_new_btn")}
|
{i18next.t("totp_view_new_btn")}
|
||||||
|
|
Loading…
Reference in a new issue