Added favicon, shifted if logic to handle default first
This commit is contained in:
parent
49acbf38dd
commit
a1d67cedb8
2 changed files with 37 additions and 18 deletions
49
chainlink.py
49
chainlink.py
|
@ -1,25 +1,34 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
"""Utilize crypto domains DNS and either redirect, or display information."""
|
"""Utilize crypto domains DNS and either redirect, or display information."""
|
||||||
from bottle import Bottle, run, response, request
|
from bottle import Bottle, run, response, request, static_file
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
import json2html
|
import json2html
|
||||||
|
|
||||||
VERSION = '0.0.1'
|
VERSION = '0.1.0'
|
||||||
|
|
||||||
app = Bottle()
|
app = Bottle()
|
||||||
|
|
||||||
|
|
||||||
def domainLookup(domain):
|
def domainLookup(domain):
|
||||||
|
"""Return a dictionary from JSON results of API call
|
||||||
|
or return False if there is an error
|
||||||
|
"""
|
||||||
|
try:
|
||||||
apibase = 'https://unstoppabledomains.com/api/v1/'
|
apibase = 'https://unstoppabledomains.com/api/v1/'
|
||||||
dnslookup = requests.get(apibase + domain)
|
dnslookup = requests.get(apibase + domain)
|
||||||
domainJSON = json.loads(dnslookup.content)
|
if dnslookup.status_code == 200:
|
||||||
print(domainJSON)
|
domainInfo = json.loads(dnslookup.content)
|
||||||
return domainJSON
|
return domainInfo
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def root():
|
def root():
|
||||||
|
"""Index page, just displays information about URL formatting"""
|
||||||
host = request.get_header('host')
|
host = request.get_header('host')
|
||||||
helptext = f"""
|
helptext = f"""
|
||||||
<p>General format is {host}/<domain>/<action>
|
<p>General format is {host}/<domain>/<action>
|
||||||
|
@ -49,10 +58,22 @@ def root():
|
||||||
@app.route("/<domain>/")
|
@app.route("/<domain>/")
|
||||||
@app.route("/<domain>/<action>")
|
@app.route("/<domain>/<action>")
|
||||||
def redirectDomain(domain, action=None):
|
def redirectDomain(domain, action=None):
|
||||||
|
"""Handle the actual redirect for the domain queried"""
|
||||||
lookupResult = domainLookup(domain)
|
lookupResult = domainLookup(domain)
|
||||||
|
if lookupResult:
|
||||||
redirect_url = lookupResult['ipfs']['redirect_domain']
|
redirect_url = lookupResult['ipfs']['redirect_domain']
|
||||||
html = lookupResult['ipfs']['html']
|
ipfs_hash = lookupResult['ipfs']['html']
|
||||||
if action == 'redir':
|
else:
|
||||||
|
return f"Unable to get info for {domain}"
|
||||||
|
if action is None or action == 'html':
|
||||||
|
response.status = 302
|
||||||
|
if not ipfs_hash.startswith('/ip'):
|
||||||
|
ipfshash = "ipfs/" + ipfs_hash
|
||||||
|
else:
|
||||||
|
ipfshash = ipfs_hash
|
||||||
|
response.set_header('Location',
|
||||||
|
f"https://cloudflare-ipfs.com/{ipfshash}")
|
||||||
|
elif action == 'redir':
|
||||||
try:
|
try:
|
||||||
if not redirect_url.startswith('http'):
|
if not redirect_url.startswith('http'):
|
||||||
redirect_url = "http://" + redirect_url
|
redirect_url = "http://" + redirect_url
|
||||||
|
@ -60,17 +81,15 @@ def redirectDomain(domain, action=None):
|
||||||
response.set_header('Location', redirect_url)
|
response.set_header('Location', redirect_url)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return f'Did not find a redirect for {domain}'
|
return f'Did not find a redirect for {domain}'
|
||||||
elif action is None or action == 'html':
|
|
||||||
response.status = 302
|
|
||||||
if not html.startswith('/ip'):
|
|
||||||
ipfshash = "ipfs/" + html
|
|
||||||
else:
|
|
||||||
ipfshash = html
|
|
||||||
response.set_header('Location',
|
|
||||||
f"https://cloudflare-ipfs.com/{ipfshash}")
|
|
||||||
elif action == 'raw':
|
elif action == 'raw':
|
||||||
return json2html.json2html.convert(json=lookupResult)
|
return json2html.json2html.convert(json=lookupResult)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/favicon.ico")
|
||||||
|
def favicon():
|
||||||
|
"""Display a favicon to make the errors go away :)"""
|
||||||
|
return static_file('favicon.ico', root='images')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
run(app, host='0.0.0.0', port='5000', reloader=True)
|
run(app, host='0.0.0.0', port='5000', reloader=True)
|
||||||
|
|
BIN
images/favicon.ico
Normal file
BIN
images/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
Loading…
Reference in a new issue