From 1479fe02650cc937cc81e039c66d882aad6a82da Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 15 Aug 2023 22:09:54 +0200 Subject: [PATCH] Continued: - use validators.hostname() as these are host names --- fba/commands.py | 12 ++++++------ fba/helpers/domain.py | 4 ++-- fba/http/federation.py | 2 +- fba/models/instances.py | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fba/commands.py b/fba/commands.py index 9d37cb7..9dea3f8 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -64,7 +64,7 @@ logger = logging.getLogger(__name__) def check_instance(args: argparse.Namespace) -> int: logger.debug("args.domain='%s' - CALLED!", args.domain) status = 0 - if not validators.domain(args.domain): + if not validators.hostname(args.domain): logger.warning("args.domain='%s' is not valid", args.domain) status = 100 elif blacklist.is_blacklisted(args.domain): @@ -266,7 +266,7 @@ def fetch_blocks(args: argparse.Namespace) -> int: logger.debug("args[]='%s' - CALLED!", type(args)) if args.domain is not None and args.domain != "": logger.debug("args.domain='%s' - checking ...", args.domain) - if not validators.domain(args.domain): + if not validators.hostname(args.domain): logger.warning("args.domain='%s' is not valid.", args.domain) return 100 elif blacklist.is_blacklisted(args.domain): @@ -914,7 +914,7 @@ def fetch_instances(args: argparse.Namespace) -> int: logger.debug("args[]='%s' - CALLED!", type(args)) logger.debug("args.domain='%s' - checking ...", args.domain) - if not validators.domain(args.domain): + if not validators.hostname(args.domain): logger.warning("args.domain='%s' is not valid.", args.domain) return 100 elif blacklist.is_blacklisted(args.domain): @@ -1065,7 +1065,7 @@ def fetch_oliphant(args: argparse.Namespace) -> int: domain = utils.deobfuscate(domain, block["blocker"]) logger.debug("domain='%s' - AFTER!", domain) - if not validators.domain(domain): + if not validators.hostname(domain): logger.debug("domain='%s' is not a valid domain - SKIPPED!") continue elif blacklist.is_blacklisted(domain): @@ -1371,7 +1371,7 @@ def fetch_joinfediverse(args: argparse.Namespace) -> int: if not isinstance(text, str): logger.debug("text[]='%s' is not of type 'str' - SKIPPED!", type(text)) continue - elif validators.domain(text.strip()): + elif validators.hostname(text.strip()): logger.debug("text='%s' is a domain - SKIPPED!", text.strip()) continue @@ -1506,7 +1506,7 @@ def recheck_obfuscation(args: argparse.Namespace) -> int: if isinstance(args.domain, str) and args.domain != "" and domain_helper.is_wanted(args.domain): database.cursor.execute("SELECT domain, software, nodeinfo_url FROM instances WHERE has_obfuscation = 1 AND domain = ?", [args.domain]) - elif isinstance(args.software, str) and args.software != "" and validators.domain(args.software) == args.software: + elif isinstance(args.software, str) and args.software != "" and validators.hostname(args.software) == args.software: database.cursor.execute("SELECT domain, software, nodeinfo_url FROM instances WHERE has_obfuscation = 1 AND software = ?", [args.software]) else: database.cursor.execute("SELECT domain, software, nodeinfo_url FROM instances WHERE has_obfuscation = 1") diff --git a/fba/helpers/domain.py b/fba/helpers/domain.py index 96aa189..6804b3a 100644 --- a/fba/helpers/domain.py +++ b/fba/helpers/domain.py @@ -35,7 +35,7 @@ def raise_on(domain: str): raise ValueError("Parameter 'domain' is empty") elif domain.lower() != domain: raise ValueError(f"Parameter domain='{domain}' must be all lower-case") - elif not validators.domain(domain.split("/")[0]): + elif not validators.hostname(domain.split("/")[0]): raise ValueError(f"domain='{domain}' is not a valid domain") elif domain.endswith(".arpa"): raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!") @@ -75,7 +75,7 @@ def is_wanted(domain: str) -> bool: raise ValueError("Parameter 'domain' is empty") elif domain.lower() != domain: wanted = False - elif not validators.domain(domain.split("/")[0]): + elif not validators.hostname(domain.split("/")[0]): logger.debug("domain='%s' is not a valid domain name - setting False ...", domain) wanted = False elif domain.endswith(".arpa"): diff --git a/fba/http/federation.py b/fba/http/federation.py index c5b4cf7..ff831e5 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -476,7 +476,7 @@ def find_domains(tag: bs4.element.Tag) -> list: "reason": reason, }) continue - elif not validators.domain(domain.split("/")[0]): + elif not validators.hostname(domain.split("/")[0]): logger.warning("domain='%s' is not a valid domain - SKIPPED!", domain) continue diff --git a/fba/models/instances.py b/fba/models/instances.py index 1bd2884..5a801b0 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -174,7 +174,7 @@ def add(domain: str, origin: str, command: str, path: str = None, software: str raise ValueError(f"software[]='{type(software)}' is not of type 'str'") elif software == "": raise ValueError("Parameter 'software' is empty") - elif origin is not None and not validators.domain(origin.split("/")[0]): + elif origin is not None and not validators.hostname(origin.split("/")[0]): raise ValueError(f"Bad origin name='{origin}'") elif blacklist.is_blacklisted(domain): raise Exception(f"domain='{domain}' is blacklisted, but function invoked") -- 2.39.5