]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub.php
Removed unneeded check
[friendica.git] / src / Protocol / ActivityPub.php
index 93204e81d3722da96c65810566a4e27e87cf8181..570348be242d7487599950a4b2a39a6cacbb3351 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -23,7 +23,9 @@ namespace Friendica\Protocol;
 
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
+use Friendica\Core\System;
 use Friendica\Model\APContact;
+use Friendica\Model\Contact;
 use Friendica\Model\User;
 use Friendica\Util\HTTPSignature;
 use Friendica\Util\JsonLD;
@@ -52,8 +54,8 @@ use Friendica\Util\JsonLD;
  * - Polling the outboxes for missing content?
  *
  * Missing parts from DFRN:
- * - Public Forum
- * - Private Forum
+ * - Public Group
+ * - Private Group
  * - Relocation
  */
 class ActivityPub
@@ -72,6 +74,8 @@ class ActivityPub
                'schema' => 'http://schema.org#',
                'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
                'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag',
+               'quoteUrl' => 'as:quoteUrl',
+               'conversation' => 'ostatus:conversation',
                'directMessage' => 'litepub:directMessage',
                'discoverable' => 'toot:discoverable',
                'PropertyValue' => 'schema:PropertyValue',
@@ -85,6 +89,8 @@ class ActivityPub
         */
        public static function isRequest(): bool
        {
+               header('Vary: Accept', false);
+
                $isrequest = stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/activity+json') ||
                        stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/json') ||
                        stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/ld+json');
@@ -273,4 +279,38 @@ class ActivityPub
        {
                return !empty(APContact::getByURL($url, $update));
        }
+
+       public static function isAcceptedRequester(int $uid = 0): bool
+       {
+               $called_by = System::callstack(1);
+
+               $signer = HTTPSignature::getSigner('', $_SERVER);
+               if (!$signer) {
+                       Logger::debug('No signer or invalid signature', ['uid' => $uid, 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '', 'called_by' => $called_by]);
+                       return false;
+               }
+
+               $apcontact = APContact::getByURL($signer);
+               if (empty($apcontact)) {
+                       Logger::info('APContact not found', ['uid' => $uid, 'handle' => $signer, 'called_by' => $called_by]);
+                       return false;
+               }
+
+               if (empty($apcontact['gsid'] || empty($apcontact['baseurl']))) {
+                       Logger::debug('No server found', ['uid' => $uid, 'signer' => $signer, 'called_by' => $called_by]);
+                       return false;
+               }
+
+               $contact = Contact::getByURL($signer, false, ['id', 'baseurl', 'gsid']);
+               if (!empty($contact) && Contact\User::isBlocked($contact['id'], $uid)) {
+                       Logger::info('Requesting contact is blocked', ['uid' => $uid, 'id' => $contact['id'], 'signer' => $signer, 'baseurl' => $contact['baseurl'], 'called_by' => $called_by]);
+                       return false;
+               }
+
+               // @todo Look for user blocked domains
+
+               Logger::debug('Server is an accepted requester', ['uid' => $uid, 'id' => $apcontact['gsid'], 'url' => $apcontact['baseurl'], 'signer' => $signer, 'called_by' => $called_by]);
+
+               return true;
+       }
 }