62 lines
1.8 KiB
Plaintext
Executable File
62 lines
1.8 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()
|
|
cert_name = os.environ.get('REMOTE_USER')
|
|
|
|
from auth import auth
|
|
auth = auth('data/data.db')
|
|
auth.pass_key(hash, cert_name)
|
|
|
|
query = os.environ.get('QUERY_STRING')
|
|
|
|
if (auth.username):
|
|
# match
|
|
if (not query):
|
|
# empty
|
|
from datetime import datetime
|
|
|
|
token = auth.request_link()
|
|
if (not token):
|
|
print('40 Unknown error\r\n')
|
|
exit()
|
|
|
|
print('20 text/gemini\r\n')
|
|
print('Here\'s your token:', token)
|
|
print('Open this page on new device and enter this code.')
|
|
print('This token will expire in', int(auth.LINK_EXPIRE/60), 'minutes')
|
|
print('=> ?cancel cancel')
|
|
elif (query == 'cancel'):
|
|
# cancel
|
|
auth.request_link(cancel=True)
|
|
print('30 index.gmi\r\n')
|
|
elif (query == auth.user_info('link_token')):
|
|
print('20 text/gemini\r\n')
|
|
print('Tip: open this link on new device in order to link new key to your account')
|
|
else:
|
|
print('59 What are you trying to do?\r\n')
|
|
else:
|
|
# mismatch
|
|
if (not query):
|
|
# empty
|
|
print('10 Enter your token\r\n')
|
|
else:
|
|
# token
|
|
res = auth.link(query)
|
|
if (res == auth.SUCCESS):
|
|
print('20 text/gemini\r\n')
|
|
print('Successfully linked to {}!'.format(auth.username))
|
|
print('=> index.gmi back to home')
|
|
elif (res == auth.BAD_TOKEN):
|
|
print('20 text/gemini\r\n')
|
|
print('It seems have you entered invalid or expired token. Try to generate a new one.')
|
|
else:
|
|
print('40 Unknown error\r\n') |