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/unlink.gmi

55 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()
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
print('30 index.gmi\r\n')
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.unlink(hash)
if (res == auth.SUCCESS):
print('30 index.gmi\r\n')
elif (res == auth.KEY_IN_USE):
print('20 text/gemini\r\n')
print('You have requested to delete the key, which is being used by you RIGHT NOW.')
print('This could lead to the loss of your account access. If you want to proceed, authenticate with another key and try again.')
print('=> index.gmi back to home')
elif (res == auth.NOT_FOUND):
print('20 text/gemini\r\n')
print('Failed to delete non-existing key, or key which does not belong to you.')
print('Maybe you\'re trying to delete already deleted key?')
print('=> index.gmi back to home')
else:
print('40 Unknown error\r\n')
else:
print('50 Bad Antic SRF (security)\r\n')