1
0
Fork 0
VaultUI/src/main.js

182 lines
4.2 KiB
JavaScript
Raw Normal View History

2021-04-15 13:01:58 +01:00
'use strict';
2021-04-18 11:28:55 +01:00
// JS & CSS
2021-04-15 13:01:58 +01:00
import "./scss/main.scss";
import UIkit from 'uikit/dist/js/uikit.min.js';
import Icons from 'uikit/dist/js/uikit-icons.min.js';
UIkit.use(Icons);
import Prism from "prismjs";
import "prismjs/components/prism-json";
Prism.highlightAll();
import {
changePage,
renderPage,
} from "./pageUtils.js";
import { PageState } from "./PageState.js";
2021-04-17 10:56:44 +01:00
import { makeElement } from "./htmlUtils.js";
import { getSealStatus } from './api.js';
2021-04-15 13:01:58 +01:00
2021-04-18 11:28:55 +01:00
// Pages
2021-04-15 13:01:58 +01:00
import {
HomePage,
MePage,
2021-04-15 13:01:58 +01:00
TOTPViewPage,
NewTOTPPage,
LoginPage,
SetVaultURLPage,
UnsealPage,
2021-04-15 15:09:43 +01:00
TransitViewPage,
TransitViewSecretPage,
2021-04-16 18:57:59 +01:00
TransitEncryptPage,
2021-04-17 10:39:07 +01:00
TransitDecryptPage,
2021-04-15 13:01:58 +01:00
KeyValueViewPage,
KeyValueSecretsPage,
KeyValueVersionsPage,
KeyValueNewPage,
KeyValueDeletePage,
KeyValueSecretsEditPage,
PwGenPage,
} from "./pages";
const pages = {
HOME: new HomePage(),
ME: new MePage(),
2021-04-15 13:01:58 +01:00
TOTP: new TOTPViewPage(),
NEW_TOTP: new NewTOTPPage(),
LOGIN: new LoginPage(),
SET_VAULT_URL: new SetVaultURLPage(),
UNSEAL: new UnsealPage(),
2021-04-15 15:09:43 +01:00
TRANSIT_VIEW: new TransitViewPage(),
TRANSIT_VIEW_SECRET: new TransitViewSecretPage(),
2021-04-16 18:57:59 +01:00
TRANSIT_ENCRYPT: new TransitEncryptPage(),
2021-04-17 10:39:07 +01:00
TRANSIT_DECRYPT: new TransitDecryptPage(),
2021-04-15 13:01:58 +01:00
KEY_VALUE_VIEW: new KeyValueViewPage(),
KEY_VALUE_SECRETS: new KeyValueSecretsPage(),
KEY_VALUE_VERSIONS: new KeyValueVersionsPage(),
KEY_VALUE_NEW_SECRET: new KeyValueNewPage(),
KEY_VALUE_DELETE: new KeyValueDeletePage(),
KEY_VALUE_SECRETS_EDIT: new KeyValueSecretsEditPage(),
PW_GEN: new PwGenPage(),
};
2021-04-18 11:28:55 +01:00
// Translations
import i18next from 'i18next';
import translation_en from './translations/en.js'
import translation_de from './translations/de.js'
// Globals
2021-04-15 13:01:58 +01:00
var pageState = new PageState();
window.pageState = pageState;
2021-04-17 11:24:43 +01:00
window.realPages = pages;
2021-04-15 13:01:58 +01:00
2021-04-17 10:56:44 +01:00
function ListItem(children) {
return makeElement({
tag: "li",
children: children
});
}
2021-04-18 11:28:55 +01:00
function onLoad() {
2021-04-17 10:56:44 +01:00
document.body.innerHTML = "";
document.body.appendChild(makeElement({
tag: "nav",
class: ["uk-navbar", "uk-navbar-container"],
2021-04-18 11:28:55 +01:00
children: [
makeElement({
2021-04-18 11:28:55 +01:00
tag: "div",
class: "uk-navbar-left",
children: makeElement({
tag: "ul",
class: "uk-navbar-nav",
children: [
ListItem(makeElement({
tag: "a",
text: i18next.t("home_btn"),
onclick: _ => { changePage("HOME"); }
})),
ListItem(makeElement({
tag: "a",
text: i18next.t("back_btn"),
onclick: _ => { pageState.currentPage.goBack(); }
})),
ListItem(makeElement({
tag: "a",
text: i18next.t("refresh_btn"),
onclick: _ => { changePage(pageState.currentPage); }
})),
]
})
}),
makeElement({
tag: "div",
class: "uk-navbar-right",
children: makeElement({
tag: "ul",
class: "uk-navbar-nav",
children: [
ListItem(makeElement({
tag: "a",
text: "Me",
onclick: _ => { changePage("ME"); }
}))
]
})
})
2021-04-18 11:28:55 +01:00
]
2021-04-17 10:56:44 +01:00
}));
document.body.appendChild(makeElement({
tag: "div",
class: ["uk-container", "uk-container-medium", "uk-align-center"],
children: makeElement({
tag: "div",
class: ["uk-card", "uk-card-body"],
children: [
makeElement({
tag: "h3",
class: "uk-card-title",
id: "pageTitle",
text: "Title"
}),
makeElement({
tag: "div",
id: "pageContent"
})
]
})
}));
2021-04-15 13:01:58 +01:00
window.pageContent = document.querySelector("#pageContent");
renderPage();
setInterval(async () => {
2021-04-17 11:24:43 +01:00
if (pageState.currentPage != "UNSEAL") {
if (!localStorage.getItem('apiurl')) { return; }
2021-04-15 13:01:58 +01:00
let sealStatus = await getSealStatus();
if (sealStatus.sealed) {
2021-04-17 11:24:43 +01:00
changePage("UNSEAL");
2021-04-15 13:01:58 +01:00
return;
}
}
}, 5000);
2021-04-18 11:28:55 +01:00
};
document.addEventListener('DOMContentLoaded', function () {
i18next.init({
lng: 'de',
debug: true,
resources: {
en: { translation: translation_en },
de: { translation: translation_de },
}
}).then(function (t) {
onLoad();
});
2021-04-15 13:01:58 +01:00
}, false);