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 Icons from 'uikit/dist/js/uikit-icons.min.js';
|
2021-05-03 09:25:42 +01:00
|
|
|
import UIkit from 'uikit/dist/js/uikit.min.js';
|
2021-04-15 13:01:58 +01:00
|
|
|
UIkit.use(Icons);
|
|
|
|
|
2021-05-03 09:30:22 +01:00
|
|
|
/* eslint-disable */
|
2021-05-03 09:25:42 +01:00
|
|
|
import Prism from "prismjs";
|
2021-05-03 09:30:22 +01: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-03 09:25:42 +01:00
|
|
|
import { PageState } from "./PageState.js";
|
2021-04-15 13:01:58 +01:00
|
|
|
import {
|
|
|
|
changePage,
|
|
|
|
renderPage,
|
|
|
|
} from "./pageUtils.js";
|
2021-04-17 11:42:06 +01:00
|
|
|
import { getSealStatus } from './api.js';
|
2021-05-03 09:25:42 +01:00
|
|
|
import { makeElement } from "./htmlUtils.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,
|
2021-05-03 09:25:42 +01:00
|
|
|
KeyValueDeletePage,
|
|
|
|
KeyValueNewPage,
|
|
|
|
KeyValueSecretEditPage,
|
|
|
|
KeyValueSecretPage,
|
|
|
|
KeyValueVersionsPage,
|
|
|
|
KeyValueViewPage,
|
|
|
|
LoginPage,
|
2021-04-18 11:05:43 +01:00
|
|
|
MePage,
|
2021-04-15 13:01:58 +01:00
|
|
|
NewTOTPPage,
|
2021-05-03 09:25:42 +01:00
|
|
|
PwGenPage,
|
|
|
|
SetLanguagePage,
|
2021-04-15 13:01:58 +01:00
|
|
|
SetVaultURLPage,
|
2021-05-03 09:25:42 +01:00
|
|
|
TOTPViewPage,
|
|
|
|
TransitDecryptPage,
|
|
|
|
TransitEncryptPage,
|
2021-04-15 15:09:43 +01:00
|
|
|
TransitViewPage,
|
|
|
|
TransitViewSecretPage,
|
2021-05-03 09:25:42 +01:00
|
|
|
UnsealPage,
|
2021-04-15 13:01:58 +01:00
|
|
|
} from "./pages";
|
|
|
|
|
|
|
|
const pages = {
|
|
|
|
HOME: new HomePage(),
|
2021-04-18 11:05:43 +01:00
|
|
|
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-19 20:17:07 +01:00
|
|
|
SET_LANGUAGE: new SetLanguagePage(),
|
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(),
|
2021-04-20 22:49:33 +01:00
|
|
|
KEY_VALUE_SECRET: new KeyValueSecretPage(),
|
2021-04-15 13:01:58 +01:00
|
|
|
KEY_VALUE_VERSIONS: new KeyValueVersionsPage(),
|
|
|
|
KEY_VALUE_NEW_SECRET: new KeyValueNewPage(),
|
|
|
|
KEY_VALUE_DELETE: new KeyValueDeletePage(),
|
2021-04-20 22:49:33 +01:00
|
|
|
KEY_VALUE_SECRET_EDIT: new KeyValueSecretEditPage(),
|
2021-04-15 13:01:58 +01:00
|
|
|
PW_GEN: new PwGenPage(),
|
|
|
|
};
|
|
|
|
|
2021-04-18 11:28:55 +01:00
|
|
|
// Translations
|
2021-05-03 15:13:30 +01:00
|
|
|
import { formatDistance } from './formatDistance.js';
|
2021-04-18 11:28:55 +01:00
|
|
|
import i18next from 'i18next';
|
2021-05-03 15:13:30 +01:00
|
|
|
import translations from './translations/index.mjs'
|
2021-04-18 11:28:55 +01:00
|
|
|
|
2021-04-20 20:19:34 +01:00
|
|
|
/*import "en-GB" as date_locale_en from 'date-fns/locale'
|
|
|
|
|
|
|
|
function getDateLocale() {
|
|
|
|
let locales = {
|
|
|
|
en:
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
2021-04-18 11:28:55 +01:00
|
|
|
|
|
|
|
// 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: [
|
2021-04-18 11:05:43 +01:00
|
|
|
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",
|
2021-04-18 11:52:24 +01:00
|
|
|
text: i18next.t("me_btn"),
|
2021-04-18 11:28:55 +01:00
|
|
|
onclick: _ => { changePage("ME"); }
|
|
|
|
}))
|
|
|
|
]
|
|
|
|
})
|
2021-04-18 11:05:43 +01:00
|
|
|
})
|
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",
|
2021-04-18 11:52:24 +01:00
|
|
|
text: ""
|
2021-04-17 10:56:44 +01:00
|
|
|
}),
|
|
|
|
makeElement({
|
|
|
|
tag: "div",
|
|
|
|
id: "pageContent"
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}));
|
|
|
|
|
2021-04-15 13:01:58 +01:00
|
|
|
window.pageContent = document.querySelector("#pageContent");
|
|
|
|
renderPage();
|
|
|
|
|
|
|
|
setInterval(async () => {
|
2021-04-19 20:17:07 +01:00
|
|
|
if (pageState.currentPageString != "UNSEAL") {
|
2021-04-30 10:38:23 +01:00
|
|
|
if (pageState.apiURL.length != 0) { 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-24 16:26:31 +01:00
|
|
|
}
|
2021-04-18 11:28:55 +01:00
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
i18next.init({
|
2021-04-30 10:38:23 +01:00
|
|
|
lng: pageState.language,
|
2021-04-19 19:45:51 +01:00
|
|
|
fallbackLng: 'en',
|
2021-04-18 11:28:55 +01:00
|
|
|
debug: true,
|
2021-05-03 15:13:30 +01:00
|
|
|
resources: Object.fromEntries(Object.entries(translations).map(([k, v]) => [k, { translation: v }])),
|
2021-04-18 11:52:24 +01:00
|
|
|
interpolation: {
|
|
|
|
format: function (value, format, _) {
|
|
|
|
if (format === 'until_date' && value instanceof Date) return formatDistance(new Date(), new Date(value));
|
|
|
|
return value;
|
|
|
|
}
|
2021-04-18 11:28:55 +01:00
|
|
|
}
|
2021-04-24 16:26:31 +01:00
|
|
|
}).then(function (_) {
|
2021-04-18 11:28:55 +01:00
|
|
|
onLoad();
|
|
|
|
});
|
2021-04-18 13:18:14 +01:00
|
|
|
}, false);
|