Compare commits
2 commits
989df5a849
...
7ba71b5eef
Author | SHA1 | Date | |
---|---|---|---|
dece | 7ba71b5eef | ||
dece | fc97ba4ef1 |
|
@ -7,6 +7,8 @@ import subprocess
|
||||||
|
|
||||||
import smolcgi
|
import smolcgi
|
||||||
|
|
||||||
|
smolcgi.require_cool_client("This script is not publicly available, sorry!")
|
||||||
|
|
||||||
if not smolcgi.query_string_dec:
|
if not smolcgi.query_string_dec:
|
||||||
smolcgi.require_input("Provide an email address to check.")
|
smolcgi.require_input("Provide an email address to check.")
|
||||||
|
|
||||||
|
|
60
smolcgi.py
60
smolcgi.py
|
@ -68,15 +68,23 @@ def header(code, meta):
|
||||||
print(f"{code} {meta}", end="\r\n")
|
print(f"{code} {meta}", end="\r\n")
|
||||||
|
|
||||||
|
|
||||||
|
def success(mime):
|
||||||
|
header(20, mime)
|
||||||
|
|
||||||
|
|
||||||
def exit_with_header(code, meta):
|
def exit_with_header(code, meta):
|
||||||
header(code, meta)
|
header(code, meta)
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
|
||||||
def require_input(reason):
|
def require_input(reason=""):
|
||||||
exit_with_header(10, reason)
|
exit_with_header(10, reason)
|
||||||
|
|
||||||
|
|
||||||
|
def require_sensitive_input(reason=""):
|
||||||
|
exit_with_header(11, reason)
|
||||||
|
|
||||||
|
|
||||||
def redirect_temp(url):
|
def redirect_temp(url):
|
||||||
exit_with_header(30, url)
|
exit_with_header(30, url)
|
||||||
|
|
||||||
|
@ -85,15 +93,43 @@ def redirect_perm(url):
|
||||||
exit_with_header(31, url)
|
exit_with_header(31, url)
|
||||||
|
|
||||||
|
|
||||||
def temp_error(reason):
|
def temp_error(reason=""):
|
||||||
|
exit_with_header(40, reason)
|
||||||
|
|
||||||
|
|
||||||
|
def server_unavailable(reason=""):
|
||||||
|
exit_with_header(41, reason)
|
||||||
|
|
||||||
|
|
||||||
|
def cgi_error(reason=""):
|
||||||
exit_with_header(42, reason)
|
exit_with_header(42, reason)
|
||||||
|
|
||||||
|
|
||||||
def not_found(reason="Not found"):
|
def proxy_error(reason=""):
|
||||||
|
exit_with_header(43, reason)
|
||||||
|
|
||||||
|
|
||||||
|
def slow_down(num_seconds):
|
||||||
|
exit_with_header(44, num_seconds)
|
||||||
|
|
||||||
|
|
||||||
|
def perm_error(reason=""):
|
||||||
|
exit_with_header(50, reason)
|
||||||
|
|
||||||
|
|
||||||
|
def not_found(reason=""):
|
||||||
exit_with_header(51, reason)
|
exit_with_header(51, reason)
|
||||||
|
|
||||||
|
|
||||||
def bad_request(reason="Bad request"):
|
def gone(reason=""):
|
||||||
|
exit_with_header(52, reason)
|
||||||
|
|
||||||
|
|
||||||
|
def proxy_request_refused(reason=""):
|
||||||
|
exit_with_header(53, reason)
|
||||||
|
|
||||||
|
|
||||||
|
def bad_request(reason=""):
|
||||||
exit_with_header(59, reason)
|
exit_with_header(59, reason)
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,6 +138,22 @@ def require_client_cert():
|
||||||
exit_with_header(60, "You need a certificate to use this app")
|
exit_with_header(60, "You need a certificate to use this app")
|
||||||
|
|
||||||
|
|
||||||
|
def cert_not_authorised(reason=""):
|
||||||
|
exit_with_header(61, reason)
|
||||||
|
|
||||||
|
|
||||||
|
def require_cool_client(reason=""):
|
||||||
|
require_client_cert()
|
||||||
|
with open(get_storage_path() / "cool_hashes", "rt") as f:
|
||||||
|
cool_hashes = f.read().rstrip().split("\n")
|
||||||
|
if tls_client_hash not in cool_hashes:
|
||||||
|
cert_not_authorised(reason)
|
||||||
|
|
||||||
|
|
||||||
|
def cert_not_valid(reason=""):
|
||||||
|
exit_with_header(62, reason)
|
||||||
|
|
||||||
|
|
||||||
def print_env():
|
def print_env():
|
||||||
globz = globals()
|
globz = globals()
|
||||||
for key in cgi_vars:
|
for key in cgi_vars:
|
||||||
|
|
Reference in a new issue