From aa79a27840275740b470219c41d6ac53e5a91b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Mah=C3=A9?= Date: Wed, 31 Oct 2018 12:29:30 -0700 Subject: [PATCH 1/7] very simple blocklist --- relay.yaml.example | 4 ++++ relay/actor.py | 5 ++++- relay/database.py | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/relay.yaml.example b/relay.yaml.example index 22195d6..4f0b69c 100644 --- a/relay.yaml.example +++ b/relay.yaml.example @@ -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' + diff --git a/relay/actor.py b/relay/actor.py index b8ff942..49abc38 100644 --- a/relay/actor.py +++ b/relay/actor.py @@ -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 re.search('https://(.*)/inbox',inbox).group(1) in AP_CONFIG['blocked_instances']: + return + if inbox not in following: following += [inbox] DATABASE['relay-list'] = following diff --git a/relay/database.py b/relay/database.py index 857af93..b60f9bb 100644 --- a/relay/database.py +++ b/relay/database.py @@ -13,6 +13,11 @@ except: logging.info('No database was found, making a new one.') DATABASE = {} +following = DATABASE.get('relay-list', []) +for inbox in following: + if re.search('https://(.*)/inbox',inbox).group(1) in CONFIG['ap']['blocked_instances']: + following.remove(inbox) + DATABASE['relay-list'] = following async def database_save(): while True: From 64d8e34904e2a9f36fc0fde7e14c3e0e33543e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Mah=C3=A9?= Date: Wed, 31 Oct 2018 12:32:00 -0700 Subject: [PATCH 2/7] Revert "format instance name instead of inbox url" This reverts commit 12af824b56159d24ffe5cd22eb9fe46be52bb25d. --- relay/default.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/relay/default.py b/relay/default.py index 172c9d3..de2dc1e 100644 --- a/relay/default.py +++ b/relay/default.py @@ -1,11 +1,10 @@ import aiohttp.web -import re from . import app, CONFIG from .database import DATABASE host = CONFIG['ap']['host'] note = CONFIG['note'] -targets = '
'.join([re.search('https://(.*)/inbox',target).group(1) for target in DATABASE.get('relay-list', [])]) +targets = '
'.join([target for target in DATABASE.get('relay-list', [])]) async def default(request): return aiohttp.web.Response( From 51d2ab4e36b03d274cea64fa97a307573a87326d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Mah=C3=A9?= Date: Wed, 31 Oct 2018 12:32:10 -0700 Subject: [PATCH 3/7] Revert "expose the list of registered targets to default page" This reverts commit b15665eb1f518ef16bc6deb87ed49dc439969b42. --- relay/default.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/relay/default.py b/relay/default.py index de2dc1e..cc08e06 100644 --- a/relay/default.py +++ b/relay/default.py @@ -1,10 +1,8 @@ import aiohttp.web from . import app, CONFIG -from .database import DATABASE host = CONFIG['ap']['host'] note = CONFIG['note'] -targets = '
'.join([target for target in DATABASE.get('relay-list', [])]) async def default(request): return aiohttp.web.Response( @@ -25,9 +23,8 @@ async def default(request):

For Mastodon instances, you may subscribe to this relay with the address: https://{host}/inbox

For Pleroma and other instances, you may subscribe to this relay with the address: https://{host}/actor

To host your own relay, you may download the code at this address: https://git.pleroma.social/pleroma/relay

-

List of registered instances:
{targets}

