From b6ae1fdd9ccf33ca2f449fe7e22eb7f30e6fba14 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Jun 2023 20:34:58 +0200 Subject: [PATCH] Continued: - imported needed module fba.helpers.cookies - some nodeinfo may return blacklisted or invalid domains, let's skip them here --- fba/commands.py | 3 ++- fba/federation.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/fba/commands.py b/fba/commands.py index 190a92d..ddeb8ec 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -32,6 +32,7 @@ from fba import federation from fba import fba from fba import network +from fba.helpers import cookies from fba.helpers import locking from fba.helpers import tidyup @@ -177,7 +178,7 @@ def fetch_blocks(args: argparse.Namespace): print("WARNING: blocker is now empty!") continue elif nodeinfo_url is None or nodeinfo_url == "": - print(f"DEBUG: blocker='{blocker}',software='{software}' has empty nodeinfo_url") + # DEBUG: print(f"DEBUG: blocker='{blocker}',software='{software}' has empty nodeinfo_url") continue elif blacklist.is_blacklisted(blocker): print(f"WARNING: blocker='{blocker}' is blacklisted now!") diff --git a/fba/federation.py b/fba/federation.py index e583949..c9d9592 100644 --- a/fba/federation.py +++ b/fba/federation.py @@ -77,9 +77,6 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path: raise ValueError(f"Parameter command[]='{type(command)}' is not 'str'") elif command == "": raise ValueError("Parameter 'command' is empty") - elif domain.endswith(".arpa"): - print(f"WARNING: domain='{domain}' is a reversed .arpa domain and should not be used generally.") - return elif not validators.domain(domain.split("/")[0]): raise ValueError(f"domain='{domain}' is not a valid domain") elif domain.endswith(".arpa"): @@ -127,11 +124,6 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path: elif blacklist.is_blacklisted(instance): # DEBUG: print("DEBUG: instance is blacklisted:", instance) continue - - # DEBUG: print("DEBUG: Handling instance:", instance) - if instance.endswith(".arpa"): - print(f"WARNING: instance='{instance}' is a reversed .arpa domain and should not be used generally.") - continue elif instance.find("/profile/") > 0 or instance.find("/users/") > 0: # DEBUG: print(f"DEBUG: instance='{instance}' is a link to a single user profile - SKIPPED!") continue @@ -354,6 +346,14 @@ def fetch_wellknown_nodeinfo(domain: str) -> dict: if components.scheme == "" and components.netloc == "": # DEBUG: print(f"DEBUG: link[href]='{link['href']}' has no scheme and host name in it, prepending from domain='{domain}'") url = f"https://{domain}{url}" + components = urlparse(url) + + if blacklist.is_blacklisted(components.netloc): + print(f"WARNING: components.netloc='{components.netloc}' is blacklisted - SKIPPED!") + continue + elif not validators.domain(components.netloc): + print(f"WARNING: components.netloc='{components.netloc}' is not a valid domain - SKIPPED!") + continue # DEBUG: print("DEBUG: Fetching nodeinfo from:", url) data = network.fetch_api_url( -- 2.39.5