Remove global "window.pages".
This commit is contained in:
parent
0a2127b626
commit
b79e1856ca
|
@ -68,10 +68,10 @@ export class PageState extends Page {
|
|||
}
|
||||
get currentPage() {
|
||||
let curPage = localStorage.getItem('currentPage') || "HOME";
|
||||
return pages[curPage];
|
||||
return realPages[curPage];
|
||||
}
|
||||
set currentPage(value) {
|
||||
let key = getKeyByObjectPropertyValue(pages, value);
|
||||
let key = getKeyByObjectPropertyValue(realPages, value);
|
||||
localStorage.setItem('currentPage', key);
|
||||
}
|
||||
}
|
|
@ -60,7 +60,7 @@ const pages = {
|
|||
|
||||
var pageState = new PageState();
|
||||
window.pageState = pageState;
|
||||
window.pages = pages;
|
||||
window.realPages = pages;
|
||||
window.changePage = changePage;
|
||||
|
||||
function ListItem(children) {
|
||||
|
@ -85,7 +85,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||
ListItem(makeElement({
|
||||
tag: "a",
|
||||
text: "Home",
|
||||
onclick: _ => { changePage(pages.HOME); }
|
||||
onclick: _ => { changePage("HOME"); }
|
||||
})),
|
||||
ListItem(makeElement({
|
||||
tag: "a",
|
||||
|
@ -126,10 +126,10 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||
renderPage();
|
||||
|
||||
setInterval(async () => {
|
||||
if (pageState.currentPage != pages.UNSEAL) {
|
||||
if (pageState.currentPage != "UNSEAL") {
|
||||
let sealStatus = await getSealStatus();
|
||||
if (sealStatus.sealed) {
|
||||
changePage(pages.UNSEAL);
|
||||
changePage("UNSEAL");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,11 @@ export function changePage(page) {
|
|||
if (pageState.currentPage) {
|
||||
pageState.currentPage.cleanup();
|
||||
}
|
||||
pageState.currentPage = page;
|
||||
if (typeof page == 'object') {
|
||||
pageState.currentPage = page;
|
||||
} else {
|
||||
pageState.currentPage = realPages[page];
|
||||
}
|
||||
renderPage();
|
||||
}
|
||||
|
||||
|
@ -61,11 +65,11 @@ export function setTitleElement(pageState) {
|
|||
pageState.currentSecretVersion = "0";
|
||||
|
||||
if (pageState.currentMountType.startsWith("kv") || pageState.currentMountType == "cubbyhole") {
|
||||
changePage(pages.KEY_VALUE_VIEW);
|
||||
changePage("KEY_VALUE_VIEW");
|
||||
} else if (pageState.currentMountType == "totp"){
|
||||
changePage(pages.TOTP);
|
||||
changePage("TOTP");
|
||||
} else if (pageState.currentMountType == "transit") {
|
||||
changePage(pages.TRANSIT_VIEW);
|
||||
changePage("TRANSIT_VIEW");
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
@ -76,7 +80,7 @@ export function setTitleElement(pageState) {
|
|||
onclick: _ => {
|
||||
if (pageState.currentMountType.startsWith("kv")) {
|
||||
pageState.currentSecretPath = secretPaths.slice(0, index + 1);
|
||||
changePage(pages.KEY_VALUE_VIEW);
|
||||
changePage("KEY_VALUE_VIEW");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -13,17 +13,17 @@ export class HomePage extends Page {
|
|||
async render() {
|
||||
pageContent.innerHTML = "";
|
||||
if (!getAPIURL()) {
|
||||
changePage(pages.SET_VAULT_URL);
|
||||
changePage("SET_VAULT_URL");
|
||||
return;
|
||||
}
|
||||
if (!getToken()) {
|
||||
localStorage.removeItem("token");
|
||||
changePage(pages.LOGIN);
|
||||
changePage("LOGIN");
|
||||
return;
|
||||
}
|
||||
let sealStatus = await getSealStatus();
|
||||
if (sealStatus.sealed) {
|
||||
changePage(pages.UNSEAL);
|
||||
changePage("UNSEAL");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ export class HomePage extends Page {
|
|||
text: "Renew Lease",
|
||||
onclick: () => {
|
||||
renewSelf().then(() => {
|
||||
changePage(pages.HOME);
|
||||
changePage("HOME");
|
||||
}).catch(e => {
|
||||
setErrorText(e.message);
|
||||
});
|
||||
|
@ -70,7 +70,7 @@ export class HomePage extends Page {
|
|||
tag: "a",
|
||||
text: "Password Generator",
|
||||
onclick: () => {
|
||||
changePage(pages.PW_GEN);
|
||||
changePage("PW_GEN");
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -89,7 +89,7 @@ export class HomePage extends Page {
|
|||
setErrorText(e.message);
|
||||
if (e.message == "permission denied") {
|
||||
localStorage.removeItem("token");
|
||||
changePage(pages.LOGIN);
|
||||
changePage("LOGIN");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ export class HomePage extends Page {
|
|||
onclick: _ => {
|
||||
pageState.currentBaseMount = "/cubbyhole";
|
||||
pageState.currentMountType = "cubbyhole";
|
||||
changePage(pages.KEY_VALUE_VIEW);
|
||||
changePage("KEY_VALUE_VIEW");
|
||||
}
|
||||
})
|
||||
}));
|
||||
|
@ -130,13 +130,13 @@ export class HomePage extends Page {
|
|||
let linkPage;
|
||||
if (mount.type == "kv") {
|
||||
linkText = `K/V (v${mount.options.version}) - ${baseMount}`;
|
||||
linkPage = pages.KEY_VALUE_VIEW;
|
||||
linkPage = "KEY_VALUE_VIEW";
|
||||
} else if (mount.type == "totp") {
|
||||
linkText = `TOTP - ${baseMount}`;
|
||||
linkPage = pages.TOTP;
|
||||
linkPage = "TOTP";
|
||||
} else if (mount.type == "transit"){
|
||||
linkText = `Transit - ${baseMount}`;
|
||||
linkPage = pages.TRANSIT_VIEW;
|
||||
linkPage = "TRANSIT_VIEW";
|
||||
}
|
||||
|
||||
navList.appendChild(makeElement({
|
||||
|
|
|
@ -10,10 +10,10 @@ export class KeyValueDeletePage extends Page {
|
|||
goBack() {
|
||||
if (pageState.currentSecretVersion != "0") {
|
||||
pageState.currentSecretVersion = "0";
|
||||
changePage(pages.KEY_VALUE_SECRETS);
|
||||
changePage("KEY_VALUE_SECRETS");
|
||||
} else {
|
||||
pageState.currentSecret = "";
|
||||
changePage(pages.KEY_VALUE_VIEW);
|
||||
changePage("KEY_VALUE_VIEW");
|
||||
}
|
||||
}
|
||||
render() {
|
||||
|
|
|
@ -8,7 +8,7 @@ export class KeyValueNewPage extends Page {
|
|||
super();
|
||||
}
|
||||
goBack() {
|
||||
changePage(pages.KEY_VALUE_VIEW);
|
||||
changePage("KEY_VALUE_VIEW");
|
||||
}
|
||||
render() {
|
||||
setTitleElement(pageState);
|
||||
|
@ -69,7 +69,7 @@ export class KeyValueNewPage extends Page {
|
|||
splitPath[splitPath.length - 1],
|
||||
keyData
|
||||
).then(_ => {
|
||||
changePage(pages.KEY_VALUE_VIEW);
|
||||
changePage("KEY_VALUE_VIEW");
|
||||
return;
|
||||
}).catch(e => {
|
||||
setErrorText(e.message);
|
||||
|
|
|
@ -13,11 +13,11 @@ export class KeyValueSecretsPage extends Page {
|
|||
goBack() {
|
||||
if (pageState.currentSecretVersion != "0") {
|
||||
pageState.currentSecretVersion = "0";
|
||||
changePage(pages.KEY_VALUE_VERSIONS);
|
||||
changePage("KEY_VALUE_VERSIONS");
|
||||
|
||||
} else {
|
||||
pageState.currentSecret = "";
|
||||
changePage(pages.KEY_VALUE_VIEW);
|
||||
changePage("KEY_VALUE_VIEW");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ export class KeyValueSecretsPage extends Page {
|
|||
tag: "button",
|
||||
id: "deleteButton",
|
||||
class: ["uk-button", "uk-button-danger"],
|
||||
onclick: _ => { changePage(pages.KEY_VALUE_DELETE); },
|
||||
onclick: _ => { changePage("KEY_VALUE_DELETE"); },
|
||||
text: deleteButtonText
|
||||
}));
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ export class KeyValueSecretsPage extends Page {
|
|||
tag: "button",
|
||||
id: "editButton",
|
||||
class: ["uk-button", "uk-margin", "uk-button-primary"],
|
||||
onclick: _ => { changePage(pages.KEY_VALUE_SECRETS_EDIT); },
|
||||
onclick: _ => { changePage("KEY_VALUE_SECRETS_EDIT"); },
|
||||
text: "Edit"
|
||||
}));
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ export class KeyValueSecretsPage extends Page {
|
|||
tag: "button",
|
||||
id: "versionsButton",
|
||||
class: ["uk-button", "uk-button-secondary"],
|
||||
onclick: _ => { changePage(pages.KEY_VALUE_VERSIONS); },
|
||||
onclick: _ => { changePage("KEY_VALUE_VERSIONS"); },
|
||||
text: "Versions"
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ export class KeyValueSecretsEditPage extends Page {
|
|||
super();
|
||||
}
|
||||
goBack() {
|
||||
changePage(pages.KEY_VALUE_SECRETS);
|
||||
changePage("KEY_VALUE_SECRETS");
|
||||
}
|
||||
render() {
|
||||
setTitleElement(pageState);
|
||||
|
@ -55,7 +55,7 @@ export class KeyValueSecretsEditPage extends Page {
|
|||
pageState.currentSecret,
|
||||
JSON.parse(jar.toString())
|
||||
).then(resp => {
|
||||
changePage(pages.KEY_VALUE_SECRETS);
|
||||
changePage("KEY_VALUE_SECRETS");
|
||||
return;
|
||||
}).catch(e => {
|
||||
setErrorText(e.message);
|
||||
|
|
|
@ -8,7 +8,7 @@ export class KeyValueVersionsPage extends Page {
|
|||
super();
|
||||
}
|
||||
goBack() {
|
||||
changePage(pages.KEY_VALUE_SECRETS);
|
||||
changePage("KEY_VALUE_SECRETS");
|
||||
}
|
||||
async render() {
|
||||
setTitleElement(pageState);
|
||||
|
@ -34,7 +34,7 @@ export class KeyValueVersionsPage extends Page {
|
|||
text: `v${ver}`,
|
||||
onclick: _ => {
|
||||
pageState.currentSecretVersion = ver;
|
||||
changePage(pages.KEY_VALUE_SECRETS);
|
||||
changePage("KEY_VALUE_SECRETS");
|
||||
}
|
||||
})
|
||||
}));
|
||||
|
|
|
@ -10,9 +10,9 @@ export class KeyValueViewPage extends Page {
|
|||
goBack() {
|
||||
if (pageState.currentSecretPath.length != 0) {
|
||||
pageState.popCurrentSecretPath();
|
||||
changePage(pages.KEY_VALUE_VIEW);
|
||||
changePage("KEY_VALUE_VIEW");
|
||||
} else {
|
||||
changePage(pages.HOME);
|
||||
changePage("HOME");
|
||||
}
|
||||
}
|
||||
async render() {
|
||||
|
@ -25,7 +25,7 @@ export class KeyValueViewPage extends Page {
|
|||
text: "New",
|
||||
class: ["uk-button", "uk-button-primary", "uk-margin-bottom"],
|
||||
onclick: () => {
|
||||
changePage(pages.KEY_VALUE_NEW_SECRET);
|
||||
changePage("KEY_VALUE_NEW_SECRET");
|
||||
}
|
||||
});
|
||||
pageContent.appendChild(newButton);
|
||||
|
@ -46,10 +46,10 @@ export class KeyValueViewPage extends Page {
|
|||
onclick: _ => {
|
||||
if (secret.endsWith("/")) {
|
||||
pageState.pushCurrentSecretPath(secret);
|
||||
changePage(pages.KEY_VALUE_VIEW);
|
||||
changePage("KEY_VALUE_VIEW");
|
||||
} else {
|
||||
pageState.currentSecret = secret;
|
||||
changePage(pages.KEY_VALUE_SECRETS);
|
||||
changePage("KEY_VALUE_SECRETS");
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -123,7 +123,7 @@ export class LoginPage extends Page {
|
|||
const token = formData.get("token");
|
||||
localStorage.setItem('token', token);
|
||||
lookupSelf().then(res => {
|
||||
changePage(pages.HOME);
|
||||
changePage("HOME");
|
||||
}).catch(e => {
|
||||
document.getElementById("tokenInput").classList.add("uk-form-danger");
|
||||
setErrorText(e.message);
|
||||
|
@ -134,7 +134,7 @@ export class LoginPage extends Page {
|
|||
let formData = new FormData(usernameLoginForm);
|
||||
usernameLogin(formData.get("username"), formData.get("password")).then(res => {
|
||||
localStorage.setItem("token", res);
|
||||
changePage(pages.HOME);
|
||||
changePage("HOME");
|
||||
}).catch(e => {
|
||||
document.getElementById("usernameInput").classList.add("uk-form-danger");
|
||||
document.getElementById("passwordInput").classList.add("uk-form-danger");
|
||||
|
|
|
@ -44,7 +44,7 @@ export class SetVaultURLPage extends Page {
|
|||
e.preventDefault();
|
||||
let formData = new FormData(document.querySelector('#setVaultURLForm'));
|
||||
localStorage.setItem('apiurl', formData.get("vaultURL"));
|
||||
changePage(pages.HOME);
|
||||
changePage("HOME");
|
||||
});
|
||||
}
|
||||
get name() {
|
||||
|
|
|
@ -10,7 +10,7 @@ export class NewTOTPPage extends Page {
|
|||
super();
|
||||
}
|
||||
goBack() {
|
||||
changePage(pages.TOTP);
|
||||
changePage("TOTP");
|
||||
}
|
||||
render() {
|
||||
setTitleElement(pageState);
|
||||
|
@ -78,7 +78,7 @@ export class NewTOTPPage extends Page {
|
|||
generate: false
|
||||
};
|
||||
addNewTOTP(pageState.currentBaseMount, parms).then(res => {
|
||||
changePage(pages.TOTP);
|
||||
changePage("TOTP");
|
||||
}).catch(e => {
|
||||
setErrorText(`API Error: ${e.message}`);
|
||||
});
|
||||
|
|
|
@ -18,7 +18,7 @@ export class TOTPViewPage extends Page {
|
|||
makeElement({
|
||||
tag: "a",
|
||||
text: "Add new TOTP",
|
||||
onclick: _ => { changePage(pages.NEW_TOTP); }
|
||||
onclick: _ => { changePage("NEW_TOTP"); }
|
||||
}),
|
||||
makeElement({
|
||||
tag: "p",
|
||||
|
|
|
@ -7,7 +7,7 @@ export class TemplatePage extends Page {
|
|||
super();
|
||||
}
|
||||
goBack() {
|
||||
changePage(pages.HOME);
|
||||
changePage("HOME");
|
||||
}
|
||||
async render() {
|
||||
setTitleElement(pageState);
|
||||
|
|
|
@ -12,7 +12,7 @@ export class TransitDecryptPage extends Page {
|
|||
super();
|
||||
}
|
||||
goBack() {
|
||||
changePage(pages.TRANSIT_VIEW_SECRET);
|
||||
changePage("TRANSIT_VIEW_SECRET");
|
||||
}
|
||||
async render() {
|
||||
setTitleElement(pageState);
|
||||
|
|
|
@ -12,7 +12,7 @@ export class TransitEncryptPage extends Page {
|
|||
super();
|
||||
}
|
||||
goBack() {
|
||||
changePage(pages.TRANSIT_VIEW_SECRET);
|
||||
changePage("TRANSIT_VIEW_SECRET");
|
||||
}
|
||||
async render() {
|
||||
setTitleElement(pageState);
|
||||
|
|
|
@ -8,7 +8,7 @@ export class TransitViewPage extends Page {
|
|||
super();
|
||||
}
|
||||
goBack() {
|
||||
changePage(pages.HOME);
|
||||
changePage("HOME");
|
||||
}
|
||||
async render() {
|
||||
pageState.currentSecret = "";
|
||||
|
@ -20,7 +20,7 @@ export class TransitViewPage extends Page {
|
|||
text: "New",
|
||||
class: ["uk-button", "uk-button-primary", "uk-margin-bottom"],
|
||||
onclick: () => {
|
||||
changePage(pages.TRANSIT_NEW_KEY);
|
||||
changePage("TRANSIT_NEW_KEY");
|
||||
}
|
||||
});
|
||||
pageContent.appendChild(newButton);
|
||||
|
@ -40,7 +40,7 @@ export class TransitViewPage extends Page {
|
|||
text: secret,
|
||||
onclick: _ => {
|
||||
pageState.currentSecret = secret;
|
||||
changePage(pages.TRANSIT_VIEW_SECRET);
|
||||
changePage("TRANSIT_VIEW_SECRET");
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
|
@ -7,7 +7,7 @@ export class TransitViewSecretPage extends Page {
|
|||
super();
|
||||
}
|
||||
goBack() {
|
||||
changePage(pages.TRANSIT_VIEW);
|
||||
changePage("TRANSIT_VIEW");
|
||||
}
|
||||
|
||||
makeTile(title, description, icon = "code", onclick = _ => { }) {
|
||||
|
@ -57,13 +57,13 @@ export class TransitViewSecretPage extends Page {
|
|||
"Encrypt",
|
||||
"Encrypt some plaintext or base64 encoded binary.",
|
||||
"lock",
|
||||
_ => { changePage(pages.TRANSIT_ENCRYPT); }
|
||||
_ => { changePage("TRANSIT_ENCRYPT"); }
|
||||
),
|
||||
this.makeTile(
|
||||
"Decrypt",
|
||||
"Decrypt some cyphertext.",
|
||||
"mail",
|
||||
_ => { changePage(pages.TRANSIT_DECRYPT); }
|
||||
_ => { changePage("TRANSIT_DECRYPT"); }
|
||||
),
|
||||
]
|
||||
}),
|
||||
|
|
|
@ -70,7 +70,7 @@ export class UnsealPage extends Page {
|
|||
progressBar.max = keysNeeded;
|
||||
if (!data.sealed) {
|
||||
progressBar.value = keysNeeded;
|
||||
changePage(pages.HOME);
|
||||
changePage("HOME");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ export class Page {
|
|||
return "";
|
||||
}
|
||||
goBack() {
|
||||
changePage(pages.HOME);
|
||||
changePage("HOME");
|
||||
}
|
||||
cleanup() {
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue