]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 21 May 2023 14:31:43 +0000 (16:31 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 21 May 2023 14:31:43 +0000 (16:31 +0200)
- also log last detailed error message
- introduced fba.is_blacklisted()

api.py
blocks_empty.db
fba.py
fetch_instances.py

diff --git a/api.py b/api.py
index f0e11ef8f0b8ec0249c1f50b1573835e49560c0a..e595f6195927c42bae00d16ad4b7c618bc148f6e 100644 (file)
--- a/api.py
+++ b/api.py
@@ -94,20 +94,20 @@ def index(request: Request, blockers: int = None, blocked: int = None, reference
     scores = None
 
     if blockers != None and blockers > 0:
-        scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blockers={blockers}")
+        res = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blockers={blockers}")
     elif blocked != None and blocked > 0:
-        scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blocked={blocked}")
+        res = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blocked={blocked}")
     elif reference != None and reference > 0:
-        scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?reference={reference}")
+        res = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?reference={reference}")
     elif software != None and software > 0:
-        scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?software={software}")
+        res = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?software={software}")
     else:
         raise HTTPException(status_code=400, detail="No filter specified")
 
-    if scores == None:
+    if res == None:
         raise HTTPException(status_code=500, detail="Could not determine scores")
-    elif not scores.ok:
-        raise HTTPException(status_code=scores.status_code, detail=scores.text)
+    elif not res.ok:
+        raise HTTPException(status_code=res.status_code, detail=res.text)
 
     return templates.TemplateResponse("index.html", {
         "base_url"  : fba.config["base_url"],
@@ -117,7 +117,7 @@ def index(request: Request, blockers: int = None, blocked: int = None, reference
         "blocked"   : blocked,
         "reference" : reference,
         "software"  : software,
-        "scores"    : scores.json()
+        "scores"    : res.json()
     })
 
 @app.get(fba.config["base_url"] + "/")
index bcb93703d52078ccf7038842654a614701d92c94..0832008ed05aaa9e89c0d6b540f1e8db3b2bd13c 100644 (file)
Binary files a/blocks_empty.db and b/blocks_empty.db differ
diff --git a/fba.py b/fba.py
index 0d467b05cb6363ff92168c5ae07d90af253e91c6..93a5de867ef99b8c5b889e432541d834bb05c62a 100644 (file)
--- a/fba.py
+++ b/fba.py
@@ -27,6 +27,17 @@ headers = {
 conn = sqlite3.connect("blocks.db")
 c = conn.cursor()
 
+def is_blacklisted(domain: str) -> bool:
+    # NOISY-DEBUG: print("DEBUG: Checking blacklist for domain:", domain)
+    blacklisted = False
+    for peer in blacklist:
+        # NOISY-DEBUG: print("DEBUG: domain,peer:", domain, peer)
+        if peer in domain:
+            blacklisted = True
+
+    # NOISY-DEBUG: print("DEBUG: blacklisted:", blacklisted)
+    return blacklisted
+
 def get_hash(domain: str) -> str:
     # NOISY-DEBUG: print("DEBUG: Calculating hash for domain:", domain)
     return sha256(domain.encode("utf-8")).hexdigest()
@@ -49,8 +60,9 @@ def update_last_error(domain: str, res: any):
     # NOISY-DEBUG: print("DEBUG: domain,res.status_code", domain, res.status_code)
 
     try:
-        c.execute("UPDATE instances SET last_status_code = ?, last_updated = ? WHERE domain = ?", [
+        c.execute("UPDATE instances SET last_status_code = ?, last_error_details = ?, last_updated = ? WHERE domain = ?", [
             res.status_code,
+            res.text,
             time.time(),
             domain
         ])
index 3a2733847c570b859eb129f586296067098d2a86..428533692764f8efeb96fc92861cae487ebfb3fe 100644 (file)
@@ -23,17 +23,13 @@ def fetch_instances(domain: str, origin: str):
     print(f"INFO: Checking {len(peerlist)} instances from {domain} ...")
     for instance in peerlist:
         instance = instance.lower()
+
         if instance.find("@") > 0:
             print("WARNING: Bad instance name,domain:", instance, domain)
             continue
 
-        blacklisted = False
-        for peer in fba.blacklist:
-            if peer in instance:
-                blacklisted = True
-
-        if blacklisted:
-            # NOISY-DEBUG: print("DEBUG: domain is blacklisted:", domain)
+        if fba.is_blacklisted(instance):
+            # NOISY-DEBUG: print("DEBUG: instance is blacklisted:", instance)
             continue
 
         # NOISY-DEBUG: print("DEBUG: Handling instance:", instance)
@@ -59,16 +55,11 @@ fetch_instances(instance, None)
 
 # Loop through some instances
 fba.c.execute(
-    "SELECT domain FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial') AND (last_nodeinfo IS NULL OR last_nodeinfo < ?) ORDER BY rowid DESC", [time.time() - fba.config["recheck_instance"]]
+    "SELECT domain FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial') AND (software IS NULL OR last_nodeinfo IS NULL OR last_nodeinfo < ?) ORDER BY rowid DESC", [time.time() - fba.config["recheck_instance"]]
 )
 
 for instance in fba.c.fetchall():
-    blacklisted = False
-    for domain in fba.blacklist:
-        if domain in instance[0]:
-            blacklisted = True
-
-    if blacklisted:
+    if fba.is_blacklisted(instance[0]):
         # NOISY-DEBUG: print("DEBUG: domain is blacklisted:", instance)
         continue