Esempio n. 1
0
 /**
  * Handler for GET verification requests from the hub.
  */
 function handleGet()
 {
     $mode = $this->arg('hub_mode');
     $topic = $this->arg('hub_topic');
     $challenge = $this->arg('hub_challenge');
     $lease_seconds = $this->arg('hub_lease_seconds');
     $verify_token = $this->arg('hub_verify_token');
     common_log(LOG_INFO, __METHOD__ . ": sub verification mode: {$mode} topic: {$topic} challenge: {$challenge} lease_seconds: {$lease_seconds} verify_token: {$verify_token}");
     if ($mode != 'subscribe' && $mode != 'unsubscribe') {
         // TRANS: Client exception. %s is an invalid value for hub.mode.
         throw new ClientException(sprintf(_m('Bad hub.mode "$s".', $mode)), 404);
     }
     $feedsub = FeedSub::staticGet('uri', $topic);
     if (!$feedsub) {
         // TRANS: Client exception. %s is an invalid feed name.
         throw new ClientException(sprintf(_m('Bad hub.topic feed "%s".'), $topic), 404);
     }
     if ($feedsub->verify_token !== $verify_token) {
         // TRANS: Client exception. %1$s the invalid token, %2$s is the topic for which the invalid token was given.
         throw new ClientException(sprintf(_m('Bad hub.verify_token %1$s for %2$s.'), $token, $topic), 404);
     }
     if ($mode == 'subscribe') {
         // We may get re-sub requests legitimately.
         if ($feedsub->sub_state != 'subscribe' && $feedsub->sub_state != 'active') {
             // TRANS: Client exception. %s is an invalid topic.
             throw new ClientException(sprintf(_m('Unexpected subscribe request for %s.'), $topic), 404);
         }
     } else {
         if ($feedsub->sub_state != 'unsubscribe') {
             // TRANS: Client exception. %s is an invalid topic.
             throw new ClientException(sprintf(_m('Unexpected unsubscribe request for %s.'), $topic), 404);
         }
     }
     if ($mode == 'subscribe') {
         if ($feedsub->sub_state == 'active') {
             common_log(LOG_INFO, __METHOD__ . ': sub update confirmed');
         } else {
             common_log(LOG_INFO, __METHOD__ . ': sub confirmed');
         }
         $feedsub->confirmSubscribe($lease_seconds);
     } else {
         common_log(LOG_INFO, __METHOD__ . ": unsub confirmed; deleting sub record for {$topic}");
         $feedsub->confirmUnsubscribe();
     }
     print $challenge;
 }
 function handle($data)
 {
     assert(is_array($data));
     $feedsub_id = $data['feedsub_id'];
     $post = $data['post'];
     $hmac = $data['hmac'];
     $feedsub = FeedSub::staticGet('id', $feedsub_id);
     if ($feedsub) {
         try {
             $feedsub->receive($post, $hmac);
         } catch (Exception $e) {
             common_log(LOG_ERR, "Exception during PuSH input processing for {$feedsub->uri}: " . $e->getMessage());
         }
     } else {
         common_log(LOG_ERR, "Discarding POST to unknown feed subscription id {$feedsub_id}");
     }
     return true;
 }
