💾 Archived View for arcanesciences.com › gemlog › 22-05-22 › lpx.py captured on 2024-08-25 at 00:52:11.

View Raw

More Information

⬅️ Previous capture (2022-06-11)

-=-=-=-=-=-=-

#!/usr/bin/python3

import os
import sys
import urllib.parse
import shelve

if not "TLS_CLIENT_AUTHORISED" in os.environ:
    print("60 This system requires TLS client authentication.")
    sys.exit()

auth = os.environ["TLS_CLIENT_AUTHORISED"]
query = os.environ["QUERY_STRING"]

if auth == '0':
    print("61 This certificate isn't authorized.")
    sys.exit()

if not query:
    print("10 Enter the track name: ")
    sys.exit()

text = urllib.parse.unquote(query)

try:
    with open("/var/cgi-data/template.gmi") as f:
        template = f.read().replace("PLAYED_TEMPLATE", text)
        with open("/var/gemini/index.gmi", "w") as o:
            o.write(template)

except Exception as e:
    print("42 Unexpected Error: ", e)
else:
    print("20 text/gemini")
    print("# Submitted")