]> git.mxchange.org Git - friendica.git/blob - src/Module/Inbox.php
4fc450d85a306e0b52323629174f8894bb403465
[friendica.git] / src / Module / Inbox.php
1 <?php
2 /**
3  * @file src/Module/Inbox.php
4  */
5 namespace Friendica\Module;
6
7 use Friendica\BaseModule;
8 use Friendica\Protocol\ActivityPub;
9 use Friendica\Core\System;
10 use Friendica\Database\DBA;
11 use Friendica\Util\HTTPSignature;
12
13 /**
14  * ActivityPub Inbox
15  */
16 class Inbox extends BaseModule
17 {
18         public static function init()
19         {
20                 $a = self::getApp();
21
22                 $postdata = file_get_contents('php://input');
23
24                 if (empty($postdata)) {
25                         System::httpExit(400);
26                 }
27
28 // Enable for test purposes
29 /*
30                 if (HTTPSignature::getSigner($postdata, $_SERVER)) {
31                         $filename = 'signed-activitypub';
32                 } else {
33                         $filename = 'failed-activitypub';
34                 }
35
36                 $tempfile = tempnam(get_temppath(), $filename);
37                 file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
38
39                 logger('Incoming message stored under ' . $tempfile);
40 */
41                 if (!empty($a->argv[1])) {
42                         $user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]);
43                         if (!DBA::isResult($user)) {
44                                 System::httpExit(404);
45                         }
46                         $uid = $user['uid'];
47                 } else {
48                         $uid = 0;
49                 }
50
51                 ActivityPub::processInbox($postdata, $_SERVER, $uid);
52
53                 System::httpExit(202);
54         }
55 }