From 62e1983c0bcf977b7dc9b2f88f2b7b44585a0cac Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 25 Jul 2023 00:51:40 +0200 Subject: [PATCH] Continued: - instances.is_recent() now checks recheck_block if 'last_blocked' is provided - command fetch_blocks() now supports --force parameter - blacklisted fnaf.stream as this domain has super-long sub-domains (troll) --- fba/boot.py | 3 ++- fba/commands.py | 8 +++++++- fba/helpers/blacklist.py | 1 + fba/models/instances.py | 8 ++++++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/fba/boot.py b/fba/boot.py index abc94ac..0da80a0 100644 --- a/fba/boot.py +++ b/fba/boot.py @@ -80,9 +80,10 @@ def init_parser(): "fetch_blocks", help="Fetches blocks from registered instances (run command fetch_instances first!).", ) + parser.set_defaults(command=commands.fetch_blocks) parser.add_argument("--domain", help="Instance name (aka. domain)") parser.add_argument("--software", help="Name of software, e.g. 'lemmy'") - parser.set_defaults(command=commands.fetch_blocks) + parser.add_argument("--force", action="store_true", help="Forces update of data, no matter what.") ### Fetch blocks from chaos.social ### parser = subparser_command.add_parser( diff --git a/fba/commands.py b/fba/commands.py index cbdc603..c6e14f4 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -279,7 +279,7 @@ def fetch_blocks(args: argparse.Namespace) -> int: if args.domain is not None and args.domain != "": # Re-check single domain - logger.debug("Querying database for single args.domain='%s' ...", args.domain) + logger.debug("Querying database for args.domain='%s' ...", args.domain) database.cursor.execute( "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE domain = ?", [args.domain] ) @@ -289,6 +289,12 @@ def fetch_blocks(args: argparse.Namespace) -> int: database.cursor.execute( "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software = ? AND nodeinfo_url IS NOT NULL", [args.software] ) + elif args.force: + # Re-check all + logger.debug("Re-checking all instances ...") + database.cursor.execute( + "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'lemmy', 'friendica', 'misskey') AND nodeinfo_url IS NOT NULL ORDER BY rowid DESC" + ) else: # Re-check after "timeout" (aka. minimum interval) database.cursor.execute( diff --git a/fba/helpers/blacklist.py b/fba/helpers/blacklist.py index a580a14..02bd319 100644 --- a/fba/helpers/blacklist.py +++ b/fba/helpers/blacklist.py @@ -35,6 +35,7 @@ _blacklist = { "grid.tf" : "Floods federation tables with fake nodes", "gitpod.io" : "Floods federation tables with fake nodes", "everyoneattack.com" : "Floods federation tables with fake nodes", + "fnaf.stream" : "Trolls with over-long sub-domain name(s)", "ngrok.io" : "Testing/developing instances shouldn't be part of public instances", "ngrok.app" : "Testing/developing instances shouldn't be part of public instances", "ngrok-free.app" : "Testing/developing instances shouldn't be part of public instances", diff --git a/fba/models/instances.py b/fba/models/instances.py index 2549ed3..c7db652 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -306,14 +306,18 @@ def is_recent(domain: str, column: str = "last_instance_fetch") -> bool: logger.debug("domain='%s' is not registered, returning False - EXIT!", domain) return False + key = "recheck_instance" + if column == "last_blocked": + key = "recheck_block" + # Query database database.cursor.execute(f"SELECT {column} FROM instances WHERE domain = ? LIMIT 1", [domain]) # Fetch row fetched = database.cursor.fetchone()[column] - logger.debug("fetched[%s]='%s'", type(fetched), fetched) - recently = isinstance(fetched, float) and (time.time() - fetched) <= config.get("recheck_instance") + logger.debug("fetched[%s]='%s',key='%s'", type(fetched), fetched, key) + recently = isinstance(fetched, float) and (time.time() - fetched) >= config.get(key) logger.debug("recently='%s' - EXIT!", recently) return recently -- 2.39.5