-""".format(host=host, note=note,targets=targets)) +""".format(host=host, note=note)) app.router.add_get('/', default) From fb669f124fd173ebab27fdbc41c14a237bbc3511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Mah=C3=A9?= Date: Wed, 31 Oct 2018 12:53:25 -0700 Subject: [PATCH 4/7] import re in database.py for removing blocked follow on load --- relay/database.py | 1 + 1 file changed, 1 insertion(+) diff --git a/relay/database.py b/relay/database.py index b60f9bb..444d4b8 100644 --- a/relay/database.py +++ b/relay/database.py @@ -1,5 +1,6 @@ import asyncio import logging +import re import simplejson as json From 39a255375ef23c6df845bf50b28c88ef4ff8eb3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Mah=C3=A9?= Date: Thu, 1 Nov 2018 13:14:37 -0700 Subject: [PATCH 5/7] use urllib.parse.urlsplit instead of regex --- relay/actor.py | 4 ++-- relay/database.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/relay/actor.py b/relay/actor.py index 49abc38..8ddcf0e 100644 --- a/relay/actor.py +++ b/relay/actor.py @@ -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 @@ -186,7 +186,7 @@ async def handle_follow(actor, data, request): following = DATABASE.get('relay-list', []) inbox = get_actor_inbox(actor) - if re.search('https://(.*)/inbox',inbox).group(1) in AP_CONFIG['blocked_instances']: + if urllib.parse.urlsplit(inbox).hostname in AP_CONFIG['blocked_instances']: return if inbox not in following: diff --git a/relay/database.py b/relay/database.py index 444d4b8..0d171a0 100644 --- a/relay/database.py +++ b/relay/database.py @@ -1,6 +1,6 @@ import asyncio import logging -import re +import urllib.parse import simplejson as json @@ -16,7 +16,7 @@ except: following = DATABASE.get('relay-list', []) for inbox in following: - if re.search('https://(.*)/inbox',inbox).group(1) in CONFIG['ap']['blocked_instances']: + if urllib.parse.urlsplit(inbox).hostname in CONFIG['ap']['blocked_instances']: following.remove(inbox) DATABASE['relay-list'] = following From ee7f1cc190286034f7aab3cfaa159569e107036c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Mah=C3=A9?= Date: Thu, 1 Nov 2018 14:49:48 -0700 Subject: [PATCH 6/7] do not use regex to parse instances, and add count of instances to default page --- relay/default.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/relay/default.py b/relay/default.py index 172c9d3..638e0c7 100644 --- a/relay/default.py +++ b/relay/default.py @@ -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 = '
'.join([re.search('https://(.*)/inbox',target).group(1) for target in DATABASE.get('relay-list', [])]) + +inboxes = DATABASE.get('relay-list', []) +targets = '
'.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):

For Mastodon instances, you may subscribe to this relay with the address: https://{host}/inbox

For Pleroma and other instances, you may subscribe to this relay with the address: https://{host}/actor

To host your own relay, you may download the code at this address: https://git.pleroma.social/pleroma/relay

-

List of registered instances:
{targets}

+

List of {count} registered instances:
{targets}

-""".format(host=host, note=note,targets=targets)) +""".format(host=host, note=note,targets=targets,count=len(inboxes))) app.router.add_get('/', default) From d74fc15198ac272180d470534aafec21210f399f Mon Sep 17 00:00:00 2001 From: tristan Date: Sun, 4 Nov 2018 18:41:08 -0800 Subject: [PATCH 7/7] Revert "Revert "expose the list of registered targets to default page"" This reverts commit 51d2ab4e36b03d274cea64fa97a307573a87326d. --- relay/default.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/relay/default.py b/relay/default.py index cc08e06..de2dc1e 100644 --- a/relay/default.py +++ b/relay/default.py @@ -1,8 +1,10 @@ import aiohttp.web from . import app, CONFIG +from .database import DATABASE host = CONFIG['ap']['host'] note = CONFIG['note'] +targets = '
'.join([target for target in DATABASE.get('relay-list', [])]) async def default(request): return aiohttp.web.Response( @@ -23,8 +25,9 @@ async def default(request):

For Mastodon instances, you may subscribe to this relay with the address: https://{host}/inbox

For Pleroma and other instances, you may subscribe to this relay with the address: https://{host}/actor

To host your own relay, you may download the code at this address: https://git.pleroma.social/pleroma/relay

+

List of registered instances:
{targets}

-""".format(host=host, note=note)) +""".format(host=host, note=note,targets=targets)) app.router.add_get('/', default)