Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 7 Dec 2024 05:24:02 +0000 (06:24 +0100)
committerRoland Häder <roland@mxchange.org>
Sat, 7 Dec 2024 05:24:02 +0000 (06:24 +0100)
- full-stop (dot) no longer at end of exception messages
- added column last_requested_path to 'instances' table

13 files changed:
blocks_empty.db
fba/helpers/blacklist.py
fba/http/csrf.py
fba/http/federation.py
fba/http/network.py
fba/models/instances.py
fba/networks/friendica.py
fba/networks/lemmy.py
fba/networks/mastodon.py
fba/networks/misskey.py
fba/networks/peertube.py
fba/networks/pleroma.py
templates/views/infos.html

index d36e78c6ff3fbe6ae1adbc06c57b9d8fcc2895cd..716df9923b70e41700066e566a0d6922a9c412ed 100644 (file)
Binary files a/blocks_empty.db and b/blocks_empty.db differ
index 5f41ff9bf15c366157088c0be4e20db3a729f70f..723bf65257280dbeb64f5e10fccce429a7965dc4 100644 (file)
@@ -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
index bf2648e56fcadf08511b40ae02dd67f0d5bc9dba..d85445bfec98ce35f13a6e06f358e8231923281a 100644 (file)
@@ -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'")
 
index 66145a319d764b35b815b2f3e09ae96d1bb2f8c9..9cddbc2441deccec34f577e5080d56569f828bbf 100644 (file)
@@ -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()
index ec020c36f17be9026338e3917f2dc01c7d978b5d..227e76fbe6ae2f7f579ff2532fd9c4c509b4bbd3 100644 (file)
@@ -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
index 7de40c670e3af8ba2f9aebafbc5ba027b65c4ab7..9c0c1bad80012020be080a5e77f3095a418fc5ca 100644 (file)
@@ -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)
index 47a247555374b3c4d48d001575db76ef0e3d20c5..abcda4c9f5f36b2234d0cc4d7fd6931bd7dcb07c 100644 (file)
@@ -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
index c97932f55a05085a712a87d125ee2c19c6e1ae34..785e5b7b9dbc8d77eb9be617539a4f75b646f14e 100644 (file)
@@ -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()
 
index 4f2af7b1dec75da92283262d00c2dde34d8da552..dddc7dd935c08cd73fcd10a7e4479887f6c1f1a8 100644 (file)
@@ -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()
index cf8849d07e2ab1f936296e012792f9fe34f05059..dcaf1d5b636aacb45c6a5bbbba54486f60e3b378 100644 (file)
@@ -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()
index 80437a1d48617340e919b85e7fb25a0e1b250807..63123b3558f840a1ce46c4cde6a1ac642810141d 100644 (file)
@@ -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()
index c3d63227a2e6ee3a276b7612bf2038c5d815bdb1..ba6f5e40f8fd64d5a2619e36f00dac7be1084b01 100644 (file)
@@ -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
index 776c6f50904166bd68701dd26eda4ab4752eda59..91c7d1699e9dc22576fd13fbf83d450db02775c2 100644 (file)
         <td>{{'%0.2f'|format(instance['last_response_time']|float)}}</td>
     </tr>
 
+    <tr>
+        <td>Last requested path:</td>
+        <td>{% if instance['last_requested_path']%}{{instance['last_requested_path']}}{%else%}-{%endif%}</td>
+    </tr>
+
     <tr>
         <td>Obfuscated blocks:</td>
         <td>{{instance['obfuscated_blocks']}}</td>