From: Roland Häder Date: Wed, 21 Jun 2023 01:52:49 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e2bdde2b8b900e15d827a355fafdab2e91a46846;p=fba.git Continued: - move fba.blacklist to fba.helpers package --- diff --git a/fba/blacklist.py b/fba/blacklist.py deleted file mode 100644 index bbe097b..0000000 --- a/fba/blacklist.py +++ /dev/null @@ -1,52 +0,0 @@ -# Fedi API Block - An aggregator for fetching blocking data from fediverse nodes -# Copyright (C) 2023 Free Software Foundation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -# Don't check these, known trolls/flooders/testing/developing -blacklist = [ - # Floods federation with fake nodes as "research" project - "activitypub-troll.cf", - # Similar troll - "gab.best", - # Similar troll - "4chan.icu", - # Flooder (?) - "social.shrimpcam.pw", - # Flooder (?) - "mastotroll.netz.org", - # Testing/developing installations - "ngrok.io", - "ngrok-free.app", - "misskeytest.chn.moe", - # block flooder - "everyoneattack.com", -] - -def is_blacklisted(domain: str) -> bool: - # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!") - if not isinstance(domain, str): - raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'") - elif domain == "": - raise ValueError("Parameter 'domain' is empty") - - blacklisted = False - for peer in blacklist: - # DEBUG: print(f"DEBUG: Checking peer='{peer}' ...") - if peer in domain: - # DEBUG: print(f"DEBUG: domain='{domain}' is blacklisted.") - blacklisted = True - - # DEBUG: print(f"DEBUG: blacklisted='{blacklisted}' - EXIT!") - return blacklisted diff --git a/fba/commands.py b/fba/commands.py index f276a1f..4dca5fd 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -26,12 +26,12 @@ import markdown import reqto import validators -from fba import blacklist from fba import config from fba import federation from fba import fba from fba import network +from fba.helpers import blacklist from fba.helpers import cookies from fba.helpers import locking from fba.helpers import tidyup diff --git a/fba/fba.py b/fba/fba.py index 335028c..db37abf 100644 --- a/fba/fba.py +++ b/fba/fba.py @@ -21,10 +21,11 @@ from urllib.parse import urlparse import requests import validators -from fba import blacklist from fba import federation from fba import network +from fba.helpers import blacklist + from fba.models import instances # Connect to database diff --git a/fba/federation.py b/fba/federation.py index 1d15450..397e63b 100644 --- a/fba/federation.py +++ b/fba/federation.py @@ -18,11 +18,11 @@ from urllib.parse import urlparse import bs4 import validators -from fba import blacklist from fba import config from fba import csrf from fba import network +from fba.helpers import blacklist from fba.helpers import tidyup from fba.helpers import version diff --git a/fba/helpers/blacklist.py b/fba/helpers/blacklist.py new file mode 100644 index 0000000..bbe097b --- /dev/null +++ b/fba/helpers/blacklist.py @@ -0,0 +1,52 @@ +# Fedi API Block - An aggregator for fetching blocking data from fediverse nodes +# Copyright (C) 2023 Free Software Foundation +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +# Don't check these, known trolls/flooders/testing/developing +blacklist = [ + # Floods federation with fake nodes as "research" project + "activitypub-troll.cf", + # Similar troll + "gab.best", + # Similar troll + "4chan.icu", + # Flooder (?) + "social.shrimpcam.pw", + # Flooder (?) + "mastotroll.netz.org", + # Testing/developing installations + "ngrok.io", + "ngrok-free.app", + "misskeytest.chn.moe", + # block flooder + "everyoneattack.com", +] + +def is_blacklisted(domain: str) -> bool: + # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!") + if not isinstance(domain, str): + raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'") + elif domain == "": + raise ValueError("Parameter 'domain' is empty") + + blacklisted = False + for peer in blacklist: + # DEBUG: print(f"DEBUG: Checking peer='{peer}' ...") + if peer in domain: + # DEBUG: print(f"DEBUG: domain='{domain}' is blacklisted.") + blacklisted = True + + # DEBUG: print(f"DEBUG: blacklisted='{blacklisted}' - EXIT!") + return blacklisted diff --git a/fba/models/blocks.py b/fba/models/blocks.py index 2111164..0858d52 100644 --- a/fba/models/blocks.py +++ b/fba/models/blocks.py @@ -17,8 +17,9 @@ import time import validators -from fba import blacklist from fba import fba + +from fba.helpers import blacklist from fba.helpers import tidyup def update_reason(reason: str, blocker: str, blocked: str, block_level: str): diff --git a/fba/models/instances.py b/fba/models/instances.py index 0ed262e..836a1ef 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -20,12 +20,12 @@ import time import requests import validators -from fba import blacklist from fba import config from fba import fba from fba import federation from fba import network +from fba.helpers import blacklist from fba.helpers import cache from fba.models import error_log diff --git a/fba/networks/lemmy.py b/fba/networks/lemmy.py index e05c2cc..541dd55 100644 --- a/fba/networks/lemmy.py +++ b/fba/networks/lemmy.py @@ -19,13 +19,13 @@ import inspect import bs4 import validators -from fba import blacklist from fba import config from fba import csrf from fba import fba from fba import federation from fba import network +from fba.helpers import blacklist from fba.helpers import tidyup from fba.models import blocks diff --git a/fba/networks/mastodon.py b/fba/networks/mastodon.py index 61971af..9aeec1b 100644 --- a/fba/networks/mastodon.py +++ b/fba/networks/mastodon.py @@ -19,12 +19,12 @@ import inspect import bs4 import validators -from fba import blacklist from fba import config from fba import csrf from fba import fba from fba import network +from fba.helpers import blacklist from fba.helpers import tidyup from fba.models import blocks diff --git a/fba/networks/misskey.py b/fba/networks/misskey.py index 152d971..3b93b54 100644 --- a/fba/networks/misskey.py +++ b/fba/networks/misskey.py @@ -16,11 +16,11 @@ import json -from fba import blacklist from fba import config from fba import csrf from fba import network +from fba.helpers import blacklist from fba.helpers import dicts from fba.helpers import tidyup diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index 546d7c5..75dfd2b 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -19,12 +19,12 @@ import inspect import bs4 import validators -from fba import blacklist from fba import config from fba import fba from fba import federation from fba import network +from fba.helpers import blacklist from fba.helpers import tidyup from fba.models import blocks