]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 8 Sep 2024 03:02:52 +0000 (05:02 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 8 Sep 2024 03:02:52 +0000 (05:02 +0200)
- added "logging" of obfuscated blocked domain/instance names
- if it has been deobfuscated, it will be removed

blocks_empty.db
fba/commands.py
fba/models/__init__.py
fba/models/obfuscation.py [new file with mode: 0644]

index 1bc4b2d1bd1b50770e447b2d5c7adb9bd16d6dc9..daea60bdb128ce57d407722a7cf6c087820d420c 100644 (file)
Binary files a/blocks_empty.db and b/blocks_empty.db differ
index d9b04dcf21c45e77eb1dbeda4a1860c7cce0c99b..080b7ff2b5b799d3325416d93ebecca99fa2f5e3 100644 (file)
@@ -49,6 +49,7 @@ from fba.http import network
 
 from fba.models import blocks
 from fba.models import instances
+from fba.models import obfuscation
 from fba.models import sources
 
 from fba.networks import friendica
@@ -399,6 +400,11 @@ def fetch_blocks(args: argparse.Namespace) -> int:
                 logger.debug("row[]='%s'", type(row))
                 if row is None:
                     logger.warning("Cannot deobfuscate block[blocked]='%s',blocker='%s',software='%s' - SKIPPED!", block["blocked"], blocker, software)
+
+                    if not obfuscation.is_added(block["blocked"]):
+                        logger.debug("Invoking add(%s)", block["blocked"])
+                        obfuscation.add(block["blocked"])
+
                     continue
 
                 deobfuscated = deobfuscated + 1
@@ -416,6 +422,11 @@ def fetch_blocks(args: argparse.Namespace) -> int:
                 logger.debug("row[]='%s'", type(row))
                 if row is None:
                     logger.warning("Cannot deobfuscate block[blocked]='%s',blocker='%s',software='%s' - SKIPPED!", block["blocked"], blocker, software)
+
+                    if not obfuscation.is_added(block["blocked"]):
+                        logger.debug("Invoking add(%s)", block["blocked"])
+                        obfuscation.add(block["blocked"])
+
                     continue
 
                 deobfuscated = deobfuscated + 1
@@ -1441,7 +1452,7 @@ def recheck_obfuscation(args: argparse.Namespace) -> int:
 
             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)
+                logger.debug("block[blocked]='%s' was deobfuscated to blocked='%s'", block["blocked"], blocked)
 
                 if blacklist.is_blacklisted(blocked):
                     logger.debug("blocked='%s' is blacklisted - SKIPPED!", blocked)
@@ -1452,6 +1463,9 @@ def recheck_obfuscation(args: argparse.Namespace) -> int:
                 elif blocks.is_instance_blocked(row["domain"], blocked):
                     logger.debug("blocked='%s' is already blocked by domain='%s' - SKIPPED!", blocked, row["domain"])
                     continue
+                elif obfuscation.is_added(block["blocked"]):
+                    logger.debug("Deleting deobfuscated pattern block[blocked]='%s' ...", block["blocked"])
+                    obfuscation.delete(block["blocked"])
 
                 logger.debug("block[block_level]='%s' - BEFORE!", block["block_level"])
                 block["block_level"] = blocks.alias_block_level(block["block_level"])
index f72332a49eccfe8e160b9e36aacb7b0282cbc3ce..bd24729b281dee5ab85b75669b88f8a8ec6bdcca 100644 (file)
@@ -17,5 +17,6 @@ __all__ = [
     'blocks',
     'error_log',
     'instances',
+    'obfuscation',
     'sources',
 ]
diff --git a/fba/models/obfuscation.py b/fba/models/obfuscation.py
new file mode 100644 (file)
index 0000000..cdbb19b
--- /dev/null
@@ -0,0 +1,70 @@
+# Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
+# Copyright (C) 2023 Free Software Foundation
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+import logging
+
+import time
+
+from fba import database
+
+logging.basicConfig(level=logging.INFO)
+logger = logging.getLogger(__name__)
+
+def is_added(pattern: str) -> bool:
+    logger.debug("pattern='%s' - CALLED!", pattern)
+    if not isinstance(pattern, str):
+        raise ValueError(f"pattern[]='{type(pattern)}' is not of type 'str'")
+    elif pattern == "":
+        raise ValueError("Parametern 'pattern' is an empty string")
+
+    database.cursor.execute("SELECT * FROM obfuscation WHERE pattern=? LIMIT 1", [pattern])
+
+    row = database.cursor.fetchone()
+    logger.debug("row[]='%s'", row)
+
+    added = (row is not None)
+
+    logger.debug("added='%s' - EXIT!", added)
+    return added
+
+def add(pattern: str) -> None:
+    logger.debug("pattern='%s' - CALLED!", pattern)
+    if not isinstance(pattern, str):
+        raise ValueError(f"pattern[]='{type(pattern)}' is not of type 'str'")
+    elif pattern == "":
+        raise ValueError("Parametern 'pattern' is an empty string")
+    elif is_added(pattern):
+        raise Exception(f"pattern='{pattern}' is already added but function was invoked")
+
+    database.cursor.execute("INSERT INTO obfuscation (pattern, added) VALUES (?, ?)", (
+        pattern,
+        time.time()
+    ))
+
+    logger.debug("EXIT!")
+
+def delete (pattern: str) -> None:
+    logger.debug("pattern='%s' - CALLED!", pattern)
+    if not isinstance(pattern, str):
+        raise ValueError(f"pattern[]='{type(pattern)}' is not of type 'str'")
+    elif pattern == "":
+        raise ValueError("Parametern 'pattern' is an empty string")
+    elif not is_added(pattern):
+        raise Exception(f"pattern='{pattern}' is not added but function was invoked")
+
+    database.cursor.execute("DELETE FROM obfuscation WHERE pattern=? LIMIT 1", [pattern])
+
+    logger.debug("EXIT!")