summaryrefslogtreecommitdiff
path: root/plugins/OStatus/actions/pushcallback.php
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2010-02-08 21:55:32 -0800
committerZach Copley <zach@status.net>2010-02-08 21:55:32 -0800
commit602b01a7554a2ba50ed169db45d57c54823642a0 (patch)
treec1ad0dc29faec3149610e6885e67e91671c5c98e /plugins/OStatus/actions/pushcallback.php
parentb56b154b51ede363ee8e49ec5b9b9332b8df923c (diff)
parent4e6f587f868d71f08c618d0dedf6ddf0331619c2 (diff)
Merge branch 'testing' of gitorious.org:statusnet/mainline into testing
* 'testing' of gitorious.org:statusnet/mainline: Pull GeoRSS locations over OStatus feeds Allow scripts/decache.php to blow out cache for objects that don't exist (anymore). OStatus cleanup... readme and version for beta5 Delete old Twitter user record when user changes screen name instead of updating. Simpler. Store Twitter screen_name, not name, for foreign_user.nickname when saving Twitter user. Actually store the timestamp on each nonce OAuth app name should not be null Fix issue with OAuth request parameters being parsed/stored twice when - Fix cache handling in TwitterStatusFetcher Added right margin for notice text. Helps Conversation notices look Confirm dialog for reset OAuth consumer key and secret button Always check for an OAuth request. This allows OAuth clients to set an Linkify notice source when posting from registered OAuth apps Suppress notice input box on OAuth authorization page Better token revocation Allow developers to delete OAuth applications OAuth app names should be unique. Prevents app statistic text from wrapping around avatar Sentence case for app statistics
Diffstat (limited to 'plugins/OStatus/actions/pushcallback.php')
-rw-r--r--plugins/OStatus/actions/pushcallback.php105
1 files changed, 105 insertions, 0 deletions
diff --git a/plugins/OStatus/actions/pushcallback.php b/plugins/OStatus/actions/pushcallback.php
new file mode 100644
index 000000000..a5e02e08f
--- /dev/null
+++ b/plugins/OStatus/actions/pushcallback.php
@@ -0,0 +1,105 @@
+<?php
+/*
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2009, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @package FeedSubPlugin
+ * @maintainer Brion Vibber <brion@status.net>
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+
+
+class PushCallbackAction extends Action
+{
+ function handle()
+ {
+ parent::handle();
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $this->handlePost();
+ } else {
+ $this->handleGet();
+ }
+ }
+
+ /**
+ * Handler for POST content updates from the hub
+ */
+ function handlePost()
+ {
+ $feedid = $this->arg('feed');
+ common_log(LOG_INFO, "POST for feed id $feedid");
+ if (!$feedid) {
+ throw new ServerException('Empty or invalid feed id', 400);
+ }
+
+ $feedinfo = Feedinfo::staticGet('id', $feedid);
+ if (!$feedinfo) {
+ throw new ServerException('Unknown feed id ' . $feedid, 400);
+ }
+
+ $hmac = '';
+ if (isset($_SERVER['HTTP_X_HUB_SIGNATURE'])) {
+ $hmac = $_SERVER['HTTP_X_HUB_SIGNATURE'];
+ }
+
+ $post = file_get_contents('php://input');
+ $feedinfo->postUpdates($post, $hmac);
+ }
+
+ /**
+ * 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') {
+ common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback with mode \"$mode\"");
+ throw new ServerException("Bogus hub callback: bad mode", 404);
+ }
+
+ $feedinfo = Feedinfo::staticGet('feeduri', $topic);
+ if (!$feedinfo) {
+ common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback for unknown feed $topic");
+ throw new ServerException("Bogus hub callback: unknown feed", 404);
+ }
+
+ # Can't currently set the token in our sub api
+ #if ($feedinfo->verify_token !== $verify_token) {
+ # common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback with bad token \"$verify_token\" for feed $topic");
+ # throw new ServerError("Bogus hub callback: bad token", 404);
+ #}
+
+ // OK!
+ common_log(LOG_INFO, __METHOD__ . ': sub confirmed');
+ $feedinfo->sub_start = common_sql_date(time());
+ if ($lease_seconds > 0) {
+ $feedinfo->sub_end = common_sql_date(time() + $lease_seconds);
+ } else {
+ $feedinfo->sub_end = null;
+ }
+ $feedinfo->update();
+
+ print $challenge;
+ }
+}