]> git.mxchange.org Git - friendica.git/blob - src/Module/WellKnown/HostMeta.php
Merge remote-tracking branch 'upstream/develop' into inbox-gsid
[friendica.git] / src / Module / WellKnown / HostMeta.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\WellKnown;
23
24 use Friendica\BaseModule;
25 use Friendica\Core\System;
26 use Friendica\DI;
27 use Friendica\Module\Response;
28 use Friendica\Protocol\Salmon;
29 use Friendica\Util\Crypto;
30 use Friendica\Util\XML;
31
32 /**
33  * Prints the metadata for describing this host
34  * @see https://tools.ietf.org/html/rfc6415
35  */
36 class HostMeta extends BaseModule
37 {
38         protected function rawContent(array $request = [])
39         {
40                 $config = DI::config();
41
42                 if (!$config->get('system', 'site_pubkey', false)) {
43                         $res = Crypto::newKeypair(1024);
44
45                         $config->set('system', 'site_prvkey', $res['prvkey']);
46                         $config->set('system', 'site_pubkey', $res['pubkey']);
47                 }
48
49                 $domain = DI::baseUrl()->get();
50
51                 $xml = null;
52                 XML::fromArray([
53                         'XRD' => [
54                                 '@attributes' => [
55                                         'xmlns'    => 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
56                                 ],
57                                 'hm:Host' => DI::baseUrl()->getHostname(),
58                                 '1:link' => [
59                                         '@attributes' => [
60                                                 'rel'      => 'lrdd',
61                                                 'type'     => 'application/xrd+xml',
62                                                 'template' => $domain . '/xrd?uri={uri}'
63                                         ]
64                                 ],
65                                 '2:link' => [
66                                         '@attributes' => [
67                                                 'rel'      => 'lrdd',
68                                                 'type'     => 'application/json',
69                                                 'template' => $domain . '/.well-known/webfinger?resource={uri}'
70                                         ]
71                                 ],
72                                 '3:link' => [
73                                         '@attributes' => [
74                                                 'rel'  => 'acct-mgmt',
75                                                 'href' => $domain . '/amcd'
76                                         ]
77                                 ],
78                                 '4:link' => [
79                                         '@attributes' => [
80                                                 'rel'  => 'http://services.mozilla.com/amcd/0.1',
81                                                 'href' => $domain . '/amcd'
82                                         ]
83                                 ],
84                                 '5:link' => [
85                                         '@attributes' => [
86                                                 'rel'  => 'http://oexchange.org/spec/0.8/rel/resident-target',
87                                                 'type' => 'application/xrd+xml',
88                                                 'href' => $domain . '/oexchange/xrd'
89                                         ]
90                                 ],
91                                 'Property' => [
92                                         '@attributes' => [
93                                                 'type'      => 'http://salmon-protocol.org/ns/magic-key',
94                                                 'mk:key_id' => '1'
95                                         ],
96                                         Salmon::salmonKey($config->get('system', 'site_pubkey'))
97                                 ]
98                         ],
99                 ], $xml, false, ['hm' => 'http://host-meta.net/xrd/1.0', 'mk' => 'http://salmon-protocol.org/ns/magic-key']);
100
101                 System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
102         }
103 }