From: Roland Häder Date: Wed, 29 Nov 2023 15:02:46 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=07c389d73b29703094af20625c9cccaabe0f37b7;p=fba.git Continued: - nodeinfo_url is not always a path only, better don't handle it over - check if parameter 'path' starts with a slash if not 'None' --- diff --git a/fba/commands.py b/fba/commands.py index 3b890ad..f24a888 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -254,7 +254,7 @@ def fetch_bkali(args: argparse.Namespace) -> int: try: logger.info("Fetching instances from domain='%s' ...", domain) - federation.fetch_instances(domain, 'tak.teleyal.blog', None, inspect.currentframe().f_code.co_name) + federation.fetch_instances(domain, "tak.teleyal.blog", None, inspect.currentframe().f_code.co_name) except network.exceptions as exception: logger.warning("Exception '%s' during fetching instances (fetch_bkali) from domain='%s'", type(exception), domain) instances.set_last_error(domain, exception) @@ -977,7 +977,7 @@ def fetch_instances(args: argparse.Namespace) -> int: # Loop through some instances database.cursor.execute( - "SELECT domain, origin, software, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'lemmy', 'peertube', 'takahe', 'gotosocial', 'brighteon', 'wildebeest', 'bookwyrm', 'mitra', 'areionskey', 'mammuthus', 'neodb') AND (last_instance_fetch IS NULL OR last_instance_fetch < ?) ORDER BY total_peers DESC, last_response_time ASC, last_updated ASC", [time.time() - config.get("recheck_instance")] + "SELECT domain, origin, software FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'lemmy', 'peertube', 'takahe', 'gotosocial', 'brighteon', 'wildebeest', 'bookwyrm', 'mitra', 'areionskey', 'mammuthus', 'neodb') AND (last_instance_fetch IS NULL OR last_instance_fetch < ?) ORDER BY total_peers DESC, last_response_time ASC, last_updated ASC", [time.time() - config.get("recheck_instance")] ) rows = database.cursor.fetchall() @@ -997,8 +997,8 @@ def fetch_instances(args: argparse.Namespace) -> int: continue try: - logger.info("Fetching instances for domain='%s',origin='%s',software='%s',nodeinfo_url='%s'", domain, row["origin"], row["software"], row["nodeinfo_url"]) - federation.fetch_instances(domain, row["origin"], row["software"], inspect.currentframe().f_code.co_name, row["nodeinfo_url"]) + logger.info("Fetching instances for domain='%s',origin='%s',software='%s' ...", domain, row["origin"], row["software"]) + federation.fetch_instances(domain, row["origin"], row["software"], inspect.currentframe().f_code.co_name) except network.exceptions as exception: logger.warning("Exception '%s' during fetching instances (fetch_instances) from domain='%s'", type(exception), domain) instances.set_last_error(domain, exception) diff --git a/fba/http/federation.py b/fba/http/federation.py index a821d23..a6af37e 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -69,6 +69,8 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path: raise ValueError(f"Parameter command='{command}' but origin is None, please fix invoking this function.") elif not isinstance(path, str) and path is not None: raise ValueError(f"Parameter path[]='{type(path)}' is not of type 'str'") + elif path is not None and not path.startswith("/"): + raise ValueError(f"path='{path}' does not start with a slash") elif _DEPTH > 0 and instances.is_recent(domain, "last_instance_fetch"): raise ValueError(f"domain='{domain}' has recently been fetched but function was invoked") elif software is None and not instances.is_recent(domain, "last_nodeinfo"): @@ -387,6 +389,8 @@ def determine_software(domain: str, path: str = None) -> str: raise Exception(f"domain='{domain}' is blacklisted but function was invoked") elif not isinstance(path, str) and path is not None: raise ValueError(f"Parameter path[]='{type(path)}' is not of type 'str'") + elif path is not None and not path.startswith("/"): + raise ValueError(f"path='{path}' does not start with a slash") logger.debug("Fetching nodeinfo from domain='%s',path='%s' ...", domain, path) data = nodeinfo.fetch(domain, path) diff --git a/fba/http/nodeinfo.py b/fba/http/nodeinfo.py index 34f912e..f66afd2 100644 --- a/fba/http/nodeinfo.py +++ b/fba/http/nodeinfo.py @@ -60,6 +60,8 @@ def fetch(domain: str, path: str = None, update_mode: bool = True) -> dict: raise Exception(f"domain='{domain}' is blacklisted but function was invoked") elif not isinstance(path, str) and path is not None: raise ValueError(f"Parameter path[]='{type(path)}' is not of type 'str'") + elif path is not None and not path.startswith("/"): + raise ValueError(f"path='{path}' does not start with a slash") elif not isinstance(update_mode, bool) and update_mode is not None: raise ValueError(f"Parameter update_mode[]='{type(update_mode)}' is not of type 'bool'") diff --git a/fba/models/instances.py b/fba/models/instances.py index 3195274..64873d5 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -210,7 +210,7 @@ def add(domain: str, origin: str, command: str, path: str = None, software: str logger.warning("domain='%s' already registered after cutting off user part. - EXIT!", domain) return - logger.info("Adding instance domain='%s',origin='%s',software='%s',command='%s'", domain, origin, software, command) + logger.info("Adding instance domain='%s',origin='%s',software='%s',command='%s' ...", domain, origin, software, command) database.cursor.execute( "INSERT INTO instances (domain, origin, command, hash, software, first_seen) VALUES (?, ?, ?, ?, ?, ?)", (