From: Roland Häder Date: Sat, 7 Dec 2024 05:24:02 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=65ee940b8a4d304af6953cd1c016ff4ec7d1d822;p=fba.git Continued: - full-stop (dot) no longer at end of exception messages - added column last_requested_path to 'instances' table --- diff --git a/blocks_empty.db b/blocks_empty.db index d36e78c..716df99 100644 Binary files a/blocks_empty.db and b/blocks_empty.db differ diff --git a/fba/helpers/blacklist.py b/fba/helpers/blacklist.py index 5f41ff9..723bf65 100644 --- a/fba/helpers/blacklist.py +++ b/fba/helpers/blacklist.py @@ -78,6 +78,7 @@ _blacklist = { "reverse.open-telekom-cloud.com" : "Please get yourself a proper domain name, no static-IP host names", "static.sl-reverse.messenger.com": "Please get yourself a proper domain name, no static-IP host names", "documentation.on.seirdy.one" : "Just ignore such lines!", + "drankdrankdrank" : "Mass flooding of instances", } @lru_cache diff --git a/fba/http/csrf.py b/fba/http/csrf.py index bf2648e..d85445b 100644 --- a/fba/http/csrf.py +++ b/fba/http/csrf.py @@ -38,7 +38,7 @@ def determine(domain: str, headers: dict) -> dict: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not isinstance(headers, dict): raise ValueError(f"Parameter headers[]='{type(headers)}' is not of type 'dict'") diff --git a/fba/http/federation.py b/fba/http/federation.py index 66145a3..9cddbc2 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -621,7 +621,7 @@ def fetch_blocks(domain: str) -> list: if blacklist.is_blacklisted(domain): raise Exception(f"domain='{domain}' is blacklisted but function was invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") # Init block list blocklist = list() diff --git a/fba/http/network.py b/fba/http/network.py index ec020c3..227e76f 100644 --- a/fba/http/network.py +++ b/fba/http/network.py @@ -99,6 +99,7 @@ def post_json_api(domain: str, path: str, data: str = "", headers: dict = dict() response_time = time.perf_counter() - start logger.debug("response_time=%s", response_time) + instances.set_last_requested_path(domain, path) instances.set_last_response_time(domain, response_time) logger.debug("response.ok='%s',response.status_code=%d,response.reason='%s',response_time=%s", response.ok, response.status_code, response.reason, response_time) @@ -306,7 +307,8 @@ def fetch_response(domain: str, path: str, headers: dict, timeout: tuple, allow_ allow_redirects=allow_redirects ) response_time = time.perf_counter() - start - logger.debug("Setting response_time=%s for domain='%s' ...", response_time, domain) + logger.debug("Setting response_time=%s,path='%s' for domain='%s' ...", response_time, path, domain) + instances.set_last_requested_path(domain, path) instances.set_last_response_time(domain, response_time) logger.debug("response.ok='%s',response.status_code=%d,response.reason='%s',response_time=%s", response.ok, response.status_code, response.reason, response_time) @@ -315,7 +317,8 @@ def fetch_response(domain: str, path: str, headers: dict, timeout: tuple, allow_ instances.set_last_error(domain, exception) response_time = time.perf_counter() - start - logger.debug("Setting response_time=%s for domain='%s' ...", response_time, domain) + logger.debug("Setting response_time=%s,path='%s' for domain='%s' ...", response_time, path, domain) + instances.set_last_requested_path(domain, path) instances.set_last_response_time(domain, response_time) raise exception diff --git a/fba/models/instances.py b/fba/models/instances.py index 7de40c6..9c0c1ba 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -64,6 +64,8 @@ _pending = { "last_nodeinfo" : {}, # Last response time "last_response_time" : {}, + # Last requested path + "last_requested_path": {}, # Last status code "last_status_code" : {}, # Last error details @@ -101,7 +103,7 @@ def has_pending(domain: str) -> bool: domain_helper.raise_on(domain) if not is_registered(domain): - raise ValueError(f"domain='{domain}' is not registered but function was invoked.") + raise ValueError(f"domain='{domain}' is not registered but function was invoked") elif blacklist.is_blacklisted(domain): raise Exception(f"domain='{domain}' is blacklisted but function has been invoked") @@ -442,6 +444,21 @@ def set_last_response_time(domain: str, response_time: float) -> None: _set_data("last_response_time", domain, response_time) logger.debug("EXIT!") +def set_last_requested_path(domain: str, path: float) -> None: + logger.debug("domain='%s',path=%d - CALLED!", domain, path) + domain_helper.raise_on(domain) + + if not isinstance(path, str): + raise ValueError(f"path[]='{type(path)}' is not of type 'str'") + elif path == "": + raise ValueError(f"path='{path}' is an empty string") + elif not path.startswith("/"): + raise ValueError(f"path='{path}' does not start with '/'") + + # Set timestamp + _set_data("last_requested_path", domain, path) + logger.debug("EXIT!") + def set_total_peers(domain: str, peers: list) -> None: logger.debug("domain='%s',peers()=%d - CALLED!", domain, len(peers)) domain_helper.raise_on(domain) diff --git a/fba/networks/friendica.py b/fba/networks/friendica.py index 47a2475..abcda4c 100644 --- a/fba/networks/friendica.py +++ b/fba/networks/friendica.py @@ -36,9 +36,9 @@ def fetch_blocks(domain: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") blocklist = list() block_tag = None diff --git a/fba/networks/lemmy.py b/fba/networks/lemmy.py index c97932f..785e5b7 100644 --- a/fba/networks/lemmy.py +++ b/fba/networks/lemmy.py @@ -73,9 +73,9 @@ def fetch_peers(domain: str, origin: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") peers = list() @@ -131,9 +131,9 @@ def fetch_blocks(domain: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") blocklist = list() @@ -244,7 +244,7 @@ def fetch_instances(domain: str, origin: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") peers = list() diff --git a/fba/networks/mastodon.py b/fba/networks/mastodon.py index 4f2af7b..dddc7dd 100644 --- a/fba/networks/mastodon.py +++ b/fba/networks/mastodon.py @@ -65,9 +65,9 @@ def fetch_blocks_from_about(domain: str) -> dict: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") # Init variables doc = None @@ -162,9 +162,9 @@ def fetch_blocks(domain: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") # Init variables blocklist = list() diff --git a/fba/networks/misskey.py b/fba/networks/misskey.py index cf8849d..dcaf1d5 100644 --- a/fba/networks/misskey.py +++ b/fba/networks/misskey.py @@ -36,9 +36,9 @@ def fetch_peers(domain: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") logger.debug("domain='%s' is misskey, sending API POST request ...", domain) peers = list() @@ -135,9 +135,9 @@ def fetch_blocks(domain: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") # No CSRF by default, you don't have to add network.api_headers by yourself here headers = tuple() diff --git a/fba/networks/peertube.py b/fba/networks/peertube.py index 80437a1..63123b3 100644 --- a/fba/networks/peertube.py +++ b/fba/networks/peertube.py @@ -33,9 +33,9 @@ def fetch_peers(domain: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") # Init variables peers = list() diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index c3d6322..ba6f5e4 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -57,9 +57,9 @@ def fetch_blocks(domain: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") # Init variables blockdict = list() @@ -288,9 +288,9 @@ def fetch_blocks_from_about(domain: str) -> dict: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") # Init variables doc = None diff --git a/templates/views/infos.html b/templates/views/infos.html index 776c6f5..91c7d16 100644 --- a/templates/views/infos.html +++ b/templates/views/infos.html @@ -96,6 +96,11 @@ {{'%0.2f'|format(instance['last_response_time']|float)}} + + Last requested path: + {% if instance['last_requested_path']%}{{instance['last_requested_path']}}{%else%}-{%endif%} + + Obfuscated blocks: {{instance['obfuscated_blocks']}}