Skip to content

Commit

Permalink
/web-site: show nice error for fediverse servers
Browse files Browse the repository at this point in the history
for #911
  • Loading branch information
snarfed committed Sep 19, 2024
1 parent e4db9d6 commit 1b19fde
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions web.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def verify(self):
urljoin(self.web_url(), '/.well-known/host-meta'),
gateway=False)
if resp.ok and domain_from_link(resp.url) not in common.DOMAINS:
logger.info(f"{domain} serves Webfinger! probably a fediverse server")
self.redirects_error = OWNS_WEBFINGER
else:
diff = '\n'.join(difflib.Differ().compare([got], [expected[0]]))
Expand Down Expand Up @@ -643,17 +644,23 @@ def check_web_site():
try:
user = Web.get_or_create(domain, enabled_protocols=['atproto'],
propagate=True, direct=True, verify=True)
if not user: # opted out
flash(f'{url} is not a valid or supported web site')
return render_template('enter_web_site.html'), 400
except BaseException as e:
code, body = util.interpret_http_exception(e)
if code:
flash(f"Couldn't connect to {url}: {e}")
return render_template('enter_web_site.html')
raise

if not user: # opted out
flash(f'{url} is not a valid or supported web site')
return render_template('enter_web_site.html'), 400

user.put()

if user.redirects_error == OWNS_WEBFINGER:
flash(f'{url} looks like a fediverse server! Try a normal web site.')
return render_template('enter_web_site.html'), 400

return redirect(user.user_page_path())


Expand Down

0 comments on commit 1b19fde

Please sign in to comment.