From: Roland Häder Date: Fri, 19 Apr 2024 23:41:39 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c7dda34b7626e556299bf86abd77d46f06611def;p=fba.git Continued: - recheck_obfuscation now supports deleting unwanted domains from both tables 'instances' and 'blocks' --- diff --git a/fba/boot.py b/fba/boot.py index d87ef4d..daccf4d 100644 --- a/fba/boot.py +++ b/fba/boot.py @@ -80,6 +80,7 @@ def init_parser(): parser.add_argument("--domain", help="Instance name (aka. domain)") parser.add_argument("--software", help="Name of software, e.g. 'lemmy'") parser.add_argument("--force", action="store_true", help="Include also already existing instances, otherwise only new are checked") + parser.add_argument("--delete-unwanted", action="store_true", help="Whether delete or keep (default) unwanted domains") ### Fetch blocks from registered instances or given ### parser = subparser_command.add_parser( diff --git a/fba/commands.py b/fba/commands.py index 87f9163..e770b1c 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -1326,8 +1326,15 @@ def recheck_obfuscation(args: argparse.Namespace) -> int: logger.info("Checking %d domains ...", len(rows)) for row in rows: logger.debug("Fetching peers from domain='%s',software='%s',nodeinfo_url='%s' ...", row["domain"], row["software"], row["nodeinfo_url"]) - if blacklist.is_blacklisted(row["domain"]): - logger.debug("row[domain]='%s' is blacklisted - SKIPPED!", row["domain"]) + if not domain_helper.is_wanted(row["domain"]): + logger.debug("row[domain]='%s' is not wanted - SKIPPED!", row["domain"]) + if args.delete_unwanted: + logger.info("Deleting unwanted row[domain]='%s' ...", row["domain"]) + instances.delete(row["domain"]) + blocks.delete(row["domain"]) + continue + elif blacklist.is_blacklisted(row["domain"]): + logger.warning("row[domain]='%s' is blacklisted - SKIPPED!", row["domain"]) continue elif (args.force is None or not args.force) and args.domain is None and args.software is None and instances.is_recent(row["domain"], "last_blocked"): logger.debug("row[domain]='%s' has recently been checked, args.force[]='%s' - SKIPPED!", row["domain"], type(args.force)) diff --git a/fba/models/blocks.py b/fba/models/blocks.py index 6782819..66424c3 100644 --- a/fba/models/blocks.py +++ b/fba/models/blocks.py @@ -272,3 +272,15 @@ def alias_block_level(block_level: str) -> str: logger.debug("block_level='%s' - EXIT!", block_level) return block_level + +def delete(domain: str): + logger.debug("domain='%s' - CALLED!", domain) + domain_helper.raise_on(domain) + + database.cursor.execute(f"DELETE FROM blocks WHERE blocker = ?", [domain]) + database.cursor.execute(f"DELETE FROM blocks WHERE blocked = ?", [domain]) + + logger.debug("Invoking commit() ...") + database.connection.commit() + + logger.debug("EXIT!") diff --git a/fba/models/instances.py b/fba/models/instances.py index 72c16ba..325be37 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -573,6 +573,17 @@ def valid(value: str, column: str) -> bool: logger.debug("is_valid='%s' - EXIT!", is_valid) return is_valid +def delete(domain: str): + logger.debug("domain='%s' - CALLED!", domain) + domain_helper.raise_on(domain) + + database.cursor.execute(f"DELETE FROM instances WHERE domain = ? LIMIT 1", [domain]) + + logger.debug("Invoking commit() ...") + database.connection.commit() + + logger.debug("EXIT!") + def translate_idnas(rows: list, column: str): logger.debug("rows[]='%s' - CALLED!", type(rows))