From ecb01dfc756b67725a7a23643c6d1b0dcdd146a7 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Wed, 31 Aug 2022 03:18:44 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20added=20key=20id=20field?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/index.py b/src/index.py index 3b9beb2..bdb617d 100644 --- a/src/index.py +++ b/src/index.py @@ -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", "
")), 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()