From cac6d4234a4ef8fea1d487f44062ae06dd9c0c52 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 12:55:51 -0500 Subject: Script to convert OMB subscriptions to OStatus subscriptions --- plugins/OStatus/scripts/updateostatus.php | 102 ++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 plugins/OStatus/scripts/updateostatus.php diff --git a/plugins/OStatus/scripts/updateostatus.php b/plugins/OStatus/scripts/updateostatus.php new file mode 100644 index 000000000..8b1081704 --- /dev/null +++ b/plugins/OStatus/scripts/updateostatus.php @@ -0,0 +1,102 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..')); + +$shortoptions = 'i:n:a'; +$longoptions = array('id=', 'nickname=', 'all'); + +$helptext = <<find()) { + while ($user->fetch()) { + updateOStatus($user); + } + } + } else { + show_help(); + exit(1); + } +} catch (Exception $e) { + print $e->getMessage()."\n"; + exit(1); +} + +function updateOStatus($user) +{ + $up = $user->getProfile(); + + $sp = $user->getSubscriptions(); + + $rps = array(); + + while ($sp->fetch()) { + $remote = Remote_profile::staticGet('id', $sp->id); + + if (!empty($remote)) { + $rps[] = clone($sp); + } + } + + foreach ($rps as $rp) { + try { + $op = Ostatus_profile::ensureProfile($rp->profileurl); + + if (!empty($op)) { + Subscription::cancel($up, $rp); + Subscription::start($up, $op->localProfile()); + } + + } catch (Exception $e) { + common_log(LOG_WARNING, "Couldn't convert OMB subscription (" . $up->nickname . ", " . $rp->nickname . + ") to OStatus: " . $e->getMessage()); + continue; + } + } +} -- cgit v1.2.3-54-g00ecf From caab6ddaa9ba9d8eb500d508e7580222886c0143 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 13:13:51 -0500 Subject: fix path for updateostatus.php --- plugins/OStatus/scripts/updateostatus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/OStatus/scripts/updateostatus.php b/plugins/OStatus/scripts/updateostatus.php index 8b1081704..1414f81e9 100644 --- a/plugins/OStatus/scripts/updateostatus.php +++ b/plugins/OStatus/scripts/updateostatus.php @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..')); +define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); $shortoptions = 'i:n:a'; $longoptions = array('id=', 'nickname=', 'all'); -- cgit v1.2.3-54-g00ecf From 6f20b74dc7b3b69365bf8de7ba0652177e570437 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 13:41:06 -0500 Subject: drop tokens for OMB on unsubscribe --- classes/Subscription.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/classes/Subscription.php b/classes/Subscription.php index d6fb3fcbd..878ab83e6 100644 --- a/classes/Subscription.php +++ b/classes/Subscription.php @@ -172,6 +172,26 @@ class Subscription extends Memcached_DataObject assert(!empty($sub)); + // @todo: move this block to EndSubscribe handler for + // OMB plugin when it exists. + + if (!empty($sub->token)) { + + $token = new Token(); + + $token->tok = $sub->token; + $token->secret = $sub->secret; + + if ($token->find(true)) { + + $result = $token->delete(); + if (!$result) { + common_log_db_error($sub, 'DELETE', __FILE__); + throw new Exception(_('Couldn\'t delete subscription OMB token.')); + } + } + } + $result = $sub->delete(); if (!$result) { -- cgit v1.2.3-54-g00ecf From ef54702008143568afa77c1dda86da530a321d0f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 14:17:25 -0500 Subject: Return empty array when no subscriptions to remote --- lib/oauthstore.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/oauthstore.php b/lib/oauthstore.php index eabe37f9f..a6a6de750 100644 --- a/lib/oauthstore.php +++ b/lib/oauthstore.php @@ -390,7 +390,7 @@ class StatusNetOAuthDataStore extends OAuthDataStore $sub->subscribed = $user->id; if (!$sub->find(true)) { - return 0; + return array(); } /* Since we do not use OMB_Service_Provider’s action methods, there -- cgit v1.2.3-54-g00ecf From 30c992004ff44516a1502f5e118b0395300bcbc0 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 14:30:28 -0500 Subject: Better logging on bad token in subscription --- classes/Subscription.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/classes/Subscription.php b/classes/Subscription.php index 878ab83e6..da695c36e 100644 --- a/classes/Subscription.php +++ b/classes/Subscription.php @@ -185,10 +185,13 @@ class Subscription extends Memcached_DataObject if ($token->find(true)) { $result = $token->delete(); + if (!$result) { - common_log_db_error($sub, 'DELETE', __FILE__); + common_log_db_error($token, 'DELETE', __FILE__); throw new Exception(_('Couldn\'t delete subscription OMB token.')); } + } else { + common_log(LOG_ERR, "Couldn't find credentials with token {$token->tok}"); } } -- cgit v1.2.3-54-g00ecf From 486cbac522b0985ac0f65c3acc61d6e3d73fbc31 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 14:35:38 -0500 Subject: Remove check for secret in token deletion on Subscription::cancel() --- classes/Subscription.php | 1 - 1 file changed, 1 deletion(-) diff --git a/classes/Subscription.php b/classes/Subscription.php index da695c36e..9cef2df1a 100644 --- a/classes/Subscription.php +++ b/classes/Subscription.php @@ -180,7 +180,6 @@ class Subscription extends Memcached_DataObject $token = new Token(); $token->tok = $sub->token; - $token->secret = $sub->secret; if ($token->find(true)) { -- cgit v1.2.3-54-g00ecf From 90689008ee8649d9592ad97579d7de44d1ce389d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 14:40:39 -0500 Subject: send smaller error pages for OMB API endpoints --- actions/postnotice.php | 3 +++ actions/updateprofile.php | 2 ++ 2 files changed, 5 insertions(+) diff --git a/actions/postnotice.php b/actions/postnotice.php index fb0670376..f092d54d1 100644 --- a/actions/postnotice.php +++ b/actions/postnotice.php @@ -54,7 +54,10 @@ class PostnoticeAction extends Action */ function prepare($argarray) { + StatusNet::setApi(true); // Send smaller error pages + parent::prepare($argarray); + try { $this->checkNotice(); } catch (Exception $e) { diff --git a/actions/updateprofile.php b/actions/updateprofile.php index e416a6fa9..dfc31f542 100644 --- a/actions/updateprofile.php +++ b/actions/updateprofile.php @@ -55,6 +55,8 @@ class UpdateprofileAction extends Action */ function prepare($argarray) { + StatusNet::setApi(true); // Send smaller error pages + parent::prepare($argarray); $license = $_POST['omb_listenee_license']; $site_license = common_config('license', 'url'); -- cgit v1.2.3-54-g00ecf From 9b4ee9070467eb5df02b350e2e3d01a2c2497836 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 15:31:20 -0500 Subject: return correct HTTP status code for OMB errors --- actions/postnotice.php | 8 ++++++++ actions/updateprofile.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/actions/postnotice.php b/actions/postnotice.php index f092d54d1..ad3f00e34 100644 --- a/actions/postnotice.php +++ b/actions/postnotice.php @@ -74,6 +74,14 @@ class PostnoticeAction extends Action $srv = new OMB_Service_Provider(null, omb_oauth_datastore(), omb_oauth_server()); $srv->handlePostNotice(); + } catch (OMB_RemoteServiceException $rse) { + $msg = $rse->getMessage(); + if (preg_match('/^Revoked accesstoken/', $msg) || + preg_match('/^No subscriber/', $msg)) { + $this->clientError($msg, 403); + } else { + $this->clientError($msg); + } } catch (Exception $e) { $this->serverError($e->getMessage()); return; diff --git a/actions/updateprofile.php b/actions/updateprofile.php index dfc31f542..44fafdd92 100644 --- a/actions/updateprofile.php +++ b/actions/updateprofile.php @@ -77,6 +77,14 @@ class UpdateprofileAction extends Action $srv = new OMB_Service_Provider(null, omb_oauth_datastore(), omb_oauth_server()); $srv->handleUpdateProfile(); + } catch (OMB_RemoteServiceException $rse) { + $msg = $rse->getMessage(); + if (preg_match('/^Revoked accesstoken/', $msg) || + preg_match('/^No subscriber/', $msg)) { + $this->clientError($msg, 403); + } else { + $this->clientError($msg); + } } catch (Exception $e) { $this->serverError($e->getMessage()); return; -- cgit v1.2.3-54-g00ecf From baee6dac9e75601cf4a49885b69e8e28c623c86f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 15:39:41 -0500 Subject: remove strict check on OMB exception strings --- actions/postnotice.php | 4 ++-- actions/updateprofile.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/actions/postnotice.php b/actions/postnotice.php index ad3f00e34..b2f6f1bb9 100644 --- a/actions/postnotice.php +++ b/actions/postnotice.php @@ -76,8 +76,8 @@ class PostnoticeAction extends Action $srv->handlePostNotice(); } catch (OMB_RemoteServiceException $rse) { $msg = $rse->getMessage(); - if (preg_match('/^Revoked accesstoken/', $msg) || - preg_match('/^No subscriber/', $msg)) { + if (preg_match('/Revoked accesstoken/', $msg) || + preg_match('/No subscriber/', $msg)) { $this->clientError($msg, 403); } else { $this->clientError($msg); diff --git a/actions/updateprofile.php b/actions/updateprofile.php index 44fafdd92..bae6108cc 100644 --- a/actions/updateprofile.php +++ b/actions/updateprofile.php @@ -79,8 +79,8 @@ class UpdateprofileAction extends Action $srv->handleUpdateProfile(); } catch (OMB_RemoteServiceException $rse) { $msg = $rse->getMessage(); - if (preg_match('/^Revoked accesstoken/', $msg) || - preg_match('/^No subscriber/', $msg)) { + if (preg_match('/Revoked accesstoken/', $msg) || + preg_match('/No subscriber/', $msg)) { $this->clientError($msg, 403); } else { $this->clientError($msg); -- cgit v1.2.3-54-g00ecf From 1ac3d15242aa2679a470948b9020714f7cce4acc Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 15:59:24 -0500 Subject: pass listener URI into consumer for OMB --- lib/omb.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/omb.php b/lib/omb.php index 17132a594..14392d079 100644 --- a/lib/omb.php +++ b/lib/omb.php @@ -77,7 +77,7 @@ function omb_broadcast_notice($notice) /* Get remote users subscribed to this profile. */ $rp = new Remote_profile(); - $rp->query('SELECT postnoticeurl, token, secret ' . + $rp->query('SELECT remote_profile.* ' . 'FROM subscription JOIN remote_profile ' . 'ON subscription.subscriber = remote_profile.id ' . 'WHERE subscription.subscribed = ' . $notice->profile_id . ' '); @@ -93,7 +93,8 @@ function omb_broadcast_notice($notice) /* Post notice. */ $service = new StatusNet_OMB_Service_Consumer( - array(OMB_ENDPOINT_POSTNOTICE => $rp->postnoticeurl)); + array(OMB_ENDPOINT_POSTNOTICE => $rp->postnoticeurl), + $rp->uri); try { $service->setToken($rp->token, $rp->secret); $service->postNotice($omb_notice); @@ -125,7 +126,7 @@ function omb_broadcast_profile($profile) /* Get remote users subscribed to this profile. */ $rp = new Remote_profile(); - $rp->query('SELECT updateprofileurl, token, secret ' . + $rp->query('SELECT remote_profile.* ' . 'FROM subscription JOIN remote_profile ' . 'ON subscription.subscriber = remote_profile.id ' . 'WHERE subscription.subscribed = ' . $profile->id . ' '); @@ -141,7 +142,8 @@ function omb_broadcast_profile($profile) /* Update profile. */ $service = new StatusNet_OMB_Service_Consumer( - array(OMB_ENDPOINT_UPDATEPROFILE => $rp->updateprofileurl)); + array(OMB_ENDPOINT_UPDATEPROFILE => $rp->updateprofileurl), + $rp->uri); try { $service->setToken($rp->token, $rp->secret); $service->updateProfile($omb_profile); @@ -159,13 +161,14 @@ function omb_broadcast_profile($profile) } class StatusNet_OMB_Service_Consumer extends OMB_Service_Consumer { - public function __construct($urls) + public function __construct($urls, $listener_uri=null) { $this->services = $urls; $this->datastore = omb_oauth_datastore(); $this->oauth_consumer = omb_oauth_consumer(); $this->fetcher = Auth_Yadis_Yadis::getHTTPFetcher(); $this->fetcher->timeout = intval(common_config('omb', 'timeout')); + $this->listener_uri = $listener_uri; } } -- cgit v1.2.3-54-g00ecf From 79b2e671c21e07a0512ea0ed95ed2e00e150c842 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 17:55:46 -0500 Subject: show service debug info --- lib/omb.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/omb.php b/lib/omb.php index 14392d079..0db178989 100644 --- a/lib/omb.php +++ b/lib/omb.php @@ -144,6 +144,9 @@ function omb_broadcast_profile($profile) $service = new StatusNet_OMB_Service_Consumer( array(OMB_ENDPOINT_UPDATEPROFILE => $rp->updateprofileurl), $rp->uri); + + common_debug('service = ' . print_r($service, true)); + try { $service->setToken($rp->token, $rp->secret); $service->updateProfile($omb_profile); -- cgit v1.2.3-54-g00ecf