]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/lib/ostatusqueuehandler.php
Test URLs against blacklist also on PuSH subscriptions.
[quix0rs-gnu-social.git] / plugins / OStatus / lib / ostatusqueuehandler.php
index fed93b6ea62b69200c7c0303ae92ec02cc4758d9..ac56e142f4af990cc858dcd9ddac50e45d2e9942 100644 (file)
@@ -60,12 +60,6 @@ class OStatusQueueHandler extends QueueHandler
             return true;
         }
 
-        if ($notice->isLocal()) {
-            // Notices generated on remote sites will have already
-            // been pushed to user's subscribers by their origin sites.
-            $this->pushUser();
-        }
-
         foreach ($notice->getAttentionProfiles() as $target) {
             common_debug("OSTATUS [{$this->notice->getID()}]: Attention target profile {$target->getNickname()} ({$target->getID()})");
             if ($target->isGroup()) {
@@ -100,6 +94,10 @@ class OStatusQueueHandler extends QueueHandler
         }
 
         if ($notice->isLocal()) {
+            // Notices generated on remote sites will have already
+            // been pushed to user's subscribers by their origin sites.
+            $this->pushUser();
+
             try {
                 $parent = $this->notice->getParent();
                 foreach($parent->getAttentionProfiles() as $related) {
@@ -185,11 +183,37 @@ class OStatusQueueHandler extends QueueHandler
      */
     function pushFeed($feed, $callback)
     {
+        // NOTE: external hub pings will not be fixed by
+        // our legacy_http thing!
         $hub = common_config('ostatus', 'hub');
         if ($hub) {
             $this->pushFeedExternal($feed, $hub);
         }
 
+        // If we used to be http but now are https, see if we find an http entry for this feed URL
+        // and then upgrade it. This self-healing feature needs to be enabled manually in config.
+        // This code is based on a patch by @hannes2peer@quitter.se
+        if (common_config('fix', 'legacy_http') && parse_url($feed, PHP_URL_SCHEME) === 'https') {
+            common_log(LOG_DEBUG, "OSTATUS [{$this->notice->getID()}]: Searching for http scheme instead for HubSub feed topic: "._ve($feed));
+            $http_feed = str_replace('https://', 'http://', $feed);
+            $sub = new HubSub();
+            $sub->topic = $http_feed;
+            // If we find it we upgrade the rows in the hubsub table.
+            if ($sub->find()) {
+                common_log(LOG_INFO, "OSTATUS [{$this->notice->getID()}]: Found topic with http scheme for "._ve($feed).", will update the rows to use https instead!");
+                // we found an http:// URL but we use https:// now
+                // so let's update the rows to reflect on this!
+                while ($sub->fetch()) {
+                    common_debug("OSTATUS [{$this->notice->getID()}]: Changing topic URL to https for feed callback "._ve($sub->callback));
+                    $orig = clone($sub);
+                    $sub->topic = $feed;
+                    // hashkey column will be set automagically in HubSub->onUpdateKeys through updateWithKeys
+                    $sub->updateWithKeys($orig);
+                    unset($orig);
+                }
+            }
+        }
+
         $sub = new HubSub();
         $sub->topic = $feed;
         if ($sub->find()) {
@@ -197,9 +221,8 @@ class OStatusQueueHandler extends QueueHandler
             $atom = call_user_func_array($callback, $args);
             $this->pushFeedInternal($atom, $sub);
         } else {
-            common_log(LOG_INFO, "No PuSH subscribers for $feed");
+            common_log(LOG_INFO, "OSTATUS [{$this->notice->getID()}]: No PuSH subscribers for $feed");
         }
-        return true;
     }
 
     /**