going-flying.com gemini git repository
41dde295a49210ac67e596d8f8d1c58d1417617f - Matthew Ernisse - 1614709865
more work
diff --git a/cgi-bin/clientcert.py b/cgi-bin/clientcert.py index 3654880..0ed7300 100755 --- a/cgi-bin/clientcert.py +++ b/cgi-bin/clientcert.py @@ -9,15 +9,8 @@ cgi = GeminiCGI() @cgi.route('') @cgi.certificate_required def default(): - - - if not os.environ.get('TLS_CLIENT_HASH'): - print('60 Client Certificate Requested\r\n') - sys.exit() - - print('20 text/gemini\r\n') + cgi.Response.Ok('text/gemini') print(''' - This is a CGI test. Below enumerates the environment passed by the server to the script. ``` diff --git a/cgi-bin/gmicgi/__init__.py b/cgi-bin/gmicgi/__init__.py index b2eca50..d54e1b3 100755 --- a/cgi-bin/gmicgi/__init__.py +++ b/cgi-bin/gmicgi/__init__.py @@ -49,7 +49,8 @@ class GeminiCGI(object): 50: ('50', 'PERMANENT FAILURE'), 51: ('51', 'NOT FOUND'), 59: ('59', 'BAD REQUEST'), - 61: ('61', 'Client Certificate Requested') + 60: ('60', 'Client Certificate Requested'), + 61: ('61', 'Client Certificate Rejected'), } def __init__(self, code=10, meta=''): @@ -65,6 +66,10 @@ class GeminiCGI(object): sys.stdout.write(header + '\r\n') @classmethod + def BadCert(cls): + return cls(61) + + @classmethod def BadRequest(cls): return cls(59) @@ -90,7 +95,7 @@ class GeminiCGI(object): @classmethod def NeedCert(cls): - return cls(61) + return cls(60) @classmethod def NotFound(cls): @@ -125,10 +130,11 @@ class GeminiCGI(object): def certificate_required(self, f): ''' Return a 61 if a certificate isn't presented. ''' def decorator(): + print(f) if not self.client_cert: return self.Response.NeedCert() - return f + return f() return decorator @@ -144,6 +150,16 @@ class GeminiCGI(object): return decorator + def needs_input(self, msg): + ''' Decorator to request input from the user.''' + def decorator(f): + if not self.query_string: + return self.Response.Input(msg) + + return f() + + return decorator + def run(self): ''' Run the route engine.''' if self.path_info in self.routes.keys():