95 lines
6.1 KiB
Python
95 lines
6.1 KiB
Python
import aiohttp.web
|
|
import urllib.parse
|
|
import time
|
|
import datetime
|
|
from . import app, CONFIG
|
|
from .database import DATABASE
|
|
|
|
host = CONFIG['ap']['host']
|
|
note = CONFIG['note']
|
|
|
|
START_TIME=time.time()
|
|
|
|
async def default(request):
|
|
from .actor import INBOUND_STATS
|
|
inboxes = DATABASE.get('relay-list', [])
|
|
target = []
|
|
for t in inboxes:
|
|
if urllib.parse.urlsplit(t).hostname not in DATABASE.get('backoff-instances',{}):
|
|
target.append('<a href=https://%s>%s</a>' % (urllib.parse.urlsplit(t).hostname,urllib.parse.urlsplit(t).hostname))
|
|
targets = '</li><li>'.join(target)
|
|
err=[]
|
|
warn=[]
|
|
not_subd = '</li><li>'.join(['<a href=https://%s>%s</a>' % (s,s) for s in DATABASE.get('not-subscribed',[])])
|
|
for instance,val in DATABASE.get('backoff-instances',{}).items():
|
|
if time.time() - val['ts'] > 86400:
|
|
err.append('<a href=https://%s>%s</a>' % (instance,instance))
|
|
else:
|
|
warn.append("<a href=https://%s>%s</a>' <span class='greyed'>(%s left before stopping attempts)</span>" % (instance,instance,str(datetime.timedelta(seconds=86400-(time.time()-val['ts']))).split(".")[0])) errs='</li><li>'.join(err)
|
|
warns='</li><li>'.join(warn)
|
|
banned='</li><li>'.join(CONFIG['ap']['blocked_instances'])
|
|
return aiohttp.web.Response(
|
|
status=200,
|
|
content_type="text/html",
|
|
charset="utf-8",
|
|
text="""
|
|
<html><head>
|
|
<title>ActivityPub Relay at {host}</title>
|
|
<style>
|
|
a {{ color: #4ea2df; text-decoration: none; }}
|
|
a:hover {{ text-decoration: underline; }}
|
|
p {{ color: #FFFFFF; font-family: monospace, arial; font-size: 100%; }}
|
|
h4 {{ color: #FFFFFF; font-family: monospace, arial; font-size: 100%; }} html, body {{
|
|
margin: 0;
|
|
height: 100%;
|
|
}}
|
|
body {{ background-color: #282c37; }}
|
|
#content {{
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100%
|
|
}}
|
|
.greyed {{ color: #606984; }}
|
|
|
|
main {{
|
|
flex: 1;
|
|
overflow: auto;
|
|
}}
|
|
.footer {{
|
|
flex-shrink: 0;
|
|
font-size: 80%;
|
|
background-color: #20232C;
|
|
}}
|
|
.header {{
|
|
text-align: center;
|
|
background-color: #20232C;
|
|
}}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id='content'>
|
|
<div class='header'>
|
|
<p>{note}</p>
|
|
<p><i>For Mastodon instances, you may subscribe to this relay with the address: <a href="https://{host}/inbox">https://{host}/inbox</a></i></p>
|
|
<p><i>For Pleroma and other instances, you may subscribe to this relay with the address: <a href="https://{host}/actor">https://{host}/actor</a></i></p>
|
|
<p class="greyed" style='font-size: 80%;'>[ <a href='#registered'>Active ({count})</a> | <a href='#nonvalid'>Invalid ({countf})</a> | <a href='#failing'>In error ({countw})</a> | <a href='#notsubd'>Non subscribed ({countn})</a> | <a href=
|
|
'#unreachable'>Unreachable ({counte})</a> | <a href='#banned'>Banned ({countb})</a> ]</p>
|
|
</div>
|
|
<main>
|
|
<h4><a name='registered'></a>List of {count} registered and active instances:</h4><ul><li>{targets}</li></ul>
|
|
<h4><a name='failing'></a>List of {countw} instances with errors (last failure to deliver a post is less than a day, not all posts are sent, only periodic retries):</h4><ul><li>{warnings}</li></ul>
|
|
<h4><a name='notsubd'></a>List of {countn} instances trying to send posts and not following the relay (those posts are ignored and nothing is sent to those instances):</h4><span class='greyed'><ul><li>{nosub}</li></ul></span>
|
|
<h4><a name='unreachable'></a>List of {counte} unreachable instances (not being delivered anything anymore till we receive a post from them again):</h4><ul><li>{errors}</li></ul>
|
|
<h4 class='greyed'><a name='banned'></a>There are currently {countb} instances banned in the configuration file of this relay.</h4>
|
|
</main>
|
|
<div class='footer'>
|
|
<p class="greyed" style='text-align: center;'><i>We processed {statuscounts} statuses and rejected {rejectcount} since last restart, {starttime} ago.</i></p>
|
|
<p class='greyed' style='text-align: center'>To host your own relay, you may download the code at this address: <a href="https://git.pleroma.social/pleroma/relay">https://git.pleroma.social/pleroma/relay</a></p>
|
|
</div>
|
|
</div>
|
|
</body></html>
|
|
|
|
""".format(host=host, note=note,targets=targets,count=len(target),warnings=warns,countw=len(warn),errors=errs,counte=len(err),nosub=not_subd,countn=len(DATABASE.get('not-subscribed',[])),starttime=str(datetime.timede
|
|
lta(seconds=(time.time()-START_TIME))).split(".")[0],statuscounts=INBOUND_STATS['processed']+INBOUND_STATS['rejected'],rejectcount=INBOUND_STATS['rejected'],countb=len(CONFIG['ap']['blocked_instances']),banned=banned))
|
|
|
|
app.router.add_get('/', default)
|