1
0
Fork 0
VaultUI/src/main.tsx

181 lines
6.7 KiB
TypeScript
Raw Normal View History

"use strict";
2021-04-15 13:01:58 +01:00
2021-04-18 11:28:55 +01:00
// JS & CSS
2021-05-10 11:35:14 +01:00
/* eslint-disable */
2021-04-15 13:01:58 +01:00
import "./scss/main.scss";
2021-05-10 12:07:19 +01:00
import UIkit from 'uikit';
// Don't Sort These!
2021-05-10 12:07:19 +01:00
import Icons from 'uikit/dist/js/uikit-icons';
2021-05-10 11:35:14 +01:00
// @ts-ignore
2021-04-15 13:01:58 +01:00
UIkit.use(Icons);
2021-05-08 03:28:37 +01:00
import Prism from "prismjs";
// Don't Sort These!
2021-05-26 12:38:40 +01:00
import "prismjs/components/prism-hcl";
2022-01-06 23:02:34 +00:00
import "prismjs/components/prism-json";
2021-04-15 13:01:58 +01:00
Prism.highlightAll();
2021-05-03 09:30:22 +01:00
/* eslint-enable */
2021-04-15 13:01:58 +01:00
2021-05-24 09:48:13 +01:00
// @ts-ignore
import translations from "./translations/index.mjs";
2021-05-24 09:48:13 +01:00
// Actual Imports
import { PageRouter } from "./pagerouter/PageRouter";
import { formatDistance } from "./formatDistance";
2021-05-09 11:18:18 +01:00
import { getSealStatus } from "./api/sys/getSealStatus";
//import { pageList } from "./allPages";
2022-01-06 23:02:34 +00:00
import { Component, render } from "preact";
import { DeleteSecretsEngine } from "./ui/pages/Secrets/DeleteSecretsEngine";
import { Home } from "./ui/pages/Home";
2022-01-06 23:02:34 +00:00
import { KeyValueDelete } from "./ui/pages/Secrets/KeyValue/KeyValueDelete";
import { KeyValueView } from "./ui/pages/Secrets/KeyValue/KeyValueView";
2022-01-07 12:05:24 +00:00
import { KeyValueEdit } from "./ui/pages/Secrets/KeyValue/KeyValueEdit";
import { KeyValueList } from "./ui/pages/Secrets/KeyValue/KeyValueList";
import { Login } from "./ui/pages/Login";
2022-01-06 23:02:34 +00:00
import { Me } from "./ui/pages/Me";
import { NavBar } from "./ui/elements/NavBar";
import { NewKVEngine } from "./ui/pages/Secrets/NewEngines/NewKVEngine";
2022-01-06 23:02:34 +00:00
import { NewSecretsEngine } from "./ui/pages/Secrets/NewSecretsEngine";
import { NewTOTPEngine } from "./ui/pages/Secrets/NewEngines/NewTOTPEngine";
import { NewTransitEngine } from "./ui/pages/Secrets/NewEngines/NewTransitEngine";
2022-01-07 12:05:24 +00:00
import { TransitNew } from "./ui/pages/Secrets/Transit/TransitNew";
2022-01-06 23:02:34 +00:00
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";
2022-01-07 12:05:24 +00:00
import { TOTPList } from "./ui/pages/Secrets/TOTP/TOTPList";
import { TransitList } from "./ui/pages/Secrets/Transit/TransitList";
import { TransitView } from "./ui/pages/Secrets/Transit/TransitView";
2022-01-06 23:02:34 +00:00
import { Unseal } from "./ui/pages/Unseal";
import { pageState } from "./globalPageState";
import { playground } from "./playground";
import Router from "preact-router";
import i18next from "i18next";
2022-01-07 12:05:24 +00:00
import { KeyValueNew } from "./ui/pages/Secrets/KeyValue/KeyValueNew";
import { TransitDecrypt } from "./ui/pages/Secrets/Transit/TransitDecrypt";
import { TransitEncrypt } from "./ui/pages/Secrets/Transit/TransitEncrypt";
import { TransitRewrap } from "./ui/pages/Secrets/Transit/TransitRewrap";
2021-05-12 17:37:09 +01:00
async function onLoad(): Promise<void> {
const Main = () => (
<Router>
<Home path="/" state={pageState} />
<Me path="/me" state={pageState} />
<Login path="/login" state={pageState} />
<PasswordGenerator path="/pw_gen" />
<SetVaultURL path="/set_vault_url" state={pageState} />
<Unseal path="/unseal" state={pageState} />
<SetLanguage path="/set_language" state={pageState} />
<Secrets path="/secrets" state={pageState} />
<DeleteSecretsEngine path="/secrets/delete_engine/:mount" state={pageState} />
<NewSecretsEngine path="/secrets/new_secrets_engine" />
<NewKVEngine path="/secrets/new_secrets_engine/kv" />
<NewTOTPEngine path="/secrets/new_secrets_engine/totp" />
<NewTransitEngine path="/secrets/new_secrets_engine/trasit" />
2022-01-07 12:05:24 +00:00
<KeyValueNew path="/secrets/kv/new/:baseMount/:secretPath*?" state={pageState} />
<KeyValueList path="/secrets/kv/list/:baseMount/:secretPath*?" state={pageState} />
<KeyValueView path="/secrets/kv/view/:item/:baseMount/:secretPath*?" state={pageState} />
<KeyValueEdit path="/secrets/kv/edit/:item/:baseMount/:secretPath*?" state={pageState} />
<KeyValueDelete path="/secrets/kv/delete/:item/:baseMount/:secretPath*?" state={pageState} />
2022-01-07 12:05:24 +00:00
<TOTPList path="/secrets/totp/list/:baseMount" state={pageState} />
<TOTPNew path="/secrets/totp/new/:baseMount" state={pageState} />
<TOTPDelete path="/secrets/totp/delete/:baseMount/:item" state={pageState} />
2022-01-07 12:05:24 +00:00
<TransitNew path="/secrets/transit/new/:baseMount" state={pageState} />
<TransitList path="/secrets/transit/list/:baseMount" state={pageState} />
<TransitView path="/secrets/transit/view/:baseMount/:secretItem" state={pageState} />
<TransitEncrypt path="/secrets/transit/encrypt/:baseMount/:secretItem" state={pageState} />
<TransitDecrypt path="/secrets/transit/decrypt/:baseMount/:secretItem" state={pageState} />
<TransitRewrap path="/secrets/transit/rewrap/:baseMount/:secretItem" state={pageState} />
2022-01-06 23:02:34 +00:00
<div default>
<p>PAGE NOT YET IMPLEMENTED</p>
</div>
</Router>
);
2021-05-24 09:48:13 +01:00
render(
<>
<NavBar />
2021-05-24 09:48:13 +01:00
<div class="uk-container uk-container-medium uk-align-center">
<div class="uk-card uk-card-body">
<Main />
2021-05-24 09:48:13 +01:00
</div>
</div>
</>,
document.body,
);
2021-04-17 10:56:44 +01:00
//const pageRouter = new PageRouter({
// pageList: pageList,
// state: pageState,
// pageTitleElement: document.querySelector("#pageTitle"),
// pageContentElement: document.querySelector("#pageContent"),
// resetElementContent: !true,
// onPageChange: async function () {
// pageState.currentPage = await pageRouter.getCurrentPageID();
// document.documentElement.dir = pageState.pageDirection;
// },
//});
//
//reloadNavBar(pageRouter);
if (process.env.NODE_ENV == "development") {
// await playground(pageRouter);
}
//await pageRouter.changePage(pageState.currentPage);
//setInterval(async () => {
// if ((await pageRouter.getCurrentPageID()) != "UNSEAL") {
// if (pageState.apiURL.length != 0) {
// return;
// }
// const sealStatus = await getSealStatus();
// if (sealStatus.sealed) {
// await pageRouter.changePage("UNSEAL");
// return;
// }
// }
//}, 5000);
2021-04-24 16:26:31 +01:00
}
2021-04-18 11:28:55 +01:00
document.addEventListener(
"DOMContentLoaded",
2021-05-16 12:37:23 +01:00
async () => {
console.log("Loading...");
// @ts-expect-error
console.log("Build Data:", BUILD_STRING);
2021-05-16 12:37:23 +01:00
await i18next.init({
lng: pageState.language,
fallbackLng: "en",
debug: true,
// @ts-ignore
resources: Object.fromEntries(
Object.entries(translations).map(([k, v]) => [k, { translation: v }]),
),
interpolation: {
2021-05-22 09:50:55 +01:00
escape: (str) => {
return str;
},
2021-05-16 12:37:23 +01:00
format: function (value: unknown, format, _): string {
if (format === "until_date" && value instanceof Date)
return formatDistance(new Date(), new Date(value), pageState.language);
return value as string;
},
2021-05-16 12:37:23 +01:00
},
});
await onLoad();
},
false,
);