mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-12-22 19:21:08 +00:00
Merge branch 'add_blocklist' into 'master'
Add blocklist See merge request pleroma/relay!3
This commit is contained in:
commit
dfee3d3658
|
@ -14,3 +14,7 @@ ap:
|
|||
# this is used for generating activitypub messages, as well as instructions for
|
||||
# linking AP identities. it should be an SSL-enabled domain reachable by https.
|
||||
host: 'relay.example.com'
|
||||
blocked_instances:
|
||||
- 'bad-instance.example.com'
|
||||
- 'another-bad-instance.example.com'
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ import aiohttp.web
|
|||
import asyncio
|
||||
import logging
|
||||
import uuid
|
||||
import re
|
||||
import urllib.parse
|
||||
import simplejson as json
|
||||
import re
|
||||
import cgi
|
||||
from Crypto.PublicKey import RSA
|
||||
from .database import DATABASE
|
||||
|
@ -32,7 +32,7 @@ from . import app, CONFIG
|
|||
from .remote_actor import fetch_actor
|
||||
|
||||
|
||||
AP_CONFIG = CONFIG.get('ap', {'host': 'localhost'})
|
||||
AP_CONFIG = CONFIG.get('ap', {'host': 'localhost','blocked_instances':[]})
|
||||
|
||||
|
||||
async def actor(request):
|
||||
|
@ -186,6 +186,9 @@ async def handle_follow(actor, data, request):
|
|||
following = DATABASE.get('relay-list', [])
|
||||
inbox = get_actor_inbox(actor)
|
||||
|
||||
if urllib.parse.urlsplit(inbox).hostname in AP_CONFIG['blocked_instances']:
|
||||
return
|
||||
|
||||
if inbox not in following:
|
||||
following += [inbox]
|
||||
DATABASE['relay-list'] = following
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import asyncio
|
||||
import logging
|
||||
import urllib.parse
|
||||
import simplejson as json
|
||||
|
||||
|
||||
|
@ -13,6 +14,11 @@ except:
|
|||
logging.info('No database was found, making a new one.')
|
||||
DATABASE = {}
|
||||
|
||||
following = DATABASE.get('relay-list', [])
|
||||
for inbox in following:
|
||||
if urllib.parse.urlsplit(inbox).hostname in CONFIG['ap']['blocked_instances']:
|
||||
following.remove(inbox)
|
||||
DATABASE['relay-list'] = following
|
||||
|
||||
async def database_save():
|
||||
while True:
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import aiohttp.web
|
||||
import re
|
||||
import urllib.parse
|
||||
from . import app, CONFIG
|
||||
from .database import DATABASE
|
||||
|
||||
host = CONFIG['ap']['host']
|
||||
note = CONFIG['note']
|
||||
targets = '<br>'.join([re.search('https://(.*)/inbox',target).group(1) for target in DATABASE.get('relay-list', [])])
|
||||
|
||||
inboxes = DATABASE.get('relay-list', [])
|
||||
targets = '<br>'.join([urllib.parse.urlsplit(target).hostname for target in inboxes])
|
||||
|
||||
async def default(request):
|
||||
return aiohttp.web.Response(
|
||||
|
@ -26,9 +28,9 @@ async def default(request):
|
|||
<p>For Mastodon instances, you may subscribe to this relay with the address: <a href="https://{host}/inbox">https://{host}/inbox</a></p>
|
||||
<p>For Pleroma and other instances, you may subscribe to this relay with the address: <a href="https://{host}/actor">https://{host}/actor</a></p>
|
||||
<p>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>
|
||||
<br><p>List of registered instances:<br>{targets}</p>
|
||||
<br><p>List of {count} registered instances:<br>{targets}</p>
|
||||
</body></html>
|
||||
|
||||
""".format(host=host, note=note,targets=targets))
|
||||
""".format(host=host, note=note,targets=targets,count=len(inboxes)))
|
||||
|
||||
app.router.add_get('/', default)
|
||||
|
|
Loading…
Reference in a new issue