Skip to content

Instantly share code, notes, and snippets.

@dece
Created June 28, 2021 15:37
Show Gist options
  • Save dece/b1b72fbb81a74505a02b97f0ea51b941 to your computer and use it in GitHub Desktop.
Save dece/b1b72fbb81a74505a02b97f0ea51b941 to your computer and use it in GitHub Desktop.
Gemini CGI helper compatible with gmnisrv
#!/bin/false
from os import environ
def getenv(name):
return environ.get(name, "")
version = getenv("GATEWAY_INTERFACE")
protocol = getenv("SERVER_PROTOCOL")
software = getenv("SERVER_SOFTWARE")
url = getenv("GEMINI_URL")
script = getenv("SCRIPT_NAME")
path = getenv("PATH_INFO")
query = getenv("QUERY_STRING")
host = getenv("SERVER_NAME")
port = getenv("SERVER_PORT")
remote = getenv("REMOTE_HOST")
tls_cipher = getenv("TLS_CIPHER")
tls_version = getenv("TLS_VERSION")
auth_type = getenv("AUTH_TYPE")
cert_hash = getenv("TLS_CLIENT_HASH")
cert_sn = getenv("TLS_CLIENT_SERIAL_NUMBER")
cert_name = getenv("REMOTE_USER")
cgi_vars = [
"version", "protocol", "software", "url", "script", "path", "query", "host",
"port", "remote", "tls_cipher", "tls_version", "auth_type", "cert_hash",
"cert_sn", "cert_name"
]
def header(code, meta):
print(f"{code} {meta}", end="\r\n")
def exit_with_header(code, meta):
header(code, meta)
exit()
def require_input(meta):
exit_with_header(10, meta)
def temp_error(meta):
exit_with_header(42, meta)
def not_found():
exit_with_header(51, "")
def debug():
header(20, "text/plain")
print_env()
exit()
def print_env():
globz = globals()
for key in cgi_vars:
print(f"{key} = {repr(globz[key])}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment