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({
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