2019-04-30 16:22:36 -04:00
|
|
|
<?php
|
2020-02-09 09:45:36 -05:00
|
|
|
/**
|
2023-01-01 09:36:24 -05:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2020-02-09 09:45:36 -05:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-04-30 16:22:36 -04:00
|
|
|
|
2019-04-30 18:14:06 -04:00
|
|
|
namespace Friendica\Module\WellKnown;
|
2019-04-30 16:22:36 -04:00
|
|
|
|
|
|
|
use Friendica\BaseModule;
|
2022-04-10 04:31:55 -04:00
|
|
|
use Friendica\Core\System;
|
2019-12-15 16:34:11 -05:00
|
|
|
use Friendica\DI;
|
2022-04-10 04:31:55 -04:00
|
|
|
use Friendica\Module\Response;
|
2019-04-30 16:22:36 -04:00
|
|
|
use Friendica\Protocol\Salmon;
|
|
|
|
use Friendica\Util\Crypto;
|
2022-09-11 03:00:16 -04:00
|
|
|
use Friendica\Util\XML;
|
2019-04-30 16:22:36 -04:00
|
|
|
|
|
|
|
/**
|
2019-04-30 18:14:06 -04:00
|
|
|
* Prints the metadata for describing this host
|
|
|
|
* @see https://tools.ietf.org/html/rfc6415
|
2019-04-30 16:22:36 -04:00
|
|
|
*/
|
2019-04-30 16:36:28 -04:00
|
|
|
class HostMeta extends BaseModule
|
2019-04-30 16:22:36 -04:00
|
|
|
{
|
2021-11-20 09:38:03 -05:00
|
|
|
protected function rawContent(array $request = [])
|
2019-04-30 16:22:36 -04:00
|
|
|
{
|
2019-12-15 17:44:33 -05:00
|
|
|
$config = DI::config();
|
2019-04-30 16:22:36 -04:00
|
|
|
|
2019-04-30 16:25:38 -04:00
|
|
|
if (!$config->get('system', 'site_pubkey', false)) {
|
2019-04-30 16:22:36 -04:00
|
|
|
$res = Crypto::newKeypair(1024);
|
|
|
|
|
2019-05-01 13:17:52 -04:00
|
|
|
$config->set('system', 'site_prvkey', $res['prvkey']);
|
|
|
|
$config->set('system', 'site_pubkey', $res['pubkey']);
|
2019-04-30 16:22:36 -04:00
|
|
|
}
|
|
|
|
|
2023-02-18 14:57:30 -05:00
|
|
|
$domain = DI::baseUrl();
|
2019-04-30 16:22:36 -04:00
|
|
|
|
2022-09-11 03:00:16 -04:00
|
|
|
XML::fromArray([
|
|
|
|
'XRD' => [
|
|
|
|
'@attributes' => [
|
|
|
|
'xmlns' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
|
|
|
|
],
|
2023-02-18 14:57:30 -05:00
|
|
|
'hm:Host' => DI::baseUrl()->getHost(),
|
2022-09-11 03:00:16 -04:00
|
|
|
'1:link' => [
|
|
|
|
'@attributes' => [
|
|
|
|
'rel' => 'lrdd',
|
|
|
|
'type' => 'application/xrd+xml',
|
|
|
|
'template' => $domain . '/xrd?uri={uri}'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'2:link' => [
|
|
|
|
'@attributes' => [
|
|
|
|
'rel' => 'lrdd',
|
|
|
|
'type' => 'application/json',
|
|
|
|
'template' => $domain . '/.well-known/webfinger?resource={uri}'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'3:link' => [
|
|
|
|
'@attributes' => [
|
|
|
|
'rel' => 'acct-mgmt',
|
|
|
|
'href' => $domain . '/amcd'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'4:link' => [
|
|
|
|
'@attributes' => [
|
|
|
|
'rel' => 'http://services.mozilla.com/amcd/0.1',
|
|
|
|
'href' => $domain . '/amcd'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'Property' => [
|
|
|
|
'@attributes' => [
|
|
|
|
'type' => 'http://salmon-protocol.org/ns/magic-key',
|
|
|
|
'mk:key_id' => '1'
|
|
|
|
],
|
|
|
|
Salmon::salmonKey($config->get('system', 'site_pubkey'))
|
|
|
|
]
|
|
|
|
],
|
|
|
|
], $xml, false, ['hm' => 'http://host-meta.net/xrd/1.0', 'mk' => 'http://salmon-protocol.org/ns/magic-key']);
|
2023-01-01 09:36:24 -05:00
|
|
|
|
2022-09-11 03:00:16 -04:00
|
|
|
System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
|
2019-04-30 16:22:36 -04:00
|
|
|
}
|
|
|
|
}
|