support other software

pull/4/head
db0 2023-06-22 19:37:03 +02:00
parent b1981a8d0c
commit 16cd128767
2 changed files with 32 additions and 9 deletions

View File

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

View File

@ -10,6 +10,7 @@ from datetime import datetime
import dateutil.relativedelta import dateutil.relativedelta
from loguru import logger from loguru import logger
from overseer.flask import SQLITE_MODE from overseer.flask import SQLITE_MODE
import requests
random.seed(random.SystemRandom().randint(0, 2**32 - 1)) random.seed(random.SystemRandom().randint(0, 2**32 - 1))
@ -101,3 +102,11 @@ def validate_regex(regex_string):
except: except:
return False return False
return True 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