feat: Can now censure unreachable domains and wildcards
parent
5f9cf5da01
commit
6c2f7ba838
|
@ -60,7 +60,7 @@ class Suspicions(Resource):
|
|||
|
||||
|
||||
|
||||
def ensure_instance_registered(domain):
|
||||
def ensure_instance_registered(domain, allow_unreachable=False):
|
||||
if domain.endswith("test.dbzer0.com"):
|
||||
# Fake instances for testing chain of trust
|
||||
requested_lemmy = Lemmy(f"https://{domain}")
|
||||
|
@ -75,7 +75,18 @@ def ensure_instance_registered(domain):
|
|||
else:
|
||||
nodeinfo = get_nodeinfo(domain)
|
||||
if not nodeinfo:
|
||||
raise e.BadRequest(f"Error encountered while polling domain {domain}. Please check it's running correctly")
|
||||
if not allow_unreachable:
|
||||
raise e.BadRequest(f"Error encountered while polling domain {domain}. Please check it's running correctly")
|
||||
else:
|
||||
software = "unknown"
|
||||
if "*" in domain:
|
||||
software = "wildcard"
|
||||
nodeinfo = {
|
||||
"openRegistrations": False,
|
||||
"software": {
|
||||
"name": software
|
||||
}
|
||||
}
|
||||
software = nodeinfo["software"]["name"]
|
||||
if software == "lemmy":
|
||||
requested_lemmy = Lemmy(f"https://{domain}")
|
||||
|
|
|
@ -95,7 +95,7 @@ class Censures(Resource):
|
|||
unbroken_chain, chainbreaker = database.has_unbroken_chain(instance.id)
|
||||
if not unbroken_chain:
|
||||
raise e.Forbidden(f"Guarantee chain for this instance has been broken. Chain ends at {chainbreaker.domain}!")
|
||||
target_instance, nodeinfo, admin_usernames = ensure_instance_registered(domain)
|
||||
target_instance, nodeinfo, admin_usernames = ensure_instance_registered(domain, allow_unreachable=True)
|
||||
if not target_instance:
|
||||
raise e.NotFound(f"Something went wrong trying to register this instance.")
|
||||
if not target_instance:
|
||||
|
|
|
@ -8,7 +8,7 @@ def get_lemmy_admins(domain):
|
|||
site = requested_lemmy.site.get()
|
||||
if not site:
|
||||
logger.warning(f"Error retrieving mastodon site info for {domain}")
|
||||
return None
|
||||
raise Exception(f"Error retrieving mastodon site info for {domain}")
|
||||
return [a["person"]["name"] for a in site["admins"]]
|
||||
|
||||
def get_mastodon_admins(domain):
|
||||
|
@ -17,13 +17,18 @@ def get_mastodon_admins(domain):
|
|||
return [site["contact"]["account"]["username"]]
|
||||
except Exception as err:
|
||||
logger.warning(f"Error retrieving mastodon site info for {domain}: {err}")
|
||||
return None
|
||||
raise Exception(f"Error retrieving mastodon site info for {domain}: {err}")
|
||||
|
||||
def get_unknown_admins(domain):
|
||||
return []
|
||||
|
||||
def get_admin_for_software(software: str, domain: str):
|
||||
software_map = {
|
||||
"lemmy": get_lemmy_admins,
|
||||
"mastodon": get_mastodon_admins,
|
||||
"friendica": get_mastodon_admins,
|
||||
"unknown": get_unknown_admins,
|
||||
"wildcard": get_unknown_admins,
|
||||
}
|
||||
if software not in software_map:
|
||||
return []
|
||||
|
|
Loading…
Reference in New Issue