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"],
"blocked" : blocked,
"reference" : reference,
"software" : software,
- "scores" : scores.json()
+ "scores" : res.json()
})
@app.get(fba.config["base_url"] + "/")
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()
# 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
])
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)
# 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