cleanup
This commit is contained in:
parent
1f008a22a8
commit
1ac7eb8bf4
@ -298,6 +298,18 @@ function resetPage() {
|
|||||||
sidebarDiv.replaceWith(activeState.orgPage.sidebar);
|
sidebarDiv.replaceWith(activeState.orgPage.sidebar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wrongPwAlert() {
|
||||||
|
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 =
|
||||||
|
"<p>all files cleared - set new password</p>";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
hideMenus,
|
hideMenus,
|
||||||
showMenu,
|
showMenu,
|
||||||
@ -311,4 +323,5 @@ export {
|
|||||||
resetNavBar,
|
resetNavBar,
|
||||||
printVersion,
|
printVersion,
|
||||||
resetPage,
|
resetPage,
|
||||||
|
wrongPwAlert
|
||||||
};
|
};
|
||||||
|
|||||||
@ -33,6 +33,7 @@ window.activeState = {
|
|||||||
notifierPause: 1,
|
notifierPause: 1,
|
||||||
persistentStorage: "false",
|
persistentStorage: "false",
|
||||||
enablePell: "false",
|
enablePell: "false",
|
||||||
|
debug: "false"
|
||||||
},
|
},
|
||||||
templates: [],
|
templates: [],
|
||||||
templateObjectsPurified: [],
|
templateObjectsPurified: [],
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { clearStorage, createStorageObj, retrieveData } from "./storage.js";
|
import { createStorageObj, retrieveData } from "./storage.js";
|
||||||
import sha256 from "./sha256.min.js";
|
import sha256 from "./sha256.min.js";
|
||||||
import XORCipher from "./xorc.js";
|
import XORCipher from "./xorc.js";
|
||||||
import getBrowserFingerprint from "./identify.js"
|
import getBrowserFingerprint from "./identify.js"
|
||||||
|
import { wrongPwAlert } from "./evts.js";
|
||||||
|
|
||||||
export const passwordHash = {
|
export const passwordHash = {
|
||||||
name: cyrb53("m21_"+getBrowserFingerprint( { hardwareOnly: true } )),
|
name: cyrb53("m21_"+getBrowserFingerprint( { hardwareOnly: true } )),
|
||||||
@ -13,32 +14,25 @@ export const passwordHash = {
|
|||||||
},
|
},
|
||||||
set: function (pw) {
|
set: function (pw) {
|
||||||
if (pw == "") return;
|
if (pw == "") return;
|
||||||
activeState.sessionToken = XORCipher.encode(this.name, pw);
|
activeState.sessionToken = XORCipher.encode(this.name, sha256(pw));
|
||||||
},
|
},
|
||||||
initHash: function () {
|
initHash: function () {
|
||||||
//check if cookie exists
|
//check if cookie exists
|
||||||
if (getCookie(sha256(this.name)) != null) {
|
if (getCookie(this.name) != null) {
|
||||||
if (getCookie(sha256(this.name)) != "") {
|
if (getCookie(this.name) != "") {
|
||||||
this.set(XORCipher.decode(sha256(this.name), getCookie(sha256(this.name))));
|
this.set(XORCipher.decode(this.name, getCookie(this.name)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let verifiedStatus = false;
|
|
||||||
let tF = retrieveData("templateFiles");
|
|
||||||
if (tF != null) {verifiedStatus = true}
|
|
||||||
|
|
||||||
|
if (retrieveData("templateFiles") != null) {
|
||||||
if (verifiedStatus == true) {
|
|
||||||
//set user id
|
//set user id
|
||||||
activeState.userId = getUsrId();
|
activeState.userId = passwordHash.name;
|
||||||
setCookie(sha256(this.name), XORCipher.encode(sha256(this.name), this), 10);
|
setCookie(this.name, XORCipher.encode(this.name, this), 10);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
verify: function () {
|
verify: function () {
|
||||||
if (passwordHash == "") return false;
|
if (passwordHash == "") return false;
|
||||||
let verifiedStatus = false;
|
return (retrieveData("templateFiles") != null) ? true : false;
|
||||||
let tF = retrieveData("templateFiles");
|
|
||||||
if (tF != null) verifiedStatus = true
|
|
||||||
return verifiedStatus;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +41,7 @@ function setPassword() {
|
|||||||
let pw = sanitize(x.elements[0].value);
|
let pw = sanitize(x.elements[0].value);
|
||||||
|
|
||||||
if (pw != "" || pw !== "undefined") {
|
if (pw != "" || pw !== "undefined") {
|
||||||
passwordHash.set(sha256(pw));
|
passwordHash.set(pw);
|
||||||
let tF = retrieveData("templateFiles");
|
let tF = retrieveData("templateFiles");
|
||||||
if (tF == null) {
|
if (tF == null) {
|
||||||
wrongPwAlert();
|
wrongPwAlert();
|
||||||
@ -63,25 +57,13 @@ function setPassword() {
|
|||||||
if (tF == null || tF.length == 0) {
|
if (tF == null || tF.length == 0) {
|
||||||
activeState.settings.persistentStorage = "false";
|
activeState.settings.persistentStorage = "false";
|
||||||
}
|
}
|
||||||
|
activeState.userId = passwordHash.name;
|
||||||
document.getElementById("login").style.display = "none";
|
document.getElementById("login").style.display = "none";
|
||||||
setCookie(sha256(passwordHash.name), XORCipher.encode(sha256(passwordHash.name), passwordHash), 10)
|
setCookie(passwordHash.name, XORCipher.encode(passwordHash.name, passwordHash), 10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrongPwAlert() {
|
export function cyrb53(str, seed = 21) {
|
||||||
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 =
|
|
||||||
"<p>all files cleared - set new password</p>";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function cyrb53(str, seed = 21) {
|
|
||||||
let h1 = 0xdeadbeef ^ seed,
|
let h1 = 0xdeadbeef ^ seed,
|
||||||
h2 = 0x41c6ce57 ^ seed;
|
h2 = 0x41c6ce57 ^ seed;
|
||||||
for (let i = 0, ch; i < str.length; i++) {
|
for (let i = 0, ch; i < str.length; i++) {
|
||||||
@ -96,11 +78,6 @@ function cyrb53(str, seed = 21) {
|
|||||||
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUsrId() {
|
|
||||||
const fingerprint = getBrowserFingerprint( { hardwareOnly: true } );
|
|
||||||
return cyrb53(fingerprint + passwordHash);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setCookie(cname, cvalue, exdays) {
|
function setCookie(cname, cvalue, exdays) {
|
||||||
const d = new Date();
|
const d = new Date();
|
||||||
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
||||||
@ -124,9 +101,9 @@ function getCookie(cname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function logout() {
|
export function logout() {
|
||||||
let id = sha256(passwordHash.name);
|
let id = passwordHash.name;
|
||||||
activeState.sessionToken = "";
|
activeState.sessionToken = "";
|
||||||
setCookie(sha256(passwordHash.name), "", 10);
|
setCookie(passwordHash.name, "", 10);
|
||||||
document.cookie = id + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
document.cookie = id + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
||||||
document.getElementById("passwordField").value = "";
|
document.getElementById("passwordField").value = "";
|
||||||
document.getElementById("login").style.display = "block";
|
document.getElementById("login").style.display = "block";
|
||||||
|
|||||||
@ -1,12 +1,21 @@
|
|||||||
import XORCipher from "./xorc.js";
|
import XORCipher from "./xorc.js";
|
||||||
import sha256 from "./sha256.min.js";
|
import sha256 from "./sha256.min.js";
|
||||||
import { getCurrentDate, passwordHash, sanitize } from "./scripts.js";
|
import { cyrb53, getCurrentDate, passwordHash, sanitize } from "./scripts.js";
|
||||||
|
|
||||||
const store = {
|
const store = {
|
||||||
getItem: function (key) {return getStor().getItem(sha256(key+activeState.userId))},
|
getItem: function (key) {
|
||||||
setItem: function (key, data) {getStor().setItem(sha256(key+activeState.userId), data)},
|
return debug("GET", key, getStor().getItem(sha256(key + activeState.userId)));
|
||||||
removeItem: function (key) {getStor().removeItem(sha256(key+activeState.userId))},
|
},
|
||||||
clear: function () {getStor().clear()},
|
setItem: function (key, data) {
|
||||||
|
debug("SET", key, "setItem: "+data);
|
||||||
|
getStor().setItem(sha256(key + activeState.userId), data);
|
||||||
|
},
|
||||||
|
removeItem: function (key) {
|
||||||
|
getStor().removeItem(sha256(key + activeState.userId));
|
||||||
|
},
|
||||||
|
clear: function () {
|
||||||
|
getStor().clear();
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const tempStore = {
|
const tempStore = {
|
||||||
@ -32,6 +41,17 @@ function getStor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function debug(mode, key, data) {
|
||||||
|
if (activeState.settings.debug == "false") return data;
|
||||||
|
console.log({
|
||||||
|
mode: mode,
|
||||||
|
key: key,
|
||||||
|
data: data.substring(0,10),
|
||||||
|
persistent: activeState.settings.persistentStorage
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
function createStorageObj() {
|
function createStorageObj() {
|
||||||
let x = document.getElementById("mainFormObj");
|
let x = document.getElementById("mainFormObj");
|
||||||
let dataArray = [];
|
let dataArray = [];
|
||||||
@ -75,9 +95,9 @@ function storeData(name, data) {
|
|||||||
name = "userInput";
|
name = "userInput";
|
||||||
}
|
}
|
||||||
let lT = activeState.loadedTemplate;
|
let lT = activeState.loadedTemplate;
|
||||||
let key = sha256(name + "_m21_" + lT);
|
let key = name + "_m21_" + lT;
|
||||||
if (name == "templateFiles") {
|
if (name == "templateFiles") {
|
||||||
key = sha256(name + "_m21_" + activeState.userId);
|
key = name + "_m21_" + activeState.userId;
|
||||||
}
|
}
|
||||||
store.setItem(key, obfuscate(data));
|
store.setItem(key, obfuscate(data));
|
||||||
}
|
}
|
||||||
@ -99,12 +119,12 @@ function retrieveData(name, template = "none") {
|
|||||||
let key;
|
let key;
|
||||||
if (template == "none") {
|
if (template == "none") {
|
||||||
let lT = activeState.loadedTemplate;
|
let lT = activeState.loadedTemplate;
|
||||||
key = sha256(name + "_m21_" + lT);
|
key = name + "_m21_" + lT;
|
||||||
if (name == "templateFiles") {
|
if (name == "templateFiles") {
|
||||||
key = sha256(name + "_m21_"+activeState.userId);
|
key = name + "_m21_" + activeState.userId;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
key = sha256(name + "_m21_" + template);
|
key = name + "_m21_" + template;
|
||||||
}
|
}
|
||||||
cdata = store.getItem(key);
|
cdata = store.getItem(key);
|
||||||
|
|
||||||
@ -127,13 +147,13 @@ function clearData(name, template = "none") {
|
|||||||
let key;
|
let key;
|
||||||
if (template == "none") {
|
if (template == "none") {
|
||||||
lT = activeState.loadedTemplate;
|
lT = activeState.loadedTemplate;
|
||||||
key = sha256(name + "_m21_" + lT);
|
key = name + "_m21_" + lT;
|
||||||
if (name == "templateFiles") {
|
if (name == "templateFiles") {
|
||||||
key = sha256(name + "_m21_"+activeState.userId);
|
key = name + "_m21_" + activeState.userId;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lT = template;
|
lT = template;
|
||||||
key = sha256(name + "_m21_" + template);
|
key = name + "_m21_" + template;
|
||||||
}
|
}
|
||||||
store.removeItem(key);
|
store.removeItem(key);
|
||||||
}
|
}
|
||||||
@ -151,7 +171,7 @@ function getFileName(ref = "none") {
|
|||||||
const metadata = {
|
const metadata = {
|
||||||
ts_create: getCurrentDate(),
|
ts_create: getCurrentDate(),
|
||||||
ts_save: "",
|
ts_save: "",
|
||||||
id: sha256(currentFileName),
|
id: cyrb53(currentFileName),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tF.length != 0) {
|
if (tF.length != 0) {
|
||||||
@ -178,11 +198,11 @@ function getFileName(ref = "none") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function obfuscate(data, mode = true) {
|
function obfuscate(data, mode = true) {
|
||||||
if (data == null | data == "") return "";
|
if ((data == null) | (data == "")) return "";
|
||||||
if (mode) {
|
if (mode) {
|
||||||
return XORCipher.encode(sha256(passwordHash), data);
|
return XORCipher.encode(passwordHash, data);
|
||||||
} else {
|
} else {
|
||||||
return XORCipher.decode(sha256(passwordHash), data);
|
return XORCipher.decode(passwordHash, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,14 +255,14 @@ function importBookShelf() {
|
|||||||
let templateFilesArray = [];
|
let templateFilesArray = [];
|
||||||
for (let file of mainArray) {
|
for (let file of mainArray) {
|
||||||
if (file.name == "hash") continue;
|
if (file.name == "hash") continue;
|
||||||
store.setItem(sha256(file.name), file.data);
|
store.setItem(file.name, file.data);
|
||||||
templateFilesArray.push({
|
templateFilesArray.push({
|
||||||
fileName: file.name.split("_m21_")[0],
|
fileName: file.name.split("_m21_")[0],
|
||||||
template: file.name.split("_m21_")[1],
|
template: file.name.split("_m21_")[1],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
store.setItem(
|
store.setItem(
|
||||||
sha256("templateFiles_m21_"+activeState.userId),
|
"templateFiles_m21_" + activeState.userId,
|
||||||
obfuscate(JSON.stringify(templateFilesArray))
|
obfuscate(JSON.stringify(templateFilesArray))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -257,17 +277,21 @@ function importBookShelf() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function storeSettings(data, get = false) {
|
function storeSettings(data, get = false) {
|
||||||
let key = sha256("settings_m21_"+activeState.userId);
|
let key = "settings_m21_" + activeState.userId;
|
||||||
|
|
||||||
if (get) {
|
if (get) {
|
||||||
let cdata = "";
|
let cdata = "";
|
||||||
if (data == "getInit") {activeState.settings.persistentStorage = "true"}
|
if (data == "getInit") {
|
||||||
|
activeState.settings.persistentStorage = "true";
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
cdata = JSON.parse(obfuscate(store.getItem(key), false));
|
cdata = JSON.parse(obfuscate(store.getItem(key), false));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
cdata = "";
|
cdata = "";
|
||||||
}
|
}
|
||||||
if (data == "getInit") {activeState.settings.persistentStorage = "false"};
|
if (data == "getInit") {
|
||||||
|
activeState.settings.persistentStorage = "false";
|
||||||
|
}
|
||||||
return cdata;
|
return cdata;
|
||||||
} else {
|
} else {
|
||||||
store.setItem(key, obfuscate(JSON.stringify(data)));
|
store.setItem(key, obfuscate(JSON.stringify(data)));
|
||||||
@ -287,5 +311,5 @@ export {
|
|||||||
createBookShelf,
|
createBookShelf,
|
||||||
importBookShelf,
|
importBookShelf,
|
||||||
storeSettings,
|
storeSettings,
|
||||||
clearStorage
|
clearStorage,
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user