From 46053ea0fa2ef1df3145d45eb84cf7ecd287ff90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 8 Jun 2023 18:50:52 +0200 Subject: [PATCH] Continued: - also tidyup reason after fetching from instance - moved validating domain to upper if/elif blocks - re-color website to more friendlier colors - rewrote some debug lines --- fba/commands.py | 8 +++-- fba/federation/pleroma.py | 18 +++++----- templates/base.html | 72 ++++++++++++++++++++++++--------------- 3 files changed, 58 insertions(+), 40 deletions(-) diff --git a/fba/commands.py b/fba/commands.py index 408eadd..6df7cd9 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -105,6 +105,7 @@ def fetch_bkali(args: argparse.Namespace): def fetch_blocks(args: argparse.Namespace): # DEBUG: print(f"DEBUG: args[]={type(args)} - CALLED!") if args.domain != None and args.domain != "": + # DEBUG: print(f"DEBUG: args.domain='{args.domain}' - checking ...") if not validators.domain(args.domain): print(f"WARNING: domain='{args.domain}' is not valid.") return @@ -118,10 +119,12 @@ def fetch_blocks(args: argparse.Namespace): boot.acquire_lock() if args.domain != None and args.domain != "": + # Re-check single domain fba.cursor.execute( "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe') AND domain = ?", [args.domain] ) else: + # Re-check after "timeout" (aka. minimum interval) fba.cursor.execute( "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe') AND (last_blocked IS NULL OR last_blocked < ?) ORDER BY rowid DESC", [time.time() - config.get("recheck_block")] ) @@ -170,9 +173,10 @@ def fetch_blocks(args: argparse.Namespace): # DEBUG: print(f"DEBUG: Checking {len(blocklist)} entries from blocker='{blocker}',software='{software}',block_level='{block_level}' ...") for block in blocklist: blocked, reason = block.values() - # DEBUG: print("DEBUG: BEFORE blocked:", blocked) + # DEBUG: print(f"DEBUG: blocked='{blocked}',reason='{reason}' - BEFORE!") 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:", blocker) diff --git a/fba/federation/pleroma.py b/fba/federation/pleroma.py index 3e47c01..7094ae4 100644 --- a/fba/federation/pleroma.py +++ b/fba/federation/pleroma.py @@ -23,7 +23,7 @@ from fba import fba from fba import instances def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): - print(f"DEBUG: domain='{domain}',origin='{origin}',nodeinfo_url='{nodeinfo_url}' - CALLED!") + # DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',nodeinfo_url='{nodeinfo_url}' - CALLED!") if type(domain) != str: raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": @@ -150,13 +150,17 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): # DEBUG: print(f"DEBUG: Checking {len(info.items())} entries from domain='{domain}',software='pleroma',block_level='{block_level}' ...") for blocked, reason in info.items(): - # DEBUG: print("DEBUG: BEFORE blocked:", blocked) + # DEBUG: print(f"DEBUG: blocked='{blocked}',reason='{reason}' - BEFORE!") 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 after fba.tidyup_domain():", domain, block_level) continue + elif not validators.domain(blocked): + print(f"WARNING: blocked='{blocked}',software='pleroma' is not a valid domain name - skipped!") + continue elif blacklist.is_blacklisted(blocked): # DEBUG: print(f"DEBUG: blocked='{blocked}' is blacklisted - skipping!") continue @@ -174,15 +178,9 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): blocked = searchres[0] origin = searchres[1] nodeinfo_url = searchres[2] - elif not validators.domain(blocked): - print(f"WARNING: blocked='{blocked}',software='pleroma' is not a valid domain name - skipped!") - continue # DEBUG: print("DEBUG: Looking up instance by domain:", blocked) - if not validators.domain(blocked): - print(f"WARNING: blocked='{blocked}',software='pleroma' is not a valid domain name - skipped!") - continue - elif not instances.is_registered(blocked): + if not instances.is_registered(blocked): # DEBUG: print(f"DEBUG: Domain blocked='{blocked}' wasn't found, adding ..., domain='{domain}',origin='{origin}',nodeinfo_url='{nodeinfo_url}'") instances.add(blocked, domain, inspect.currentframe().f_code.co_name, nodeinfo_url) diff --git a/templates/base.html b/templates/base.html index 6933f3e..07700d2 100644 --- a/templates/base.html +++ b/templates/base.html @@ -2,64 +2,86 @@ fedi-block-api - {% block title %}{% endblock %} {% block rss %} - + {% endblock %} +