65 lines
1.7 KiB
Plaintext
Executable File
65 lines
1.7 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()
|
|
|
|
print('20 text/gemini\r\n')
|
|
|
|
from auth import auth
|
|
auth = auth('data/data.db')
|
|
auth.passKey(hash)
|
|
|
|
if (not auth.username):
|
|
# mismatch
|
|
print('=> register.gmi register')
|
|
print('=> link.gmi link existing account')
|
|
else:
|
|
# match
|
|
from datetime import datetime
|
|
|
|
print('Hello, {}!'.format(auth.username))
|
|
print('## Your keys')
|
|
|
|
for key in auth.getKeys():
|
|
hash = key['hash']
|
|
lastSeen = datetime.fromtimestamp(key['last_seen'])
|
|
current = hash == auth.hash
|
|
|
|
name = key['name']
|
|
if (name):
|
|
name = '"' + name + '"'
|
|
else:
|
|
name = '[no name]'
|
|
|
|
txt = '* ' + name
|
|
if (current):
|
|
txt += ' (currently used)'
|
|
print(txt)
|
|
|
|
print('hash:', hash)
|
|
print('last seen:', lastSeen)
|
|
|
|
linkToken = auth.userInfo('link_token')
|
|
if(linkToken):
|
|
from datetime import datetime
|
|
linkTokenExpire = datetime.fromtimestamp(auth.userInfo('link_token_time') + auth.LINK_EXPIRE)
|
|
delta = linkTokenExpire - datetime.now()
|
|
seconds = delta.seconds
|
|
minutes = seconds // 60
|
|
seconds = seconds % 60
|
|
# TODO: calibration - it displays 00:00 for one second
|
|
def zero(n):
|
|
return str(n) if n>10 else '0'+str(n)
|
|
print('### Link new key')
|
|
print('Token {} will expire in {}:{}'.format(linkToken, zero(minutes), zero(seconds)))
|
|
print('=> link.gmi?cancel cancel')
|
|
else:
|
|
print('=> link.gmi Link new key') |