]
def remove_version(software: str) -> str:
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' - CALLED!")
+ # DEBUG: print(f"DEBUG: software='{software}' - CALLED!")
if not "." in software and " " not in software:
print(f"WARNING: software='{software}' does not contain a version number.")
return software
elif " - " in software:
temp = software.split(" - ")[0]
- # NOISY-DEBUG: print(f"DEBUG: software='{software}'")
+ # DEBUG: print(f"DEBUG: software='{software}'")
version = None
if " " in software:
version = temp.split(" ")[-1]
elif "-" in software:
version = temp.split("-")[-1]
else:
- # NOISY-DEBUG: print(f"DEBUG: Was not able to find common seperator, returning untouched software='{software}'")
+ # DEBUG: print(f"DEBUG: Was not able to find common seperator, returning untouched software='{software}'")
return software
matches = None
match = None
- # NOISY-DEBUG: print(f"DEBUG: Checking {len(patterns)} patterns ...")
+ # DEBUG: print(f"DEBUG: Checking {len(patterns)} patterns ...")
for pattern in patterns:
# Run match()
match = pattern.match(version)
- # NOISY-DEBUG: print(f"DEBUG: match[]={type(match)}")
+ # DEBUG: print(f"DEBUG: match[]={type(match)}")
if type(match) is re.Match:
break
- # NOISY-DEBUG: print(f"DEBUG: version[{type(version)}]='{version}',match='{match}'")
+ # DEBUG: print(f"DEBUG: version[{type(version)}]='{version}',match='{match}'")
if type(match) is not re.Match:
print(f"WARNING: version='{version}' does not match regex, leaving software='{software}' untouched.")
return software
- # NOISY-DEBUG: print(f"DEBUG: Found valid version number: '{version}', removing it ...")
+ # DEBUG: print(f"DEBUG: Found valid version number: '{version}', removing it ...")
end = len(temp) - len(version) - 1
- # NOISY-DEBUG: print(f"DEBUG: end[{type(end)}]={end}")
+ # DEBUG: print(f"DEBUG: end[{type(end)}]={end}")
software = temp[0:end].strip()
if " version" in software:
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' contains word ' version'")
+ # DEBUG: print(f"DEBUG: software='{software}' contains word ' version'")
software = strip_until(software, " version")
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
+ # DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
return software
def strip_powered_by(software: str) -> str:
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' - CALLED!")
+ # DEBUG: print(f"DEBUG: software='{software}' - CALLED!")
if software == "":
print(f"ERROR: Bad method call, 'software' is empty")
raise Exception("Parameter 'software' is empty")
return software
start = software.find("powered by ")
- # NOISY-DEBUG: print(f"DEBUG: start[{type(start)}]='{start}'")
+ # DEBUG: print(f"DEBUG: start[{type(start)}]='{start}'")
software = software[start + 11:].strip()
- # NOISY-DEBUG: print(f"DEBUG: software='{software}'")
+ # DEBUG: print(f"DEBUG: software='{software}'")
software = strip_until(software, " - ")
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
+ # DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
return software
def strip_until(software: str, until: str) -> str:
- # NOISY-DEBUG: print(f"DEBUG: software='{software}',until='{until}' - CALLED!")
+ # DEBUG: print(f"DEBUG: software='{software}',until='{until}' - CALLED!")
if software == "":
print(f"ERROR: Bad method call, 'software' is empty")
raise Exception("Parameter 'software' is empty")
# Next, strip until part
end = software.find(until)
- # NOISY-DEBUG: print(f"DEBUG: end[{type(end)}]='{end}'")
+ # DEBUG: print(f"DEBUG: end[{type(end)}]='{end}'")
if end > 0:
software = software[0:end].strip()
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
+ # DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
return software
def is_blacklisted(domain: str) -> bool:
return hashlib.sha256(domain.encode("utf-8")).hexdigest()
def update_last_blocked(domain: str):
- # NOISY-DEBUG: print("DEBUG: Updating last_blocked for domain", domain)
+ # DEBUG: print("DEBUG: Updating last_blocked for domain", domain)
try:
cursor.execute("UPDATE instances SET last_blocked = ?, last_updated = ? WHERE domain = ? LIMIT 1", [
time.time(),
print("ERROR: failed SQL query:", domain, e)
sys.exit(255)
- # NOISY-DEBUG: print("DEBUG: EXIT!")
+ # DEBUG: print("DEBUG: EXIT!")
def update_nodeinfos(domain: str):
- # NOISY-DEBUG: print("DEBUG: Updating nodeinfo for domain:", domain)
+ # DEBUG: print("DEBUG: Updating nodeinfo for domain:", domain)
sql_string = ''
fields = list()
for key in nodeinfos:
- # NOISY-DEBUG: print("DEBUG: key:", key)
+ # DEBUG: print("DEBUG: key:", key)
if domain in nodeinfos[key]:
- # NOISY-DEBUG: print(f"DEBUG: Adding '{nodeinfos[key][domain]}' for key='{key}' ...")
+ # DEBUG: print(f"DEBUG: Adding '{nodeinfos[key][domain]}' for key='{key}' ...")
fields.append(nodeinfos[key][domain])
sql_string += f" {key} = ?,"
fields.append(domain)
- # NOISY-DEBUG: print(f"DEBUG: sql_string='{sql_string}',fields()={len(fields)}")
+ # DEBUG: print(f"DEBUG: sql_string='{sql_string}',fields()={len(fields)}")
sql = "UPDATE instances SET" + sql_string + " last_status_code = NULL, last_error_details = NULL WHERE domain = ? LIMIT 1"
- # NOISY-DEBUG: print("DEBUG: sql:", sql)
+ # DEBUG: print("DEBUG: sql:", sql)
try:
- # NOISY-DEBUG: print("DEBUG: Executing SQL:", sql)
+ # DEBUG: print("DEBUG: Executing SQL:", sql)
cursor.execute(sql, fields)
- # NOISY-DEBUG: print(f"DEBUG: Success! (rowcount={cursor.rowcount })")
+ # DEBUG: print(f"DEBUG: Success! (rowcount={cursor.rowcount })")
if cursor.rowcount == 0:
print("WARNING: Did not update any rows:", domain)
print(f"ERROR: failed SQL query: domain='{domain}',sql='{sql}',exception:'{e}'")
sys.exit(255)
- # NOISY-DEBUG: print("DEBUG: Deleting nodeinfos for domain:", domain)
+ # DEBUG: print("DEBUG: Deleting nodeinfos for domain:", domain)
for key in nodeinfos:
try:
- # NOISY-DEBUG: print("DEBUG: Deleting key:", key)
+ # DEBUG: print("DEBUG: Deleting key:", key)
del nodeinfos[key][domain]
except:
pass
- # NOISY-DEBUG: print("DEBUG: EXIT!")
+ # DEBUG: print("DEBUG: EXIT!")
def update_last_error(domain: str, res: any):
- # NOISY-DEBUG: print("DEBUG: domain,res[]:", domain, type(res))
+ # DEBUG: print("DEBUG: domain,res[]:", domain, type(res))
try:
- # NOISY-DEBUG: print("DEBUG: BEFORE res[]:", type(res))
+ # 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))
+ # DEBUG: print("DEBUG: AFTER res[]:", type(res))
if type(res) is str:
- # NOISY-DEBUG: print(f"DEBUG: Setting last_error_details='{res}'");
+ # DEBUG: print(f"DEBUG: Setting last_error_details='{res}'");
cursor.execute("UPDATE instances SET last_status_code = 999, last_error_details = ?, last_updated = ? WHERE domain = ? LIMIT 1", [
res,
time.time(),
domain
])
else:
- # NOISY-DEBUG: print(f"DEBUG: Setting last_error_details='{res.reason}'");
+ # DEBUG: print(f"DEBUG: Setting last_error_details='{res.reason}'");
cursor.execute("UPDATE instances SET last_status_code = ?, last_error_details = ?, last_updated = ? WHERE domain = ? LIMIT 1", [
res.status_code,
res.reason,
])
if cursor.rowcount == 0:
- # NOISY-DEBUG: print("DEBUG: Did not update any rows:", domain)
+ # DEBUG: print("DEBUG: Did not update any rows:", domain)
pending_errors[domain] = res
except BaseException as e:
print("ERROR: failed SQL query:", domain, e)
sys.exit(255)
- # NOISY-DEBUG: print("DEBUG: EXIT!")
+ # DEBUG: print("DEBUG: EXIT!")
def update_last_nodeinfo(domain: str):
- # NOISY-DEBUG: print("DEBUG: Updating last_nodeinfo for domain:", domain)
+ # DEBUG: print("DEBUG: Updating last_nodeinfo for domain:", domain)
try:
cursor.execute("UPDATE instances SET last_nodeinfo = ?, last_updated = ? WHERE domain = ? LIMIT 1", [
time.time(),
sys.exit(255)
connection.commit()
- # NOISY-DEBUG: print("DEBUG: EXIT!")
+ # DEBUG: print("DEBUG: EXIT!")
def get_peers(domain: str, software: str) -> list:
- # NOISY-DEBUG: print("DEBUG: Getting peers for domain:", domain, software)
+ # DEBUG: print("DEBUG: Getting peers for domain:", domain, software)
peers = list()
- if software == "lemmy":
- # NOISY-DEBUG: print(f"DEBUG: domain='{domain}' is Lemmy, fetching JSON ...")
+ if software == "misskey":
+ print(f"DEBUG: domain='{domain}' is misskey, sending API POST request ...")
+
+ counter = 0
+ step = 99
+ while True:
+ if counter == 0:
+ fetched = post_json_api(domain, "/api/federation/instances", json.dumps({
+ "sort" : "+caughtAt",
+ "host" : None,
+ "limit": step
+ }))
+ else:
+ fetched = post_json_api(domain, "/api/federation/instances", json.dumps({
+ "sort" : "+caughtAt",
+ "host" : None,
+ "limit" : step,
+ "offset": counter - 1
+ }))
+
+ # DEBUG: print("DEBUG: fetched():", len(fetched))
+ if len(fetched) == 0:
+ # DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain)
+ break
+
+ # Check records
+ for row in fetched:
+ # DEBUG: print(f"DEBUG: row():{len(row)}")
+ if "host" in row:
+ # DEBUG: print(f"DEBUG: Adding peer: '{row['host']}'")
+ peers.append(row["host"])
+
+ # DEBUG: print("DEBUG: Returning peers[]:", type(peers))
+ sys.exit(255)
+ return peers
+ elif software == "lemmy":
+ # 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"]))
- # NOISY-DEBUG: print(f"DEBUG: res.ok={res.ok},res.json[]={type(res.json())}")
+ # DEBUG: print(f"DEBUG: res.ok={res.ok},res.json[]={type(res.json())}")
if res.ok and isinstance(res.json(), dict):
- # NOISY-DEBUG: print("DEBUG: Success, res.json():", len(res.json()))
- json = res.json()
+ # DEBUG: print("DEBUG: Success, res.json():", len(res.json()))
+ data = 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"]
+ if "federated_instances" in data and "linked" in data["federated_instances"]:
+ # DEBUG: print("DEBUG: Found federated_instances", domain)
+ peers = data["federated_instances"]["linked"] + data["federated_instances"]["allowed"] + data["federated_instances"]["blocked"]
except BaseException as e:
print("WARNING: Exception during fetching JSON:", domain, e)
update_last_nodeinfo(domain)
- # NOISY-DEBUG: print("DEBUG: Returning peers[]:", type(peers))
+ # DEBUG: print("DEBUG: Returning peers[]:", type(peers))
return peers
elif software == "peertube":
- # NOISY-DEBUG: print(f"DEBUG: domain='{domain}' is a PeerTube, fetching JSON ...")
+ # DEBUG: print(f"DEBUG: domain='{domain}' is a PeerTube, fetching JSON ...")
start = 0
for mode in ["followers", "following"]:
- # NOISY-DEBUG: print(f"DEBUG: domain='{domain}',mode='{mode}'")
+ # DEBUG: print(f"DEBUG: domain='{domain}',mode='{mode}'")
while True:
try:
res = reqto.get(f"https://{domain}/api/v1/server/{mode}?start={start}&count=100", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
- # NOISY-DEBUG: print(f"DEBUG: res.ok={res.ok},res.json[]={type(res.json())}")
+ # DEBUG: print(f"DEBUG: res.ok={res.ok},res.json[]={type(res.json())}")
if res.ok and isinstance(res.json(), dict):
- # NOISY-DEBUG: print("DEBUG: Success, res.json():", len(res.json()))
- json = res.json()
+ # DEBUG: print("DEBUG: Success, res.json():", len(res.json()))
+ data = res.json()
- if "data" in json:
- # NOISY-DEBUG: print(f"DEBUG: Found {len(json['data'])} record(s).")
- for record in json["data"]:
- # NOISY-DEBUG: print(f"DEBUG: record()={len(record)}")
+ if "data" in data:
+ # DEBUG: print(f"DEBUG: Found {len(data['data'])} record(s).")
+ for record in data["data"]:
+ # DEBUG: print(f"DEBUG: record()={len(record)}")
if mode in record and "host" in record[mode]:
- # NOISY-DEBUG: print(f"DEBUG: Found host={record[mode]['host']}, adding ...")
+ # DEBUG: print(f"DEBUG: Found host={record[mode]['host']}, adding ...")
peers.append(record[mode]["host"])
else:
print(f"WARNING: record from '{domain}' has no '{mode}' or 'host' record: {record}")
- if len(json["data"]) < 100:
- # NOISY-DEBUG: print("DEBUG: Reached end of JSON response:", domain)
+ if len(data["data"]) < 100:
+ # DEBUG: print("DEBUG: Reached end of JSON response:", domain)
break
# Continue with next row
update_last_nodeinfo(domain)
- # NOISY-DEBUG: print("DEBUG: Returning peers[]:", type(peers))
+ # DEBUG: print("DEBUG: Returning peers[]:", type(peers))
return peers
- # NOISY-DEBUG: print(f"DEBUG: Fetching '{get_peers_url}' from '{domain}' ...")
+ # DEBUG: print(f"DEBUG: Fetching '{get_peers_url}' from '{domain}' ...")
try:
res = reqto.get(f"https://{domain}{get_peers_url}", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
- # NOISY-DEBUG: print("DEBUG: res.ok,res.json[]:", res.ok, type(res.json()))
+ # DEBUG: print("DEBUG: res.ok,res.json[]:", res.ok, type(res.json()))
if not res.ok or res.status_code >= 400:
res = reqto.get(f"https://{domain}/api/v3/site", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
print("WARNING: Could not reach any JSON API:", domain)
update_last_error(domain, res)
elif "federated_instances" in res.json() and "linked" in res.json()["federated_instances"]:
- # NOISY-DEBUG: print("DEBUG: Found federated_instances", domain)
+ # DEBUG: print("DEBUG: Found federated_instances", domain)
peers = res.json()["federated_instances"]["linked"] + res.json()["federated_instances"]["allowed"] + res.json()["federated_instances"]["blocked"]
else:
print("WARNING: JSON response does not contain 'federated_instances':", domain)
update_last_error(domain, res)
else:
- # NOISY-DEBUG: print("DEBUG:Querying API was successful:", domain, len(res.json()))
+ # DEBUG: print("DEBUG:Querying API was successful:", domain, len(res.json()))
peers = res.json()
nodeinfos["get_peers_url"][domain] = get_peers_url
update_last_nodeinfo(domain)
- # NOISY-DEBUG: print("DEBUG: Returning peers[]:", type(peers))
+ # DEBUG: print("DEBUG: Returning peers[]:", type(peers))
return peers
def post_json_api(domain: str, path: str, data: str) -> list:
- # NOISY-DEBUG: print("DEBUG: Sending POST to domain,path,data:", domain, path, data)
- json = {}
+ # DEBUG: print("DEBUG: Sending POST to domain,path,data:", domain, path, data)
+ data = {}
try:
res = reqto.post(f"https://{domain}{path}", data=data, headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
- # NOISY-DEBUG: print("DEBUG: res.ok,res.json[]:", res.ok, type(res.json()))
+ # DEBUG: print("DEBUG: res.ok,res.json[]:", res.ok, type(res.json()))
if not res.ok or res.status_code >= 400:
print("WARNING: Cannot query JSON API:", domain, path, data, res.status_code)
update_last_error(domain, res)
else:
update_last_nodeinfo(domain)
- json = res.json()
+ data = res.json()
except BaseException as e:
print("WARNING: Some error during post():", domain, path, data, e)
- # NOISY-DEBUG: print("DEBUG: Returning json():", len(json))
- return json
+ # DEBUG: print("DEBUG: Returning data():", len(data))
+ return data
def fetch_nodeinfo(domain: str) -> list:
- # NOISY-DEBUG: print("DEBUG: Fetching nodeinfo from domain:", domain)
+ # DEBUG: print("DEBUG: Fetching nodeinfo from domain:", domain)
nodeinfo = fetch_wellknown_nodeinfo(domain)
- # NOISY-DEBUG: print("DEBUG:nodeinfo:", len(nodeinfo))
+ # DEBUG: print("DEBUG:nodeinfo:", len(nodeinfo))
if len(nodeinfo) > 0:
- # NOISY-DEBUG: print("DEBUG: Returning auto-discovered nodeinfo:", len(nodeinfo))
+ # DEBUG: print("DEBUG: Returning auto-discovered nodeinfo:", len(nodeinfo))
return nodeinfo
requests = [
f"https://{domain}/api/v1/instance"
]
- json = {}
+ data = {}
for request in requests:
try:
- # NOISY-DEBUG: print("DEBUG: Fetching request:", request)
+ # DEBUG: print("DEBUG: Fetching request:", request)
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()))
+ # DEBUG: print("DEBUG: res.ok,res.json[]:", res.ok, type(res.json()))
if res.ok and isinstance(res.json(), dict):
- # NOISY-DEBUG: print("DEBUG: Success:", request)
- json = res.json()
+ # DEBUG: print("DEBUG: Success:", request)
+ data = res.json()
nodeinfos["detection_mode"][domain] = "STATIC_CHECK"
nodeinfos["nodeinfo_url"][domain] = request
break
continue
except BaseException as e:
- # NOISY-DEBUG: print("DEBUG: Cannot fetch API request:", request)
+ # DEBUG: print("DEBUG: Cannot fetch API request:", request)
update_last_error(domain, e)
pass
- # NOISY-DEBUG: print("DEBUG: Returning json[]:", type(json))
- return json
+ # DEBUG: print("DEBUG: Returning data[]:", type(data))
+ return data
def fetch_wellknown_nodeinfo(domain: str) -> list:
- # NOISY-DEBUG: print("DEBUG: Fetching .well-known info for domain:", domain)
- json = {}
+ # DEBUG: print("DEBUG: Fetching .well-known info for domain:", domain)
+ data = {}
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,res.json[]:", domain, res.ok, type(res.json()))
+ # DEBUG: print("DEBUG: domain,res.ok,res.json[]:", domain, res.ok, type(res.json()))
if res.ok and isinstance(res.json(), dict):
nodeinfo = res.json()
- # NOISY-DEBUG: print("DEBUG: Found entries:", len(nodeinfo), domain)
+ # DEBUG: print("DEBUG: Found entries:", len(nodeinfo), domain)
if "links" in nodeinfo:
- # NOISY-DEBUG: print("DEBUG: Found links in nodeinfo():", len(nodeinfo["links"]))
+ # DEBUG: print("DEBUG: Found links in nodeinfo():", len(nodeinfo["links"]))
for link in nodeinfo["links"]:
- # NOISY-DEBUG: print("DEBUG: rel,href:", link["rel"], link["href"])
+ # DEBUG: print("DEBUG: rel,href:", link["rel"], link["href"])
if link["rel"] in nodeinfo_identifier:
- # NOISY-DEBUG: print("DEBUG: Fetching nodeinfo from:", link["href"])
+ # 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)
+ # DEBUG: print("DEBUG: href,res.ok,res.status_code:", link["href"], res.ok, res.status_code)
if res.ok and isinstance(res.json(), dict):
- # NOISY-DEBUG: print("DEBUG: Found JSON nodeinfo():", len(res.json()))
- json = res.json()
+ # DEBUG: print("DEBUG: Found JSON nodeinfo():", len(res.json()))
+ data = res.json()
nodeinfos["detection_mode"][domain] = "AUTO_DISCOVERY"
nodeinfos["nodeinfo_url"][domain] = link["href"]
break
update_last_error(domain, e)
pass
- # NOISY-DEBUG: print("DEBUG: Returning json[]:", type(json))
- return json
+ # DEBUG: print("DEBUG: Returning data[]:", type(data))
+ return data
def fetch_generator_from_path(domain: str, path: str = "/") -> str:
- # NOISY-DEBUG: print(f"DEBUG: domain='{domain}',path='{path}' - CALLED!")
+ # DEBUG: print(f"DEBUG: domain='{domain}',path='{path}' - CALLED!")
software = None
try:
- # NOISY-DEBUG: print(f"DEBUG: Fetching '{path}' from '{domain}' ...")
+ # DEBUG: print(f"DEBUG: Fetching '{path}' from '{domain}' ...")
res = reqto.get(f"https://{domain}{path}", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
- # NOISY-DEBUG: print("DEBUG: domain,res.ok,res.status_code,res.text[]:", domain, res.ok, res.status_code, type(res.text))
+ # DEBUG: print("DEBUG: domain,res.ok,res.status_code,res.text[]:", domain, res.ok, res.status_code, type(res.text))
if res.ok and res.status_code < 300 and len(res.text) > 0:
- # NOISY-DEBUG: print("DEBUG: Search for <meta name='generator'>:", domain)
+ # DEBUG: print("DEBUG: Search for <meta name='generator'>:", domain)
doc = bs4.BeautifulSoup(res.text, "html.parser")
- # NOISY-DEBUG: print("DEBUG: doc[]:", type(doc))
+ # DEBUG: print("DEBUG: doc[]:", type(doc))
tag = doc.find("meta", {"name": "generator"})
- # NOISY-DEBUG: print(f"DEBUG: tag[{type(tag)}: {tag}")
+ # DEBUG: print(f"DEBUG: tag[{type(tag)}: {tag}")
if isinstance(tag, bs4.element.Tag):
- # NOISY-DEBUG: print("DEBUG: Found generator meta tag: ", domain)
+ # DEBUG: print("DEBUG: Found generator meta tag: ", domain)
software = tidyup(tag.get("content"))
print(f"INFO: domain='{domain}' is generated by '{software}'")
nodeinfos["detection_mode"][domain] = "GENERATOR"
remove_pending_error(domain)
except BaseException as e:
- # NOISY-DEBUG: print(f"DEBUG: Cannot fetch / from '{domain}':", e)
+ # DEBUG: print(f"DEBUG: Cannot fetch / from '{domain}':", e)
update_last_error(domain, e)
pass
- # NOISY-DEBUG: print(f"DEBUG: software[]={type(software)}")
+ # DEBUG: print(f"DEBUG: software[]={type(software)}")
if type(software) is str and software == "":
- # NOISY-DEBUG: print(f"DEBUG: Corrected empty string to None for software of domain='{domain}'")
+ # DEBUG: print(f"DEBUG: Corrected empty string to None for software of domain='{domain}'")
software = None
elif type(software) is str and ("." in software or " " in software):
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' may contain a version number, domain='{domain}', removing it ...")
+ # DEBUG: print(f"DEBUG: software='{software}' may contain a version number, domain='{domain}', removing it ...")
software = remove_version(software)
- # NOISY-DEBUG: print(f"DEBUG: software[]={type(software)}")
+ # DEBUG: print(f"DEBUG: software[]={type(software)}")
if type(software) is str and "powered by" in software:
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' has 'powered by' in it")
+ # DEBUG: print(f"DEBUG: software='{software}' has 'powered by' in it")
software = remove_version(strip_powered_by(software))
elif type(software) is str and " by " in software:
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' has ' by ' in it")
+ # DEBUG: print(f"DEBUG: software='{software}' has ' by ' in it")
software = strip_until(software, " by ")
elif type(software) is str and " see " in software:
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' has ' see ' in it")
+ # DEBUG: print(f"DEBUG: software='{software}' has ' see ' in it")
software = strip_until(software, " see ")
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
+ # DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
return software
def determine_software(domain: str) -> str:
- # NOISY-DEBUG: print("DEBUG: Determining software for domain:", domain)
+ # DEBUG: print("DEBUG: Determining software for domain:", domain)
software = None
- # NOISY-DEBUG: print(f"DEBUG: Fetching nodeinfo from '{domain}' ...")
- json = fetch_nodeinfo(domain)
+ # DEBUG: print(f"DEBUG: Fetching nodeinfo from '{domain}' ...")
+ data = fetch_nodeinfo(domain)
- # NOISY-DEBUG: print("DEBUG: json[]:", type(json))
- if not isinstance(json, dict) or len(json) == 0:
- # NOISY-DEBUG: print("DEBUG: Could not determine software type:", domain)
+ # DEBUG: print("DEBUG: data[]:", type(data))
+ if not isinstance(data, dict) or len(data) == 0:
+ # DEBUG: print("DEBUG: Could not determine software type:", domain)
return fetch_generator_from_path(domain)
- # NOISY-DEBUG: print("DEBUG: json():", len(json), json)
- if "status" in json and json["status"] == "error" and "message" in json:
- print("WARNING: JSON response is an error:", json["message"])
- update_last_error(domain, json["message"])
+ # DEBUG: print("DEBUG: data():", len(data), data)
+ if "status" in data and data["status"] == "error" and "message" in data:
+ print("WARNING: JSON response is an error:", data["message"])
+ update_last_error(domain, data["message"])
return fetch_generator_from_path(domain)
- elif "software" not in json or "name" not in json["software"]:
- # NOISY-DEBUG: print(f"DEBUG: JSON response from {domain} does not include [software][name], fetching / ...")
+ elif "software" not in data or "name" not in data["software"]:
+ # DEBUG: print(f"DEBUG: JSON response from {domain} does not include [software][name], fetching / ...")
software = fetch_generator_from_path(domain)
- # NOISY-DEBUG: print(f"DEBUG: Generator for domain='{domain}' is: {software}, EXIT!")
+ # DEBUG: print(f"DEBUG: Generator for domain='{domain}' is: {software}, EXIT!")
return software
- software = tidyup(json["software"]["name"])
+ software = tidyup(data["software"]["name"])
- # NOISY-DEBUG: print("DEBUG: sofware after tidyup():", software)
+ # DEBUG: print("DEBUG: sofware after tidyup():", software)
if software in ["akkoma", "rebased"]:
- # NOISY-DEBUG: print("DEBUG: Setting pleroma:", domain, software)
+ # DEBUG: print("DEBUG: Setting pleroma:", domain, software)
software = "pleroma"
elif software in ["hometown", "ecko"]:
- # NOISY-DEBUG: print("DEBUG: Setting mastodon:", domain, software)
+ # DEBUG: print("DEBUG: Setting mastodon:", domain, software)
software = "mastodon"
elif software in ["calckey", "groundpolis", "foundkey", "cherrypick", "meisskey"]:
- # NOISY-DEBUG: print("DEBUG: Setting misskey:", domain, software)
+ # DEBUG: print("DEBUG: Setting misskey:", domain, software)
software = "misskey"
elif software.find("/") > 0:
print("WARNING: Spliting of slash:", software)
print("WARNING: Spliting of pipe:", software)
software = tidyup(software.split("|")[0]);
elif "powered by" in software:
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' has 'powered by' in it")
+ # DEBUG: print(f"DEBUG: software='{software}' has 'powered by' in it")
software = strip_powered_by(software)
elif type(software) is str and " by " in software:
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' has ' by ' in it")
+ # DEBUG: print(f"DEBUG: software='{software}' has ' by ' in it")
software = strip_until(software, " by ")
elif type(software) is str and " see " in software:
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' has ' see ' in it")
+ # DEBUG: print(f"DEBUG: software='{software}' has ' see ' in it")
software = strip_until(software, " see ")
- # NOISY-DEBUG: print(f"DEBUG: software[]={type(software)}")
+ # DEBUG: print(f"DEBUG: software[]={type(software)}")
if software == "":
print("WARNING: tidyup() left no software name behind:", domain)
software = None
- # NOISY-DEBUG: print(f"DEBUG: software[]={type(software)}")
+ # DEBUG: print(f"DEBUG: software[]={type(software)}")
if str(software) == "":
- # NOISY-DEBUG: print(f"DEBUG: software for '{domain}' was not detected, trying generator ...")
+ # DEBUG: print(f"DEBUG: software for '{domain}' was not detected, trying generator ...")
software = fetch_generator_from_path(domain)
elif len(str(software)) > 0 and ("." in software or " " in software):
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' may contain a version number, domain='{domain}', removing it ...")
+ # DEBUG: print(f"DEBUG: software='{software}' may contain a version number, domain='{domain}', removing it ...")
software = remove_version(software)
- # NOISY-DEBUG: print(f"DEBUG: software[]={type(software)}")
+ # DEBUG: print(f"DEBUG: software[]={type(software)}")
if type(software) is str and "powered by" in software:
- # NOISY-DEBUG: print(f"DEBUG: software='{software}' has 'powered by' in it")
+ # DEBUG: print(f"DEBUG: software='{software}' has 'powered by' in it")
software = remove_version(strip_powered_by(software))
- # NOISY-DEBUG: print("DEBUG: Returning domain,software:", domain, software)
+ # DEBUG: print("DEBUG: Returning domain,software:", domain, software)
return software
def update_block_reason(reason: str, blocker: str, blocked: str, block_level: str):
- # NOISY-DEBUG: print("DEBUG: Updating block reason:", reason, blocker, blocked, block_level)
+ # DEBUG: print("DEBUG: Updating block reason:", reason, blocker, blocked, block_level)
try:
cursor.execute(
"UPDATE blocks SET reason = ?, last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ? AND reason = ''",
),
)
- # NOISY-DEBUG: print(f"DEBUG: cursor.rowcount={cursor.rowcount}")
+ # DEBUG: print(f"DEBUG: cursor.rowcount={cursor.rowcount}")
if cursor.rowcount == 0:
print("WARNING: Did not update any rows:", domain)
print("ERROR: failed SQL query:", reason, blocker, blocked, block_level, e)
sys.exit(255)
- # NOISY-DEBUG: print("DEBUG: EXIT!")
+ # DEBUG: print("DEBUG: EXIT!")
def update_last_seen(blocker: str, blocked: str, block_level: str):
- # NOISY-DEBUG: print("DEBUG: Updating last_seen for:", blocker, blocked, block_level)
+ # DEBUG: print("DEBUG: Updating last_seen for:", blocker, blocked, block_level)
try:
cursor.execute(
"UPDATE blocks SET last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ?",
print("ERROR: failed SQL query:", last_seen, blocker, blocked, block_level, e)
sys.exit(255)
- # NOISY-DEBUG: print("DEBUG: EXIT!")
+ # DEBUG: print("DEBUG: EXIT!")
def block_instance(blocker: str, blocked: str, reason: str, block_level: str):
- # NOISY-DEBUG: print("DEBUG: blocker,blocked,reason,block_level:", blocker, blocked, reason, block_level)
+ # DEBUG: print("DEBUG: blocker,blocked,reason,block_level:", blocker, blocked, reason, block_level)
if not validators.domain(blocker):
print("WARNING: Bad blocker:", blocker)
raise
print("ERROR: failed SQL query:", blocker, blocked, reason, block_level, first_added, last_seen, e)
sys.exit(255)
- # NOISY-DEBUG: print("DEBUG: EXIT!")
+ # DEBUG: print("DEBUG: EXIT!")
def is_instance_registered(domain: str) -> bool:
- # NOISY-DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
+ # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
# Default is not registered
registered = False
print("ERROR: failed SQL query:", blocker, blocked, reason, block_level, first_added, last_seen, e)
sys.exit(255)
- # NOISY-DEBUG: print("DEBUG: registered='{registered}' - EXIT!")
+ # DEBUG: print("DEBUG: registered='{registered}' - EXIT!")
return registered
def add_instance(domain: str, origin: str, originator: str):
- # NOISY-DEBUG: print("DEBUG: domain,origin:", domain, origin, originator)
+ # DEBUG: print("DEBUG: domain,origin:", domain, origin, originator)
if not validators.domain(domain):
print("WARNING: Bad domain name:", domain)
raise
raise
software = determine_software(domain)
- # NOISY-DEBUG: print("DEBUG: Determined software:", software)
+ # DEBUG: print("DEBUG: Determined software:", software)
print(f"INFO: Adding instance {domain} (origin: {origin})")
try:
)
for key in nodeinfos:
- # NOISY-DEBUG: pprint(f"DEBUG: key='{key}',domain='{domain}',nodeinfos[key]={nodeinfos[key]}")
+ # DEBUG: pprint(f"DEBUG: key='{key}',domain='{domain}',nodeinfos[key]={nodeinfos[key]}")
if domain in nodeinfos[key]:
- # NOISY-DEBUG: pprint(f"DEBUG: domain='{domain}' has pending nodeinfo being updated ...")
+ # DEBUG: pprint(f"DEBUG: domain='{domain}' has pending nodeinfo being updated ...")
update_nodeinfos(domain)
remove_pending_error(domain)
break
if domain in pending_errors:
- # NOISY-DEBUG: print("DEBUG: domain has pending error being updated:", domain)
+ # DEBUG: print("DEBUG: domain has pending error being updated:", domain)
update_last_error(domain, pending_errors[domain])
remove_pending_error(domain)
print("ERROR: failed SQL query:", domain, e)
sys.exit(255)
else:
- # NOISY-DEBUG: print("DEBUG: Updating nodeinfo for domain:", domain)
+ # DEBUG: print("DEBUG: Updating nodeinfo for domain:", domain)
update_last_nodeinfo(domain)
- # NOISY-DEBUG: print("DEBUG: EXIT!")
+ # DEBUG: print("DEBUG: EXIT!")
def send_bot_post(instance: str, blocks: dict):
message = instance + " has blocked the following instances:\n\n"
return True
def get_mastodon_blocks(domain: str) -> dict:
- # NOISY-DEBUG: print("DEBUG: Fetching mastodon blocks from domain:", domain)
+ # DEBUG: print("DEBUG: Fetching mastodon blocks from domain:", domain)
blocks = {
"Suspended servers": [],
"Filtered media" : [],
header_text = tidyup(header.text)
if header_text in language_mapping:
- # NOISY-DEBUG: print(f"DEBUG: header_text='{header_text}'")
+ # DEBUG: print(f"DEBUG: header_text='{header_text}'")
header_text = language_mapping[header_text]
if header_text in blocks or header_text.lower() in blocks:
}
)
- # NOISY-DEBUG: print("DEBUG: Returning blocks for domain:", domain)
+ # DEBUG: print("DEBUG: Returning blocks for domain:", domain)
return {
"reject" : blocks["Suspended servers"],
"media_removal" : blocks["Filtered media"],
}
def get_friendica_blocks(domain: str) -> dict:
- # NOISY-DEBUG: print("DEBUG: Fetching friendica blocks from domain:", domain)
+ # DEBUG: print("DEBUG: Fetching friendica blocks from domain:", domain)
blocks = []
try:
# Prevents exceptions:
if blocklist is None:
- # NOISY-DEBUG: print("DEBUG:Instance has no block list:", domain)
+ # DEBUG: print("DEBUG:Instance has no block list:", domain)
return {}
for line in blocklist.find("table").find_all("tr")[1:]:
"reason": tidyup(line.find_all("td")[1].text)
})
- # NOISY-DEBUG: print("DEBUG: Returning blocks() for domain:", domain, len(blocks))
+ # DEBUG: print("DEBUG: Returning blocks() for domain:", domain, len(blocks))
return {
"reject": blocks
}
def get_misskey_blocks(domain: str) -> dict:
- # NOISY-DEBUG: print("DEBUG: Fetching misskey blocks from domain:", domain)
+ # DEBUG: print("DEBUG: Fetching misskey blocks from domain:", domain)
blocks = {
"suspended": [],
"blocked" : []
# sending them all at once
try:
if counter == 0:
- # NOISY-DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
+ # 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,
"limit" : step
}))
else:
- # NOISY-DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
+ # 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,
"offset" : counter-1
}))
- # NOISY-DEBUG: print("DEBUG: doc():", len(doc))
+ # DEBUG: print("DEBUG: doc():", len(doc))
if len(doc) == 0:
- # NOISY-DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain)
+ # DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain)
break
for instance in doc:
)
if len(doc) < step:
- # NOISY-DEBUG: print("DEBUG: End of request:", len(doc), step)
+ # DEBUG: print("DEBUG: End of request:", len(doc), step)
break
- # NOISY-DEBUG: print("DEBUG: Raising counter by step:", step)
+ # DEBUG: print("DEBUG: Raising counter by step:", step)
counter = counter + step
except BaseException as e:
# 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)
+ # 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,
"limit" : step
}))
else:
- # NOISY-DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
+ # 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,
"offset" : counter-1
}))
- # NOISY-DEBUG: print("DEBUG: doc():", len(doc))
+ # DEBUG: print("DEBUG: doc():", len(doc))
if len(doc) == 0:
- # NOISY-DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain)
+ # DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain)
break
for instance in doc:
})
if len(doc) < step:
- # NOISY-DEBUG: print("DEBUG: End of request:", len(doc), step)
+ # DEBUG: print("DEBUG: End of request:", len(doc), step)
break
- # NOISY-DEBUG: print("DEBUG: Raising counter by step:", step)
+ # DEBUG: print("DEBUG: Raising counter by step:", step)
counter = counter + step
except BaseException as e:
counter = 0
break
- # NOISY-DEBUG: print("DEBUG: Returning for domain,blocked(),suspended():", domain, len(blocks["blocked"]), len(blocks["suspended"]))
+ # DEBUG: print("DEBUG: Returning for domain,blocked(),suspended():", domain, len(blocks["blocked"]), len(blocks["suspended"]))
return {
"reject" : blocks["blocked"],
"followers_only": blocks["suspended"]