fix for bug #6140 (jabber not working)

git-svn-id: file:///svn/phpbb/trunk@6771 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2006-12-16 12:57:01 +00:00
parent 2e4cd16058
commit 204187187d
3 changed files with 34 additions and 21 deletions

View file

@ -58,7 +58,7 @@ class acp_jabber
{ {
if (!$jabber->connect()) if (!$jabber->connect())
{ {
trigger_error($user->lang['ERR_JAB_CONNECT'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($user->lang['ERR_JAB_CONNECT'] . $jabber->get_log() . adm_back_link($this->u_action), E_USER_WARNING);
} }
// First we'll try to authorise using this account, if that fails we'll try to create it. // First we'll try to authorise using this account, if that fails we'll try to create it.
@ -87,16 +87,16 @@ class acp_jabber
{ {
if (!$jabber->connect()) if (!$jabber->connect())
{ {
trigger_error($user->lang['ERR_JAB_CONNECT'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($user->lang['ERR_JAB_CONNECT'] . $jabber->get_log() . adm_back_link($this->u_action), E_USER_WARNING);
} }
if (!$jabber->send_auth()) if (!$jabber->send_auth())
{ {
trigger_error($user->lang['ERR_JAB_AUTH'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($user->lang['ERR_JAB_AUTH'] . $jabber->get_log() . adm_back_link($this->u_action), E_USER_WARNING);
} }
$jabber->send_presence(NULL, NULL, 'online'); $jabber->send_presence(NULL, NULL, 'online');
if (($result = $jabber->change_password($jab_password)) <> 2) if (($result = $jabber->change_password($jab_password)) <> 2)
{ {
$error[] = ($result == 1) ? $user->lang['ERR_JAB_PASSCHG'] : sprintf($user->lang['ERR_JAB_PASSFAIL'], $result); $error[] = ($result == 1) ? $user->lang['ERR_JAB_PASSCHG'] : sprintf($user->lang['ERR_JAB_PASSFAIL'], $result);
} }

View file

@ -20,7 +20,7 @@
* last modified: 24.03.2004 13:01:53 * last modified: 24.03.2004 13:01:53
* *
* Modified by phpBB Development Team * Modified by phpBB Development Team
* version: v0.4.3a * version: v0.4.3a1
* *
* @package phpBB3 * @package phpBB3
*/ */
@ -113,7 +113,7 @@ class jabber
if ($this->connector->open_socket($this->server, $this->port)) if ($this->connector->open_socket($this->server, $this->port))
{ {
$this->send_packet("<?xml version='1.0' encoding='UTF-8' ?" . ">\n"); $this->send_packet("<?xml version='1.0' encoding='UTF-8' ?" . ">\n");
$this->send_packet("<stream:stream to='{$this->server}' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>\n"); $this->send_packet("<stream:stream to='{$this->server}' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='0.9'>\n");
sleep(2); sleep(2);
@ -672,7 +672,7 @@ class jabber
{ {
if ($this->enable_logging && sizeof($this->log_array)) if ($this->enable_logging && sizeof($this->log_array))
{ {
return implode("\n\n", $this->log_array); return implode("<br /><br />", $this->log_array);
} }
return ''; return '';
@ -805,7 +805,7 @@ class jabber
* Check if connected * Check if connected
* @access private * @access private
*/ */
function _check_connected() function _check_connected($in_tls = false)
{ {
$incoming_array = $this->_listen_incoming(); $incoming_array = $this->_listen_incoming();
@ -815,14 +815,16 @@ class jabber
{ {
$this->stream_id = $incoming_array['stream:stream']['@']['id']; $this->stream_id = $incoming_array['stream:stream']['@']['id'];
if (!empty($incoming_array['stream:stream']['#']['stream:features'][0]['#']['starttls'][0]['@']['xmlns']) && $incoming_array['stream:stream']['#']['stream:features'][0]['#']['starttls'][0]['@']['xmlns'] == 'urn:ietf:params:xml:ns:xmpp-tls') // We only start TLS authentication if not called within TLS authentication itself, which may produce a never ending loop...
if (!$in_tls)
{ {
return $this->_starttls(); if (!empty($incoming_array['stream:stream']['#']['stream:features'][0]['#']['starttls'][0]['@']['xmlns']) && $incoming_array['stream:stream']['#']['stream:features'][0]['#']['starttls'][0]['@']['xmlns'] == 'urn:ietf:params:xml:ns:xmpp-tls')
} {
else return $this->_starttls();
{ }
return true;
} }
return true;
} }
else else
{ {
@ -843,12 +845,21 @@ class jabber
*/ */
function _starttls() function _starttls()
{ {
if (!function_exists('stream_socket_enable_crypto') || !function_exists('stream_get_meta_data') || !function_exists('socket_set_blocking')) if (!function_exists('stream_socket_enable_crypto') || !function_exists('stream_get_meta_data') || !function_exists('socket_set_blocking') || !function_exists('stream_get_wrappers'))
{ {
$this->add_to_log('WARNING: TLS is not available'); $this->add_to_log('WARNING: TLS is not available');
return true; return true;
} }
// Make sure the encryption stream is supported
$streams = stream_get_wrappers();
if (!in_array('streams.crypto', $streams))
{
$this->add_to_log('WARNING: SSL/crypto stream not supported');
return true;
}
$this->send_packet("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>\n"); $this->send_packet("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>\n");
sleep(2); sleep(2);
$incoming_array = $this->_listen_incoming(); $incoming_array = $this->_listen_incoming();
@ -868,19 +879,21 @@ class jabber
$meta = stream_get_meta_data($this->connector->active_socket); $meta = stream_get_meta_data($this->connector->active_socket);
socket_set_blocking($this->connector->active_socket, 1); socket_set_blocking($this->connector->active_socket, 1);
if (!stream_socket_enable_crypto($this->connector->active_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) $result = @stream_socket_enable_crypto($this->connector->active_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
if (!$result)
{ {
socket_set_blocking($this->connector->active_socket, $meta['blocked']); socket_set_blocking($this->connector->active_socket, $meta['blocked']);
$this->add_to_log('ERROR: _starttls() #3'); $this->add_to_log('ERROR: _starttls() #3');
return false; return false;
} }
socket_set_blocking($this->connector->active_socket, $meta['blocked']); socket_set_blocking($this->connector->active_socket, $meta['blocked']);
$this->send_packet("<?xml version='1.0' encoding='UTF-8' ?" . ">\n"); $this->send_packet("<?xml version='1.0' encoding='UTF-8' ?" . ">\n");
$this->send_packet("<stream:stream to='{$this->server}' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>\n"); $this->send_packet("<stream:stream to='{$this->server}' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>\n");
sleep(2); sleep(2);
if (!$this->_check_connected()) if (!$this->_check_connected(true))
{ {
$this->add_to_log('ERROR: _starttls() #4'); $this->add_to_log('ERROR: _starttls() #4');
return false; return false;

View file

@ -453,18 +453,18 @@ class messenger
if (!$use_queue) if (!$use_queue)
{ {
include_once($phpbb_root_path . 'includes/functions_jabber.'.$phpEx); include_once($phpbb_root_path . 'includes/functions_jabber.' . $phpEx);
$this->jabber = new jabber($config['jab_host'], $config['jab_port'], $config['jab_username'], $config['jab_password'], $config['jab_resource']); $this->jabber = new jabber($config['jab_host'], $config['jab_port'], $config['jab_username'], $config['jab_password'], $config['jab_resource']);
if (!$this->jabber->connect()) if (!$this->jabber->connect())
{ {
$this->error('JABBER', 'Could not connect to Jabber server'); $this->error('JABBER', 'Could not connect to Jabber server<br />' . $this->jabber->get_log());
return false; return false;
} }
if (!$this->jabber->send_auth()) if (!$this->jabber->send_auth())
{ {
$this->error('JABBER', 'Could not authorise on Jabber server'); $this->error('JABBER', 'Could not authorise on Jabber server<br />' . $this->jabber->get_log());
return false; return false;
} }
$this->jabber->send_presence(NULL, NULL, 'online'); $this->jabber->send_presence(NULL, NULL, 'online');
@ -636,7 +636,7 @@ class queue
{ {
if ($this->jabber->send_message($address, 'normal', NULL, array('body' => $msg)) === false) if ($this->jabber->send_message($address, 'normal', NULL, array('body' => $msg)) === false)
{ {
messenger::error('JABBER', $this->jabber_get_log()); messenger::error('JABBER', $this->jabber->get_log());
continue 3; continue 3;
} }
} }