]> git.mxchange.org Git - friendica.git/blob - src/Module/Inbox.php
Merge remote-tracking branch 'upstream/2018.08-rc' into ap1
[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
12 /**
13  * ActivityPub Inbox
14  */
15 class Inbox extends BaseModule
16 {
17         public static function init()
18         {
19                 $a = self::getApp();
20
21                 $postdata = file_get_contents('php://input');
22
23                 if (empty($postdata)) {
24                         System::httpExit(400);
25                 }
26
27                 if (ActivityPub::verifySignature($postdata, $_SERVER)) {
28                         $filename = 'signed-activitypub';
29                 } else {
30                         $filename = 'failed-activitypub';
31                 }
32
33                 $tempfile = tempnam(get_temppath(), $filename);
34                 file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata]));
35
36                 logger('Incoming message stored under ' . $tempfile);
37
38                 if (!empty($a->argv[1])) {
39                         $user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]);
40                         if (!DBA::isResult($user)) {
41                                 System::httpExit(404);
42                         }
43                         $uid = $user['uid'];
44                 } else {
45                         $uid = 0;
46                 }
47
48                 ActivityPub::processInbox($postdata, $_SERVER, $uid);
49
50                 System::httpExit(202);
51         }
52 }