From 002a03365cbb81659c5c62eb5166820c45ea6cfb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 8 Jun 2023 20:03:43 +0200 Subject: [PATCH] Continued: - some block reasons have a long domain list (which can be taken as instance names, too) with no space after a comma - this causes the web page to be very(!) wide - added missing "import inspect" - improved some debug messages --- api.py | 4 ++++ fba/federation/mastodon.py | 9 ++++++--- fba/federation/misskey.py | 8 ++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/api.py b/api.py index ec459f5..7c41eed 100644 --- a/api.py +++ b/api.py @@ -110,6 +110,9 @@ def blocked(domain: str = None, reason: str = None, reverse: str = None): result = {} for blocker, blocked, block_level, reason, first_seen, last_seen in blocklist: + if reason != None and reason != "": + reason = reason.replace(",", " ").replace(" ", " ") + entry = { "blocker" : blocker, "blocked" : blocked, @@ -117,6 +120,7 @@ def blocked(domain: str = None, reason: str = None, reverse: str = None): "first_seen": first_seen, "last_seen" : last_seen } + if block_level in result: result[block_level].append(entry) else: diff --git a/fba/federation/mastodon.py b/fba/federation/mastodon.py index 11eac1b..4752ca1 100644 --- a/fba/federation/mastodon.py +++ b/fba/federation/mastodon.py @@ -15,6 +15,7 @@ # along with this program. If not, see . import bs4 +import inspect import validators from fba import blacklist @@ -127,7 +128,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): "reject" : [], "media_removal" : [], "followers_only": [], - "report_removal": [] + "report_removal": [], } # handling CSRF, I've saw at least one server requiring it to access the endpoint @@ -187,10 +188,12 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): # DEBUG: print(f"DEBUG: Checking {len(blocklist)} entries from domain='{domain}',software='mastodon',block_level='{block_level}' ...") for block in blocklist: + # DEBUG: print(f"DEBUG: block[]='{type(block)}'") blocked, blocked_hash, reason = block.values() - # DEBUG: print("DEBUG: blocked,hash,reason:", blocked, blocked_hash, reason) + # DEBUG: print(f"DEBUG: blocked='{blocked}',blocked_hash='{blocked_hash}',reason='{reason}':") blocked = fba.tidyup_domain(blocked) - # DEBUG: print("DEBUG: AFTER-blocked:", blocked) + reason = fba.tidyup_reason(reason) + # DEBUG: print(f"DEBUG: blocked='{blocked}',reason='{reason}' - AFTER!") if blocked == "": print("WARNING: blocked is empty:", domain) diff --git a/fba/federation/misskey.py b/fba/federation/misskey.py index 1428948..8ea0b2b 100644 --- a/fba/federation/misskey.py +++ b/fba/federation/misskey.py @@ -58,13 +58,13 @@ def fetch_peers(domain: str) -> list: # DEBUG: print(f"DEBUG: fetched()={len(fetched)}") if len(fetched) == 0: - # DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain) + # DEBUG: print(f"DEBUG: Returned zero bytes, exiting loop, domain='{domain}'") break elif len(fetched) != config.get("misskey_limit"): # DEBUG: print(f"DEBUG: Fetched '{len(fetched)}' row(s) but expected: '{config.get('misskey_limit')}'") offset = offset + (config.get("misskey_limit") - len(fetched)) else: - # DEBUG: print("DEBUG: Raising offset by step:", step) + # DEBUG: print(f"DEBUG: Raising offset by step={step}") offset = offset + step # Check records @@ -76,7 +76,7 @@ def fetch_peers(domain: str) -> list: already = 0 for row in fetched: - # DEBUG: print(f"DEBUG: row():{len(row)}") + # DEBUG: print(f"DEBUG: row()={len(row)}") if not "host" in row: print(f"WARNING: row()={len(row)} does not contain key 'host': {row},domain='{domain}'") continue @@ -104,5 +104,5 @@ def fetch_peers(domain: str) -> list: # DEBUG: print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...") instances.update_last_instance_fetch(domain) - # DEBUG: print("DEBUG: Returning peers[]:", type(peers)) + # DEBUG: print(f"DEBUG: Returning peers[]='{type(peers)}'") return peers -- 2.39.5