💡 add comments + all urls https
This commit is contained in:
parent
e9b84ce522
commit
8249ac0355
2 changed files with 18 additions and 4 deletions
|
@ -12,6 +12,7 @@ def filesend(path):
|
|||
return send_from_directory(dirpath, filename)
|
||||
|
||||
|
||||
# Profile Picture Asset
|
||||
@asset_pages.route("/me", methods=["GET"])
|
||||
def me_picture():
|
||||
return filesend("/config/me.avif")
|
||||
|
|
21
src/index.py
21
src/index.py
|
@ -8,6 +8,7 @@ import gnupg
|
|||
|
||||
main_pages = Blueprint("main", __name__)
|
||||
|
||||
# Bootstrap CSS
|
||||
BOOTSTRAP = [
|
||||
Reference(
|
||||
"https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css",
|
||||
|
@ -22,13 +23,14 @@ BOOTSTRAP = [
|
|||
),
|
||||
]
|
||||
|
||||
|
||||
# Encrypt msg with GPG
|
||||
def encrypt(msg):
|
||||
pgp = gnupg.GPG()
|
||||
pgp.import_keys(open("/config/pub.key").read())
|
||||
return str(pgp.encrypt(msg, pgp.list_keys()[0]["fingerprint"]))
|
||||
|
||||
|
||||
# Save msg in `/data/messages`
|
||||
def save_message(msg, name=""):
|
||||
os.makedirs("/data/messages", exist_ok=True)
|
||||
dt = datetime.datetime.now().strftime("%Y-%m-%d.%H-%M")
|
||||
|
@ -36,16 +38,19 @@ def save_message(msg, name=""):
|
|||
f.write(msg)
|
||||
|
||||
|
||||
# Message Sending Page
|
||||
@main_pages.route("/message", methods=["GET", "POST"])
|
||||
def send_message():
|
||||
if request.method == "POST":
|
||||
# If POST handle message
|
||||
msg = request.form["message"]
|
||||
name = request.form["msg_name"]
|
||||
if msg is not None:
|
||||
cipher = encrypt(msg)
|
||||
save_message(cipher, name)
|
||||
return redirect(request.url_root)
|
||||
return redirect(request.url_root.replace("http", "https"))
|
||||
else:
|
||||
# Return Message Form
|
||||
return buildSite(
|
||||
[
|
||||
Div(
|
||||
|
@ -53,7 +58,7 @@ def send_message():
|
|||
Heading(1, "Message"),
|
||||
LineBreak(),
|
||||
Form(
|
||||
destination=request.url,
|
||||
destination=request.url.replace("http", "https"),
|
||||
inner=[
|
||||
Input(
|
||||
"",
|
||||
|
@ -92,6 +97,7 @@ def send_message():
|
|||
).to_code()
|
||||
|
||||
|
||||
# Wrapper for Base HTML
|
||||
def buildSite(content):
|
||||
return Document(
|
||||
head=Head(
|
||||
|
@ -112,6 +118,7 @@ def buildSite(content):
|
|||
)
|
||||
|
||||
|
||||
# Public Key Page
|
||||
@main_pages.route("/public_key", methods=["GET"])
|
||||
def public_key():
|
||||
try:
|
||||
|
@ -119,6 +126,7 @@ def public_key():
|
|||
|
||||
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
|
||||
return buildSite(
|
||||
[
|
||||
Div(
|
||||
|
@ -126,7 +134,7 @@ def public_key():
|
|||
[
|
||||
Bold("To Import: "),
|
||||
Span(
|
||||
f'curl -sL "{request.base_url}"|gpg --import',
|
||||
f'curl -sL "{request.base_url.replace("http", "https")}"|gpg --import',
|
||||
global_attr=GlobalAttributes(
|
||||
style="display: block;font-family: monospace,monospace;margin-top: 10px; font-size: 20px;overflow-wrap: break-word;"
|
||||
),
|
||||
|
@ -147,12 +155,15 @@ def public_key():
|
|||
]
|
||||
).to_code()
|
||||
|
||||
# Return raw key
|
||||
resp = Response(response=ret, status=200, mimetype="application/pgp-keys")
|
||||
return resp
|
||||
except:
|
||||
# If key does not exist return error
|
||||
return Response(response="", status=502)
|
||||
|
||||
|
||||
# Contact
|
||||
def build_contact_block():
|
||||
return Div(
|
||||
[
|
||||
|
@ -174,6 +185,7 @@ def build_contact_block():
|
|||
)
|
||||
|
||||
|
||||
# Donations
|
||||
def build_donation_block():
|
||||
return Div(
|
||||
[
|
||||
|
@ -197,6 +209,7 @@ def build_donation_block():
|
|||
)
|
||||
|
||||
|
||||
# Basic Information
|
||||
def build_information_block():
|
||||
return Div(
|
||||
[
|
||||
|
|
Loading…
Add table
Reference in a new issue