diff --git a/index.html b/index.html index 112f92b..a2ef8ef 100644 --- a/index.html +++ b/index.html @@ -313,7 +313,7 @@ style="display: none" > × @@ -322,7 +322,6 @@ clear all files? diff --git a/js/9.9.9/init.js b/js/9.9.9/init.js index 5fd3e00..11e54ef 100644 --- a/js/9.9.9/init.js +++ b/js/9.9.9/init.js @@ -55,6 +55,7 @@ function init() { try { window.localStorage.getItem("test") } catch (e) { + console.log("localStorage not available"); activeState.settings.persistentStorage = "false"; } @@ -76,12 +77,13 @@ function init() { //load settings from storage let settings = storeSettings("getInit", true); - if (settings != "") { + if (settings != null) { for (let setting of Object.entries(settings)) { activeState.settings[setting[0]] = setting[1]; } } + //load NavigationBar with templates according to server loadNavBar(); diff --git a/js/9.9.9/scripts.js b/js/9.9.9/scripts.js index ed133b4..8ea1616 100644 --- a/js/9.9.9/scripts.js +++ b/js/9.9.9/scripts.js @@ -1,4 +1,4 @@ -import { createStorageObj, retrieveData } from "./storage.js"; +import { clearStorage, createStorageObj, retrieveData } from "./storage.js"; import sha256 from "./sha256.min.js"; import XORCipher from "./xorc.js"; import getBrowserFingerprint from "./identify.js" @@ -7,29 +7,42 @@ export const passwordHash = { name: cyrb53("m21_"+getBrowserFingerprint( { hardwareOnly: true } )), toString: function () { let token = window.activeState.sessionToken; - if (token == null || token == "") return "none"; + if (token == null) return ""; + if (token == "") return ""; return XORCipher.decode(this.name, token); }, set: function (pw) { activeState.sessionToken = XORCipher.encode(this.name, pw); + }, init: function () { //check if cookie exists if (getCookie(sha256(this.name)) != null) { - this.set(XORCipher.decode(sha256(this.name), getCookie(sha256(this.name)))); + if (getCookie(sha256(this.name)) != "") { + this.set(XORCipher.decode(sha256(this.name), getCookie(sha256(this.name)))); + } + } + if (passwordHash == "") { + return; } let verifiedStatus = false; let tF = retrieveData("templateFiles"); if (tF != null) {verifiedStatus = true} + if (verifiedStatus == true) { setCookie(sha256(this.name), XORCipher.encode(sha256(this.name), this), 10); } }, verify: function () { + if (passwordHash == "") { + return false; + } let verifiedStatus = false; let tF = retrieveData("templateFiles"); - if (tF != null) {verifiedStatus = true} + if (tF != null) { + verifiedStatus = true + } return verifiedStatus; } } @@ -43,16 +56,28 @@ function setPassword() { passwordHash.set(sha256(pw)); let templateFiles = retrieveData("templateFiles"); if (templateFiles == null) { - document.getElementById("wrongPWAlert").style.display = "block"; - const alertTimeout = setTimeout(() => { - document.getElementById("wrongPWAlert").style.display = "none"; - }, 5000); + let wrongPWAlert = document.getElementById("wrongPWAlert"); + wrongPWAlert.style.display = "block"; + wrongPWAlert.addEventListener("click", (e) => { + if (e.target && e.target.tagName === "A") { + clearStorage(); + document.getElementById("wrongPWAlert").innerHTML = + "

all files cleared - set new password

"; + } + }); passwordHash.set(pwOld); x.elements[0].value = ""; return; } //user logged in + //make sure to bring back persistent stat after logout + activeState.settings.persistentStorage = "true"; + let tF = retrieveData("templateFiles"); + if (tF == null || tF.length == 0) { + activeState.settings.persistentStorage = "false"; + } + document.getElementById("login").style.display = "none"; setCookie(sha256(passwordHash.name), XORCipher.encode(sha256(passwordHash.name), passwordHash), 10) } diff --git a/js/9.9.9/settings.js b/js/9.9.9/settings.js index db43a24..c1318e4 100644 --- a/js/9.9.9/settings.js +++ b/js/9.9.9/settings.js @@ -1,7 +1,6 @@ import { hideMenus, modalNotifier, printVersion, resetNavBar } from "./evts.js"; import { passwordHash, sanitize } from "./scripts.js"; -import sha256 from "./sha256.min.js"; -import { retrieveData, storeData, storeSettings } from "./storage.js"; +import { clearData, retrieveData, storeData, storeSettings } from "./storage.js"; const buildSettings = () => { //set current page value in activeState object @@ -185,16 +184,14 @@ function saveSettings() { if (setting[0] == "persistentStorage") { let tF = retrieveData("templateFiles"); let settings = storeSettings("get", true); + storeSettings(obj); activeState.settings[setting[0]] = setting[1]; if (setting[1] == "false") { - try { - window.localStorage.removeItem(sha256("settings_m21_")); - } catch (e) {} let msg = (activeState.settings.persistentStorage == "false") ? "temporary" : "persistent"; printVersion("storage mode: "+msg+" |"); } - if (settings != "") storeSettings(settings); + if (settings != "") storeSettings(obj); if (tF != null) storeData("templateFiles", tF); } } diff --git a/js/9.9.9/storage.js b/js/9.9.9/storage.js index da4f3fc..b3f276e 100644 --- a/js/9.9.9/storage.js +++ b/js/9.9.9/storage.js @@ -133,6 +133,9 @@ function clearData(name, template = "none") { lT = template; key = sha256(name + "_m21_" + template); } + if (name == "templateFiles") { + key = sha256(name + "_m21_"); + } store.removeItem(key); } @@ -176,6 +179,7 @@ function getFileName(ref = "none") { } function obfuscate(data, mode = true) { + if (data == null | data == "") return ""; if (mode) { return XORCipher.encode(sha256(passwordHash), data); } else { @@ -271,6 +275,10 @@ function storeSettings(data, get = false) { } } +function clearStorage() { + store.clear(); +} + export { createStorageObj, storeData, @@ -280,4 +288,5 @@ export { createBookShelf, importBookShelf, storeSettings, + clearStorage }; diff --git a/js/9.9.9/web.js b/js/9.9.9/web.js index 9a3f7d4..a484825 100644 --- a/js/9.9.9/web.js +++ b/js/9.9.9/web.js @@ -48,8 +48,10 @@ function loadTemplate(template, newFlag = false, loadOnly = false) { } else { cdata = retrieveData("userInputForce"); } - if (cdata != "" || cdata == null) { - retrieveForm(cdata); + if (cdata != "") { + if (cdata == null) { + retrieveForm(cdata); + } } //select first object and focus on it