From cac6d4234a4ef8fea1d487f44062ae06dd9c0c52 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 12:55:51 -0500 Subject: [PATCH 01/25] 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 0000000000..8b10817040 --- /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; + } + } +} From caab6ddaa9ba9d8eb500d508e7580222886c0143 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 13:13:51 -0500 Subject: [PATCH 02/25] 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 8b10817040..1414f81e93 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'); From 6f20b74dc7b3b69365bf8de7ba0652177e570437 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 13:41:06 -0500 Subject: [PATCH 03/25] 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 d6fb3fcbdd..878ab83e63 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) { From ef54702008143568afa77c1dda86da530a321d0f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 14:17:25 -0500 Subject: [PATCH 04/25] 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 eabe37f9fa..a6a6de7505 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 From 30c992004ff44516a1502f5e118b0395300bcbc0 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 14:30:28 -0500 Subject: [PATCH 05/25] 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 878ab83e63..da695c36e5 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}"); } } From 486cbac522b0985ac0f65c3acc61d6e3d73fbc31 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 14:35:38 -0500 Subject: [PATCH 06/25] 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 da695c36e5..9cef2df1ad 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)) { From 90689008ee8649d9592ad97579d7de44d1ce389d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 14:40:39 -0500 Subject: [PATCH 07/25] 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 fb06703766..f092d54d1d 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 e416a6fa93..dfc31f5427 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'); From 9b4ee9070467eb5df02b350e2e3d01a2c2497836 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 15:31:20 -0500 Subject: [PATCH 08/25] 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 f092d54d1d..ad3f00e349 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 dfc31f5427..44fafdd926 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; From baee6dac9e75601cf4a49885b69e8e28c623c86f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 15:39:41 -0500 Subject: [PATCH 09/25] 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 ad3f00e349..b2f6f1bb95 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 44fafdd926..bae6108cce 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); From 1ac3d15242aa2679a470948b9020714f7cce4acc Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 15:59:24 -0500 Subject: [PATCH 10/25] 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 17132a594f..14392d0799 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; } } From 79b2e671c21e07a0512ea0ed95ed2e00e150c842 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 17:55:46 -0500 Subject: [PATCH 11/25] show service debug info --- lib/omb.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/omb.php b/lib/omb.php index 14392d0799..0db178989c 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); From 3ff3abb247062ed61486930ed1203c286b1378b2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 12:55:51 -0500 Subject: [PATCH 12/25] 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 0000000000..8b10817040 --- /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; + } + } +} From d77248343f173d5a25e674abfc4bffe59d55300c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 13:13:51 -0500 Subject: [PATCH 13/25] 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 8b10817040..1414f81e93 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'); From 320036dbfbd1d4b2b1e866aafb5da26330cc1e21 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 13:41:06 -0500 Subject: [PATCH 14/25] 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 d6fb3fcbdd..878ab83e63 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) { From c3ba26bb9955ae5d924426dc0e4ff6c48b4399ad Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 14:17:25 -0500 Subject: [PATCH 15/25] 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 eabe37f9fa..a6a6de7505 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 From 48ce511f947e966b624dc3cf6e6b884361c3370d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 14:30:28 -0500 Subject: [PATCH 16/25] 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 878ab83e63..da695c36e5 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}"); } } From 17c2c793a5d9e1e7066715e57694678296f2221a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 14:35:38 -0500 Subject: [PATCH 17/25] 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 da695c36e5..9cef2df1ad 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)) { From 1414b6b84954939b2f120443ab90a75d1ffb2a65 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 14:40:39 -0500 Subject: [PATCH 18/25] 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 fb06703766..f092d54d1d 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 e416a6fa93..dfc31f5427 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'); From c7d8641e7dcb2af0ab9ad682f64c5ebc45fbbeae Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 15:31:20 -0500 Subject: [PATCH 19/25] 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 f092d54d1d..ad3f00e349 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 dfc31f5427..44fafdd926 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; From 656a977016701e7a0a1f936909cd7d4a5975f5be Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 15:39:41 -0500 Subject: [PATCH 20/25] 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 ad3f00e349..b2f6f1bb95 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 44fafdd926..bae6108cce 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); From 64918cfd352c50385ab4f0283fe09589018bcce5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 15:59:24 -0500 Subject: [PATCH 21/25] 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 17132a594f..14392d0799 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; } } From 19ec0e3a62d4c60d7e5581b4e38ec705650b1d18 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 17:55:46 -0500 Subject: [PATCH 22/25] show service debug info --- lib/omb.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/omb.php b/lib/omb.php index 14392d0799..0db178989c 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); From f7c2c19ce89868fee5ce51d793d45c05ab209866 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 18:07:21 -0500 Subject: [PATCH 23/25] lost important fields when switching queries --- lib/omb.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/omb.php b/lib/omb.php index 0db178989c..8bbe5e8aac 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 remote_profile.* ' . + $rp->query('SELECT remote_profile.*, secret, token ' . 'FROM subscription JOIN remote_profile ' . 'ON subscription.subscriber = remote_profile.id ' . 'WHERE subscription.subscribed = ' . $notice->profile_id . ' '); @@ -126,7 +126,7 @@ function omb_broadcast_profile($profile) /* Get remote users subscribed to this profile. */ $rp = new Remote_profile(); - $rp->query('SELECT remote_profile.* ' . + $rp->query('SELECT remote_profile.*, secret, token ' . 'FROM subscription JOIN remote_profile ' . 'ON subscription.subscriber = remote_profile.id ' . 'WHERE subscription.subscribed = ' . $profile->id . ' '); From 0512151eabf64e88b4648869b3d029800d30668a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 1 Mar 2010 18:19:20 -0500 Subject: [PATCH 24/25] more output in updateostatus.php --- plugins/OStatus/scripts/updateostatus.php | 29 +++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/plugins/OStatus/scripts/updateostatus.php b/plugins/OStatus/scripts/updateostatus.php index 1414f81e93..d553a7d625 100644 --- a/plugins/OStatus/scripts/updateostatus.php +++ b/plugins/OStatus/scripts/updateostatus.php @@ -24,7 +24,7 @@ $shortoptions = 'i:n:a'; $longoptions = array('id=', 'nickname=', 'all'); $helptext = <<nickname}..."; + } + $up = $user->getProfile(); $sp = $user->getSubscriptions(); @@ -84,16 +88,37 @@ function updateOStatus($user) } } + if (!have_option('q', 'quiet')) { + echo count($rps) . "\n"; + } + foreach ($rps as $rp) { try { + if (!have_option('q', 'quiet')) { + echo "Checking {$rp->nickname}..."; + } + $op = Ostatus_profile::ensureProfile($rp->profileurl); - if (!empty($op)) { + if (empty($op)) { + echo "can't convert.\n"; + continue; + } else { + if (!have_option('q', 'quiet')) { + echo "Converting..."; + } Subscription::cancel($up, $rp); Subscription::start($up, $op->localProfile()); + if (!have_option('q', 'quiet')) { + echo "done.\n"; + } } } catch (Exception $e) { + if (!have_option('q', 'quiet')) { + echo "fail.\n"; + } + continue; common_log(LOG_WARNING, "Couldn't convert OMB subscription (" . $up->nickname . ", " . $rp->nickname . ") to OStatus: " . $e->getMessage()); continue; From 45e8819c1b9cc618e9b2d6678b0ff14c653a09d3 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 1 Mar 2010 16:35:36 -0800 Subject: [PATCH 25/25] Fix a bunch of notice & warning-level messages that were breaking my inter-instance communications --- plugins/OStatus/classes/Magicsig.php | 4 +++- plugins/OStatus/classes/Ostatus_profile.php | 2 +- plugins/OStatus/lib/discovery.php | 2 +- plugins/OStatus/lib/xrd.php | 11 ++++++++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/plugins/OStatus/classes/Magicsig.php b/plugins/OStatus/classes/Magicsig.php index 96900d8761..5a46aeeb6e 100644 --- a/plugins/OStatus/classes/Magicsig.php +++ b/plugins/OStatus/classes/Magicsig.php @@ -146,8 +146,10 @@ class Magicsig extends Memcached_DataObject $mod = base64_url_decode($matches[1]); $exp = base64_url_decode($matches[2]); - if ($matches[4]) { + if (!empty($matches[4])) { $private_exp = base64_url_decode($matches[4]); + } else { + $private_exp = false; } $params['public_key'] = new Crypt_RSA_KEY($mod, $exp, 'public'); diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index 7b1aec76ba..93e8934c9e 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -1145,7 +1145,7 @@ class Ostatus_profile extends Memcached_DataObject if (!empty($poco)) { $url = $poco->getPrimaryURL(); - if ($url->type == 'homepage') { + if ($url && $url->type == 'homepage') { $homepage = $url->value; } } diff --git a/plugins/OStatus/lib/discovery.php b/plugins/OStatus/lib/discovery.php index 388df0a28f..f8449b309e 100644 --- a/plugins/OStatus/lib/discovery.php +++ b/plugins/OStatus/lib/discovery.php @@ -94,7 +94,7 @@ class Discovery $links = call_user_func(array($class, 'discover'), $uri); if ($link = Discovery::getService($links, Discovery::LRDD_REL)) { // Load the LRDD XRD - if ($link['template']) { + if (!empty($link['template'])) { $xrd_uri = Discovery::applyTemplate($link['template'], $uri); } else { $xrd_uri = $link['href']; diff --git a/plugins/OStatus/lib/xrd.php b/plugins/OStatus/lib/xrd.php index 16d27f8eb7..1de065db9f 100644 --- a/plugins/OStatus/lib/xrd.php +++ b/plugins/OStatus/lib/xrd.php @@ -53,17 +53,22 @@ class XRD $xrd = new XRD(); $dom = new DOMDocument(); - $dom->loadXML($xml); + if (!$dom->loadXML($xml)) { + throw new Exception("Invalid XML"); + } $xrd_element = $dom->getElementsByTagName('XRD')->item(0); // Check for host-meta host - $host = $xrd_element->getElementsByTagName('Host')->item(0)->nodeValue; + $host = $xrd_element->getElementsByTagName('Host')->item(0); if ($host) { - $xrd->host = $host; + $xrd->host = $host->nodeValue; } // Loop through other elements foreach ($xrd_element->childNodes as $node) { + if (!($node instanceof DOMElement)) { + continue; + } switch ($node->tagName) { case 'Expires': $xrd->expires = $node->nodeValue;