From 029b8c90142e08b0ed44f0528ddea7d4dcc32980 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 5 Mar 2010 02:27:01 +0000 Subject: [PATCH 01/14] Fix for errant deletion of all Twitter foreign_links --- plugins/TwitterBridge/twitter.php | 11 ++++++++++- plugins/TwitterBridge/twitterauthorization.php | 13 ++++++++++++- plugins/TwitterBridge/twittersettings.php | 11 ++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/plugins/TwitterBridge/twitter.php b/plugins/TwitterBridge/twitter.php index ceb83b037f..42db3c673d 100644 --- a/plugins/TwitterBridge/twitter.php +++ b/plugins/TwitterBridge/twitter.php @@ -264,7 +264,16 @@ function remove_twitter_link($flink) common_log(LOG_INFO, 'Removing Twitter bridge Foreign link for ' . "user $user->nickname (user id: $user->id)."); - $result = $flink->delete(); + $result = false; + + // Be extra careful to make sure we have a good flink + // before deleting + if (!empty($flink->user_id) + && !empty($flink->foreign_id) + && !empty($flink->service)) + { + $result = $flink->delete(); + } if (empty($result)) { common_log(LOG_ERR, 'Could not remove Twitter bridge ' . diff --git a/plugins/TwitterBridge/twitterauthorization.php b/plugins/TwitterBridge/twitterauthorization.php index c93f6666bc..029c3a44b4 100644 --- a/plugins/TwitterBridge/twitterauthorization.php +++ b/plugins/TwitterBridge/twitterauthorization.php @@ -273,7 +273,13 @@ class TwitterauthorizationAction extends Action $flink->user_id = $user_id; $flink->service = TWITTER_SERVICE; - $flink->delete(); // delete stale flink, if any + + // delete stale flink, if any + $result = $flink->find(true); + + if (!empty($result)) { + $flink->delete(); + } $flink->user_id = $user_id; $flink->foreign_id = $twuid; @@ -455,6 +461,11 @@ class TwitterauthorizationAction extends Action $user = User::register($args); + if (empty($user)) { + $this->serverError(_('Error registering user.')); + return; + } + $result = $this->saveForeignLink($user->id, $this->twuid, $this->access_token); diff --git a/plugins/TwitterBridge/twittersettings.php b/plugins/TwitterBridge/twittersettings.php index 0137060e9c..f22a059f74 100644 --- a/plugins/TwitterBridge/twittersettings.php +++ b/plugins/TwitterBridge/twittersettings.php @@ -250,7 +250,16 @@ class TwittersettingsAction extends ConnectSettingsAction $user = common_current_user(); $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE); - $result = $flink->delete(); + $result = false; + + // Be extra careful to make sure we have a good flink + // before deleting + if (!empty($flink->user_id) + && !empty($flink->foreign_id) + && !empty($flink->service)) + { + $result = $flink->delete(); + } if (empty($result)) { common_log_db_error($flink, 'DELETE', __FILE__); From 6a377a4ba409083e05d16b163013f0f09c606170 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 5 Mar 2010 03:14:40 +0000 Subject: [PATCH 02/14] A better way to safely delete Foreign_links --- classes/Foreign_link.php | 17 +++++++++++++++++ plugins/TwitterBridge/twitter.php | 11 +---------- plugins/TwitterBridge/twitterauthorization.php | 2 +- plugins/TwitterBridge/twittersettings.php | 11 +---------- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/classes/Foreign_link.php b/classes/Foreign_link.php index ae8c22fd84..e47b2e3096 100644 --- a/classes/Foreign_link.php +++ b/classes/Foreign_link.php @@ -113,4 +113,21 @@ class Foreign_link extends Memcached_DataObject return User::staticGet($this->user_id); } + // Make sure we only ever delete one record at a time + function safeDelete() + { + if (!empty($this->user_id) + && !empty($this->foreign_id) + && !empty($this->service)) + { + return $this->delete(); + } else { + common_debug(LOG_WARNING, + 'Foreign_link::safeDelete() tried to delete a ' + . 'Foreign_link without a fully specified compound key: ' + . var_export($this, true)); + return false; + } + } + } diff --git a/plugins/TwitterBridge/twitter.php b/plugins/TwitterBridge/twitter.php index 42db3c673d..5086999394 100644 --- a/plugins/TwitterBridge/twitter.php +++ b/plugins/TwitterBridge/twitter.php @@ -264,16 +264,7 @@ function remove_twitter_link($flink) common_log(LOG_INFO, 'Removing Twitter bridge Foreign link for ' . "user $user->nickname (user id: $user->id)."); - $result = false; - - // Be extra careful to make sure we have a good flink - // before deleting - if (!empty($flink->user_id) - && !empty($flink->foreign_id) - && !empty($flink->service)) - { - $result = $flink->delete(); - } + $result = $flink->safeDelete(); if (empty($result)) { common_log(LOG_ERR, 'Could not remove Twitter bridge ' . diff --git a/plugins/TwitterBridge/twitterauthorization.php b/plugins/TwitterBridge/twitterauthorization.php index 029c3a44b4..bc004cb955 100644 --- a/plugins/TwitterBridge/twitterauthorization.php +++ b/plugins/TwitterBridge/twitterauthorization.php @@ -278,7 +278,7 @@ class TwitterauthorizationAction extends Action $result = $flink->find(true); if (!empty($result)) { - $flink->delete(); + $flink->safeDelete(); } $flink->user_id = $user_id; diff --git a/plugins/TwitterBridge/twittersettings.php b/plugins/TwitterBridge/twittersettings.php index f22a059f74..631b29f52a 100644 --- a/plugins/TwitterBridge/twittersettings.php +++ b/plugins/TwitterBridge/twittersettings.php @@ -250,16 +250,7 @@ class TwittersettingsAction extends ConnectSettingsAction $user = common_current_user(); $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE); - $result = false; - - // Be extra careful to make sure we have a good flink - // before deleting - if (!empty($flink->user_id) - && !empty($flink->foreign_id) - && !empty($flink->service)) - { - $result = $flink->delete(); - } + $result = $flink->safeDelete(); if (empty($result)) { common_log_db_error($flink, 'DELETE', __FILE__); From 89e313e45b1b08fc80ab908e4dd531689319aa6f Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 5 Mar 2010 10:55:07 -0800 Subject: [PATCH 03/14] OStatus fix: send the feed's root element, not the DOM document, down to low-level feed processing as entry context on PuSH input. --- plugins/OStatus/classes/Ostatus_profile.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index fcca1a2521..abc8100cee 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -428,10 +428,18 @@ class Ostatus_profile extends Memcached_DataObject * Currently assumes that all items in the feed are new, * coming from a PuSH hub. * - * @param DOMDocument $feed + * @param DOMDocument $doc + * @param string $source identifier ("push") */ - public function processFeed($feed, $source) + public function processFeed(DOMDocument $doc, $source) { + $feed = $doc->documentElement; + + if ($feed->localName != 'feed' || $feed->namespaceURI != Activity::ATOM) { + common_log(LOG_ERR, __METHOD__ . ": not an Atom feed, ignoring"); + return; + } + $entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry'); if ($entries->length == 0) { common_log(LOG_ERR, __METHOD__ . ": no entries in feed update, ignoring"); @@ -449,6 +457,7 @@ class Ostatus_profile extends Memcached_DataObject * * @param DOMElement $entry * @param DOMElement $feed for context + * @param string $source identifier ("push" or "salmon") */ public function processEntry($entry, $feed, $source) { From 248aed7cf430d263f3d5dd98552f35f69de6fe67 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 5 Mar 2010 12:21:30 -0800 Subject: [PATCH 04/14] ticket #697: merge two dupe config bits in config.php.sample --- config.php.sample | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.php.sample b/config.php.sample index b8852dc672..33ac94a6d0 100644 --- a/config.php.sample +++ b/config.php.sample @@ -124,6 +124,8 @@ $config['sphinx']['port'] = 3312; // Email info, used for all outbound email // $config['mail']['notifyfrom'] = 'microblog@example.net'; +// Domain for generating no-reply and incoming email addresses, if enabled. +// Defaults to site server name. // $config['mail']['domain'] = 'microblog.example.net'; // See http://pear.php.net/manual/en/package.mail.mail.factory.php for options // $config['mail']['backend'] = 'smtp'; @@ -131,8 +133,6 @@ $config['sphinx']['port'] = 3312; // 'host' => 'localhost', // 'port' => 25, // ); -// For incoming email, if enabled. Defaults to site server name. -// $config['mail']['domain'] = 'incoming.example.net'; // exponential decay factor for tags, default 10 days // raise this if traffic is slow, lower it if it's fast From 54de8ad9f20a51cdaf78404c45e91a1f652670f1 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 5 Mar 2010 11:27:48 -0800 Subject: [PATCH 05/14] Initial install-time test for PCRE compiled without Unicode properties, which causes corruption in feeds and other linking problems. Error message links to help info at http://status.net/wiki/Red_Hat_Enterprise_Linux#PCRE_library --- install.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/install.php b/install.php index 8c9b6138b8..7fece8999f 100644 --- a/install.php +++ b/install.php @@ -301,6 +301,19 @@ function checkPrereqs() $pass = false; } + // Look for known library bugs + $str = "abcdefghijklmnopqrstuvwxyz"; + $replaced = preg_replace('/[\p{Cc}\p{Cs}]/u', '*', $str); + if ($str != $replaced) { + printf('

