💾 Archived View for pantasya.mooo.com › cgi-bin › helpers.py captured on 2023-09-08 at 16:04:55.

View Raw

More Information

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

import os
import string
import random

def get_client_cert(ok_if_found = True):
    TLS_CLIENT_HASH = os.getenv('TLS_CLIENT_HASH')
    if (TLS_CLIENT_HASH is None):
        show_header_cert_required()
    elif ok_if_found:
        show_header_ok()
    return TLS_CLIENT_HASH

def get_query_string(msg, ok_if_found = True):
    QUERY_STRING = os.getenv('QUERY_STRING')
    if(not QUERY_STRING):
        show_query_string_required(msg)
    elif ok_if_found:
        show_header_ok()
    return QUERY_STRING

def show_header_ok():
    print("20 text/gemini; charset=utf-8", end = "\r\n")

def show_header_cert_required():
    print("60 text/gemini; charset=utf-8", end = "\r\n")
    quit()

def show_query_string_required(msg):
    print("10 " + msg, end = "\r\n")
    quit()

def show_redirect(url):
    print("30 " + url, end = "\r\n")
    quit()


def id_generator(size=12, chars=string.ascii_uppercase + string.digits):
    return ''.join(random.choice(chars) for _ in range(size))

#vim:fenc=utf-8:ts=4:sw=4:sta:noet:sts=4:fdm=marker:ai