From 37f73f8b545fe0a8a3809b4138b0d872e690fa14 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 29 Jun 2023 07:24:40 +0200 Subject: [PATCH] Continued: - some block entries seem to contain https:// at the start, also try this varriant --- fba/models/instances.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fba/models/instances.py b/fba/models/instances.py index a812a85..25ea215 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -28,6 +28,7 @@ from fba.helpers import blacklist from fba.helpers import cache from fba.helpers import config from fba.helpers import domain as domain_helper +from fba.helpers import tidyup from fba.http import federation from fba.http import network @@ -330,6 +331,9 @@ def deobfuscate(char: str, domain: str, blocked_hash: str = None) -> tuple: elif not isinstance(blocked_hash, str) and blocked_hash is not None: raise ValueError(f"Parameter blocked_hash[]='{type(blocked_hash)}' is not 'str'") + # Init row + row = None + 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) @@ -343,10 +347,20 @@ def deobfuscate(char: str, domain: str, blocked_hash: str = None) -> tuple: if row is None: logger.debug("blocked_hash='%s' not found, trying domain='%s' ...", blocked_hash, domain) return deobfuscate(char, domain) - else: - logger.debug("Looking up domain='%s' ...", domain) + elif not domain.startswith("*."): + logger.debug("domain='%s' - BEFORE!", domain) + domain = tidyup.domain(domain) + logger.debug("domain='%s' - AFTER!", domain) + + if domain == "": + debug.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 ? ORDER BY rowid LIMIT 1", [domain.replace(char, "_")] + "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() -- 2.39.5