print(f"ERROR: failed SQL query: domain='{domain}',sql='{sql}',exception='{e}'")
sys.exit(255)
- # NOISY-DEBUG: # NOISY-DEBUG: print("DEBUG: Deleting nodeinfos for domain:", domain)
+ # NOISY-DEBUG: print("DEBUG: Deleting nodeinfos for domain:", domain)
for key in nodeinfos:
try:
# NOISY-DEBUG: print("DEBUG: Deleting key:", key)
# NOISY-DEBUG: print("DEBUG: EXIT!")
def update_last_error(domain: str, res: any):
- # NOISY-DEBUG: print("DEBUG: domain,res.status_code:", domain, res.status_code, res.reason)
+ # NOISY-DEBUG: print("DEBUG: domain,res[]:", domain, type(res))
try:
- # NOISY-DEBUG: print("DEBUG: res[]:", type(res))
- if isinstance(res, BaseException):
+ # NOISY-DEBUG: print("DEBUG: BEFORE res[]:", type(res))
+ if isinstance(res, BaseException) or isinstance(res, json.JSONDecodeError):
res = str(res)
+ # NOISY-DEBUG: print("DEBUG: AFTER res[]:", type(res))
if type(res) is str:
cursor.execute("UPDATE instances SET last_status_code = 999, last_error_details = ?, last_updated = ? WHERE domain = ? LIMIT 1", [
res,
connection.commit()
# NOISY-DEBUG: print("DEBUG: EXIT!")
-def get_peers(domain: str) -> list:
- # NOISY-DEBUG: print("DEBUG: Getting peers for domain:", domain)
+def get_peers(domain: str, software: str) -> list:
+ # NOISY-DEBUG: print("DEBUG: Getting peers for domain:", domain, software)
peers = None
+ if software == "lemmy":
+ # NOISY-DEBUG: print(f"DEBUG: domain='{domain}' is Lemmy. fetching JSON ...")
+ try:
+ res = reqto.get(f"https://{domain}/api/v3/site", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
+
+ if res.ok and res.json() is not None:
+ # NOISY-DEBUG: print("DEBUG: Success, res.json():", len(res.json()))
+ json = res.json()
+
+ if "federated_instances" in json and "linked" in json["federated_instances"]:
+ # NOISY-DEBUG: print("DEBUG: Found federated_instances", domain)
+ peers = json["federated_instances"]["linked"] + json["federated_instances"]["allowed"] + json["federated_instances"]["blocked"]
+
+ except BaseException as e:
+ print("WARNING: Exception during fetching JSON:", domain, e)
+
+ # NOISY-DEBUG: print("DEBUG: Returning peers[]:", type(peers))
+ return peers
+
try:
- res = reqto.get(f"https://{domain}{get_peers_url}", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
+ res = reqto.get(f"https://{domain}/api/v1/instance/peers", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
if not res.ok or res.status_code >= 400:
- print("WARNING: Cannot fetch peers:", domain)
- update_last_error(domain, res)
+ res = reqto.get(f"https://{domain}/api/v3/site", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
+
+ if "federated_instances" in json and "linked" in json["federated_instances"]:
+ # NOISY-DEBUG: print("DEBUG: Found federated_instances", domain)
+ peers = json["federated_instances"]["linked"] + json["federated_instances"]["allowed"] + json["federated_instances"]["blocked"]
+ else:
+ print("WARNING: Could not reach any JSON API:", domain)
+ update_last_error(domain, res)
else:
# NOISY-DEBUG: print("DEBUG: Querying API was successful:", domain, len(res.json()))
peers = res.json()
nodeinfos["get_peers_url"][domain] = get_peers_url
- except:
- print("WARNING: Some error during get():", domain)
+ except BaseException as e:
+ print("WARNING: Some error during get():", domain, e)
+ update_last_error(domain, e)
update_last_nodeinfo(domain)
update_last_nodeinfo(domain)
json = res.json()
- except:
- print("WARNING: Some error during post():", domain, path, data)
+ except BaseException as e:
+ print("WARNING: Some error during post():", domain, path, data, e)
# NOISY-DEBUG: print("DEBUG: Returning json():", len(json))
return json
res = reqto.get(request, headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
# NOISY-DEBUG: print("DEBUG: res.ok,res.json[]:", res.ok, type(res.json()))
- if res.ok and res.json() is not None:
+ if res.ok and res.json() is dict:
# NOISY-DEBUG: print("DEBUG: Success:", request)
json = res.json()
nodeinfos["detection_mode"][domain] = "STATIC_CHECK"
try:
res = reqto.get(f"https://{domain}/.well-known/nodeinfo", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
- # NOISY-DEBUG: print("DEBUG: domain,res.ok:", domain, res.ok)
- if res.ok and res.json() is not None:
+ # NOISY-DEBUG: print("DEBUG: domain,res.ok,res.json[]:", domain, res.ok, type(res.json()))
+ if res.ok and res.json() is dict:
nodeinfo = res.json()
# NOISY-DEBUG: print("DEBUG: Found entries:", len(nodeinfo), domain)
if "links" in nodeinfo:
# NOISY-DEBUG: print("DEBUG: Fetching nodeinfo from:", link["href"])
res = reqto.get(link["href"])
# NOISY-DEBUG: print("DEBUG: href,res.ok,res.status_code:", link["href"], res.ok, res.status_code)
- if res.ok and res.json() is not None:
+ if res.ok and res.json() is dict:
# NOISY-DEBUG: print("DEBUG: Found JSON nodeinfo():", len(res.json()))
json = res.json()
nodeinfos["detection_mode"][domain] = "AUTO_DISCOVERY"
if cursor.rowcount == 0:
print("WARNING: Did not update any rows:", domain)
- except:
- print("ERROR: failed SQL query:", reason, blocker, blocked, block_level)
+ except baseException as e:
+ print("ERROR: failed SQL query:", reason, blocker, blocked, block_level, e)
sys.exit(255)
def update_last_seen(blocker: str, blocked: str, block_level: str):
if cursor.rowcount == 0:
print("WARNING: Did not update any rows:", domain)
- except:
- print("ERROR: failed SQL query:", last_seen, blocker, blocked, block_level)
+ except BaseException as e:
+ print("ERROR: failed SQL query:", last_seen, blocker, blocked, block_level, e)
sys.exit(255)
# NOISY-DEBUG: print("DEBUG: EXIT!")
),
)
- except:
- print("ERROR: failed SQL query:", blocker, blocked, reason, block_level, first_added, last_seen)
+ except BaseException as e:
+ print("ERROR: failed SQL query:", blocker, blocked, reason, block_level, first_added, last_seen, e)
sys.exit(255)
# NOISY-DEBUG: print("DEBUG: EXIT!")
)
if domain in nodeinfos["nodeinfo_url"]:
- # NOISY-DEBUG print("DEBUG: domain has pending nodeinfo being updated:", domain)
+ # NOISY-DEBUG # NOISY-DEBUG: print("DEBUG: domain has pending nodeinfo being updated:", domain)
update_nodeinfos(domain)
if domain in pending_errors:
reqto.get(f"https://{domain}/about/more", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"])).text,
"html.parser",
)
- except:
- print("ERROR: Cannot fetch from domain:", domain)
+ except BaseException as e:
+ print("ERROR: Cannot fetch from domain:", domain, e)
+ update_last_error(domain, e)
return {}
for header in doc.find_all("h3"):
reqto.get(f"https://{domain}/friendica", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"])).text,
"html.parser",
)
- except:
- print("WARNING: Failed to fetch /friendica from domain:", domain)
+ except baseException as e:
+ print("WARNING: Failed to fetch /friendica from domain:", domain, e)
+ update_last_error(domain, e)
return {}
blocklist = doc.find(id="about_blocklist")
"blocked" : []
}
- try:
- counter = 0
- step = 99
- while True:
- # iterating through all "suspended" (follow-only in its terminology)
- # instances page-by-page, since that troonware doesn't support
- # sending them all at once
- try:
- if counter == 0:
- # NOISY-DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
- doc = post_json_api(domain, "/api/federation/instances/", json.dumps({
- "sort" : "+caughtAt",
- "host" : None,
- "suspended": True,
- "limit" : step
- }))
- else:
- # NOISY-DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
- doc = post_json_api(domain, "/api/federation/instances/", json.dumps({
- "sort" : "+caughtAt",
- "host" : None,
- "suspended": True,
- "limit" : step,
- "offset" : counter-1
- }))
-
- # NOISY-DEBUG: print("DEBUG: doc():", len(doc))
- if len(doc) == 0:
- # NOISY-DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain)
- break
-
- for instance in doc:
- # just in case
- if instance["isSuspended"]:
- blocks["suspended"].append(
- {
- "domain": tidyup(instance["host"]),
- # no reason field, nothing
- "reason": ""
- }
- )
-
- if len(doc) < step:
- # NOISY-DEBUG: print("DEBUG: End of request:", len(doc), step)
- break
-
- # NOISY-DEBUG: print("DEBUG: Raising counter by step:", step)
- counter = counter + step
-
- except:
- print("WARNING: Caught error, exiting loop:", domain)
- counter = 0
+ counter = 0
+ step = 99
+ while True:
+ # iterating through all "suspended" (follow-only in its terminology)
+ # instances page-by-page, since that troonware doesn't support
+ # sending them all at once
+ try:
+ if counter == 0:
+ # NOISY-DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
+ doc = post_json_api(domain, "/api/federation/instances/", json.dumps({
+ "sort" : "+caughtAt",
+ "host" : None,
+ "suspended": True,
+ "limit" : step
+ }))
+ else:
+ # NOISY-DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
+ doc = post_json_api(domain, "/api/federation/instances/", json.dumps({
+ "sort" : "+caughtAt",
+ "host" : None,
+ "suspended": True,
+ "limit" : step,
+ "offset" : counter-1
+ }))
+
+ # NOISY-DEBUG: print("DEBUG: doc():", len(doc))
+ if len(doc) == 0:
+ # NOISY-DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain)
break
- while True:
- # same shit, different asshole ("blocked" aka full suspend)
- try:
- if counter == 0:
- # NOISY-DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
- doc = post_json_api(domain,"/api/federation/instances", json.dumps({
- "sort" : "+caughtAt",
- "host" : None,
- "blocked": True,
- "limit" : step
- }))
- else:
- # NOISY-DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
- doc = post_json_api(domain,"/api/federation/instances", json.dumps({
- "sort" : "+caughtAt",
- "host" : None,
- "blocked": True,
- "limit" : step,
- "offset" : counter-1
- }))
-
- # NOISY-DEBUG: print("DEBUG: doc():", len(doc))
- if len(doc) == 0:
- # NOISY-DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain)
- break
-
- for instance in doc:
- if instance["isBlocked"]:
- blocks["blocked"].append({
+ for instance in doc:
+ # just in case
+ if instance["isSuspended"]:
+ blocks["suspended"].append(
+ {
"domain": tidyup(instance["host"]),
+ # no reason field, nothing
"reason": ""
- })
+ }
+ )
+
+ if len(doc) < step:
+ # NOISY-DEBUG: print("DEBUG: End of request:", len(doc), step)
+ break
+
+ # NOISY-DEBUG: print("DEBUG: Raising counter by step:", step)
+ counter = counter + step
+
+ except BaseException as e:
+ print("WARNING: Caught error, exiting loop:", domain, e)
+ update_last_error(domain, e)
+ counter = 0
+ break
- if len(doc) < step:
- # NOISY-DEBUG: print("DEBUG: End of request:", len(doc), step)
- break
+ while True:
+ # same shit, different asshole ("blocked" aka full suspend)
+ try:
+ if counter == 0:
+ # NOISY-DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
+ doc = post_json_api(domain,"/api/federation/instances", json.dumps({
+ "sort" : "+caughtAt",
+ "host" : None,
+ "blocked": True,
+ "limit" : step
+ }))
+ else:
+ # NOISY-DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
+ doc = post_json_api(domain,"/api/federation/instances", json.dumps({
+ "sort" : "+caughtAt",
+ "host" : None,
+ "blocked": True,
+ "limit" : step,
+ "offset" : counter-1
+ }))
+
+ # NOISY-DEBUG: print("DEBUG: doc():", len(doc))
+ if len(doc) == 0:
+ # NOISY-DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain)
+ break
- # NOISY-DEBUG: print("DEBUG: Raising counter by step:", step)
- counter = counter + step
+ for instance in doc:
+ if instance["isBlocked"]:
+ blocks["blocked"].append({
+ "domain": tidyup(instance["host"]),
+ "reason": ""
+ })
- except:
- counter = 0
+ if len(doc) < step:
+ # NOISY-DEBUG: print("DEBUG: End of request:", len(doc), step)
break
- # NOISY-DEBUG: print("DEBUG: Returning for domain,blocked(),suspended():", domain, len(blocks["blocked"]), len(blocks["suspended"]))
- return {
- "reject" : blocks["blocked"],
- "followers_only": blocks["suspended"]
- }
+ # NOISY-DEBUG: print("DEBUG: Raising counter by step:", step)
+ counter = counter + step
- except:
- print("WARNING: API request failed for domain:", domain)
- return {}
+ except BaseException as e:
+ print("ERROR: Exception during POST:", domain, e)
+ update_last_error(domain, e)
+ counter = 0
+ break
+
+ # NOISY-DEBUG: print("DEBUG: Returning for domain,blocked(),suspended():", domain, len(blocks["blocked"]), len(blocks["suspended"]))
+ return {
+ "reject" : blocks["blocked"],
+ "followers_only": blocks["suspended"]
+ }
def tidyup(string: str) -> str:
# some retards put their blocks in variable case