2020-01-03 15:00:44 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""Utilize crypto domains DNS and either redirect, or display information."""
|
2020-01-03 16:17:43 -05:00
|
|
|
from bottle import Bottle, run, response, request
|
2020-01-03 15:00:44 -05:00
|
|
|
import json
|
|
|
|
import requests
|
|
|
|
|
|
|
|
VERSION = '0.0.1'
|
|
|
|
|
2020-01-03 16:17:43 -05:00
|
|
|
app = Bottle()
|
2020-01-03 15:00:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
@app.route("/")
|
|
|
|
def root():
|
2020-01-03 16:17:43 -05:00
|
|
|
host = request.get_header('host')
|
|
|
|
return f'specify domain in URL like {host}/domain.crypto'
|
2020-01-03 15:00:44 -05:00
|
|
|
|
|
|
|
|
2020-01-03 16:17:43 -05:00
|
|
|
@app.route("/<domain>")
|
2020-01-03 15:00:44 -05:00
|
|
|
def showdomain(domain):
|
2020-01-03 16:17:43 -05:00
|
|
|
apiurl =f'https://unstoppabledomains.com/api/v1/{domain}'
|
|
|
|
redirect = requests.get(apiurl)
|
|
|
|
try:
|
|
|
|
if redirect.status_code == 200:
|
|
|
|
body = json.loads(redirect.content)
|
|
|
|
print(body)
|
|
|
|
redirect_url = body['ipfs']['redirect_domain']
|
|
|
|
# TODO: Add handler for the ipfs vs redirect
|
|
|
|
# if body['ipfs']['html']:
|
|
|
|
# print('We have html')
|
|
|
|
response.status = 302
|
|
|
|
response.set_header('Location',redirect_url)
|
|
|
|
else:
|
|
|
|
return f'Error making call to {apiurl} for {domain}'
|
|
|
|
except KeyError:
|
|
|
|
return f'Did not find a redirect for {domain}'
|
|
|
|
|
2020-01-03 15:00:44 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-01-03 16:17:43 -05:00
|
|
|
run(app, host='localhost', port='5000', reloader=True)
|