Merge pull request #4 from db0/nodeinfo

feat: support other software
pull/6/head
Divided by Zer0 2023-06-22 19:43:36 +02:00 committed by GitHub
commit 2b16dc6dba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 10 deletions

View File

@ -5,3 +5,5 @@ This service provides an REST API which can be used to retrieve various informat
It's reliant on the [Lemmy Fediverse Observer](https://lemmy.fediverse.observer/)
The currently running instance is on https://overseer.dbzer0.com
See devlog: https://dbzer0.com/blog/overseer-a-fediverse-chain-of-trust/

View File

@ -1,4 +1,5 @@
from overseer.apis.v1.base import *
from overseer.utils import get_nodeinfo
class Whitelist(Resource):
get_parser = reqparse.RequestParser()
@ -68,21 +69,34 @@ class WhitelistDomain(Resource):
if domain.endswith("test.dbzer0.com"):
requested_lemmy = Lemmy(f"https://{domain}")
requested_lemmy._requestor.nodeinfo = {"software":{"name":"lemmy"}}
site = {"site_view":{"local_site":{"require_email_verification": True,"registration_mode":"open"}}}
open_registrations = False
email_verify = True
software = "lemmy"
else:
nodeinfo = get_nodeinfo(domain)
if not nodeinfo:
raise e.BadRequest(f"Error encountered while polling domain {domain}. Please check it's running correctly")
software = nodeinfo["software"]["name"]
if software == "lemmy":
requested_lemmy = Lemmy(f"https://{domain}")
site = requested_lemmy.site.get()
if not site:
raise e.BadRequest(f"Error encountered while polling domain {domain}. Please check it's running correctly")
raise e.BadRequest(f"Error encountered while polling lemmy domain {domain}. Please check it's running correctly")
open_registrations = site["site_view"]["local_site"]["registration_mode"] == "open"
email_verify = site["site_view"]["local_site"]["require_email_verification"]
software = software
else:
open_registrations = nodeinfo["openRegistrations"]
email_verify = False
api_key = pm_new_api_key(domain)
if not api_key:
raise e.BadRequest("Failed to generate API Key")
new_instance = Instance(
domain=domain,
api_key=hash_api_key(api_key),
open_registrations=site["site_view"]["local_site"]["registration_mode"] == "open",
email_verify=site["site_view"]["local_site"]["require_email_verification"],
software=requested_lemmy.nodeinfo['software']['name'],
open_registrations=open_registrations,
email_verify=email_verify,
software=software,
)
new_instance.create()
if guarantor_instance:

View File

@ -2,6 +2,14 @@
This is a [FOSS service](https://github.com/db0/lemmy-overseer) to help Lemmy instances detect and avoid suspcicious instances
[Release Devlog](https://dbzer0.com/blog/overseer-a-fediverse-chain-of-trust/)
## Scope
This Overseer is focused around anti-spam verification. We make no judgement on the content of the guaranteed communities other than they have been verified to not be fake spam instances and are making a good effort to block spam accounts.
However using the endorsement system, you can create a further customized whitelist around the endorsement of instances you trust.
## REST API
[Full Documentation](/api)

View File

@ -10,6 +10,7 @@ from datetime import datetime
import dateutil.relativedelta
from loguru import logger
from overseer.flask import SQLITE_MODE
import requests
random.seed(random.SystemRandom().randint(0, 2**32 - 1))
@ -101,3 +102,11 @@ def validate_regex(regex_string):
except:
return False
return True
def get_nodeinfo(domain):
try:
wellknown = requests.get(f"https://{domain}/.well-known/nodeinfo", timeout=2).json()
nodeinfo = requests.get(wellknown['links'][0]['href'], timeout=2).json()
return nodeinfo
except Exception as err:
return None