feat: Add domain verification
All checks were successful
Build Docker / Build Image (push) Successful in 22s

This commit is contained in:
Nathan Woodburn 2023-11-09 22:15:26 +11:00
parent db2b41cee7
commit a805f8c451
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

11
main.py
View File

@ -3,6 +3,7 @@ import os
import dotenv
import requests
import hip02
import re
app = Flask(__name__)
@ -16,6 +17,10 @@ if os.getenv('HSD_IP'):
if os.getenv('HSD_PORT'):
HSD_PORT = os.getenv('HSD_PORT')
def valid_domain(domain):
regex = "^((xn--)?[a-z0-9]+\.)*((xn--)?[a-z0-9]+)$"
return re.match(regex, domain)
@app.route('/')
def index():
@ -34,6 +39,9 @@ def favicon():
@app.route('/<path>.json')
def jsonlookup(path):
if not valid_domain(path):
return make_response({"success":False,"error":"Invalid domain"}, 200, {'Content-Type': 'application/json'})
TLSA = hip02.TLSA_check(HSD_IP,HSD_PORT,path)
if not TLSA:
return make_response({"success":False,"error":TLSA}, 200, {'Content-Type': 'application/json'})
@ -51,6 +59,9 @@ def jsonlookup(path):
@app.route('/<path>')
def lookup(path):
if not valid_domain(path):
return make_response("Invalid domain", 200, {'Content-Type': 'text/plain'})
TLSA = hip02.TLSA_check(HSD_IP,HSD_PORT,path)
if not TLSA:
return make_response(TLSA, 200, {'Content-Type': 'text/plain'})