PHP is linked to a version of the PCRE library ' . + 'that does not support Unicode properties. ' . + 'If you are running Red Hat Enterprise Linux / ' . + 'CentOS 5.3 or earlier, see our documentation page on fixing this.

'); + $pass = false; + } + $reqs = array('gd', 'curl', 'xmlwriter', 'mbstring', 'xml', 'dom', 'simplexml'); From 5355c3b7b579f803bb18913db3b4d9cf380f17ac Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 5 Mar 2010 15:00:27 -0800 Subject: [PATCH 06/14] OpenID fix: - avoid notice on insert (missing sequenceKeys()) - avoid cache corruption on delete (user_id was missing from keys list, cache not cleared for user_id lookups) --- plugins/OpenID/User_openid.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/OpenID/User_openid.php b/plugins/OpenID/User_openid.php index 801b49eccd..5ef05b4c77 100644 --- a/plugins/OpenID/User_openid.php +++ b/plugins/OpenID/User_openid.php @@ -39,9 +39,21 @@ class User_openid extends Memcached_DataObject ); } + /** + * List primary and unique keys in this table. + * Unique keys used for lookup *MUST* be listed to ensure proper caching. + */ function keys() { - return array('canonical' => 'K', 'display' => 'U'); + return array('canonical' => 'K', 'display' => 'U', 'user_id' => 'U'); + } + + /** + * No sequence keys in this table. + */ + function sequenceKey() + { + return array(false, false, false); } Static function hasOpenID($user_id) From ab8aa670087580f164f96af6727eef5d2cf0a6e1 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 5 Mar 2010 16:20:33 -0800 Subject: [PATCH 07/14] Fix for blank RSS1 tag feeds --- actions/tagrss.php | 1 + 1 file changed, 1 insertion(+) diff --git a/actions/tagrss.php b/actions/tagrss.php index 75cbfa274b..467a64abed 100644 --- a/actions/tagrss.php +++ b/actions/tagrss.php @@ -35,6 +35,7 @@ class TagrssAction extends Rss10Action $this->clientError(_('No such tag.')); return false; } else { + $this->notices = $this->getNotices($this->limit); return true; } } From 1a03820628d37b9db6e47be22d98789f551f1959 Mon Sep 17 00:00:00 2001 From: Christopher Vollick Date: Thu, 11 Feb 2010 11:19:50 -0500 Subject: [PATCH 08/14] UserRSS Didn't Use the Tag Propery. This meant that server.com/user/tag/TAG/rss just returned all user data. That was incorrect. --- actions/userrss.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/actions/userrss.php b/actions/userrss.php index 19e610551d..6029f44318 100644 --- a/actions/userrss.php +++ b/actions/userrss.php @@ -38,7 +38,11 @@ class UserrssAction extends Rss10Action $this->clientError(_('No such user.')); return false; } else { - $this->notices = $this->getNotices($this->limit); + if ($this->tag) { + $this->notices = $this->getTaggedNotices($tag, $this->limit); + } else { + $this->notices = $this->getNotices($this->limit); + } return true; } } From 4ada86560c7c9ef43e41e6c3cdf279d64ea132ba Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 5 Mar 2010 16:40:35 -0800 Subject: [PATCH 09/14] Fix undefined variable error and some other cleanup --- actions/userrss.php | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/actions/userrss.php b/actions/userrss.php index 6029f44318..77bd316b2d 100644 --- a/actions/userrss.php +++ b/actions/userrss.php @@ -29,6 +29,8 @@ class UserrssAction extends Rss10Action function prepare($args) { + common_debug("UserrssAction"); + parent::prepare($args); $nickname = $this->trimmed('nickname'); $this->user = User::staticGet('nickname', $nickname); @@ -38,8 +40,8 @@ class UserrssAction extends Rss10Action $this->clientError(_('No such user.')); return false; } else { - if ($this->tag) { - $this->notices = $this->getTaggedNotices($tag, $this->limit); + if (!empty($this->tag)) { + $this->notices = $this->getTaggedNotices($this->tag, $this->limit); } else { $this->notices = $this->getNotices($this->limit); } @@ -47,15 +49,15 @@ class UserrssAction extends Rss10Action } } - function getTaggedNotices($tag = null, $limit=0) + function getTaggedNotices() { - $user = $this->user; - - if (is_null($user)) { - return null; - } - - $notice = $user->getTaggedNotices(0, ($limit == 0) ? NOTICES_PER_PAGE : $limit, 0, 0, null, $tag); + $notice = $this->user->getTaggedNotices( + $this->tag, + 0, + ($this->limit == 0) ? NOTICES_PER_PAGE : $this->limit, + 0, + 0 + ); $notices = array(); while ($notice->fetch()) { @@ -66,15 +68,12 @@ class UserrssAction extends Rss10Action } - function getNotices($limit=0) + function getNotices() { - $user = $this->user; - - if (is_null($user)) { - return null; - } - - $notice = $user->getNotices(0, ($limit == 0) ? NOTICES_PER_PAGE : $limit); + $notice = $this->user->getNotices( + 0, + ($limit == 0) ? NOTICES_PER_PAGE : $limit + ); $notices = array(); while ($notice->fetch()) { From 773626aac49dce2dd350a4e15f36aa5c9b4924cd Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 5 Mar 2010 16:52:15 -0800 Subject: [PATCH 10/14] No need to pass in $this->limit and $this-tag --- actions/userrss.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actions/userrss.php b/actions/userrss.php index 77bd316b2d..e03eb93566 100644 --- a/actions/userrss.php +++ b/actions/userrss.php @@ -41,9 +41,9 @@ class UserrssAction extends Rss10Action return false; } else { if (!empty($this->tag)) { - $this->notices = $this->getTaggedNotices($this->tag, $this->limit); + $this->notices = $this->getTaggedNotices(); } else { - $this->notices = $this->getNotices($this->limit); + $this->notices = $this->getNotices(); } return true; } From 5adb494c26e431948b50690b8efaeedb3f3513d1 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 5 Mar 2010 17:05:00 -0800 Subject: [PATCH 11/14] Remove unused variables, update Twitter ones --- config.php.sample | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/config.php.sample b/config.php.sample index 33ac94a6d0..3d2a52becc 100644 --- a/config.php.sample +++ b/config.php.sample @@ -188,9 +188,6 @@ $config['sphinx']['port'] = 3312; // Disable SMS // $config['sms']['enabled'] = false; -// Disable Twitter integration -// $config['twitter']['enabled'] = false; - // Twitter integration source attribute. Note: default is StatusNet // $config['integration']['source'] = 'StatusNet'; @@ -198,7 +195,7 @@ $config['sphinx']['port'] = 3312; // // NOTE: if you enable this you must also set $config['avatar']['path'] // -// $config['twitterbridge']['enabled'] = true; +// $config['twitterimport']['enabled'] = true; // Twitter OAuth settings // $config['twitter']['consumer_key'] = 'YOURKEY'; @@ -212,10 +209,6 @@ $config['sphinx']['port'] = 3312; // $config['throttle']['count'] = 100; // $config['throttle']['timespan'] = 3600; -// List of users banned from posting (nicknames and/or IDs) -// $config['profile']['banned'][] = 'hacker'; -// $config['profile']['banned'][] = 12345; - // Config section for the built-in Facebook application // $config['facebook']['apikey'] = 'APIKEY'; // $config['facebook']['secret'] = 'SECRET'; From a77efb2447abe75d3b9902410bced61b76377de3 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 8 Mar 2010 10:32:40 -0800 Subject: [PATCH 12/14] XMPP cleanup: fix outgoing XMPP when queuing is disabled; fix notice for first access to undefined member variable --- lib/jabber.php | 34 +++++++++++++++++++++------------- lib/xmppmanager.php | 1 + 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/jabber.php b/lib/jabber.php index e1bf06ba66..db4e2e9a70 100644 --- a/lib/jabber.php +++ b/lib/jabber.php @@ -88,22 +88,30 @@ class Sharing_XMPP extends XMPPHP_XMPP /** * Build an XMPP proxy connection that'll save outgoing messages * to the 'xmppout' queue to be picked up by xmppdaemon later. + * + * If queueing is disabled, we'll grab a live connection. + * + * @return XMPPHP */ function jabber_proxy() { - $proxy = new Queued_XMPP(common_config('xmpp', 'host') ? - common_config('xmpp', 'host') : - common_config('xmpp', 'server'), - common_config('xmpp', 'port'), - common_config('xmpp', 'user'), - common_config('xmpp', 'password'), - common_config('xmpp', 'resource') . 'daemon', - common_config('xmpp', 'server'), - common_config('xmpp', 'debug') ? - true : false, - common_config('xmpp', 'debug') ? - XMPPHP_Log::LEVEL_VERBOSE : null); - return $proxy; + if (common_config('queue', 'enabled')) { + $proxy = new Queued_XMPP(common_config('xmpp', 'host') ? + common_config('xmpp', 'host') : + common_config('xmpp', 'server'), + common_config('xmpp', 'port'), + common_config('xmpp', 'user'), + common_config('xmpp', 'password'), + common_config('xmpp', 'resource') . 'daemon', + common_config('xmpp', 'server'), + common_config('xmpp', 'debug') ? + true : false, + common_config('xmpp', 'debug') ? + XMPPHP_Log::LEVEL_VERBOSE : null); + return $proxy; + } else { + return jabber_connect(); + } } /** diff --git a/lib/xmppmanager.php b/lib/xmppmanager.php index f376358555..cca54db08d 100644 --- a/lib/xmppmanager.php +++ b/lib/xmppmanager.php @@ -36,6 +36,7 @@ class XmppManager extends IoManager protected $site = null; protected $pingid = 0; protected $lastping = null; + protected $conn = null; static protected $singletons = array(); From 217ad420ac8085fe620235dfc47bea27e4ac75dc Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 8 Mar 2010 12:19:06 -0800 Subject: [PATCH 13/14] Fix ticket #2208: regression in XMPP sending when server != host The upstream class sets $this->basejid with host unconditionally, which wasn't previously an issue as the fulljid would always be filled in by the server at connect time before sending messages. With the new queued messaging, we need to make sure we've filled out $this->fulljid correctly without making a connection. Now using $server if provided to build $this->basejid and $this->fulljid in the queued XMPP proxy class, so queued messages are sent correctly. --- lib/queued_xmpp.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/queued_xmpp.php b/lib/queued_xmpp.php index fdd074db29..f6bccfd5ba 100644 --- a/lib/queued_xmpp.php +++ b/lib/queued_xmpp.php @@ -49,10 +49,20 @@ class Queued_XMPP extends XMPPHP_XMPP */ public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) { - parent::__construct($host, $port, $user, $password, $resource, $server, $printlog, $loglevel); - // Normally the fulljid isn't filled out until resource binding time; - // we need to save it here since we're not talking to a real server. - $this->fulljid = "{$this->basejid}/{$this->resource}"; + parent::__construct($host, $port, $user, $password, $resource, $server, $printlog, $loglevel); + + // We use $host to connect, but $server to build JIDs if specified. + // This seems to fix an upstream bug where $host was used to build + // $this->basejid, never seen since it isn't actually used in the base + // classes. + if (!$server) { + $server = $this->host; + } + $this->basejid = $this->user . '@' . $server; + + // Normally the fulljid is filled out by the server at resource binding + // time, but we need to do it since we're not talking to a real server. + $this->fulljid = "{$this->basejid}/{$this->resource}"; } /** From 7e7d88831cf8b3e8876499b86890da2e63b08c97 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 8 Mar 2010 13:32:18 -0800 Subject: [PATCH 14/14] CentOS 5.4 still bogus on a stock install. --- extlib/Auth/OpenID/Consumer.php | 3 +++ install.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/extlib/Auth/OpenID/Consumer.php b/extlib/Auth/OpenID/Consumer.php index 500890b656..130fe07130 100644 --- a/extlib/Auth/OpenID/Consumer.php +++ b/extlib/Auth/OpenID/Consumer.php @@ -966,6 +966,9 @@ class Auth_OpenID_GenericConsumer { // framework will not want to block on this call to // _checkAuth. if (!$this->_checkAuth($message, $server_url)) { + var_dump($message); + var_dump($server_url); + var_dump($this); return new Auth_OpenID_FailureResponse(null, "Server denied check_authentication"); } diff --git a/install.php b/install.php index 7fece8999f..929277e5e8 100644 --- a/install.php +++ b/install.php @@ -308,7 +308,7 @@ function checkPrereqs() printf('

PHP is linked to a version of the PCRE library ' . 'that does not support Unicode properties. ' . 'If you are running Red Hat Enterprise Linux / ' . - 'CentOS 5.3 or earlier, see our documentation page on fixing this.

'); $pass = false;