]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 29 Jun 2023 04:11:00 +0000 (06:11 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 29 Jun 2023 04:11:00 +0000 (06:11 +0200)
- command recheck_obfuscation now accepts parameter --domain and --software
- encapsulated aliasing unwanted block_level into function
  utils.alias_block_level()

fba/boot.py
fba/commands.py
fba/networks/mastodon.py
fba/networks/misskey.py
fba/networks/pleroma.py
fba/utils.py

index a8109fc5b46c403c8d0cf1740b94039d9d1cb9a0..d72c8e4c59279340d360378da00dc439834575f9 100644 (file)
@@ -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 ###
index 8812cf1e0e888d3cda6ff7cc39dbd752477c50a1..0b5715ef3a50f01da9ada3ed19a4de0a03dc2dbd 100644 (file)
@@ -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"):
index ca33c10bc6632ba4af33e623d79ee2eb50344aac..0dc4dfaa1b8e0025d9052795862cdeff8e558956 100644 (file)
@@ -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
index e47c7dd9d04548c5d63171fec5dfb7665a83e69a..0614a5728a399bfd5175599729843ece1404ea0c 100644 (file)
@@ -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
index 64729f113ab56dd49a48f597214f94f71581fd9b..60822825865f4a779312a500a361b9020be805bf 100644 (file)
@@ -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():
index c91bba488849c5dcb26cfb2083cdbdc0e66cf7a3..2befee36a97ff4728027bfb1ec102cbdf3f6bc4f 100644 (file)
@@ -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