added key id field

This commit is contained in:
JMARyA 2022-08-31 03:18:44 +02:00
parent f9ce89fb4f
commit ecb01dfc75
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263

View file

@ -1,4 +1,4 @@
from flask import request, session, Blueprint, Response, redirect
from flask import request, session, Blueprint, Response, redirect, escape
from htmlpy import *
from config import CONFIG
from os.path import exists
@ -15,6 +15,7 @@ def download_file(url, file):
r = requests.get(url, allow_redirects=True)
open(file, "wb").write(r.content)
# Downloads all bootstrap files to flasks static directory
def cache_bootstrap():
download_file(
@ -58,6 +59,7 @@ def save_message(msg, name=""):
f = open(f"/data/messages/{name}-{dt}.asc", "w")
f.write(msg)
# Send Notification to all handlers
def notify(msg, title=None):
try:
@ -65,6 +67,7 @@ def notify(msg, title=None):
except:
pass
# Gotify Notification Handler
def gotify_notification(msg, title=None):
token = CONFIG["notify"]["gotify"]["token"]
@ -86,7 +89,7 @@ def send_message():
cipher = encrypt(msg)
save_message(cipher, name)
notify(f"New Message from {name}")
return redirect(request.url_root.replace("http", "https"))
return redirect(request.url_root)
else:
# Return Message Form
return buildSite(
@ -96,7 +99,7 @@ def send_message():
Heading(1, "Message"),
LineBreak(),
Form(
destination=request.url.replace("http", "https"),
destination=request.url,
inner=[
Input(
"",
@ -131,7 +134,8 @@ def send_message():
css_class="container", style="margin-top: 25px"
),
)
], "Send a message"
],
"Send a message",
).to_code()
@ -163,6 +167,12 @@ def public_key():
try:
ret = open("/config/pub.key").read()
pgp = gnupg.GPG()
pgp.import_keys(open("/config/pub.key").read())
key_id = (
str(pgp.list_keys()[0]["uids"][0]).replace("<", "[ ").replace(">", " ]")
)
ua = request.user_agent.string.lower()
if "chrome" in ua or "safari" in ua or "firefox" in ua:
# If request is from common browser return stylized html
@ -173,7 +183,7 @@ def public_key():
[
Bold("To Import: "),
Span(
f'curl -sL "{request.base_url.replace("http", "https")}"|gpg --import',
f'curl -sL "{request.base_url}"|gpg --import',
global_attr=GlobalAttributes(
style="display: block;font-family: monospace,monospace;margin-top: 10px; font-size: 20px;overflow-wrap: break-word;"
),
@ -185,13 +195,22 @@ def public_key():
css_class="container", style="margin-top: 25px"
),
),
Heading(
4,
key_id,
global_attr=GlobalAttributes(
css_class="container card",
style="padding-top: 10px; padding-bottom: 10px; background: black; margin-bottom: 15px;",
),
),
Div(
Paragraph(ret.replace("\n", "<br>")),
global_attr=GlobalAttributes(
css_class="container card bg-primary"
),
),
], "Public Key"
],
"Public Key",
).to_code()
# Return raw key
@ -274,5 +293,6 @@ def build_information_block():
@main_pages.route("/", methods=["GET"])
def index():
return buildSite(
[build_information_block(), build_contact_block(), build_donation_block()], "About Me"
[build_information_block(), build_contact_block(), build_donation_block()],
"About Me",
).to_code()