✨ added key id field
This commit is contained in:
parent
f9ce89fb4f
commit
ecb01dfc75
1 changed files with 27 additions and 7 deletions
34
src/index.py
34
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 htmlpy import *
|
||||||
from config import CONFIG
|
from config import CONFIG
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
|
@ -15,6 +15,7 @@ def download_file(url, file):
|
||||||
r = requests.get(url, allow_redirects=True)
|
r = requests.get(url, allow_redirects=True)
|
||||||
open(file, "wb").write(r.content)
|
open(file, "wb").write(r.content)
|
||||||
|
|
||||||
|
|
||||||
# Downloads all bootstrap files to flasks static directory
|
# Downloads all bootstrap files to flasks static directory
|
||||||
def cache_bootstrap():
|
def cache_bootstrap():
|
||||||
download_file(
|
download_file(
|
||||||
|
@ -58,6 +59,7 @@ def save_message(msg, name=""):
|
||||||
f = open(f"/data/messages/{name}-{dt}.asc", "w")
|
f = open(f"/data/messages/{name}-{dt}.asc", "w")
|
||||||
f.write(msg)
|
f.write(msg)
|
||||||
|
|
||||||
|
|
||||||
# Send Notification to all handlers
|
# Send Notification to all handlers
|
||||||
def notify(msg, title=None):
|
def notify(msg, title=None):
|
||||||
try:
|
try:
|
||||||
|
@ -65,6 +67,7 @@ def notify(msg, title=None):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Gotify Notification Handler
|
# Gotify Notification Handler
|
||||||
def gotify_notification(msg, title=None):
|
def gotify_notification(msg, title=None):
|
||||||
token = CONFIG["notify"]["gotify"]["token"]
|
token = CONFIG["notify"]["gotify"]["token"]
|
||||||
|
@ -86,7 +89,7 @@ def send_message():
|
||||||
cipher = encrypt(msg)
|
cipher = encrypt(msg)
|
||||||
save_message(cipher, name)
|
save_message(cipher, name)
|
||||||
notify(f"New Message from {name}")
|
notify(f"New Message from {name}")
|
||||||
return redirect(request.url_root.replace("http", "https"))
|
return redirect(request.url_root)
|
||||||
else:
|
else:
|
||||||
# Return Message Form
|
# Return Message Form
|
||||||
return buildSite(
|
return buildSite(
|
||||||
|
@ -96,7 +99,7 @@ def send_message():
|
||||||
Heading(1, "Message"),
|
Heading(1, "Message"),
|
||||||
LineBreak(),
|
LineBreak(),
|
||||||
Form(
|
Form(
|
||||||
destination=request.url.replace("http", "https"),
|
destination=request.url,
|
||||||
inner=[
|
inner=[
|
||||||
Input(
|
Input(
|
||||||
"",
|
"",
|
||||||
|
@ -131,7 +134,8 @@ def send_message():
|
||||||
css_class="container", style="margin-top: 25px"
|
css_class="container", style="margin-top: 25px"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
], "Send a message"
|
],
|
||||||
|
"Send a message",
|
||||||
).to_code()
|
).to_code()
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,6 +167,12 @@ def public_key():
|
||||||
try:
|
try:
|
||||||
ret = open("/config/pub.key").read()
|
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()
|
ua = request.user_agent.string.lower()
|
||||||
if "chrome" in ua or "safari" in ua or "firefox" in ua:
|
if "chrome" in ua or "safari" in ua or "firefox" in ua:
|
||||||
# If request is from common browser return stylized html
|
# If request is from common browser return stylized html
|
||||||
|
@ -173,7 +183,7 @@ def public_key():
|
||||||
[
|
[
|
||||||
Bold("To Import: "),
|
Bold("To Import: "),
|
||||||
Span(
|
Span(
|
||||||
f'curl -sL "{request.base_url.replace("http", "https")}"|gpg --import',
|
f'curl -sL "{request.base_url}"|gpg --import',
|
||||||
global_attr=GlobalAttributes(
|
global_attr=GlobalAttributes(
|
||||||
style="display: block;font-family: monospace,monospace;margin-top: 10px; font-size: 20px;overflow-wrap: break-word;"
|
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"
|
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(
|
Div(
|
||||||
Paragraph(ret.replace("\n", "<br>")),
|
Paragraph(ret.replace("\n", "<br>")),
|
||||||
global_attr=GlobalAttributes(
|
global_attr=GlobalAttributes(
|
||||||
css_class="container card bg-primary"
|
css_class="container card bg-primary"
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
], "Public Key"
|
],
|
||||||
|
"Public Key",
|
||||||
).to_code()
|
).to_code()
|
||||||
|
|
||||||
# Return raw key
|
# Return raw key
|
||||||
|
@ -274,5 +293,6 @@ def build_information_block():
|
||||||
@main_pages.route("/", methods=["GET"])
|
@main_pages.route("/", methods=["GET"])
|
||||||
def index():
|
def index():
|
||||||
return buildSite(
|
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()
|
).to_code()
|
||||||
|
|
Loading…
Add table
Reference in a new issue