Reformat code.
This commit is contained in:
parent
9fc0f9347b
commit
e0a3106d2e
|
@ -4,45 +4,45 @@ import { setPageContent, setTitleElement } from "../pageUtils.js";
|
||||||
import { makeElement } from "../htmlUtils.js";
|
import { makeElement } from "../htmlUtils.js";
|
||||||
|
|
||||||
export class KeyValueVersionsPage extends Page {
|
export class KeyValueVersionsPage extends Page {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
}
|
|
||||||
goBack() {
|
|
||||||
changePage(pages.KEY_VALUE_SECRETS);
|
|
||||||
}
|
|
||||||
async render() {
|
|
||||||
setTitleElement(pageState);
|
|
||||||
|
|
||||||
let versionsList = makeElement({
|
|
||||||
tag: "ul",
|
|
||||||
id: "versionsList",
|
|
||||||
class: ["uk-nav", "uk-nav-default"]
|
|
||||||
});
|
|
||||||
setPageContent(versionsList);
|
|
||||||
|
|
||||||
let metadata = await getSecretMetadata(
|
|
||||||
pageState.currentBaseMount,
|
|
||||||
pageState.currentSecretPath,
|
|
||||||
pageState.currentSecret
|
|
||||||
);
|
|
||||||
|
|
||||||
new Map(Object.entries(metadata.versions)).forEach((_, ver) => {
|
|
||||||
versionsList.appendChild(makeElement({
|
|
||||||
tag: "li",
|
|
||||||
children: makeElement({
|
|
||||||
tag: "a",
|
|
||||||
text: `v${ver}`,
|
|
||||||
onclick: _ => {
|
|
||||||
pageState.currentSecretVersion = ver;
|
|
||||||
changePage(pages.KEY_VALUE_SECRETS);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
get name() {
|
|
||||||
return "K/V Versions";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
goBack() {
|
||||||
|
changePage(pages.KEY_VALUE_SECRETS);
|
||||||
|
}
|
||||||
|
async render() {
|
||||||
|
setTitleElement(pageState);
|
||||||
|
|
||||||
|
let versionsList = makeElement({
|
||||||
|
tag: "ul",
|
||||||
|
id: "versionsList",
|
||||||
|
class: ["uk-nav", "uk-nav-default"]
|
||||||
|
});
|
||||||
|
setPageContent(versionsList);
|
||||||
|
|
||||||
|
let metadata = await getSecretMetadata(
|
||||||
|
pageState.currentBaseMount,
|
||||||
|
pageState.currentSecretPath,
|
||||||
|
pageState.currentSecret
|
||||||
|
);
|
||||||
|
|
||||||
|
new Map(Object.entries(metadata.versions)).forEach((_, ver) => {
|
||||||
|
versionsList.appendChild(makeElement({
|
||||||
|
tag: "li",
|
||||||
|
children: makeElement({
|
||||||
|
tag: "a",
|
||||||
|
text: `v${ver}`,
|
||||||
|
onclick: _ => {
|
||||||
|
pageState.currentSecretVersion = ver;
|
||||||
|
changePage(pages.KEY_VALUE_SECRETS);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
get name() {
|
||||||
|
return "K/V Versions";
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,77 +4,77 @@ import { setErrorText, setTitleElement } from "../pageUtils.js";
|
||||||
import { makeElement } from "../htmlUtils.js";
|
import { makeElement } from "../htmlUtils.js";
|
||||||
|
|
||||||
export class KeyValueViewPage extends Page {
|
export class KeyValueViewPage extends Page {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
}
|
||||||
|
goBack() {
|
||||||
|
if (pageState.currentSecretPath.length != 0) {
|
||||||
|
pageState.popCurrentSecretPath();
|
||||||
|
changePage(pages.KEY_VALUE_VIEW);
|
||||||
|
} else {
|
||||||
|
changePage(pages.HOME);
|
||||||
}
|
}
|
||||||
goBack() {
|
}
|
||||||
if (pageState.currentSecretPath.length != 0) {
|
async render() {
|
||||||
pageState.popCurrentSecretPath();
|
pageState.currentSecret = "";
|
||||||
changePage(pages.KEY_VALUE_VIEW);
|
|
||||||
} else {
|
|
||||||
changePage(pages.HOME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async render() {
|
|
||||||
pageState.currentSecret = "";
|
|
||||||
|
|
||||||
setTitleElement(pageState);
|
setTitleElement(pageState);
|
||||||
|
|
||||||
let newButton = makeElement({
|
let newButton = makeElement({
|
||||||
tag: "button",
|
tag: "button",
|
||||||
text: "New",
|
text: "New",
|
||||||
class: ["uk-button", "uk-button-primary", "uk-margin-bottom"],
|
class: ["uk-button", "uk-button-primary", "uk-margin-bottom"],
|
||||||
onclick: () => {
|
onclick: () => {
|
||||||
changePage(pages.KEY_VALUE_NEW_SECRET);
|
changePage(pages.KEY_VALUE_NEW_SECRET);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
pageContent.appendChild(newButton);
|
pageContent.appendChild(newButton);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let res = await getSecrets(pageState.currentBaseMount, pageState.currentSecretPath);
|
let res = await getSecrets(pageState.currentBaseMount, pageState.currentSecretPath);
|
||||||
|
|
||||||
pageContent.appendChild(makeElement({
|
pageContent.appendChild(makeElement({
|
||||||
tag: "ul",
|
tag: "ul",
|
||||||
class: ["uk-nav", "uk-nav-default"],
|
class: ["uk-nav", "uk-nav-default"],
|
||||||
children: [
|
children: [
|
||||||
...res.map(function (secret) {
|
...res.map(function (secret) {
|
||||||
return makeElement({
|
return makeElement({
|
||||||
tag: "li",
|
tag: "li",
|
||||||
children: makeElement({
|
children: makeElement({
|
||||||
tag: "a",
|
tag: "a",
|
||||||
text: secret,
|
text: secret,
|
||||||
onclick: _ => {
|
onclick: _ => {
|
||||||
if (secret.endsWith("/")) {
|
if (secret.endsWith("/")) {
|
||||||
pageState.pushCurrentSecretPath(secret);
|
pageState.pushCurrentSecretPath(secret);
|
||||||
changePage(pages.KEY_VALUE_VIEW);
|
changePage(pages.KEY_VALUE_VIEW);
|
||||||
} else {
|
} else {
|
||||||
pageState.currentSecret = secret;
|
pageState.currentSecret = secret;
|
||||||
changePage(pages.KEY_VALUE_SECRETS);
|
changePage(pages.KEY_VALUE_SECRETS);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
})
|
|
||||||
]
|
|
||||||
}));
|
|
||||||
} catch (e) {
|
|
||||||
if (e == DoesNotExistError) {
|
|
||||||
// getSecrets also 404's on no keys so dont go all the way back.
|
|
||||||
if (pageState.currentSecretPath.length != 0) {
|
|
||||||
return this.goBack();
|
|
||||||
} else {
|
|
||||||
pageContent.appendChild(makeElement({
|
|
||||||
tag: "p",
|
|
||||||
text: "You seem to have no secrets here, would you like to create one?"
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
} else {
|
})
|
||||||
setErrorText(e.message);
|
});
|
||||||
}
|
})
|
||||||
|
]
|
||||||
|
}));
|
||||||
|
} catch (e) {
|
||||||
|
if (e == DoesNotExistError) {
|
||||||
|
// getSecrets also 404's on no keys so dont go all the way back.
|
||||||
|
if (pageState.currentSecretPath.length != 0) {
|
||||||
|
return this.goBack();
|
||||||
|
} else {
|
||||||
|
pageContent.appendChild(makeElement({
|
||||||
|
tag: "p",
|
||||||
|
text: "You seem to have no secrets here, would you like to create one?"
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
setErrorText(e.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return "K/V View";
|
return "K/V View";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,52 +5,52 @@ import { makeElement } from "../htmlUtils.js";
|
||||||
import { CopyableInputBox } from "../elements/CopyableInputBox.js";
|
import { CopyableInputBox } from "../elements/CopyableInputBox.js";
|
||||||
|
|
||||||
function random() {
|
function random() {
|
||||||
const {
|
const {
|
||||||
crypto,
|
crypto,
|
||||||
Uint32Array
|
Uint32Array
|
||||||
} = window;
|
} = window;
|
||||||
|
|
||||||
if (typeof (crypto === null || crypto === void 0 ? void 0 : crypto.getRandomValues) === 'function' && typeof Uint32Array === 'function') {
|
if (typeof (crypto === null || crypto === void 0 ? void 0 : crypto.getRandomValues) === 'function' && typeof Uint32Array === 'function') {
|
||||||
return window.crypto.getRandomValues(new Uint32Array(1))[0] / 4294967295;
|
return window.crypto.getRandomValues(new Uint32Array(1))[0] / 4294967295;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Math.random();
|
return Math.random();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function genPw(len) {
|
function genPw(len) {
|
||||||
let pw = "";
|
let pw = "";
|
||||||
const pwArray = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\]^_{|}~".split('');
|
const pwArray = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\]^_{|}~".split('');
|
||||||
for (let i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
pw = pw.concat(pwArray[Math.floor(random() * pwArray.length)]);
|
pw = pw.concat(pwArray[Math.floor(random() * pwArray.length)]);
|
||||||
}
|
}
|
||||||
return pw;
|
return pw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class PwGenPage extends Page {
|
export class PwGenPage extends Page {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
async render() {
|
async render() {
|
||||||
let inputBox = CopyableInputBox(genPw(24));
|
let inputBox = CopyableInputBox(genPw(24));
|
||||||
setPageContent(makeElement({
|
setPageContent(makeElement({
|
||||||
tag: "div",
|
tag: "div",
|
||||||
children: [
|
children: [
|
||||||
inputBox,
|
inputBox,
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "button",
|
tag: "button",
|
||||||
text: "Gen New Password",
|
text: "Gen New Password",
|
||||||
class: ["uk-button", "uk-button-primary", "uk-margin-bottom"],
|
class: ["uk-button", "uk-button-primary", "uk-margin-bottom"],
|
||||||
onclick: () => {
|
onclick: () => {
|
||||||
inputBox.setText(genPw(24));
|
inputBox.setText(genPw(24));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return "Password Generator";
|
return "Password Generator";
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,8 +25,8 @@ export class TOTPViewPage extends Page {
|
||||||
id: "loadingText",
|
id: "loadingText",
|
||||||
text: "Loading TOTP Codes..",
|
text: "Loading TOTP Codes..",
|
||||||
}),
|
}),
|
||||||
makeElement({tag: "br"}),
|
makeElement({ tag: "br" }),
|
||||||
makeElement({tag: "br"}),
|
makeElement({ tag: "br" }),
|
||||||
totpList
|
totpList
|
||||||
]
|
]
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -7,14 +7,14 @@ export class TransitViewSecretPage extends Page {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
makeTile(title, description, icon = "code", onclick = _ => {}) {
|
makeTile(title, description, icon = "code", onclick = _ => { }) {
|
||||||
return makeElement({
|
return makeElement({
|
||||||
tag: "div",
|
tag: "a",
|
||||||
class: ["uk-tile", "uk-tile-default", "uk-tile-primary", "uk-padding-small"],
|
class: "uk-link-heading",
|
||||||
|
onclick: onclick,
|
||||||
children: makeElement({
|
children: makeElement({
|
||||||
tag: "a",
|
tag: "div",
|
||||||
class: "uk-link-heading",
|
class: ["uk-tile", "uk-tile-default", "uk-tile-primary", "uk-padding-small"],
|
||||||
onclick: onclick,
|
|
||||||
children: [
|
children: [
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "p",
|
tag: "p",
|
||||||
|
@ -37,7 +37,6 @@ export class TransitViewSecretPage extends Page {
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ export class UnsealPage extends Page {
|
||||||
this.unsealProgress = makeElement({
|
this.unsealProgress = makeElement({
|
||||||
tag: "progress",
|
tag: "progress",
|
||||||
class: "uk-progress",
|
class: "uk-progress",
|
||||||
attributes: {value: "0", max: "0"}
|
attributes: { value: "0", max: "0" }
|
||||||
});
|
});
|
||||||
this.unsealProgressText = makeElement({
|
this.unsealProgressText = makeElement({
|
||||||
tag: "p",
|
tag: "p",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {changePage} from "../pageUtils.js";
|
import { changePage } from "../pageUtils.js";
|
||||||
|
|
||||||
export class Page {
|
export class Page {
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
26
src/utils.js
26
src/utils.js
|
@ -1,27 +1,27 @@
|
||||||
export function removeDoubleSlash(str) {
|
export function removeDoubleSlash(str) {
|
||||||
return str.replace(/\/\/+/g, "/");
|
return str.replace(/\/\/+/g, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getKeyByObjectPropertyValue(map, searchValue) {
|
export function getKeyByObjectPropertyValue(map, searchValue) {
|
||||||
for (let key of Object.getOwnPropertyNames(map)) {
|
for (let key of Object.getOwnPropertyNames(map)) {
|
||||||
if (map[key] === searchValue)
|
if (map[key] === searchValue)
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function verifyJSONString(str) {
|
export function verifyJSONString(str) {
|
||||||
try {
|
try {
|
||||||
JSON.parse(str);
|
JSON.parse(str);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getToken() {
|
export function getToken() {
|
||||||
return localStorage.getItem('token');
|
return localStorage.getItem('token');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAPIURL() {
|
export function getAPIURL() {
|
||||||
return localStorage.getItem('apiurl');
|
return localStorage.getItem('apiurl');
|
||||||
}
|
}
|
Loading…
Reference in a new issue