]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub.php
Removed unneeded check
[friendica.git] / src / Protocol / ActivityPub.php
index d1177e0b07375962c58665976e2fb6a0a43b2860..570348be242d7487599950a4b2a39a6cacbb3351 100644 (file)
@@ -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
@@ -87,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');
@@ -275,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;
+       }
 }