Esempio n. 3
0
 /**
  * Handler for GET verification requests from the hub.
  */
 function handleGet()
 {
     $mode = $this->arg('hub_mode');
     $topic = $this->arg('hub_topic');
     $challenge = $this->arg('hub_challenge');
     $lease_seconds = $this->arg('hub_lease_seconds');
     $verify_token = $this->arg('hub_verify_token');
     if ($mode != 'subscribe' && $mode != 'unsubscribe') {
         throw new ClientException("Bad hub.mode {$mode}", 404);
     }
     $feedsub = FeedSub::staticGet('uri', $topic);
     if (!$feedsub) {
         // @todo i18n FIXME: added i18n and use sprintf when using parameters.
         throw new ClientException("Bad hub.topic feed {$topic}.", 404);
     }
     if ($feedsub->verify_token !== $verify_token) {
         // @todo i18n FIXME: added i18n and use sprintf when using parameters.
         throw new ClientException("Bad hub.verify_token {$token} for {$topic}.", 404);
     }
     if ($mode == 'subscribe') {
         // We may get re-sub requests legitimately.
         if ($feedsub->sub_state != 'subscribe' && $feedsub->sub_state != 'active') {
             // @todo i18n FIXME: added i18n and use sprintf when using parameters.
             throw new ClientException("Unexpected subscribe request for {$topic}.", 404);
         }
     } else {
         if ($feedsub->sub_state != 'unsubscribe') {
             // @todo i18n FIXME: added i18n and use sprintf when using parameters.
             throw new ClientException("Unexpected unsubscribe request for {$topic}.", 404);
         }
     }
     if ($mode == 'subscribe') {
         if ($feedsub->sub_state == 'active') {
             common_log(LOG_INFO, __METHOD__ . ': sub update confirmed');
         } else {
             common_log(LOG_INFO, __METHOD__ . ': sub confirmed');
         }
         $feedsub->confirmSubscribe($lease_seconds);
     } else {
         common_log(LOG_INFO, __METHOD__ . ": unsub confirmed; deleting sub record for {$topic}");
         $feedsub->confirmUnsubscribe();
     }
     print $challenge;
 }
Mainly intended for testing funky feed formats.

     --skip=N   Ignore the first N items in the feed.
     --count=N  Only process up to N items from the feed, after skipping.


END_OF_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
if (empty($args[0]) || !Validate::uri($args[0])) {
    print "{$helptext}";
    exit(1);
}
$feedurl = $args[0];
$skip = have_option('skip') ? intval(get_option_value('skip')) : 0;
$count = have_option('count') ? intval(get_option_value('count')) : 0;
$sub = FeedSub::staticGet('topic', $feedurl);
if (!$sub) {
    print "Feed {$feedurl} is not subscribed.\n";
    exit(1);
}
$xml = file_get_contents($feedurl);
if ($xml === false) {
    print "Bad fetch.\n";
    exit(1);
}
$feed = new DOMDocument();
if (!$feed->loadXML($xml)) {
    print "Bad XML.\n";
    exit(1);
}
if ($skip || $count) {
Esempio n. 5
0
Mainly intended for testing funky feed formats.

     --skip=N   Ignore the first N items in the feed.
     --count=N  Only process up to N items from the feed, after skipping.


END_OF_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
if (empty($args[0]) || !Validate::uri($args[0])) {
    print "{$helptext}";
    exit(1);
}
$feedurl = $args[0];
$skip = have_option('skip') ? intval(get_option_value('skip')) : 0;
$count = have_option('count') ? intval(get_option_value('count')) : 0;
$sub = FeedSub::staticGet('uri', $feedurl);
if (!$sub) {
    print "Feed {$feedurl} is not subscribed.\n";
    exit(1);
}
$xml = file_get_contents($feedurl);
if ($xml === false) {
    print "Bad fetch.\n";
    exit(1);
}
$feed = new DOMDocument();
if (!$feed->loadXML($xml)) {
    print "Bad XML.\n";
    exit(1);
}
if ($skip || $count) {
Esempio n. 6
0
 /**
  * Check if this remote profile has any active local subscriptions, and
  * if not drop the PuSH subscription feed.
  *
  * @return boolean
  */
 public function garbageCollect()
 {
     $feedsub = FeedSub::staticGet('uri', $this->feeduri);
     return $feedsub->garbageCollect();
 }
 /**
  * Send a PuSH unsubscription request to the hub for this feed.
  * The hub will later send us a confirmation POST to /main/push/callback.
  *
  * @return bool true on success, false on failure
  * @throws ServerException if feed state is not valid
  */
 public function unsubscribe()
 {
     $feedsub = FeedSub::staticGet('uri', $this->feeduri);
     if (!$feedsub || $feedsub->sub_state == '' || $feedsub->sub_state == 'inactive') {
         // No active PuSH subscription, we can just leave it be.
         return true;
     } else {
         // PuSH subscription is either active or in an indeterminate state.
         // Send an unsubscribe.
         return $feedsub->unsubscribe();
     }
 }