function handle($data)
 {
     $feedsub_id = $data['feedsub_id'];
     $feedsub = FeedSub::getKV('id', $feedsub_id);
     if ($feedsub instanceof FeedSub) {
         try {
             common_log(LOG_INFO, "Renewing feed subscription\n\tExp.: {$feedsub->sub_end}\n\tFeed: {$feedsub->uri}\n\tHub:  {$feedsub->huburi}");
             $feedsub->renew();
         } catch (Exception $e) {
             common_log(LOG_ERR, "Exception during PuSH renew processing for {$feedsub->uri}: " . $e->getMessage());
         }
     } else {
         common_log(LOG_ERR, "Discarding renew for unknown feed subscription id {$feedsub_id}");
     }
     return true;
 }
 public function handle($item)
 {
     $feedsub = FeedSub::getKV('id', $item['id']);
     if (!$feedsub instanceof FeedSub) {
         // Removed from the feedsub table I guess
         return true;
     }
     if (!$feedsub->sub_state == 'nohub') {
         // We're not supposed to poll this (either it's PuSH or it's unsubscribed)
         return true;
     }
     try {
         FeedPoll::checkUpdates($feedsub);
     } catch (Exception $e) {
         common_log(LOG_ERR, "Failed to check feedsub id= " . $feedsub->id . ' ("' . $e->getMessage() . '")');
     }
     return true;
 }
 function handle($data)
 {
     assert(is_array($data));
     $feedsub_id = $data['feedsub_id'];
     $post = $data['post'];
     $hmac = $data['hmac'];
     $feedsub = FeedSub::getKV('id', $feedsub_id);
     if ($feedsub instanceof 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;
 }
Exemplo n.º 4
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');
     // Must be >0 for PuSH 0.4!
     common_log(LOG_INFO, __METHOD__ . ": sub verification mode: {$mode} topic: {$topic} challenge: {$challenge} lease_seconds: {$lease_seconds}");
     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::getKV('uri', $topic);
     if (!$feedsub instanceof FeedSub) {
         // TRANS: Client exception. %s is an invalid feed name.
         throw new ClientException(sprintf(_m('Bad hub.topic feed "%s".'), $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;
 }
Exemplo n.º 5
0
 public function updateUriKeys($profile_uri, array $hints = array())
 {
     $orig = clone $this;
     common_debug('URIFIX These identities both say they are each other: "' . $orig->uri . '" and "' . $profile_uri . '"');
     $this->uri = $profile_uri;
     if (array_key_exists('feedurl', $hints)) {
         if (!empty($this->feeduri)) {
             common_debug('URIFIX Changing FeedSub [' . $feedsub->id . '] feeduri "' . $feedsub->uri . '" to "' . $hints['feedurl']);
             $feedsub = FeedSub::getKV('uri', $this->feeduri);
             $feedorig = clone $feedsub;
             $feedsub->uri = $hints['feedurl'];
             $feedsub->updateWithKeys($feedorig);
         } else {
             common_debug('URIFIX Old Ostatus_profile did not have feedurl set, ensuring feed: ' . $hints['feedurl']);
             FeedSub::ensureFeed($hints['feedurl']);
         }
         $this->feeduri = $hints['feedurl'];
     }
     if (array_key_exists('salmon', $hints)) {
         common_debug('URIFIX Changing Ostatus_profile salmonuri from "' . $this->salmonuri . '" to "' . $hints['salmon'] . '"');
         $this->salmonuri = $hints['salmon'];
     }
     common_debug('URIFIX Updating Ostatus_profile URI for ' . $orig->uri . ' to ' . $this->uri);
     $this->updateWithKeys($orig, 'uri');
     // 'uri' is the primary key column
     common_debug('URIFIX Subscribing/renewing feedsub for Ostatus_profile ' . $this->uri);
     $this->subscribe();
 }
Exemplo n.º 6
0
     --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';
$validate = new Validate();
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::getKV('uri', $feedurl);
if (!$sub) {
    print "Feed {$feedurl} is not subscribed.\n";
    exit(1);
}
// Fetch the URL
try {
    $xml = HTTPClient::quickGet($feedurl, 'text/html,application/xhtml+xml');
} catch (Exception $e) {
    echo sprintf("Could not fetch feedurl %s (%d).\n", $e->getMessage(), $e->getCode());
    exit(1);
}
$feed = new DOMDocument();
if (!$feed->loadXML($xml)) {
    print "Bad XML.\n";
    exit(1);
Exemplo n.º 7
0
 /**
  * Check if this remote profile has any active local subscriptions, and
  * if not drop the PuSH subscription feed.
  *
  * @return boolean true if subscription is removed, false if there are still subscribers to the feed
  * @throws Exception of various kinds on failure.
  */
 public function garbageCollect()
 {
     $feedsub = FeedSub::getKV('uri', $this->feeduri);
     if ($feedsub instanceof FeedSub) {
         return $feedsub->garbageCollect();
     }
     // Since there's no FeedSub we can assume it's already garbage collected
     return true;
 }
Exemplo n.º 8
0
 */
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
$helptext = <<<END_OF_HELP
pollfeed.php feeduri

Poll the feed, assuming it has sub_state 'nohub'.

END_OF_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
require_once __DIR__ . '/../lib/feedpoll.php';
if (empty($args[0]) || !Validate::uri($args[0])) {
    echo "{$helptext}\n";
    exit(1);
}
$uri = $args[0];
$feedsub = FeedSub::getKV('uri', $uri);
if (!$feedsub instanceof FeedSub) {
    echo "No FeedSub feed known for URI {$uri}\n";
    exit(1);
}
if ($feedsub->sub_state != 'nohub') {
    echo "Feed is a PuSH feed, so we will not poll it.\n";
    exit(1);
}
showSub($feedsub);
try {
    FeedPoll::checkUpdates($feedsub);
} catch (Exception $e) {
    echo "Could not check updates for feed: " . $e->getMessage();
    echo $e->getTraceAsString();
    exit(1);