From 3f72e05d2e3c87dfba70f0eaa862032ecf5b0c6f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 12 Sep 2023 12:10:42 +0200 Subject: [PATCH] Continued: - if later more "hidden" blocklists are added --domain=foo can only process foo's blocklist --- fba/boot.py | 1 + fba/commands.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/fba/boot.py b/fba/boot.py index a2941ab..d7dbb2f 100644 --- a/fba/boot.py +++ b/fba/boot.py @@ -129,6 +129,7 @@ def init_parser(): help="Fetches CSV files (block recommendations) for more possible instances to disover", ) parser.set_defaults(command=commands.fetch_csv) + parser.add_argument("--domain", help="Instance name (aka. domain) to check") ### Fetch instances from given initial instance ### parser = subparser_command.add_parser( diff --git a/fba/commands.py b/fba/commands.py index b88fde6..f62de80 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -1002,6 +1002,13 @@ def fetch_csv(args: argparse.Namespace) -> int: logger.info("Checking %d CSV files ...", len(blocklists.csv_files)) for block in blocklists.csv_files: logger.debug("block[blocker]='%s',block[csv_url]='%s'", block["blocker"], block["csv_url"]) + + # Is domain given and not equal blocker? + if isinstance(args.domain, str) and args.domain != block["blocker"]: + logger.debug("Skipping blocker='%s', not matching args.domain='%s'", block["blocker"], args.domain) + continue + + logger.debug("Invoking processing.csv_block(%s, %s, fetch_csv) ...", block["blocker"], block["csv_url"]) processing.csv_block(block["blocker"], block["csv_url"], inspect.currentframe().f_code.co_name) logger.debug("Success - EXIT!") @@ -1031,7 +1038,10 @@ def fetch_oliphant(args: argparse.Namespace) -> int: logger.debug("Skipping blocker='%s', not matching args.domain='%s'", block["blocker"], args.domain) continue - processing.csv_block(block["blocker"], f"{base_url}/{block['csv_url']}", inspect.currentframe().f_code.co_name) + url = f"{base_url}/{block['csv_url']}" + + logger.debug("Invoking processing.csv_block(%s, %s, fetch_oliphant) ...", block["blocker"], url) + processing.csv_block(block["blocker"], url, inspect.currentframe().f_code.co_name) logger.debug("Success! - EXIT!") return 0 -- 2.39.5