This repository has been archived on 2024-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
gemini-auth/public/cgi/account/rename-request.gmi

68 lines
1.9 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)
if (not auth.username):
# mismatch
print('61 Unknown key\r\n')
else:
# match
query = os.environ.get('QUERY_STRING')
if (not query):
# empty
from datetime import datetime
print('20 text/gemini\r\n')
print('Which key would you like to rename?')
my_keys = auth.get_keys(['last_seen'])
for hash in my_keys:
key = my_keys['hash']
last_seen = datetime.fromtimestamp(key['last_seen'])
current = hash == auth.hash
name = key['name']
name = '"' + name + '"' if name else '[no name]'
label = '=> rename-request.gmi?{} {}'.format(auth.gen_anticsrf() + hash, name)
if (current):
label += ' (currently used)'
print(label)
print('hash:', hash)
print('last seen:', last_seen)
else:
anticsrf = query[:4]
hash = query[4:]
if (not anticsrf or not hash):
print('59 What are you trying to do?\r\n')
exit()
# anticsrf+hash
if (auth.check_anticsrf(anticsrf)):
res = auth.request_rename(hash)
if (res == auth.STATUS.SUCCESS):
print('30 rename.gmi\r\n')
elif (res == auth.STATUS.NOT_FOUND):
print('20 text/gemini\r\n')
print('Failed to rename non-existing key, or key which does not belong to you.')
print('=> index.gmi back to home')
else:
print('40 Unknown error\r\n')
else:
print('50 Bad Antic SRF (security)\r\n')