formatting run linter --fix src
This commit is contained in:
parent
ff8a2995cb
commit
6131a13331
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
|
||||
|
||||
export async function getSecrets(
|
||||
baseMount: string,
|
||||
secretPath: string[],
|
||||
): Promise<string[]> {
|
||||
export async function getSecrets(baseMount: string, secretPath: string[]): Promise<string[]> {
|
||||
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`;
|
||||
|
|
|
@ -29,7 +29,6 @@ export async function getMount(mountName: string): Promise<MountType> {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
56
src/main.tsx
56
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<void> {
|
||||
const Main = () => (
|
||||
|
@ -88,9 +88,9 @@ async function onLoad(): Promise<void> {
|
|||
<TransitViewSecret path="/secrets/transit/view/:baseMount/:secretItem" state={pageState} />
|
||||
<NewTransitKey path="/secrets/transit/new/:baseMount" state={pageState} />
|
||||
|
||||
|
||||
<div default><p>PAGE NOT YET IMPLEMENTED</p></div>
|
||||
|
||||
<div default>
|
||||
<p>PAGE NOT YET IMPLEMENTED</p>
|
||||
</div>
|
||||
</Router>
|
||||
);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -3,4 +3,4 @@ import { PageType } from "./PageType";
|
|||
export type PageListType = {
|
||||
getPageIDs(): Promise<string[]>;
|
||||
getPage(pageID: string): Promise<PageType>;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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<void> {
|
||||
|
|
|
@ -6,4 +6,4 @@ export type PageType = {
|
|||
goBack(): Promise<void>;
|
||||
cleanup(): Promise<void>;
|
||||
setRouterAndState(router: PageRouter, state: unknown): Promise<void>;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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),
|
||||
|
|
5
src/translations/de.js
vendored
5
src/translations/de.js
vendored
|
@ -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",
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { PageState } from "../state/PageState";
|
||||
|
||||
export type DefaultPageProps = {
|
||||
state: PageState;
|
||||
matches?: {[key: string]: string}
|
||||
};
|
||||
state: PageState;
|
||||
matches?: { [key: string]: string };
|
||||
};
|
||||
|
|
|
@ -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<void> {
|
||||
render(
|
||||
<>
|
||||
<span>{this.name}</span>
|
||||
<CopyStateLinkButton state={this.state} />
|
||||
<span>{this.name}</span>
|
||||
<CopyStateLinkButton state={this.state} />
|
||||
</>,
|
||||
this.router.pageTitleElement,
|
||||
);
|
||||
|
|
|
@ -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<CopyStateLinkButtonProps, unknown> {
|
||||
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 (
|
||||
<a
|
||||
ref={this.buttonRef}
|
||||
class="uk-icon uk-margin-small-left"
|
||||
uk-icon={"icon: copy"}
|
||||
role="img"
|
||||
aria-label="Copy Link"
|
||||
data-clipboard-text={newURL.toString()}
|
||||
></a>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<a
|
||||
ref={this.buttonRef}
|
||||
class="uk-icon uk-margin-small-left"
|
||||
uk-icon={"icon: copy"}
|
||||
role="img"
|
||||
aria-label="Copy Link"
|
||||
data-clipboard-text={newURL.toString()}
|
||||
></a>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
|||
<div class="uk-navbar-left">
|
||||
<ul class="uk-navbar-nav">
|
||||
<li>
|
||||
<a href="/">
|
||||
{i18next.t("home_btn")}
|
||||
</a>
|
||||
<a href="/">{i18next.t("home_btn")}</a>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
onClick={async () => {
|
||||
window.history.back()
|
||||
window.history.back();
|
||||
// maybe???
|
||||
}}
|
||||
>
|
||||
|
@ -50,4 +47,4 @@ export function NavBar(): JSX.Element {
|
|||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import { JSX } from "preact";
|
||||
|
||||
export type PageTitleProps = {
|
||||
title: string;
|
||||
title: string;
|
||||
};
|
||||
|
||||
export function PageTitle(props: PageTitleProps): JSX.Element {
|
||||
return <h3 class="uk-card-title" id="pageTitle">{props.title}</h3>;
|
||||
return (
|
||||
<h3 class="uk-card-title" id="pageTitle">
|
||||
{props.title}
|
||||
</h3>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<HomeProps, HomeState> {
|
||||
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<HomeProps, HomeState> {
|
|||
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<HomeProps, HomeState> {
|
|||
selfTokenInfo: selfTokenInfo,
|
||||
authCaps: authCaps,
|
||||
policiesCaps: policiesCaps,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
render(): JSX.Element {
|
||||
return this.state.selfTokenInfo && (
|
||||
<>
|
||||
<PageTitle title={this.name} />
|
||||
<div>
|
||||
<ul id="textList" class="uk-nav">
|
||||
<li>
|
||||
<span>{i18next.t("home_vaulturl_text", { text: this.props.state.apiURL })}</span>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/pw_gen">
|
||||
{i18next.t("home_password_generator_btn")}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<span>
|
||||
{i18next.t("home_your_token_expires_in", {
|
||||
date: new Date(this.state.selfTokenInfo.expire_time),
|
||||
})}
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
<Margin>
|
||||
<Grid size={GridSizes.MATCHING_TWO_ROWS}>
|
||||
<Tile
|
||||
title={i18next.t("home_secrets_title")}
|
||||
description={i18next.t("home_secrets_description")}
|
||||
icon="file-edit"
|
||||
onclick={async () => {
|
||||
route("/secrets");
|
||||
}}
|
||||
/>
|
||||
<Tile
|
||||
title={i18next.t("home_access_title")}
|
||||
description={i18next.t("home_access_description")}
|
||||
icon="users"
|
||||
disabled={!this.state.authCaps.includes("read")}
|
||||
onclick={async () => {
|
||||
route("/access");
|
||||
}}
|
||||
/>
|
||||
<Tile
|
||||
title={i18next.t("home_policies_title")}
|
||||
description={i18next.t("home_policies_description")}
|
||||
icon="pencil"
|
||||
disabled={!this.state.policiesCaps.includes("read")}
|
||||
onclick={async () => {
|
||||
route("/policies");
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
</Margin>
|
||||
</div>
|
||||
</>
|
||||
return (
|
||||
this.state.selfTokenInfo && (
|
||||
<>
|
||||
<PageTitle title={this.name} />
|
||||
<div>
|
||||
<ul id="textList" class="uk-nav">
|
||||
<li>
|
||||
<span>{i18next.t("home_vaulturl_text", { text: this.props.state.apiURL })}</span>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/pw_gen">{i18next.t("home_password_generator_btn")}</a>
|
||||
</li>
|
||||
<li>
|
||||
<span>
|
||||
{i18next.t("home_your_token_expires_in", {
|
||||
date: new Date(this.state.selfTokenInfo.expire_time),
|
||||
})}
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
<Margin>
|
||||
<Grid size={GridSizes.MATCHING_TWO_ROWS}>
|
||||
<Tile
|
||||
title={i18next.t("home_secrets_title")}
|
||||
description={i18next.t("home_secrets_description")}
|
||||
icon="file-edit"
|
||||
onclick={async () => {
|
||||
route("/secrets");
|
||||
}}
|
||||
/>
|
||||
<Tile
|
||||
title={i18next.t("home_access_title")}
|
||||
description={i18next.t("home_access_description")}
|
||||
icon="users"
|
||||
disabled={!this.state.authCaps.includes("read")}
|
||||
onclick={async () => {
|
||||
route("/access");
|
||||
}}
|
||||
/>
|
||||
<Tile
|
||||
title={i18next.t("home_policies_title")}
|
||||
description={i18next.t("home_policies_description")}
|
||||
icon="pencil"
|
||||
disabled={!this.state.policiesCaps.includes("read")}
|
||||
onclick={async () => {
|
||||
route("/policies");
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
</Margin>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<DefaultPageProps, MeState> {
|
||||
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<DefaultPageProps, MeState> {
|
|||
}
|
||||
|
||||
render(): JSX.Element {
|
||||
return this.state.loaded && (
|
||||
<>
|
||||
<PageTitle title={this.name} />
|
||||
<ul class="uk-nav">
|
||||
<li>
|
||||
<a
|
||||
onClick={async () => {
|
||||
this.props.state.token = "";
|
||||
route("/");
|
||||
}}
|
||||
>
|
||||
{i18next.t("me_log_out_btn")}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<CopyLink text={i18next.t("me_copy_token_btn")} data={this.props.state.token} />
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
onClick={async () => {
|
||||
try {
|
||||
await renewSelf();
|
||||
route("/");
|
||||
} catch (e: unknown) {
|
||||
const error = e as Error;
|
||||
setErrorText(error.message);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{i18next.t("me_renew_lease_btn")}
|
||||
</a>
|
||||
</li>
|
||||
{this.state.canSealVault && (
|
||||
return (
|
||||
this.state.loaded && (
|
||||
<>
|
||||
<PageTitle title={this.name} />
|
||||
<ul class="uk-nav">
|
||||
<li>
|
||||
<a
|
||||
onClick={async () => {
|
||||
await sealVault();
|
||||
route("/unseal", true);
|
||||
this.props.state.token = "";
|
||||
route("/");
|
||||
}}
|
||||
>
|
||||
{i18next.t("me_seal_vault_btn")}
|
||||
{i18next.t("me_log_out_btn")}
|
||||
</a>
|
||||
</li>
|
||||
)}
|
||||
<li>
|
||||
<a href="/set_language">
|
||||
{i18next.t("me_change_language_btn")}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/set_vault_url">
|
||||
{i18next.t("me_set_vault_url_btn")}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</>
|
||||
<li>
|
||||
<CopyLink text={i18next.t("me_copy_token_btn")} data={this.props.state.token} />
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
onClick={async () => {
|
||||
try {
|
||||
await renewSelf();
|
||||
route("/");
|
||||
} catch (e: unknown) {
|
||||
const error = e as Error;
|
||||
setErrorText(error.message);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{i18next.t("me_renew_lease_btn")}
|
||||
</a>
|
||||
</li>
|
||||
{this.state.canSealVault && (
|
||||
<li>
|
||||
<a
|
||||
onClick={async () => {
|
||||
await sealVault();
|
||||
route("/unseal", true);
|
||||
}}
|
||||
>
|
||||
{i18next.t("me_seal_vault_btn")}
|
||||
</a>
|
||||
</li>
|
||||
)}
|
||||
<li>
|
||||
<a href="/set_language">{i18next.t("me_change_language_btn")}</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/set_vault_url">{i18next.t("me_set_vault_url_btn")}</a>
|
||||
</li>
|
||||
</ul>
|
||||
</>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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> {
|
|||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<DefaultPageProps> {
|
||||
render() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageTitle title={i18next.t("delete_secrets_engine_title", { mount: this.props.matches["mount"] })}/>
|
||||
<PageTitle
|
||||
title={i18next.t("delete_secrets_engine_title", { mount: this.props.matches["mount"] })}
|
||||
/>
|
||||
<Form
|
||||
onSubmit={async () => {
|
||||
await this.onSubmit();
|
||||
|
|
|
@ -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<DefaultPageProps> {
|
||||
render() {
|
||||
|
@ -25,11 +25,7 @@ export class KeyValueDelete extends Component<DefaultPageProps> {
|
|||
<button
|
||||
class="uk-button uk-button-danger"
|
||||
onClick={async () => {
|
||||
await deleteSecret(
|
||||
baseMount,
|
||||
secretPath,
|
||||
item,
|
||||
);
|
||||
await deleteSecret(baseMount, secretPath, item);
|
||||
window.history.back();
|
||||
}}
|
||||
>
|
||||
|
@ -37,7 +33,6 @@ export class KeyValueDelete extends Component<DefaultPageProps> {
|
|||
</button>
|
||||
</div>
|
||||
</>
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<DefaultPageProps> {
|
||||
render(){
|
||||
render() {
|
||||
const baseMount = this.props.matches["baseMount"];
|
||||
const secretPath = (this.props.matches["secretPath"] || "").split("/");
|
||||
|
||||
return(
|
||||
return (
|
||||
<>
|
||||
<SecretTitleElement
|
||||
type="kv"
|
||||
|
@ -22,40 +22,43 @@ export class KeyValueNewPage extends Component<DefaultPageProps> {
|
|||
secretPath={secretPath}
|
||||
suffix={i18next.t("kv_sec_edit_suffix")}
|
||||
/>
|
||||
<div>
|
||||
<Form onSubmit={async (formData) => await this.newKVSecretHandleForm(formData, baseMount, secretPath)}>
|
||||
<Margin>
|
||||
<input
|
||||
class="uk-input uk-form-width-medium"
|
||||
name="path"
|
||||
placeholder={i18next.t("kv_new_path")}
|
||||
required
|
||||
/>
|
||||
</Margin>
|
||||
<p class="uk-text-danger" id="errorText" />
|
||||
<button class="uk-button uk-button-primary" type="submit">
|
||||
{i18next.t("kv_new_create_btn")}
|
||||
</button>
|
||||
</Form>
|
||||
</div>
|
||||
<div>
|
||||
<Form
|
||||
onSubmit={async (formData) =>
|
||||
await this.newKVSecretHandleForm(formData, baseMount, secretPath)
|
||||
}
|
||||
>
|
||||
<Margin>
|
||||
<input
|
||||
class="uk-input uk-form-width-medium"
|
||||
name="path"
|
||||
placeholder={i18next.t("kv_new_path")}
|
||||
required
|
||||
/>
|
||||
</Margin>
|
||||
<p class="uk-text-danger" id="errorText" />
|
||||
<button class="uk-button uk-button-primary" type="submit">
|
||||
{i18next.t("kv_new_create_btn")}
|
||||
</button>
|
||||
</Form>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
async newKVSecretHandleForm(formData: FormData, baseMount: string, secretPath: string[]): Promise<void> {
|
||||
async newKVSecretHandleForm(
|
||||
formData: FormData,
|
||||
baseMount: string,
|
||||
secretPath: string[],
|
||||
): Promise<void> {
|
||||
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);
|
||||
|
|
|
@ -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<string, unknown>;
|
||||
|
@ -48,7 +48,7 @@ type KeyValueSecretState = {
|
|||
secretItem: string;
|
||||
caps: string[];
|
||||
secretInfo: Record<string, unknown>;
|
||||
}
|
||||
};
|
||||
|
||||
export class KeyValueSecret extends Component<DefaultPageProps, KeyValueSecretState> {
|
||||
async componentDidMount() {
|
||||
|
@ -56,30 +56,25 @@ export class KeyValueSecret extends Component<DefaultPageProps, KeyValueSecretSt
|
|||
const secretPath = this.props.matches["secretPath"].split("/");
|
||||
const secretItem = this.props.matches["item"];
|
||||
|
||||
const caps = (
|
||||
await getCapabilities(baseMount, secretPath, secretItem)
|
||||
).capabilities;
|
||||
const caps = (await getCapabilities(baseMount, secretPath, secretItem)).capabilities;
|
||||
|
||||
let secretPathAPI = secretPath.map((e) => 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<DefaultPageProps, KeyValueSecretSt
|
|||
/>
|
||||
<div>
|
||||
<p id="buttonsBlock">
|
||||
{
|
||||
this.state.caps.includes("delete") && (
|
||||
<button
|
||||
class="uk-button uk-button-danger"
|
||||
onClick={async () => {
|
||||
route(kvDeleteURL(this.state.baseMount, this.state.secretPath, this.state.secretItem))
|
||||
}}
|
||||
>
|
||||
{i18next.t("kv_secret_delete_btn")}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
{this.state.caps.includes("delete") && (
|
||||
<button
|
||||
class="uk-button uk-button-danger"
|
||||
onClick={async () => {
|
||||
route(
|
||||
kvDeleteURL(this.state.baseMount, this.state.secretPath, this.state.secretItem),
|
||||
);
|
||||
}}
|
||||
>
|
||||
{i18next.t("kv_secret_delete_btn")}
|
||||
</button>
|
||||
)}
|
||||
{this.state.caps.includes("update") && (
|
||||
<button
|
||||
class="uk-button uk-button-primary"
|
||||
onClick={async () => {
|
||||
route(kvEditURL(this.state.baseMount, this.state.secretPath, this.state.secretItem))
|
||||
route(
|
||||
kvEditURL(this.state.baseMount, this.state.secretPath, this.state.secretItem),
|
||||
);
|
||||
}}
|
||||
>
|
||||
{i18next.t("kv_secret_edit_btn")}
|
||||
|
@ -119,7 +116,6 @@ export class KeyValueSecret extends Component<DefaultPageProps, KeyValueSecretSt
|
|||
{<KVSecretVew kvData={this.state.secretInfo} />}
|
||||
</div>
|
||||
</>
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<string, unknown>;
|
||||
code: string;
|
||||
};
|
||||
dataLoaded: true;
|
||||
kvData: Record<string, unknown>;
|
||||
code: string;
|
||||
};
|
||||
|
||||
export class KVEditor extends Component<KVEditProps, KVEditState> {
|
||||
constructor() {
|
||||
|
|
|
@ -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[])
|
|||
<li>
|
||||
<a
|
||||
onClick={async () => {
|
||||
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<KVKeysListProps, KVKeysListState> {
|
|||
|
||||
async loadData(): Promise<void> {
|
||||
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<DefaultPageProps, KeyValueViewState> {
|
||||
async componentDidMount() {
|
||||
|
@ -181,7 +182,7 @@ export class KeyValueView extends Component<DefaultPageProps, KeyValueViewState>
|
|||
<button
|
||||
class="uk-button uk-button-primary"
|
||||
onClick={async () => {
|
||||
route(kvNewURL(baseMount, secretPath.length > 0 ? secretPath : null))
|
||||
route(kvNewURL(baseMount, secretPath.length > 0 ? secretPath : null));
|
||||
}}
|
||||
>
|
||||
{i18next.t("kv_view_new_btn")}
|
||||
|
@ -191,7 +192,7 @@ export class KeyValueView extends Component<DefaultPageProps, KeyValueViewState>
|
|||
<button
|
||||
class="uk-button uk-button-danger"
|
||||
onClick={async () => {
|
||||
route(delSecretsEngineURL(baseMount))
|
||||
route(delSecretsEngineURL(baseMount));
|
||||
}}
|
||||
>
|
||||
{i18next.t("kv_view_delete_btn")}
|
||||
|
@ -206,4 +207,4 @@ export class KeyValueView extends Component<DefaultPageProps, KeyValueViewState>
|
|||
get name(): string {
|
||||
return i18next.t("kv_view_title");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
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 { kvListURL } from "../../pageLinks";
|
||||
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";
|
||||
import { kvListURL } from "../../pageLinks";
|
||||
|
||||
export class NewKVEngine extends Component {
|
||||
render() {
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
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 { newMount } from "../../../../api/sys/newMount";
|
||||
import { Component, render } from "preact";
|
||||
import { setErrorText } from "../../../../pageUtils";
|
||||
import i18next from "i18next";
|
||||
import { route } from "preact-router";
|
||||
import { PageTitle } from "../../../elements/PageTitle";
|
||||
import { newMount } from "../../../../api/sys/newMount";
|
||||
import { route } from "preact-router";
|
||||
import { setErrorText } from "../../../../pageUtils";
|
||||
import { totpListURL } from "../../pageLinks";
|
||||
import i18next from "i18next";
|
||||
|
||||
export class NewTOTPEngine extends Component {
|
||||
render() {
|
||||
|
@ -31,7 +31,8 @@ export class NewTOTPEngine extends Component {
|
|||
{i18next.t("new_totp_engine_create_btn")}
|
||||
</button>
|
||||
</MarginInline>
|
||||
</Form>,
|
||||
</Form>
|
||||
,
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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")}
|
||||
</button>
|
||||
</MarginInline>
|
||||
</Form>,
|
||||
</Form>
|
||||
,
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@ -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);
|
||||
|
|
|
@ -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 (
|
||||
<>
|
||||
<PageTitle title={i18next.t("new_secrets_engine_title")} />
|
||||
<Grid size={GridSizes.MATCHING_TWO_ROWS}>
|
||||
<Tile
|
||||
title={i18next.t("new_secrets_engine_kv_title")}
|
||||
description={i18next.t("new_secrets_engine_kv_description")}
|
||||
onclick={async () => {
|
||||
route("/secrets/new_secrets_engine/kv")
|
||||
}}
|
||||
/>
|
||||
<Tile
|
||||
title={i18next.t("new_secrets_engine_totp_title")}
|
||||
description={i18next.t("new_secrets_engine_totp_description")}
|
||||
onclick={async () => {
|
||||
route("/secrets/new_secrets_engine/totp")
|
||||
}}
|
||||
/>
|
||||
<Tile
|
||||
title={i18next.t("new_secrets_engine_transit_title")}
|
||||
description={i18next.t("new_secrets_engine_transit_description")}
|
||||
onclick={async () => {
|
||||
route("/secrets/new_secrets_engine/transit")
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
<PageTitle title={i18next.t("new_secrets_engine_title")} />
|
||||
<Grid size={GridSizes.MATCHING_TWO_ROWS}>
|
||||
<Tile
|
||||
title={i18next.t("new_secrets_engine_kv_title")}
|
||||
description={i18next.t("new_secrets_engine_kv_description")}
|
||||
onclick={async () => {
|
||||
route("/secrets/new_secrets_engine/kv");
|
||||
}}
|
||||
/>
|
||||
<Tile
|
||||
title={i18next.t("new_secrets_engine_totp_title")}
|
||||
description={i18next.t("new_secrets_engine_totp_description")}
|
||||
onclick={async () => {
|
||||
route("/secrets/new_secrets_engine/totp");
|
||||
}}
|
||||
/>
|
||||
<Tile
|
||||
title={i18next.t("new_secrets_engine_transit_title")}
|
||||
description={i18next.t("new_secrets_engine_transit_description")}
|
||||
onclick={async () => {
|
||||
route("/secrets/new_secrets_engine/transit");
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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 (
|
||||
<h3 class="uk-card-title" id="pageTitle">
|
||||
<div>
|
||||
|
@ -30,24 +29,29 @@ export function SecretTitleElement(props: SecretTitleElementProps): JSX.Element
|
|||
{"/ "}
|
||||
</a>
|
||||
|
||||
<a href={"/secrets/" + type + "/list/" + baseMount + "/"} test-data="secrets-title-baseMount">
|
||||
<a
|
||||
href={"/secrets/" + type + "/list/" + baseMount + "/"}
|
||||
test-data="secrets-title-baseMount"
|
||||
>
|
||||
{baseMount + "/ "}
|
||||
</a>
|
||||
|
||||
{...secretPath.map((secretPath, index, secretPaths) => {
|
||||
// TODO: find where a '' is returned so dont need this
|
||||
if (secretPath.length < 1) return;
|
||||
return <a test-data="secrets-title-secretPath"
|
||||
onClick={async () => {
|
||||
|
||||
if (type == "kv") {
|
||||
let secretPath = secretPaths.slice(0, index + 1);
|
||||
route(kvListURL(baseMount, secretPath))
|
||||
}
|
||||
}}
|
||||
>
|
||||
{secretPath + "/" + " "}
|
||||
</a>
|
||||
return (
|
||||
<a
|
||||
test-data="secrets-title-secretPath"
|
||||
onClick={async () => {
|
||||
if (type == "kv") {
|
||||
const secretPath = secretPaths.slice(0, index + 1);
|
||||
route(kvListURL(baseMount, secretPath));
|
||||
}
|
||||
}}
|
||||
>
|
||||
{secretPath + "/" + " "}
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
{item.length != 0 && <span>{item}</span>}
|
||||
{suffix.length != 0 && <span>{suffix}</span>}
|
||||
|
|
|
@ -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 (
|
||||
<li>
|
||||
<a href={link}>
|
||||
{linkText}
|
||||
</a>
|
||||
<a href={link}>{linkText}</a>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
type SecretsState = {
|
||||
mountsMap: Map<String, MountType>;
|
||||
mountsMap: Map<string, MountType>;
|
||||
capabilities: string[];
|
||||
}
|
||||
};
|
||||
|
||||
export class Secrets extends Component<DefaultPageProps, SecretsState> {
|
||||
async componentDidMount() {
|
||||
|
@ -72,44 +70,48 @@ export class Secrets extends Component<DefaultPageProps, SecretsState> {
|
|||
const mountsMap = sortedObjectMap(mounts);
|
||||
this.setState({
|
||||
capabilities: mountsCapabilities,
|
||||
mountsMap: mountsMap as Map<String, MountType>
|
||||
})
|
||||
mountsMap: mountsMap as Map<string, MountType>,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
return this.state.mountsMap && (
|
||||
<>
|
||||
<PageTitle title={i18next.t("secrets_home_page_title")} />
|
||||
<div>
|
||||
return (
|
||||
this.state.mountsMap && (
|
||||
<>
|
||||
<PageTitle title={i18next.t("secrets_home_page_title")} />
|
||||
<div>
|
||||
<p>
|
||||
{this.state.capabilities.includes("sudo") && this.state.capabilities.includes("create") && (
|
||||
<button
|
||||
class="uk-button uk-button-primary"
|
||||
onClick={() => {
|
||||
route("/secrets/new_secrets_engine")
|
||||
}}
|
||||
>
|
||||
{i18next.t("secrets_home_new_secrets_engine_button")}
|
||||
</button>
|
||||
)}
|
||||
</p>
|
||||
<div>
|
||||
<p>
|
||||
{this.state.capabilities.includes("sudo") &&
|
||||
this.state.capabilities.includes("create") && (
|
||||
<button
|
||||
class="uk-button uk-button-primary"
|
||||
onClick={() => {
|
||||
route("/secrets/new_secrets_engine");
|
||||
}}
|
||||
>
|
||||
{i18next.t("secrets_home_new_secrets_engine_button")}
|
||||
</button>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<div class="uk-margin-top">
|
||||
<ul class="uk-nav uk-nav-default">
|
||||
{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 (
|
||||
<MountLink state={this.props.state} mount={mount} baseMount={baseMount} />
|
||||
);
|
||||
}
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-margin-top">
|
||||
<ul class="uk-nav uk-nav-default">
|
||||
{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 <MountLink state={this.props.state} mount={mount} baseMount={baseMount} />;
|
||||
}
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
</>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<DefaultPageProps> {
|
||||
render() {
|
||||
|
@ -22,8 +22,8 @@ export class TOTPDelete extends Component<DefaultPageProps> {
|
|||
<button
|
||||
class="uk-button uk-button-danger"
|
||||
onClick={async () => {
|
||||
let baseMount = this.props.matches["baseMount"];
|
||||
let item = this.props.matches["item"];
|
||||
const baseMount = this.props.matches["baseMount"];
|
||||
const item = this.props.matches["item"];
|
||||
await deleteTOTP(baseMount, item);
|
||||
route(totpListURL(baseMount));
|
||||
}}
|
||||
|
@ -32,7 +32,6 @@ export class TOTPDelete extends Component<DefaultPageProps> {
|
|||
</button>
|
||||
</div>
|
||||
</>
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<DefaultPageProps> {
|
|||
const baseMount = this.props.matches["baseMount"];
|
||||
return (
|
||||
<>
|
||||
<SecretTitleElement type="totp" baseMount={baseMount} suffix={i18next.t("totp_new_suffix")} />
|
||||
<SecretTitleElement
|
||||
type="totp"
|
||||
baseMount={baseMount}
|
||||
suffix={i18next.t("totp_new_suffix")}
|
||||
/>
|
||||
<TOTPNewForm baseMount={baseMount} />
|
||||
</>
|
||||
);
|
||||
|
|
|
@ -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<TOTPGridItemProps, { totpValue: string }> {
|
||||
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<DefaultPageProps, TOTPViewState> {
|
||||
constructor() {
|
||||
|
@ -85,7 +88,7 @@ export class TOTPView extends Component<DefaultPageProps, TOTPViewState> {
|
|||
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<DefaultPageProps, TOTPViewState> {
|
|||
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<DefaultPageProps, TOTPViewState> {
|
|||
|
||||
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<DefaultPageProps, TOTPViewState> {
|
|||
|
||||
return (
|
||||
<>
|
||||
<SecretTitleElement type="totp" baseMount={baseMount} />
|
||||
<div>
|
||||
<p>
|
||||
{totpCaps.includes("create") && (
|
||||
<button
|
||||
class="uk-button uk-button-primary"
|
||||
onClick={async () => {
|
||||
route(totpNewURL(baseMount))
|
||||
}}
|
||||
>
|
||||
{i18next.t("totp_view_new_btn")}
|
||||
</button>
|
||||
)}
|
||||
{mountCaps.includes("delete") && (
|
||||
<button
|
||||
class="uk-button uk-button-danger"
|
||||
onClick={async () => {
|
||||
route(delSecretsEngineURL(baseMount))
|
||||
}}
|
||||
>
|
||||
{i18next.t("totp_view_delete_btn")}
|
||||
</button>
|
||||
)}
|
||||
</p>
|
||||
<div id="totpList">
|
||||
{
|
||||
(() => {
|
||||
<SecretTitleElement type="totp" baseMount={baseMount} />
|
||||
<div>
|
||||
<p>
|
||||
{totpCaps.includes("create") && (
|
||||
<button
|
||||
class="uk-button uk-button-primary"
|
||||
onClick={async () => {
|
||||
route(totpNewURL(baseMount));
|
||||
}}
|
||||
>
|
||||
{i18next.t("totp_view_new_btn")}
|
||||
</button>
|
||||
)}
|
||||
{mountCaps.includes("delete") && (
|
||||
<button
|
||||
class="uk-button uk-button-danger"
|
||||
onClick={async () => {
|
||||
route(delSecretsEngineURL(baseMount));
|
||||
}}
|
||||
>
|
||||
{i18next.t("totp_view_delete_btn")}
|
||||
</button>
|
||||
)}
|
||||
</p>
|
||||
<div id="totpList">
|
||||
{(() => {
|
||||
if (this.state.totpItems.length == 0) {
|
||||
return <p>{i18next.t("totp_view_empty")}</p>;
|
||||
} else {
|
||||
return this.state.totpItems.map((totpItem) => {
|
||||
return <RefreshingTOTPGridItem
|
||||
baseMount={totpItem.baseMount}
|
||||
totpKey={totpItem.totpKey}
|
||||
canDelete={totpItem.canDelete}
|
||||
/>
|
||||
})
|
||||
return (
|
||||
<RefreshingTOTPGridItem
|
||||
baseMount={totpItem.baseMount}
|
||||
totpKey={totpItem.totpKey}
|
||||
canDelete={totpItem.canDelete}
|
||||
/>
|
||||
);
|
||||
});
|
||||
}
|
||||
})()
|
||||
}
|
||||
})()}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<DefaultPageProps> {
|
||||
constructor() {
|
||||
|
@ -65,7 +65,6 @@ export class NewTransitKey extends Component<DefaultPageProps> {
|
|||
</MarginInline>
|
||||
</Form>
|
||||
</>
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -80,7 +79,7 @@ export class NewTransitKey extends Component<DefaultPageProps> {
|
|||
name: name,
|
||||
type: type,
|
||||
});
|
||||
route(transitViewSecretURL(baseMount, name))
|
||||
route(transitViewSecretURL(baseMount, name));
|
||||
} catch (e) {
|
||||
const error = e as Error;
|
||||
setErrorText(error.message);
|
||||
|
|
|
@ -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
|
|||
<li>
|
||||
<a
|
||||
onClick={async () => {
|
||||
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<DefaultPageProps, {caps: CapabilitiesType}> {
|
||||
export class TransitView extends Component<DefaultPageProps, { caps: CapabilitiesType }> {
|
||||
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<DefaultPageProps, {caps: Capabilities
|
|||
<button
|
||||
class="uk-button uk-button-danger"
|
||||
onClick={async () => {
|
||||
route(delSecretsEngineURL(baseMount))
|
||||
route(delSecretsEngineURL(baseMount));
|
||||
}}
|
||||
>
|
||||
{i18next.t("transit_view_delete_btn")}
|
||||
|
|
|
@ -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<DefaultPageProps, {transitKey: TransitKeyType}> {
|
||||
export class TransitViewSecret extends Component<DefaultPageProps, { transitKey: TransitKeyType }> {
|
||||
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<DefaultPageProps, {transitKey:
|
|||
const baseMount = this.props.matches["baseMount"];
|
||||
const secretItem = this.props.matches["secretItem"];
|
||||
const transitKey = this.state.transitKey;
|
||||
|
||||
|
||||
return (
|
||||
<Grid size={GridSizes.MATCHING_TWO_ROWS}>
|
||||
|
|
|
@ -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<DefaultPageProps> {
|
|||
</Form>
|
||||
</>
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
async onSubmit(data: FormData): Promise<void> {
|
||||
|
|
|
@ -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<DefaultPageProps> {
|
||||
render() {
|
||||
return (
|
||||
<>
|
||||
<PageTitle title={this.name} />
|
||||
<Form onSubmit={(data) => this.onSubmit(data)}>
|
||||
<Margin>
|
||||
<input
|
||||
class="uk-input uk-form-width-medium"
|
||||
name="vaultURL"
|
||||
type="text"
|
||||
placeholder="Vault URL"
|
||||
required
|
||||
/>
|
||||
</Margin>
|
||||
<p id="errorText" class="uk-text-danger" />
|
||||
<Margin>
|
||||
<button class="uk-button uk-button-primary" type="submit">
|
||||
Set
|
||||
</button>
|
||||
</Margin>
|
||||
</Form>
|
||||
<PageTitle title={this.name} />
|
||||
<Form onSubmit={(data) => this.onSubmit(data)}>
|
||||
<Margin>
|
||||
<input
|
||||
class="uk-input uk-form-width-medium"
|
||||
name="vaultURL"
|
||||
type="text"
|
||||
placeholder="Vault URL"
|
||||
required
|
||||
/>
|
||||
</Margin>
|
||||
<p id="errorText" class="uk-text-danger" />
|
||||
<Margin>
|
||||
<button class="uk-button uk-button-primary" type="submit">
|
||||
Set
|
||||
</button>
|
||||
</Margin>
|
||||
</Form>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@ -35,11 +35,11 @@ export class SetVaultURL extends Component<DefaultPageProps> {
|
|||
async onSubmit(data: FormData): Promise<void> {
|
||||
// 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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<DefaultPageProps, UnsealPageState> {
|
|||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}`;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue