From: Roland Häder Date: Thu, 29 Jun 2023 04:11:00 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e53fd0eb5905f0b7b20b278dbfe3309df9689a78;p=fba.git Continued: - command recheck_obfuscation now accepts parameter --domain and --software - encapsulated aliasing unwanted block_level into function utils.alias_block_level() --- diff --git a/fba/boot.py b/fba/boot.py index a8109fc..d72c8e4 100644 --- a/fba/boot.py +++ b/fba/boot.py @@ -70,6 +70,8 @@ def init_parser(): "recheck_obfuscation", help="Checks all instance's obfuscated peers if they can be de-obfuscated now.", ) + 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.recheck_obfuscation) ### Fetch blocks from registered instances or given ### diff --git a/fba/commands.py b/fba/commands.py index 8812cf1..0b5715e 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -189,6 +189,7 @@ def fetch_bkali(args: argparse.Namespace) -> int: except network.exceptions as exception: logger.warning("Exception '%s' during fetching instances (fetch_bkali) from domain='%s'", type(exception), domain) instances.set_last_error(domain, exception) + return 100 logger.debug("Success - EXIT!") return 0 @@ -336,12 +337,7 @@ def fetch_blocks(args: argparse.Namespace) -> int: logger.debug("Hash wasn't found, adding: blocked='%s',blocker='%s'", block["blocked"], blocker) federation.fetch_instances(block["blocked"], blocker, None, inspect.currentframe().f_code.co_name) - if block["block_level"] == "silence": - logger.debug("Block level 'silence' has been changed to 'silenced'") - block["block_level"] = "silenced" - elif block["block_level"] == "suspend": - logger.debug("Block level 'suspend' has been changed to 'suspended'") - block["block_level"] = "suspended" + block["block_level"] = utils.alias_block_level(block["block_level"]) if utils.process_block(blocker, block["blocked"], block["reason"], block["block_level"]) and block["block_level"] == "reject" and config.get("bot_enabled"): logger.debug("Appending blocked='%s',reason='%s' for blocker='%s' ...", block["blocked"], block["block_level"], blocker) @@ -641,6 +637,7 @@ def fetch_fba_rss(args: argparse.Namespace) -> int: except network.exceptions as exception: logger.warning("Exception '%s' during fetching instances (fetch_fba_rss) from domain='%s'", type(exception), domain) instances.set_last_error(domain, exception) + return 100 logger.debug("Success! - EXIT!") return 0 @@ -698,6 +695,7 @@ def fetch_fbabot_atom(args: argparse.Namespace) -> int: except network.exceptions as exception: logger.warning("Exception '%s' during fetching instances (fetch_fbabot_atom) from domain='%s'", type(exception), domain) instances.set_last_error(domain, exception) + return 100 logger.debug("Success! - EXIT!") return 0 @@ -1119,7 +1117,13 @@ def recheck_obfuscation(args: argparse.Namespace) -> int: locking.acquire() - database.cursor.execute("SELECT domain, software, nodeinfo_url FROM instances WHERE has_obfuscation = 1") + if args.domain != "" and utils.is_domain_wanted(args.domain): + database.cursor.execute("SELECT domain, software, nodeinfo_url FROM instances WHERE has_obfuscation = 1 AND domain = ?", [args.domain]) + elif args.domain != "" and validators.domain(args.software) == args.software: + database.cursor.execute("SELECT domain, software, nodeinfo_url FROM instances WHERE has_obfuscation = 1 AND software = ?", [args.software]) + else: + database.cursor.execute("SELECT domain, software, nodeinfo_url FROM instances WHERE has_obfuscation = 1") + rows = database.cursor.fetchall() logger.info("Checking %d domains ...", len(rows)) for row in rows: @@ -1171,6 +1175,7 @@ def recheck_obfuscation(args: argparse.Namespace) -> int: logger.debug("blocked='%s' is already blocked - SKIPPED!", block["blocked"]) continue + logger.debug("blocked[%s]='%s',block[blocked]='%s'", type(blocked), blocked, block["blocked"]) if blocked is not None and blocked != block["blocked"]: logger.debug("blocked='%s' was deobfuscated to blocked='%s'", block["blocked"], blocked) obfuscated = obfuscated - 1 @@ -1178,12 +1183,7 @@ def recheck_obfuscation(args: argparse.Namespace) -> int: logger.debug("blocked='%s' is already blocked by domain='%s' - SKIPPED!", blocked, row[0]) continue - if block["block_level"] == "silence": - logger.debug("Block level 'silence' has been changed to 'silenced'") - block["block_level"] = "silenced" - elif block["block_level"] == "suspend": - logger.debug("Block level 'suspend' has been changed to 'suspended'") - block["block_level"] = "suspended" + block["block_level"] = utils.alias_block_level(block["block_level"]) logger.info("blocked='%s' has been deobfuscated to blocked='%s', adding ...", block["blocked"], blocked) if utils.process_block(row[0], blocked, block["reason"], block["block_level"]) and block["block_level"] == "reject" and config.get("bot_enabled"): diff --git a/fba/networks/mastodon.py b/fba/networks/mastodon.py index ca33c10..0dc4dfa 100644 --- a/fba/networks/mastodon.py +++ b/fba/networks/mastodon.py @@ -147,7 +147,7 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list: except network.exceptions as exception: logger.warning("Exception '%s' during checking CSRF (fetch_blocks,%s) - EXIT!", type(exception), __name__) instances.set_last_error(domain, exception) - return blocklist + return list() try: # json endpoint for newer mastodongs diff --git a/fba/networks/misskey.py b/fba/networks/misskey.py index e47c7dd..0614a57 100644 --- a/fba/networks/misskey.py +++ b/fba/networks/misskey.py @@ -141,7 +141,7 @@ def fetch_blocks(domain: str) -> list: except network.exceptions as exception: logger.warning("Exception '%s' during checking CSRF (fetch_blocks,%s) - EXIT!", type(exception), __name__) instances.set_last_error(domain, exception) - return blocklist + return list() # iterating through all "suspended" (follow-only in its terminology) # instances page-by-page since it doesn't support sending them all at once diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index 64729f1..6082282 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -64,7 +64,7 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list: logger.warning("rows()=%d does not have key 'metadata', domain='%s'", len(rows), domain) return list() elif "federation" not in rows["metadata"]: - logger.warning("rows()=%d does not have key 'federation', domain='%s'", len(rows['metadata']), domain) + logger.warning("rows()=%d does not have key 'federation', domain='%s'", len(rows["metadata"]), domain) return list() data = rows["metadata"]["federation"] @@ -92,12 +92,8 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list: elif block_level == "accept": logger.debug("domain='%s' skipping block_level='accept'", domain) continue - elif block_level == "suspend": - logger.debug("domain='%s', mapping 'suspend' to 'suspended'", domain) - block_level = "suspended" - elif block_level == "silence": - logger.debug("domain='%s', mapping 'silence' to 'silenced'", domain) - block_level = "silenced" + + block_level = utils.alias_block_level(block_level) logger.debug("Checking %d entries from domain='%s',block_level='%s' ...", len(blocklist), domain, block_level) if len(blocklist) > 0: @@ -186,14 +182,10 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list: logger.warning("block_level is now empty!") continue elif block_level == "accept": - logger.debug("domain='%s' skipping block_level='accept'", domain) + logger.debug("domain='%s': Skipping block_level='%s' ...", domain, block_level) continue - elif block_level == "suspend": - logger.debug("domain='%s', mapping 'suspend' to 'suspended'", domain) - block_level = "suspended" - elif block_level == "silence": - logger.debug("domain='%s', mapping 'silence' to 'silenced'", domain) - block_level = "silenced" + + block_level = utils.alias_block_level(block_level) logger.debug("Checking %d entries from domain='%s',block_level='%s' ...", len(info.items()), domain, block_level) for blocked, reason in info.items(): diff --git a/fba/utils.py b/fba/utils.py index c91bba4..2befee3 100644 --- a/fba/utils.py +++ b/fba/utils.py @@ -244,4 +244,20 @@ def process_block(blocker: str, blocked: str, reason: str, block_level: str) -> logger.debug("added='%s' - EXIT!", added) return added - \ No newline at end of file + +def alias_block_level(block_level: str) -> str: + logger.debug("block_level='%s' - CALLED!", block_level) + if not isinstance(block_level, str): + raise ValueError(f"Parameter block_level[]='%s' is not of type 'str'", type(block_level)) + elif block_level == "": + raise ValueError("Parameter 'block_level' is empty") + + if block_level == "silence": + logger.debug("Block level 'silence' has been changed to 'silenced'") + block_level = "silenced" + elif block_level == "suspend": + logger.debug("Block level 'suspend' has been changed to 'suspended'") + block_level = "suspended" + + logger.debug("block_level='%s' - EXIT!", block_level) + return block_level