2013-10-01 00:13:03 +09:00
|
|
|
<?php
|
2020-07-22 07:30:04 +09:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social 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.
|
|
|
|
//
|
|
|
|
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2013-10-01 00:13:03 +09:00
|
|
|
/**
|
|
|
|
* Implementation of WebFinger resource discovery (RFC7033)
|
|
|
|
*
|
|
|
|
* @category Discovery
|
2013-10-15 07:20:36 +09:00
|
|
|
* @package GNUsocial
|
2013-10-01 00:13:03 +09:00
|
|
|
* @author Mikael Nordfeldth <mmn@hethane.se>
|
2020-07-22 07:30:04 +09:00
|
|
|
* @copyright 2013 Free Software Foundation, Inc http://www.fsf.org
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2013-10-01 00:13:03 +09:00
|
|
|
*/
|
|
|
|
class LRDDMethod_WebFinger extends LRDDMethod
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Simply returns the WebFinger URL over HTTPS at the uri's domain:
|
|
|
|
* https://{domain}/.well-known/webfinger?resource={uri}
|
|
|
|
*/
|
|
|
|
public function discover($uri)
|
|
|
|
{
|
2020-07-22 07:30:04 +09:00
|
|
|
$parts = explode('@', parse_url($uri, PHP_URL_PATH), 2);
|
|
|
|
|
|
|
|
if (!Discovery::isAcct($uri) || count($parts) != 2) {
|
|
|
|
throw new Exception('Bad resource URI: ' . $uri);
|
2013-10-01 00:13:03 +09:00
|
|
|
}
|
2020-07-22 07:30:04 +09:00
|
|
|
[, $domain] = $parts;
|
2013-10-01 00:13:03 +09:00
|
|
|
if (!filter_var($domain, FILTER_VALIDATE_IP)
|
2020-07-22 07:30:04 +09:00
|
|
|
&& !filter_var(gethostbyname($domain), FILTER_VALIDATE_IP)) {
|
2013-10-01 00:13:03 +09:00
|
|
|
throw new Exception('Bad resource host.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$link = new XML_XRD_Element_Link(
|
2020-07-22 07:30:04 +09:00
|
|
|
Discovery::LRDD_REL,
|
|
|
|
'https://' . $domain . '/.well-known/webfinger?resource={uri}',
|
|
|
|
Discovery::JRD_MIMETYPE,
|
|
|
|
true // isTemplate
|
|
|
|
);
|
2013-10-01 00:13:03 +09:00
|
|
|
|
2020-07-22 07:30:04 +09:00
|
|
|
return [$link];
|
2013-10-01 00:13:03 +09:00
|
|
|
}
|
|
|
|
}
|