Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1 KiB

3 years ago
  1. <?php
  2. /**
  3. * @file src/Module/Inbox.php
  4. */
  5. namespace Friendica\Module;
  6. use Friendica\BaseModule;
  7. use Friendica\Protocol\ActivityPub;
  8. use Friendica\Core\System;
  9. use Friendica\Database\DBA;
  10. /**
  11. * ActivityPub Inbox
  12. */
  13. class Inbox extends BaseModule
  14. {
  15. public static function init()
  16. {
  17. $a = self::getApp();
  18. $postdata = file_get_contents('php://input');
  19. if (empty($postdata)) {
  20. System::httpExit(400);
  21. }
  22. if (ActivityPub::verifySignature($postdata, $_SERVER)) {
  23. $filename = 'signed-activitypub';
  24. } else {
  25. $filename = 'failed-activitypub';
  26. }
  27. $tempfile = tempnam(get_temppath(), $filename);
  28. file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata]));
  29. logger('Incoming message stored under ' . $tempfile);
  30. if (!empty($a->argv[1])) {
  31. $user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]);
  32. if (!DBA::isResult($user)) {
  33. System::httpExit(404);
  34. }
  35. $uid = $user['uid'];
  36. } else {
  37. $uid = 0;
  38. }
  39. ActivityPub::processInbox($postdata, $_SERVER, $uid);
  40. System::httpExit(202);
  41. }
  42. }