From 4df23f1981b14bd52a850ac7c6a9248ffabc3869 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Sat, 5 Nov 2022 13:34:31 -0700 Subject: [PATCH] start on user page UI. in progress! --- app.py | 23 ++++- templates/base.html | 60 +++++++++++ templates/index.html | 239 +++++++++++++++++++++++++++++++++++++++++++ templates/user.html | 37 +++++++ webfinger.py | 2 +- 5 files changed, 359 insertions(+), 2 deletions(-) create mode 100644 templates/base.html create mode 100644 templates/index.html create mode 100644 templates/user.html diff --git a/app.py b/app.py index 11a626c..cb71727 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,8 @@ """Main Flask application.""" -from flask import Flask +from flask import Flask, render_template from flask_caching import Cache import flask_gae_static +from google.cloud.ndb import AND, OR, Key from oauth_dropins.webutil import ( appengine_info, appengine_config, @@ -10,6 +11,7 @@ from oauth_dropins.webutil import ( ) import common +from models import Response app = Flask(__name__, static_folder=None) @@ -37,4 +39,23 @@ cache = Cache(app) util.set_user_agent('Bridgy Fed (https://fed.brid.gy/)') +@app.get(f'/domain/') +def domain(domain): + """Serves a domain page.""" + responses = Response.query( + OR(AND(Response.key > Key('Response', f'http://{domain}/'), + Response.key < Key('Response', f'http://{domain}{chr(ord("/") + 1)}')), + AND(Response.key > Key('Response', f'https://{domain}/'), + Response.key < Key('Response', f'https://{domain}{chr(ord("/") + 1)}'))) + ).order(-Response.updated) + + return render_template( + 'user.html', + domain= domain, + responses= responses, + logs= logs, + util= util, + ) + + import activitypub, add_webmention, logs, redirect, render, salmon, superfeedr, webfinger, webmention diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..df4789e --- /dev/null +++ b/templates/base.html @@ -0,0 +1,60 @@ + + + + +{% block title %}Bridgy{% endblock %} + + + + + + + + + + + + + + +
+ +
+ +
+
+ +
+ +
+ + +
+ + +
+ +

+ +{% block content %} +{% endblock %} + + + + +
+ + + + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..0506167 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,239 @@ +{% extends "base.html" %} + +{% block content %} + +
+ +
+ + +
    +
  • How does it work?
  • +
  • +

    +Bridgy Fed lets you interact with federated social networks like Mastodon and Hubzilla from your IndieWeb site. It translates posts, replies, likes, reposts, and follows from webmentions to federated social networking protocols like ActivityPub and OStatus, and vice versa. +

    + +

    +This isn't syndication or POSSE! You don't need an account on Mastodon, Hubzilla, or anywhere else. Bridgy Fed lets your site act like a first class member of the fediverse. People on federated social networks (aka fedsocnets) will see your posts directly from your own site, and vice versa. +

    + +

    +Here's an example on Mastodon, and another example on Hubzilla. +

    + +

    +(If you just want people in the fediverse to see posts from your web site, consider an RSS or Atom feed bot instead. Bridgy Fed is more powerful, but also more work to set up and use.) +

    + +
  • Which sites are supported?
  • +
  • +

    +These sites are currently supported: +

    +
      +
    • Mastodon: posts, replies, likes, reposts aka boosts, @-mentions, and follows, both directions, via ActivityPub.
      +The instance must be running at least Mastodon 1.6, and more reliably with 2.0 and up. You can find its version on the bottom or right of its /about/more page, e.g. mastodon.social/about/more. +
    • +
    • Hubzilla: replies, likes, and reposts aka shares, both directions, via OStatus.
      +The instance must be running Hubzilla 2.6 or higher. You can find its version on its /siteinfo page, e.g. hub.somaton.com/siteinfo. It also needs the GNU Social addon installed and enabled, and you also need to enable it in your account settings on the Feature/Addon settings page (/settings/featured). +
    • +
    + +

    +We're aware of the sites below, and we've made progress on some, but they're not yet supported. Click through and vote for their feature requests if you're interested in any of them! +

    + +
  • + +
  • How do I use it?
  • +
  • + +

    +Federated social network identities take the form @username@example.com, like an email address with a leading @. Your site's identity via Bridgy Fed will be @yourdomain.com@yourdomain.com. Once you've set up Atom on your site, people can follow you at that address. +

    + +

    +Most fedsocnets also publish Atom themselves, so you can add profile URLs like mastodon.technology/@snarfed to your reader and see their posts there too. +

    + +

    +To use it, first set up your site, then create an IndieWeb post, like, repost, reply, or follow as usual, and include a link to https://fed.brid.gy/ in that post. Your web server should then send Bridgy Fed a webmention, which it will translate to a Salmon slap or ActivityPub activity and forward to the destination. For example: +

    + +
    <div class="h-entry">
    +  Regarding <a class="u-in-reply-to" href="https://mastodon.technology/@snarfed/3194674">this post</a>:
    +  <p class="e-content">Highly entertaining. Please subscribe me to your newsletter.</p>
    +  <a href="https://fed.brid.gy/"></a>
    +</div>
    +
    + +

    +To receive likes, reposts, replies, and follows from fedsocnets, just make sure your site accepts webmentions! Bridgy translates incoming Salmon slaps and ActivityPub activities to webmentions and sends them to your site.

    + +

    +The webmention source URL will usually be a proxy page on fed.brid.gy. For best results, make sure your webmention handler detects and handles u-url links! +

    +
  • + +
  • How do I set it up?
  • +
  • +

    +First, your site needs to support webmentions. Check out the IndieWeb wiki for instructions for your web server. +

    + +

    +Next, add an Atom feed if your site doesn't already have one. If you're on WordPress, add this to your site's HTML <head> and replace [DOMAIN] with your site's domain: +

    +
    <link rel="alternate" type="application/atom+xml" href="http://[DOMAIN]/?feed=atom" />
    +

    If you're not on WordPress, you can use granary: +

    +
    <link rel="alternate" type="application/atom+xml"
    +      href="https://granary.io/url?url=http://[DOMAIN]/&input=html&output=atom&hub=https://bridgy-fed.superfeedr.com/" />
    + +

    +Finally, configure your web site to redirect these URL paths to the same paths on https://fed.brid.gy/, including query parameters: +

    +
    +/.well-known/host-meta
    +/.well-known/host-meta.xrd
    +/.well-known/host-meta.jrd
    +/.well-known/webfinger
    +
    + +

    Here are instructions for a few common web servers:

    + +
      +
    • +

      WordPress (self-hosted): install the Safe Redirect Manager plugin, then add these entries:

      + + /.well-known/host-meta* => https://fed.brid.gy/.well-known/host-meta*
      + /.well-known/webfinger* => https://fed.brid.gy/.well-known/webfinger* +
      +
    • + +
    • Known or Drupal: follow the Apache or nginx instructions below. +
    • + +
    • Apache: add this to your .htaccess file:
      +
      RewriteEngine on
      +RewriteBase /
      +RewriteRule ^.well-known/(host-meta|webfinger).* https://fed.brid.gy/$0  [redirect=302,last]
      +(RewriteEngine on is optional if you already have it earlier in your .htaccess. RewriteBase / is optional if you don't have any other RewriteBase directives, or if you put this RewriteRule inside an existing RewriteBase / section.) +
    • + +
    • nginx: add this to your nginx.conf file, in the server section:
      +
      rewrite ^/.well-known/(host-meta|webfinger).* https://fed.brid.gy$request_uri redirect;
      +
    • + + + +
    + +

    +If you want people on OStatus sites like Hubzilla to see your posts, your web site will also need to support WebSub (née PubSubHubbub). Specifically, your Atom feed needs to advertise it. Example details for Mastodon. If you're on a CMS, it may already have a plugin! WordPress has a couple, and Known has it built in. Or you can use Superfeedr or Switchboard. +

    + + +
  • + +
  • How do I include an image in a post?
  • +
  • +

    +Use <img class="u-photo"> for the image in your post. For example: + +

    +<img class="u-photo" src="/full_glass.jpg" />
    +I love scotch. Scotchy scotchy scotch.
    +
    +

    +
  • + +
  • How can people on the fediverse find me?
  • +
  • +

    In general, all you have to do is use Bridgy Fed to interact with the fediverse once. Send an original post from your site, like or repost something, follow someone, etc. Then, when other users search for @yourdomain.com@yourdomain.com, they should find your profile! +

    +

    In practice, this can be a bit finicky, and takes time to propagate to other instances besides the one you first interacted with, but it generally does work. +

    +
  • + +
  • I tried it, and it didn't work!
  • +
  • +

    If you sent a webmention, check the HTTP response code and body. It will usually describe the error.

    +

    If you got an HTTP 204 from an attempt to federate a response to Mastodon, that means Mastodon accepted the response. If it doesn't show up, that's a known inconsistency right now. We're actively working with them to debug these cases.

    +

    You can also see recent Bridgy Fed requests here, including raw logs. Warning: not for the faint of heart!

    +
  • + +
  • How much does it cost?
  • +
  • +

    Nothing! Bridgy Fed is small, and it doesn't cost much to run. We don't need donations, promise. +

    +

    If you really want to contribute, file an issue or send a pull request, or donate to the IndieWeb! +

  • + +
  • Who are you? Why did you make this?
  • +
  • +

    +I'm Ryan Barrett. I'm just a guy who +likes the web and owning my data. +

    +
  • + +
  • What do you do with my data?
  • +
  • +

    Nothing! Bridgy Fed isn't a business, and never will be, so we don't have the same motivations to abuse your data that other services might. More concretely, Bridgy Fed won't ever send you email, it stores as little of your PII (personally identifiable information) as possible, and it never has access to any of your passwords. +

    +
  • + +
  • How long has this been around?
  • +
  • +

    I started thinking about bridging federated social networks and peer to peer networks when I discovered them in the early 2000s. I started talking about bridging them to the IndieWeb in 2016, led a session on it at IndieWeb Summit in July 2017, wrote up concrete designs soon after, and started working on Bridgy Fed in August 2017. +

  • + +
  • I found a bug! I have a feature request!
  • +
  • +

    Great! Please file it in GitHub. Thank you! +

    +
  • + +
+
+ +{% endblock %} diff --git a/templates/user.html b/templates/user.html new file mode 100644 index 0000000..68cbba4 --- /dev/null +++ b/templates/user.html @@ -0,0 +1,37 @@ +{% extends "base.html" %} + +{% block title %}{{ domain }} - Bridgy Fed{% endblock %} + +{% block content %} + + + +

Responses:

+ + +{% endblock %} diff --git a/webfinger.py b/webfinger.py index feaae19..476c661 100644 --- a/webfinger.py +++ b/webfinger.py @@ -192,7 +192,7 @@ def host_meta_xrds(): app.add_url_rule(f'/acct:', - view_func=User.as_view('user')) + view_func=User.as_view('acct')) app.add_url_rule('/.well-known/webfinger', view_func=Webfinger.as_view('webfinger')) app.add_url_rule('/.well-known/host-meta', view_func=HostMeta.as_view('hostmeta')) app.add_url_rule('/.well-known/host-meta.json', view_func=HostMeta.as_view('hostmeta-json'))