]> git.mxchange.org Git - friendica.git/blob - src/Module/WellKnown/HostMeta.php
Remove DI dependency from Module\Contact\Profile
[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 = (string)DI::baseUrl();
50
51                 XML::fromArray([
52                         'XRD' => [
53                                 '@attributes' => [
54                                         'xmlns'    => 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
55                                 ],
56                                 'hm:Host' => DI::baseUrl()->getHost(),
57                                 '1:link' => [
58                                         '@attributes' => [
59                                                 'rel'      => 'lrdd',
60                                                 'type'     => 'application/xrd+xml',
61                                                 'template' => $domain . '/xrd?uri={uri}'
62                                         ]
63                                 ],
64                                 '2:link' => [
65                                         '@attributes' => [
66                                                 'rel'      => 'lrdd',
67                                                 'type'     => 'application/json',
68                                                 'template' => $domain . '/.well-known/webfinger?resource={uri}'
69                                         ]
70                                 ],
71                                 '3:link' => [
72                                         '@attributes' => [
73                                                 'rel'  => 'acct-mgmt',
74                                                 'href' => $domain . '/amcd'
75                                         ]
76                                 ],
77                                 '4:link' => [
78                                         '@attributes' => [
79                                                 'rel'  => 'http://services.mozilla.com/amcd/0.1',
80                                                 'href' => $domain . '/amcd'
81                                         ]
82                                 ],
83                                 'Property' => [
84                                         '@attributes' => [
85                                                 'type'      => 'http://salmon-protocol.org/ns/magic-key',
86                                                 'mk:key_id' => '1'
87                                         ],
88                                         Salmon::salmonKey($config->get('system', 'site_pubkey'))
89                                 ]
90                         ],
91                 ], $xml, false, ['hm' => 'http://host-meta.net/xrd/1.0', 'mk' => 'http://salmon-protocol.org/ns/magic-key']);
92
93                 System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
94         }
95 }