friendica-github/src/Module/WellKnown/HostMeta.php

73 lines
1.7 KiB
PHP
Raw Normal View History

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
namespace Friendica\Module\WellKnown;
2019-04-30 22:22:36 +02:00
use Friendica\BaseModule;
use Friendica\DI;
use Friendica\Module\Response;
2019-04-30 22:22:36 +02:00
use Friendica\Util\Crypto;
use Friendica\Util\XML;
2019-04-30 22:22:36 +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
{
protected function rawContent(array $request = [])
2019-04-30 22:22:36 +02: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);
$config->set('system', 'site_prvkey', $res['prvkey']);
$config->set('system', 'site_pubkey', $res['pubkey']);
2019-04-30 22:22:36 +02:00
}
$domain = (string)DI::baseUrl();
2019-04-30 22:22:36 +02:00
XML::fromArray([
'XRD' => [
'@attributes' => [
'xmlns' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
],
'hm:Host' => DI::baseUrl()->getHost(),
'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
$this->httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
2019-04-30 22:22:36 +02:00
}
}