diff --git a/src/PageState.js b/src/PageState.js index b4c2a8d..0cc8a54 100644 --- a/src/PageState.js +++ b/src/PageState.js @@ -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); } } \ No newline at end of file diff --git a/src/main.js b/src/main.js index a455527..fafce16 100644 --- a/src/main.js +++ b/src/main.js @@ -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; } } diff --git a/src/pageUtils.js b/src/pageUtils.js index 00a0967..714687b 100644 --- a/src/pageUtils.js +++ b/src/pageUtils.js @@ -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"); } } }); diff --git a/src/pages/Home.js b/src/pages/Home.js index 89b20ae..682b555 100644 --- a/src/pages/Home.js +++ b/src/pages/Home.js @@ -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({ diff --git a/src/pages/KeyValue/KeyValueDelete.js b/src/pages/KeyValue/KeyValueDelete.js index fe09227..2b4dc9b 100644 --- a/src/pages/KeyValue/KeyValueDelete.js +++ b/src/pages/KeyValue/KeyValueDelete.js @@ -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() { diff --git a/src/pages/KeyValue/KeyValueNew.js b/src/pages/KeyValue/KeyValueNew.js index 6959b62..4451fcc 100644 --- a/src/pages/KeyValue/KeyValueNew.js +++ b/src/pages/KeyValue/KeyValueNew.js @@ -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); diff --git a/src/pages/KeyValue/KeyValueSecrets.js b/src/pages/KeyValue/KeyValueSecrets.js index 91d054e..f275fb4 100644 --- a/src/pages/KeyValue/KeyValueSecrets.js +++ b/src/pages/KeyValue/KeyValueSecrets.js @@ -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" })); } diff --git a/src/pages/KeyValue/KeyValueSecretsEdit.js b/src/pages/KeyValue/KeyValueSecretsEdit.js index 60d0f4e..fcb3bd4 100644 --- a/src/pages/KeyValue/KeyValueSecretsEdit.js +++ b/src/pages/KeyValue/KeyValueSecretsEdit.js @@ -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); diff --git a/src/pages/KeyValue/KeyValueVersions.js b/src/pages/KeyValue/KeyValueVersions.js index 2b51ea6..94f36c8 100644 --- a/src/pages/KeyValue/KeyValueVersions.js +++ b/src/pages/KeyValue/KeyValueVersions.js @@ -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"); } }) })); diff --git a/src/pages/KeyValue/KeyValueView.js b/src/pages/KeyValue/KeyValueView.js index 5805009..86f1e87 100644 --- a/src/pages/KeyValue/KeyValueView.js +++ b/src/pages/KeyValue/KeyValueView.js @@ -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"); } } }) diff --git a/src/pages/Login.js b/src/pages/Login.js index 513a4b2..0272987 100644 --- a/src/pages/Login.js +++ b/src/pages/Login.js @@ -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"); diff --git a/src/pages/SetVaultURL.js b/src/pages/SetVaultURL.js index 072a6ae..ae7ac8b 100644 --- a/src/pages/SetVaultURL.js +++ b/src/pages/SetVaultURL.js @@ -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() { diff --git a/src/pages/TOTP/NewTOTP.js b/src/pages/TOTP/NewTOTP.js index 7b0dcf7..a89ad31 100644 --- a/src/pages/TOTP/NewTOTP.js +++ b/src/pages/TOTP/NewTOTP.js @@ -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}`); }); diff --git a/src/pages/TOTP/TOTPView.js b/src/pages/TOTP/TOTPView.js index 2b25da4..2db42d1 100644 --- a/src/pages/TOTP/TOTPView.js +++ b/src/pages/TOTP/TOTPView.js @@ -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", diff --git a/src/pages/Template.js b/src/pages/Template.js index 58ee40f..0cf8f6f 100644 --- a/src/pages/Template.js +++ b/src/pages/Template.js @@ -7,7 +7,7 @@ export class TemplatePage extends Page { super(); } goBack() { - changePage(pages.HOME); + changePage("HOME"); } async render() { setTitleElement(pageState); diff --git a/src/pages/Transit/TransitDecrypt.js b/src/pages/Transit/TransitDecrypt.js index b199f8e..8d9572a 100644 --- a/src/pages/Transit/TransitDecrypt.js +++ b/src/pages/Transit/TransitDecrypt.js @@ -12,7 +12,7 @@ export class TransitDecryptPage extends Page { super(); } goBack() { - changePage(pages.TRANSIT_VIEW_SECRET); + changePage("TRANSIT_VIEW_SECRET"); } async render() { setTitleElement(pageState); diff --git a/src/pages/Transit/TransitEncrypt.js b/src/pages/Transit/TransitEncrypt.js index 17c0764..8d5ff75 100644 --- a/src/pages/Transit/TransitEncrypt.js +++ b/src/pages/Transit/TransitEncrypt.js @@ -12,7 +12,7 @@ export class TransitEncryptPage extends Page { super(); } goBack() { - changePage(pages.TRANSIT_VIEW_SECRET); + changePage("TRANSIT_VIEW_SECRET"); } async render() { setTitleElement(pageState); diff --git a/src/pages/Transit/TransitView.js b/src/pages/Transit/TransitView.js index fcdb7dd..308fda6 100644 --- a/src/pages/Transit/TransitView.js +++ b/src/pages/Transit/TransitView.js @@ -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"); } }) }); diff --git a/src/pages/Transit/TransitViewSecret.js b/src/pages/Transit/TransitViewSecret.js index cca7242..1b1315a 100644 --- a/src/pages/Transit/TransitViewSecret.js +++ b/src/pages/Transit/TransitViewSecret.js @@ -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"); } ), ] }), diff --git a/src/pages/Unseal.js b/src/pages/Unseal.js index 71031d7..06d3832 100644 --- a/src/pages/Unseal.js +++ b/src/pages/Unseal.js @@ -70,7 +70,7 @@ export class UnsealPage extends Page { progressBar.max = keysNeeded; if (!data.sealed) { progressBar.value = keysNeeded; - changePage(pages.HOME); + changePage("HOME"); } } diff --git a/src/types/Page.js b/src/types/Page.js index 3267557..89228b2 100644 --- a/src/types/Page.js +++ b/src/types/Page.js @@ -11,7 +11,7 @@ export class Page { return ""; } goBack() { - changePage(pages.HOME); + changePage("HOME"); } cleanup() { }