forked from GNUsocial/gnu-social
Implemented WebFinger and replaced our XRD with PEAR XML_XRD
New plugins: * LRDD LRDD implements client-side RFC6415 and RFC7033 resource descriptor discovery procedures. I.e. LRDD, host-meta and WebFinger stuff. OStatus and OpenID now depend on the LRDD plugin (XML_XRD). * WebFinger This plugin implements the server-side of RFC6415 and RFC7033. Note: WebFinger technically doesn't handle XRD, but we serve both that and JRD (JSON Resource Descriptor), depending on Accept header and one ugly hack to check for old StatusNet installations. WebFinger depends on LRDD. We might make this even prettier by using Net_WebFinger, but it is not currently RFC7033 compliant (no /.well-known/webfinger resource GETs). Disabling the WebFinger plugin would effectively render your site non- federated (which might be desired on a private site). Disabling the LRDD plugin would make your site unable to do modern web URI lookups (making life just a little bit harder).
This commit is contained in:
@@ -18,13 +18,15 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* OStatusPlugin implementation for GNU Social
|
||||
*
|
||||
* Depends on: WebFinger plugin
|
||||
*
|
||||
* @package OStatusPlugin
|
||||
* @maintainer Brion Vibber <brion@status.net>
|
||||
*/
|
||||
|
||||
if (!defined('STATUSNET')) {
|
||||
exit(1);
|
||||
}
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/');
|
||||
|
||||
@@ -52,8 +54,6 @@ class OStatusPlugin extends Plugin
|
||||
function onRouterInitialized($m)
|
||||
{
|
||||
// Discovery actions
|
||||
$m->connect('main/ownerxrd',
|
||||
array('action' => 'ownerxrd'));
|
||||
$m->connect('main/ostatustag',
|
||||
array('action' => 'ostatustag'));
|
||||
$m->connect('main/ostatustag?nickname=:nickname',
|
||||
@@ -137,20 +137,6 @@ class OStatusPlugin extends Plugin
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a link header for LRDD Discovery
|
||||
*/
|
||||
function onStartShowHTML($action)
|
||||
{
|
||||
if ($action instanceof ShowstreamAction) {
|
||||
$acct = 'acct:'. $action->profile->nickname .'@'. common_config('site', 'server');
|
||||
$url = common_local_url('userxrd');
|
||||
$url.= '?uri='. $acct;
|
||||
|
||||
header('Link: <'.$url.'>; rel="'. Discovery::LRDD_REL.'"; type="application/xrd+xml"');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up a PuSH hub link to our internal link for canonical timeline
|
||||
* Atom feeds for users and groups.
|
||||
@@ -1328,42 +1314,38 @@ class OStatusPlugin extends Plugin
|
||||
return true;
|
||||
}
|
||||
|
||||
function onEndXrdActionLinks(&$xrd, $user)
|
||||
function onEndXrdActionLinks(XML_XRD $xrd, Profile $target)
|
||||
{
|
||||
$xrd->links[] = array('rel' => Discovery::UPDATESFROM,
|
||||
'href' => common_local_url('ApiTimelineUser',
|
||||
array('id' => $user->id,
|
||||
'format' => 'atom')),
|
||||
'type' => 'application/atom+xml');
|
||||
$xrd->links[] = new XML_XRD_Element_Link(Discovery::UPDATESFROM,
|
||||
common_local_url('ApiTimelineUser',
|
||||
array('id' => $target->id, 'format' => 'atom')),
|
||||
'application/atom+xml');
|
||||
|
||||
// Salmon
|
||||
$salmon_url = common_local_url('usersalmon',
|
||||
array('id' => $user->id));
|
||||
array('id' => $target->id));
|
||||
|
||||
$xrd->links[] = array('rel' => Salmon::REL_SALMON,
|
||||
'href' => $salmon_url);
|
||||
$xrd->links[] = new XML_XRD_Element_Link(Salmon::REL_SALMON, $salmon_url);
|
||||
// XXX : Deprecated - to be removed.
|
||||
$xrd->links[] = array('rel' => Salmon::NS_REPLIES,
|
||||
'href' => $salmon_url);
|
||||
|
||||
$xrd->links[] = array('rel' => Salmon::NS_MENTIONS,
|
||||
'href' => $salmon_url);
|
||||
$xrd->links[] = new XML_XRD_Element_Link(Salmon::NS_REPLIES, $salmon_url);
|
||||
$xrd->links[] = new XML_XRD_Element_Link(Salmon::NS_MENTIONS, $salmon_url);
|
||||
|
||||
// Get this user's keypair
|
||||
$magickey = Magicsig::getKV('user_id', $user->id);
|
||||
if (!$magickey) {
|
||||
$magickey = Magicsig::getKV('user_id', $target->id);
|
||||
if (!($magickey instanceof Magicsig)) {
|
||||
// No keypair yet, let's generate one.
|
||||
$magickey = new Magicsig();
|
||||
$magickey->generate($user->id);
|
||||
$magickey->generate($target->id);
|
||||
}
|
||||
|
||||
$xrd->links[] = array('rel' => Magicsig::PUBLICKEYREL,
|
||||
'href' => 'data:application/magic-public-key,'. $magickey->toString(false));
|
||||
$xrd->links[] = new XML_XRD_Element_Link(Magicsig::PUBLICKEYREL,
|
||||
'data:application/magic-public-key,'. $magickey->toString(false));
|
||||
|
||||
// TODO - finalize where the redirect should go on the publisher
|
||||
$url = common_local_url('ostatussub') . '?profile={uri}';
|
||||
$xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/subscribe',
|
||||
'template' => $url );
|
||||
$xrd->links[] = new XML_XRD_Element_Link('http://ostatus.org/schema/1.0/subscribe',
|
||||
common_local_url('ostatussub') . '?profile={uri}',
|
||||
null, // type not set
|
||||
true); // isTemplate
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -175,20 +175,14 @@ class OStatusInitAction extends Action
|
||||
$target_profile = $this->targetProfile();
|
||||
|
||||
$disco = new Discovery;
|
||||
$result = $disco->lookup($acct);
|
||||
if (!$result) {
|
||||
// TRANS: Client error.
|
||||
$this->clientError(_m('Could not look up OStatus account profile.'));
|
||||
}
|
||||
|
||||
foreach ($result->links as $link) {
|
||||
if ($link['rel'] == 'http://ostatus.org/schema/1.0/subscribe') {
|
||||
// We found a URL - let's redirect!
|
||||
$url = Discovery::applyTemplate($link['template'], $target_profile);
|
||||
common_log(LOG_INFO, "Sending remote subscriber $acct to $url");
|
||||
common_redirect($url, 303);
|
||||
}
|
||||
$xrd = $disco->lookup($acct);
|
||||
|
||||
$link = $xrd->get('http://ostatus.org/schema/1.0/subscribe');
|
||||
if (!is_null($link)) {
|
||||
// We found a URL - let's redirect!
|
||||
$url = Discovery::applyTemplate($link['template'], $target_profile);
|
||||
common_log(LOG_INFO, "Sending remote subscriber $acct to $url");
|
||||
common_redirect($url, 303);
|
||||
}
|
||||
// TRANS: Client error.
|
||||
$this->clientError(_m('Could not confirm remote profile address.'));
|
||||
|
@@ -87,20 +87,14 @@ class OStatusTagAction extends OStatusInitAction
|
||||
$target_profile = $this->targetProfile();
|
||||
|
||||
$disco = new Discovery;
|
||||
$result = $disco->lookup($acct);
|
||||
if (!$result) {
|
||||
// TRANS: Client error displayed when remote profile could not be looked up.
|
||||
$this->clientError(_m('Could not look up OStatus account profile.'));
|
||||
}
|
||||
|
||||
foreach ($result->links as $link) {
|
||||
if ($link['rel'] == 'http://ostatus.org/schema/1.0/tag') {
|
||||
// We found a URL - let's redirect!
|
||||
$url = Discovery::applyTemplate($link['template'], $target_profile);
|
||||
common_log(LOG_INFO, "Sending remote subscriber $acct to $url");
|
||||
common_redirect($url, 303);
|
||||
}
|
||||
$xrd = $disco->lookup($acct);
|
||||
|
||||
$link = $xrd->get('http://ostatus.org/schema/1.0/tag');
|
||||
if (!is_null($link)) {
|
||||
// We found a URL - let's redirect!
|
||||
$url = Discovery::applyTemplate($link->template, $target_profile);
|
||||
common_log(LOG_INFO, "Sending remote subscriber $acct to $url");
|
||||
common_redirect($url, 303);
|
||||
}
|
||||
// TRANS: Client error displayed when remote profile address could not be confirmed.
|
||||
$this->clientError(_m('Could not confirm remote profile address.'));
|
||||
|
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* StatusNet - the distributed open-source microblogging tool
|
||||
* Copyright (C) 2010, StatusNet, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package OStatusPlugin
|
||||
* @maintainer James Walker <james@status.net>
|
||||
*/
|
||||
|
||||
if (!defined('STATUSNET')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
class OwnerxrdAction extends XrdAction
|
||||
{
|
||||
|
||||
public $uri;
|
||||
|
||||
function prepare($args)
|
||||
{
|
||||
$this->user = User::siteOwner();
|
||||
|
||||
if (!$this->user) {
|
||||
// TRANS: Client error displayed when referring to a non-existing user.
|
||||
$this->clientError(_m('No such user.'), 404);
|
||||
return false;
|
||||
}
|
||||
|
||||
$nick = common_canonical_nickname($this->user->nickname);
|
||||
$acct = 'acct:' . $nick . '@' . common_config('site', 'server');
|
||||
|
||||
$this->xrd = new XRD();
|
||||
|
||||
// Check to see if a $config['webfinger']['owner'] has been set
|
||||
if ($owner = common_config('webfinger', 'owner')) {
|
||||
$this->xrd->subject = Discovery::normalize($owner);
|
||||
$this->xrd->alias[] = $acct;
|
||||
} else {
|
||||
$this->xrd->subject = $acct;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,126 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* StatusNet - the distributed open-source microblogging tool
|
||||
* Copyright (C) 2010, StatusNet, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package OStatusPlugin
|
||||
* @maintainer James Walker <james@status.net>
|
||||
*/
|
||||
|
||||
if (!defined('STATUSNET')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
class XrdAction extends Action
|
||||
{
|
||||
public $uri;
|
||||
|
||||
public $user;
|
||||
|
||||
public $xrd;
|
||||
|
||||
function handle()
|
||||
{
|
||||
$nick = $this->user->nickname;
|
||||
$profile = $this->user->getProfile();
|
||||
|
||||
if (empty($this->xrd)) {
|
||||
$xrd = new XRD();
|
||||
} else {
|
||||
$xrd = $this->xrd;
|
||||
}
|
||||
|
||||
if (empty($xrd->subject)) {
|
||||
$xrd->subject = Discovery::normalize($this->uri);
|
||||
}
|
||||
|
||||
// Possible aliases for the user
|
||||
|
||||
$uris = array($this->user->uri, $profile->profileurl);
|
||||
|
||||
// FIXME: Webfinger generation code should live somewhere on its own
|
||||
|
||||
$path = common_config('site', 'path');
|
||||
|
||||
if (empty($path)) {
|
||||
$uris[] = sprintf('acct:%s@%s', $nick, common_config('site', 'server'));
|
||||
}
|
||||
|
||||
foreach ($uris as $uri) {
|
||||
if ($uri != $xrd->subject) {
|
||||
$xrd->alias[] = $uri;
|
||||
}
|
||||
}
|
||||
|
||||
$xrd->links[] = array('rel' => Discovery::PROFILEPAGE,
|
||||
'type' => 'text/html',
|
||||
'href' => $profile->profileurl);
|
||||
|
||||
$xrd->links[] = array('rel' => Discovery::UPDATESFROM,
|
||||
'href' => common_local_url('ApiTimelineUser',
|
||||
array('id' => $this->user->id,
|
||||
'format' => 'atom')),
|
||||
'type' => 'application/atom+xml');
|
||||
|
||||
// XFN
|
||||
$xrd->links[] = array('rel' => 'http://gmpg.org/xfn/11',
|
||||
'type' => 'text/html',
|
||||
'href' => $profile->profileurl);
|
||||
// FOAF
|
||||
$xrd->links[] = array('rel' => 'describedby',
|
||||
'type' => 'application/rdf+xml',
|
||||
'href' => common_local_url('foaf',
|
||||
array('nickname' => $nick)));
|
||||
|
||||
// Salmon
|
||||
$salmon_url = common_local_url('usersalmon',
|
||||
array('id' => $this->user->id));
|
||||
|
||||
$xrd->links[] = array('rel' => Salmon::REL_SALMON,
|
||||
'href' => $salmon_url);
|
||||
// XXX : Deprecated - to be removed.
|
||||
$xrd->links[] = array('rel' => Salmon::NS_REPLIES,
|
||||
'href' => $salmon_url);
|
||||
|
||||
$xrd->links[] = array('rel' => Salmon::NS_MENTIONS,
|
||||
'href' => $salmon_url);
|
||||
|
||||
// Get this user's keypair
|
||||
$magickey = Magicsig::getKV('user_id', $this->user->id);
|
||||
if (!$magickey) {
|
||||
// No keypair yet, let's generate one.
|
||||
$magickey = new Magicsig();
|
||||
$magickey->generate($this->user->id);
|
||||
}
|
||||
|
||||
$xrd->links[] = array('rel' => Magicsig::PUBLICKEYREL,
|
||||
'href' => 'data:application/magic-public-key,'. $magickey->toString(false));
|
||||
|
||||
// TODO - finalize where the redirect should go on the publisher
|
||||
$url = common_local_url('ostatussub') . '?profile={uri}';
|
||||
$xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/subscribe',
|
||||
'template' => $url );
|
||||
|
||||
$url = common_local_url('tagprofile') . '?uri={uri}';
|
||||
$xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/tag',
|
||||
'template' => $url );
|
||||
|
||||
header('Content-type: application/xrd+xml');
|
||||
print $xrd->toXML();
|
||||
}
|
||||
}
|
@@ -1011,14 +1011,14 @@ class Ostatus_profile extends Managed_DataObject
|
||||
|
||||
// Check if they've got an LRDD header
|
||||
|
||||
$lrdd = LinkHeader::getLink($response, 'lrdd', 'application/xrd+xml');
|
||||
|
||||
if (!empty($lrdd)) {
|
||||
|
||||
$xrd = Discovery::fetchXrd($lrdd);
|
||||
$lrdd = LinkHeader::getLink($response, 'lrdd');
|
||||
try {
|
||||
$xrd = new XML_XRD();
|
||||
$xrd->loadFile($lrdd);
|
||||
$xrdHints = DiscoveryHints::fromXRD($xrd);
|
||||
|
||||
$hints = array_merge($hints, $xrdHints);
|
||||
} catch (Exception $e) {
|
||||
// No hints available from XRD
|
||||
}
|
||||
|
||||
// If discovery found a feedurl (probably from LRDD), use it.
|
||||
|
@@ -20,26 +20,26 @@
|
||||
*/
|
||||
|
||||
class DiscoveryHints {
|
||||
static function fromXRD($xrd)
|
||||
static function fromXRD(XML_XRD $xrd)
|
||||
{
|
||||
$hints = array();
|
||||
|
||||
foreach ($xrd->links as $link) {
|
||||
switch ($link['rel']) {
|
||||
case Discovery::PROFILEPAGE:
|
||||
$hints['profileurl'] = $link['href'];
|
||||
foreach ($xrd->getAll() as $link) {
|
||||
switch ($link->rel) {
|
||||
case WebFinger::PROFILEPAGE:
|
||||
$hints['profileurl'] = $link->href;
|
||||
break;
|
||||
case Salmon::NS_MENTIONS:
|
||||
case Salmon::NS_REPLIES:
|
||||
$hints['salmon'] = $link['href'];
|
||||
$hints['salmon'] = $link->href;
|
||||
break;
|
||||
case Discovery::UPDATESFROM:
|
||||
if (empty($link['type']) || $link['type'] == 'application/atom+xml') {
|
||||
$hints['feedurl'] = $link['href'];
|
||||
if (empty($link->type) || $link->type == 'application/atom+xml') {
|
||||
$hints['feedurl'] = $link->href;
|
||||
}
|
||||
break;
|
||||
case Discovery::HCARD:
|
||||
$hints['hcardurl'] = $link['href'];
|
||||
$hints['hcardurl'] = $link->href;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@@ -56,23 +56,22 @@ class MagicEnvelope
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
if ($xrd->links) {
|
||||
if ($link = Discovery::getService($xrd->links, Magicsig::PUBLICKEYREL)) {
|
||||
$keypair = false;
|
||||
$parts = explode(',', $link['href']);
|
||||
$link = $xrd->get(Magicsig::PUBLICKEYREL);
|
||||
if (!is_null($link)) {
|
||||
$keypair = false;
|
||||
$parts = explode(',', $link['href']);
|
||||
if (count($parts) == 2) {
|
||||
$keypair = $parts[1];
|
||||
} else {
|
||||
// Backwards compatibility check for separator bug in 0.9.0
|
||||
$parts = explode(';', $link['href']);
|
||||
if (count($parts) == 2) {
|
||||
$keypair = $parts[1];
|
||||
} else {
|
||||
// Backwards compatibility check for separator bug in 0.9.0
|
||||
$parts = explode(';', $link['href']);
|
||||
if (count($parts) == 2) {
|
||||
$keypair = $parts[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($keypair) {
|
||||
return $keypair;
|
||||
}
|
||||
if ($keypair) {
|
||||
return $keypair;
|
||||
}
|
||||
}
|
||||
// TRANS: Exception.
|
||||
|
@@ -157,13 +157,13 @@ class LooseOstatusProfile extends Ostatus_profile
|
||||
// Check if they've got an LRDD header
|
||||
|
||||
$lrdd = LinkHeader::getLink($response, 'lrdd', 'application/xrd+xml');
|
||||
|
||||
if (!empty($lrdd)) {
|
||||
|
||||
$xrd = Discovery::fetchXrd($lrdd);
|
||||
try {
|
||||
$xrd = new XML_XRD();
|
||||
$xrd->loadFile($lrdd);
|
||||
$xrdHints = DiscoveryHints::fromXRD($xrd);
|
||||
|
||||
$hints = array_merge($hints, $xrdHints);
|
||||
} catch (Exception $e) {
|
||||
// No hints available from XRD
|
||||
}
|
||||
|
||||
// If discovery found a feedurl (probably from LRDD), use it.
|
||||
|
Reference in New Issue
Block a user