]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Fri, 23 Jun 2023 14:05:13 +0000 (16:05 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 23 Jun 2023 14:05:13 +0000 (16:05 +0200)
- changed 'silence' to 'silenced', makes more sense
- bot POSTs are now centralized in fba.commands.fetch_blocks()
- more logging added

fba/commands.py
fba/models/blocks.py
fba/networks/pleroma.py

index da62329fc71449258824371a100fa7303f2e9393..6a773764c8ed88d55f8777403cbfc72ef5dc3952 100644 (file)
@@ -172,7 +172,6 @@ def fetch_blocks(args: argparse.Namespace) -> int:
     logger.info("Checking %d entries ...", len(rows))
     for blocker, software, origin, nodeinfo_url in rows:
         logger.debug("blocker='%s',software='%s',origin='%s',nodeinfo_url='%s'", blocker, software, origin, nodeinfo_url)
-        blockdict = list()
         blocker = tidyup.domain(blocker)
         logger.debug("blocker='%s' - AFTER!", blocker)
 
@@ -191,6 +190,7 @@ def fetch_blocks(args: argparse.Namespace) -> int:
         instances.set_has_obfuscation(blocker, False)
 
         blocking = list()
+        blockdict = list()
         if software == "pleroma":
             logger.info("blocker='%s',software='%s'", blocker, software)
             blocking = pleroma.fetch_blocks(blocker, nodeinfo_url)
@@ -260,6 +260,9 @@ def fetch_blocks(args: argparse.Namespace) -> int:
             if not utils.is_domain_wanted(block['blocked']):
                 logger.debug("blocked='%s' is not wanted - SKIPPED!", block['blocked'])
                 continue
+            elif block['block_level'] in ["accept", "accepted"]:
+                logger.debug("blocked='%s' is accepted, not wanted here - SKIPPED!", block['blocked'])
+                continue
             elif not instances.is_registered(block['blocked']):
                 logger.debug("Hash wasn't found, adding: blocked='%s',blocker='%s'", block['blocked'], blocker)
                 try:
@@ -268,10 +271,17 @@ def fetch_blocks(args: argparse.Namespace) -> int:
                     logger.warning("Exception during adding blocked='%s',blocker='%s': '%s'", block['blocked'], blocker, type(exception))
                     continue
 
+            if block['block_level'] == "silence":
+                logger.debug("Block level 'silence' has been changed to 'silenced'")
+                block['block_level'] = "silenced"
+
             if not blocks.is_instance_blocked(blocker, block['blocked'], block['block_level']):
+                logger.debug("Invoking blocks.add_instance(%s, %s, %s, %s)", blocker, block['blocked'], block['reason'], block['block_level'])
                 blocks.add_instance(blocker, block['blocked'], block['reason'], block['block_level'])
 
-                if block['block_level'] == "reject":
+                logger.debug("block_level='%s',config[bot_enabled]=%s", block['block_level'], config.get("bot_enabled"))
+                if block['block_level'] == "reject" and config.get("bot_enabled"):
+                    logger.debug("blocker='%s' has blocked '%s' with reason='%s' - Adding to bot notification ...", blocker, block['blocked'], block['reason'])
                     blockdict.append({
                         "blocked": block['blocked'],
                         "reason" : block['reason'],
@@ -291,12 +301,14 @@ def fetch_blocks(args: argparse.Namespace) -> int:
         logger.debug("Invoking commit() ...")
         database.connection.commit()
 
-        if config.get("bot_enabled") and len(blockdict) > 0:
-            network.send_bot_post(blocker, blockdict)
-
         logger.debug("Invoking cookies.clear(%s) ...", blocker)
         cookies.clear(blocker)
 
+        logger.debug("config[bot_enabled]='%s',blockdict()=%d'", config.get("bot_enabled"), len(blockdict))
+        if config.get("bot_enabled") and len(blockdict) > 0:
+            logger.info("Sending bot POST for blocker='%s,blockdict()=%d ...", blocker, len(blockdict))
+            network.send_bot_post(blocker, blockdict)
+
     logger.debug("Success! - EXIT!")
     return 0
 
index 589c6d16611a80e257036bdcad1d112674aea02f..67f36d30e7e1d6c06224d016fd851598231053eb 100644 (file)
@@ -47,7 +47,7 @@ def update_reason(reason: str, blocker: str, blocked: str, block_level: str):
         raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not 'str'")
     elif block_level == "":
         raise ValueError("Parameter 'block_level' is empty")
-    elif block_level in ["accept", "suspended", "silenced"]:
+    elif block_level in ["accept", "suspended", "silence"]:
         raise ValueError(f"block_level='{block_level}' is not wanted.")
 
     logger.debug("Updating block reason='%s',blocker='%s',blocked='%s',block_level='%s'", reason, blocker, blocked, block_level)
@@ -81,8 +81,8 @@ def update_last_seen(blocker: str, blocked: str, block_level: str):
         raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not 'str'")
     elif block_level == "":
         raise ValueError("Parameter 'block_level' is empty")
-    elif block_level in ["accept", "suspended", "silenced"]:
-        raise ValueError("Accepted domains are not wanted here")
+    elif block_level in ["accept", "suspended", "silence"]:
+        raise ValueError(f"blocked='{blocked}' has unwanted block_level='{block_level}'")
 
     database.cursor.execute(
         "UPDATE blocks SET last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1",
@@ -113,8 +113,8 @@ def is_instance_blocked(blocker: str, blocked: str, block_level: str) -> bool:
         raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not of type 'str'")
     elif block_level == "":
         raise ValueError("Parameter 'block_level' is empty")
-    elif block_level in ["accept", "suspended", "silenced"]:
-        raise ValueError("Accepted domains are not wanted here")
+    elif block_level in ["accept", "suspended", "silence"]:
+        raise ValueError(f"blocked='{blocked}' has unwanted block_level='{block_level}'")
 
     database.cursor.execute(
         "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1",
@@ -143,8 +143,8 @@ def add_instance(blocker: str, blocked: str, reason: str, block_level: str):
         raise Exception(f"blocker='{blocker}' is blacklisted but function invoked")
     elif blacklist.is_blacklisted(blocked):
         raise Exception(f"blocked='{blocked}' is blacklisted but function invoked")
-    elif block_level in ["accept", "suspended", "silenced"]:
-        raise ValueError("Accepted domains are not wanted here")
+    elif block_level in ["accept", "suspended", "silence"]:
+        raise ValueError(f"blocked='{blocked}' has unwanted block_level='{block_level}'")
 
     if reason is not None:
         # Maybe needs cleaning
index f132ba348c98842f2a97d0d6221646168a01c390..c616cfd3bfd1ae9d3fee68a55d20e9075aaafe4f 100644 (file)
@@ -95,9 +95,9 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list:
             elif block_level == "suspended":
                 logger.debug("domain='%s', mapping 'suspended' to 'suspend'", domain)
                 block_level = "suspend"
-            elif block_level == "silenced":
-                logger.debug("domain='%s', mapping 'silenced' to 'silence'", domain)
-                block_level = "silence"
+            elif block_level == "silence":
+                logger.debug("domain='%s', mapping 'silence' to 'silenced'", domain)
+                block_level = "silenced"
 
             logger.debug("Checking %d entries from domain='%s',block_level='%s' ...", len(blocklist), domain, block_level)
             if len(blocklist) > 0:
@@ -247,9 +247,9 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list:
             elif block_level == "suspended":
                 logger.debug("domain='%s', mapping 'suspended' to 'suspend'", domain)
                 block_level = "suspend"
-            elif block_level == "silenced":
-                logger.debug("domain='%s', mapping 'silenced' to 'silence'", domain)
-                block_level = "silence"
+            elif block_level == "silence":
+                logger.debug("domain='%s', mapping 'silence' to 'silenced'", domain)
+                block_level = "silenced"
 
             logger.debug("Checking %d entries from domain='%s',block_level='%s' ...", len(info.items()), domain, block_level)
             for blocked, reason in info.items():