43 lines
1.1 KiB
Plaintext
Executable File
43 lines
1.1 KiB
Plaintext
Executable File
#!/usr/bin/python3
|
|
import os
|
|
import sys
|
|
|
|
os.chdir('..')
|
|
sys.path.append('lib')
|
|
|
|
hash = os.environ.get('TLS_CLIENT_HASH')
|
|
if (not hash):
|
|
# no CC
|
|
print('60 Authentication is required\r\n')
|
|
exit()
|
|
certName = os.environ.get('REMOTE_USER')
|
|
|
|
from auth import auth
|
|
auth = auth('data/data.db')
|
|
auth.passKey(hash, certName)
|
|
|
|
if (auth.username):
|
|
# match
|
|
print('20 text/gemini\r\n')
|
|
print('Already logged in as', auth.username)
|
|
print('=> index.gmi back to home')
|
|
else:
|
|
# mismatch
|
|
if (not auth.ENABLE_REGISTRATION):
|
|
print('50 Registration is disabled\r\n')
|
|
exit()
|
|
|
|
username = os.environ.get('QUERY_STRING')
|
|
if (not username):
|
|
# empty
|
|
print('10 Choose your name\r\n')
|
|
else:
|
|
# string
|
|
res = auth.registerUser(username)
|
|
if (res == auth.SUCCESS):
|
|
print('31 index.gmi\r\n')
|
|
elif (res == auth.NAME_IN_USE):
|
|
print('10 Chose your name (name already in use)\r\n')
|
|
# Skipped ACTION_DISABLED because we already checked that
|
|
else:
|
|
print('40 Unknown error\r\n') |