init with smolcgi and demo script
This commit is contained in:
commit
3096c1435a
4
helloworld
Executable file
4
helloworld
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import smolcgi
|
||||||
|
smolcgi.header(20, "text/plain")
|
||||||
|
print("Hello world!")
|
60
smolcgi.py
Normal file
60
smolcgi.py
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
#!/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 redirect_temp(url):
|
||||||
|
exit_with_header(30, url)
|
||||||
|
|
||||||
|
def redirect_perm(url):
|
||||||
|
exit_with_header(31, url)
|
||||||
|
|
||||||
|
def temp_error(meta):
|
||||||
|
exit_with_header(42, meta)
|
||||||
|
|
||||||
|
def not_found():
|
||||||
|
exit_with_header(51, "File not found.")
|
||||||
|
|
||||||
|
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])}")
|
Reference in a new issue