summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guard/templates.py25
-rw-r--r--static/main.js12
2 files changed, 27 insertions, 10 deletions
diff --git a/guard/templates.py b/guard/templates.py
index e8d63a0..3cc1373 100644
--- a/guard/templates.py
+++ b/guard/templates.py
@@ -7,19 +7,19 @@ from lxml import etree
from flask import url_for
-def _html(title: str, body: etree.Element) -> str:
+def _html(head: etree.Element, body: etree.Element) -> str:
return etree.tostring(E.html(
- E.head(E.title(title)),
- E.body(body)
+ head,
+ body
), encoding='utf-8')
def login() -> str:
- return _html("Login", E.form(
+ return _html(E.head(E.titile("Login")), E.body(E.form(
E.input(type="password", name="secret", placeholder="Secret admin token"),
E.button("login", type="submit"),
method="POST"
- ))
+ )))
def _index_access(accesses: Iterable[model.Access]):
@@ -40,8 +40,11 @@ def _index_access(accesses: Iterable[model.Access]):
def index(serverport: str, cookiename: str) -> str:
return _html(
- "Manage access tokens",
- E.div(
+ E.head(
+ E.title("Manage access tokens"),
+ E.script("", src="static/main.js")
+ ),
+ E.body(E.div(
E.p(E.a("Logout", href=url_for("logout"))),
E.p("Call the write-service like: ",
E.pre("http://thisMachine:{}/write".format(serverport)),
@@ -50,10 +53,12 @@ def index(serverport: str, cookiename: str) -> str:
E.pre("http://thisMachine:{}/write/<token>".format(serverport))),
E.form(
E.input(type="hidden", name="action", value="create"),
- E.input(name="token", placeholder="Token secret"),
+ E.input(name="token", placeholder="Token secret", id="tokenField"),
+ E.input(value="↻", type="button", onclick="genToken()"),
E.input(name="pattern", placeholder="Paths pattern"),
E.input(name="comment", placeholder="Comment"),
- E.button("Create", type="submit"), method="POST"),
+ E.button("Create", type="submit"),
+ method="POST"),
E.hr(),
E.table(
E.tr(
@@ -61,5 +66,5 @@ def index(serverport: str, cookiename: str) -> str:
E.th("Create Date"), E.th("Comment"), E.th()
), border="1", style="width: 100%",
*_index_access(model.Access.select().order_by(model.Access.create_date))
- ))
+ )))
)
diff --git a/static/main.js b/static/main.js
new file mode 100644
index 0000000..e00efd4
--- /dev/null
+++ b/static/main.js
@@ -0,0 +1,12 @@
+// Generate random token string
+
+const KEY_LENGTH = 20;
+const ALPHABET_BASE58 = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
+
+function genToken() {
+ const rand_buffer = Array.from(window.crypto.getRandomValues(new Uint32Array(KEY_LENGTH)));
+ const rand_chars = rand_buffer.map(elem => ALPHABET_BASE58.charAt(Math.round(elem/4294967295*58)));
+ const token = rand_chars.join("");
+
+ document.getElementById("tokenField").value = token;
+}