2019-04-30 22:22:36 +02:00
|
|
|
<?php
|
2024-08-24 15:27:00 +02:00
|
|
|
|
|
|
|
// Copyright (C) 2010-2024, the Friendica project
|
|
|
|
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
2019-04-30 22:22:36 +02:00
|
|
|
|
2019-05-01 00:14:06 +02:00
|
|
|
namespace Friendica\Module\WellKnown;
|
2019-04-30 22:22:36 +02:00
|
|
|
|
|
|
|
use Friendica\BaseModule;
|
2019-12-15 22:34:11 +01:00
|
|
|
use Friendica\DI;
|
2022-04-10 08:31:55 +00:00
|
|
|
use Friendica\Module\Response;
|
2019-04-30 22:22:36 +02:00
|
|
|
use Friendica\Util\Crypto;
|
2022-09-11 07:00:16 +00:00
|
|
|
use Friendica\Util\XML;
|
2019-04-30 22:22:36 +02:00
|
|
|
|
|
|
|
/**
|
2019-05-01 00:14:06 +02:00
|
|
|
* Prints the metadata for describing this host
|
|
|
|
* @see https://tools.ietf.org/html/rfc6415
|
2019-04-30 22:22:36 +02:00
|
|
|
*/
|
2019-04-30 22:36:28 +02:00
|
|
|
class HostMeta extends BaseModule
|
2019-04-30 22:22:36 +02:00
|
|
|
{
|
2021-11-20 15:38:03 +01:00
|
|
|
protected function rawContent(array $request = [])
|
2019-04-30 22:22:36 +02:00
|
|
|
{
|
2019-12-15 23:44:33 +01:00
|
|
|
$config = DI::config();
|
2019-04-30 22:22:36 +02:00
|
|
|
|
2019-04-30 22:25:38 +02:00
|
|
|
if (!$config->get('system', 'site_pubkey', false)) {
|
2019-04-30 22:22:36 +02:00
|
|
|
$res = Crypto::newKeypair(1024);
|
|
|
|
|
2019-05-01 19:17:52 +02:00
|
|
|
$config->set('system', 'site_prvkey', $res['prvkey']);
|
|
|
|
$config->set('system', 'site_pubkey', $res['pubkey']);
|
2019-04-30 22:22:36 +02:00
|
|
|
}
|
|
|
|
|
2023-05-11 08:13:19 +00:00
|
|
|
$domain = (string)DI::baseUrl();
|
2019-04-30 22:22:36 +02:00
|
|
|
|
2022-09-11 07:00:16 +00:00
|
|
|
XML::fromArray([
|
|
|
|
'XRD' => [
|
|
|
|
'@attributes' => [
|
|
|
|
'xmlns' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
|
|
|
|
],
|
2023-02-18 20:57:30 +01:00
|
|
|
'hm:Host' => DI::baseUrl()->getHost(),
|
2022-09-11 07:00:16 +00: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'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
],
|
2024-08-24 04:27:00 +00:00
|
|
|
], $xml, false, ['hm' => 'http://host-meta.net/xrd/1.0']);
|
2023-01-01 09:36:24 -05:00
|
|
|
|
2023-09-21 12:35:55 -04:00
|
|
|
$this->httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
|
2019-04-30 22:22:36 +02:00
|
|
|
}
|
|
|
|
}
|