gemspace/cgi-example/helpers.py

36 lines
969 B
Python
Raw Normal View History

2022-02-20 20:50:55 +00:00
import os
2022-02-21 00:52:45 +00:00
import string
import random
2022-02-20 20:50:55 +00:00
2022-02-21 00:17:45 +00:00
def get_client_cert(ok_if_found = True):
2022-02-20 20:50:55 +00:00
TLS_CLIENT_HASH = os.getenv('TLS_CLIENT_HASH')
2022-02-21 00:17:45 +00:00
if (TLS_CLIENT_HASH is None):
2022-02-20 20:50:55 +00:00
show_header_cert_required()
2022-02-21 00:17:45 +00:00
elif ok_if_found:
2022-02-20 20:50:55 +00:00
show_header_ok()
return TLS_CLIENT_HASH
2022-02-21 01:08:40 +00:00
def get_query_string(msg, ok_if_found = True):
2022-02-21 00:17:45 +00:00
QUERY_STRING = os.getenv('QUERY_STRING')
if(QUERY_STRING is None):
show_query_string_required(msg)
2022-02-21 01:08:40 +00:00
elif ok_if_found:
2022-02-21 00:17:45 +00:00
show_header_ok()
return QUERY_STRING
2022-02-20 20:50:55 +00:00
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()
2022-02-21 00:17:45 +00:00
def show_query_string_required(msg):
print("10 " + msg, end = "\r\n")
quit()
2022-02-21 00:52:45 +00:00
def id_generator(size=12, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
2022-02-20 20:50:55 +00:00
#vim:fenc=utf-8:ts=4:sw=4:sta:noet:sts=4:fdm=marker:ai