From 8640bbafd6086002081676c9beec7afd1b69dc97 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 22 Jun 2023 18:03:49 +0200 Subject: [PATCH] Continued: - need to set has_obsfucation = False first, then later when obsfucated domains are found set it to True - only find entries with has_obsfucation=1 --- api.py | 4 ++-- fba/commands.py | 1 + fba/models/instances.py | 2 +- fba/utils.py | 7 +++++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api.py b/api.py index 2d3bbe1..3c03c6f 100644 --- a/api.py +++ b/api.py @@ -70,9 +70,9 @@ def api_scoreboard(mode: str, amount: int): elif mode == "error_code": database.cursor.execute("SELECT last_status_code, COUNT(domain) AS score FROM instances WHERE last_status_code IS NOT NULL AND last_status_code != '200' GROUP BY last_status_code ORDER BY score DESC LIMIT ?", [amount]) elif mode == "avg_peers": - database.cursor.execute("SELECT software, AVG(total_peers) AS sum FROM instances WHERE software IS NOT NULL GROUP BY software HAVING sum>0 ORDER BY sum DESC LIMIT ?", [amount]) + database.cursor.execute("SELECT software, AVG(total_peers) AS average FROM instances WHERE software IS NOT NULL GROUP BY software HAVING average>0 ORDER BY average DESC LIMIT ?", [amount]) elif mode == "obsfucator": - database.cursor.execute("SELECT software, COUNT(domain) AS cnt FROM instances WHERE has_obsfucation IS NOT NULL GROUP BY software ORDER BY cnt DESC LIMIT ?", [amount]) + database.cursor.execute("SELECT software, COUNT(domain) AS cnt FROM instances WHERE has_obsfucation = 1 GROUP BY software ORDER BY cnt DESC LIMIT ?", [amount]) else: raise HTTPException(status_code=400, detail="No filter specified") diff --git a/fba/commands.py b/fba/commands.py index f388f57..5070aa4 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -187,6 +187,7 @@ def fetch_blocks(args: argparse.Namespace): logger.debug(f"blocker='{blocker}'") instances.set_last_blocked(blocker) + instances.set_has_obsfucation(blocker, False) if software == "pleroma": logger.info("blocker='%s',software='%s'", blocker, software) diff --git a/fba/models/instances.py b/fba/models/instances.py index 2632f41..aa7039a 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -387,7 +387,7 @@ def set_detection_mode(domain: str, mode: str): logger.debug("EXIT!") def set_has_obsfucation(domain: str, status: bool): - logger.debug("domain(%d)='%s',status='%s' - CALLED!", len(domain), domain) + logger.debug("domain(%d)='%s',status='%s' - CALLED!", len(domain), domain, status) domain_helper.raise_on(domain) if not isinstance(status, bool): diff --git a/fba/utils.py b/fba/utils.py index a0ee299..e7056c8 100644 --- a/fba/utils.py +++ b/fba/utils.py @@ -109,6 +109,13 @@ def process_domain(domain: str, blocker: str, command: str) -> bool: logger.debug(f"domain='{domain}' de-obscured to '{row[0]}'") domain = row[0] + else: + logger.debug("blocker='%s' has NO obsfucation on their block list", blocker) + instances.set_has_obsfucation(blocker, False) + + if instances.has_pending(blocker): + logger.debug("Invoking instances.update_data(%s) ...", blocker) + instances.update_data(blocker) if not is_domain_wanted(domain): logger.debug("domain='%s' is not wanted - SKIPPED!", domain) -- 2.39.5