From 833e6744be828c12ff7787302220c143858ac981 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 4 Sep 2024 01:07:37 +0200 Subject: [PATCH] Continued: - don't log an info after a "filter function" - initialize variable 'search' as both if() blocks use the same code - check variable 'domain' before 'char' as 'char' needs to be in a supported 'domain' string --- fba/commands.py | 3 ++- fba/models/instances.py | 31 +++++++++++-------------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/fba/commands.py b/fba/commands.py index a6c18db..66af1ff 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -1453,9 +1453,10 @@ def recheck_obfuscation(args: argparse.Namespace) -> int: logger.debug("blocked='%s' is already blocked by domain='%s' - SKIPPED!", blocked, row["domain"]) continue + logger.debug("block[block_level]='%s' - BEFORE!", block["block_level"]) block["block_level"] = blocks.alias_block_level(block["block_level"]) + logger.debug("block[block_level]='%s' - AFTER!", block["block_level"]) - logger.info("blocked='%s' has been deobfuscated to blocked='%s', adding ...", block["blocked"], blocked) if processing.block(row["domain"], blocked, block["reason"], block["block_level"]) and block["block_level"] in ["suspended", "rejected"] and config.get("bot_enabled"): logger.debug("Appending blocked='%s',reason='%s' for blocker='%s' ...", block["blocked"], block["block_level"], row["domain"]) blockdict.append({ diff --git a/fba/models/instances.py b/fba/models/instances.py index ff3c0fc..77e8922 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -373,51 +373,42 @@ def is_recent(domain: str, column: str = "last_instance_fetch") -> bool: def deobfuscate(char: str, domain: str, blocked_hash: str = None) -> tuple: logger.debug("char='%s',domain='%s',blocked_hash='%s' - CALLED!", char, domain, blocked_hash) - if not isinstance(char, str): + if not isinstance(domain, str): + raise ValueError(f"Parameter domain[]='{type(domain)}'") + elif not isinstance(char, str): raise ValueError(f"Parameter char[]='{type(char)}' is not of type 'str'") elif char == "": raise ValueError("Parameter 'char' is empty") elif not char in domain: raise ValueError(f"char='{char}' not found in domain='{domain}' but function invoked") - elif not isinstance(domain, str): - raise ValueError(f"Parameter domain[]='{type(domain)}'") elif not isinstance(blocked_hash, str) and blocked_hash is not None: raise ValueError(f"Parameter blocked_hash[]='{type(blocked_hash)}' is not of type 'str'") - # Init row + # Init variables row = None + search = domain.replace(char, "_") - logger.debug("blocked_hash[]='%s'", type(blocked_hash)) - if isinstance(blocked_hash, str): - logger.debug("Looking up blocked_hash='%s',domain='%s' ...", blocked_hash, domain) + logger.debug("search='%s'", search) + if isinstance(blocked_hash, str) and blocked_hash != "": + logger.debug("Looking up blocked_hash='%s',search='%s',domain='%s' ...", blocked_hash, search, domain) database.cursor.execute( - "SELECT domain, origin, nodeinfo_url FROM instances WHERE hash = ? OR domain LIKE ? LIMIT 1", [blocked_hash, domain.replace(char, "_")] + "SELECT domain, origin, nodeinfo_url FROM instances WHERE hash = ? OR domain LIKE ? LIMIT 1", [blocked_hash, search] ) row = database.cursor.fetchone() - logger.debug("row[]='%s'", type(row)) + logger.debug("row[]='%s' - After quering database.", type(row)) if row is None: logger.debug("blocked_hash='%s' not found, trying domain='%s' ...", blocked_hash, domain) return deobfuscate(char, domain) elif not domain.startswith("*."): - logger.debug("domain='%s' - BEFORE!", domain) - domain = tidyup.domain(domain) - logger.debug("domain='%s' - AFTER!", domain) - - if domain == "": - logger.warning("domain is empty after tidyup - EXIT!") - return None - - search = domain.replace(char, "_") - logger.debug("Looking up domain='%s',search='%s' ...", domain, search) database.cursor.execute( "SELECT domain, origin, nodeinfo_url FROM instances WHERE domain LIKE ? OR 'https://' || domain LIKE ? ORDER BY rowid LIMIT 1", [search, search] ) row = database.cursor.fetchone() - logger.debug("row[]='%s'", type(row)) + logger.debug("row[]='%s' - After quering database.", type(row)) logger.debug("row[]='%s' - EXIT!", type(row)) return row -- 2.39.5