phpBB

Code Changes

File: includes/functions_jabber.php

  Unmodified   Added   Modified   Removed
Line 20Line 20
*
* Jabber class from Flyspray project
*

*
* Jabber class from Flyspray project
*

* @version class.jabber2.php 1306 2007-06-21

* @version class.jabber2.php 1595 2008-09-19 (0.9.9)

* @copyright 2006 Flyspray.org
* @author Florian Schmitz (floele)
*

* @copyright 2006 Flyspray.org
* @author Florian Schmitz (floele)
*

* Modified by Acyd Burn

* Only slightly modified by Acyd Burn

*
* @package phpBB3
*/

*
* @package phpBB3
*/

Line 35Line 35
	var $timeout = 10;

var $server;

	var $timeout = 10;

var $server;

 
	var $connect_server;

	var $port;
var $username;
var $password;

	var $port;
var $username;
var $password;

Line 50Line 51
	*/
function jabber($server, $port, $username, $password, $use_ssl = false)
{

	*/
function jabber($server, $port, $username, $password, $use_ssl = false)
{

		$this->server				= ($server) ? $server : 'localhost';

		$this->connect_server		= ($server) ? $server : 'localhost';

		$this->port					= ($port) ? $port : 5222;

		$this->port					= ($port) ? $port : 5222;

		$this->username				= $username;
















// Get the server and the username
if (strpos($username, '@') === false)
{
$this->server = $this->connect_server;
$this->username = $username;
}
else
{
$jid = explode('@', $username, 2);

$this->username = $jid[0];
$this->server = $jid[1];
}


		$this->password				= $password;
$this->use_ssl = ($use_ssl && $this->can_use_ssl()) ? true : false;


		$this->password				= $password;
$this->use_ssl = ($use_ssl && $this->can_use_ssl()) ? true : false;


Line 123Line 138

$this->session['ssl'] = $this->use_ssl;



$this->session['ssl'] = $this->use_ssl;


		if ($this->open_socket($this->server, $this->port, $this->use_ssl))

		if ($this->open_socket($this->connect_server, $this->port, $this->use_ssl))

		{
$this->send("<?xml version='1.0' encoding='UTF-8' ?" . ">\n");
$this->send("<stream:stream to='{$this->server}' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>\n");

		{
$this->send("<?xml version='1.0' encoding='UTF-8' ?" . ">\n");
$this->send("<stream:stream to='{$this->server}' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>\n");

Line 235Line 250
			return true;
}


			return true;
}


		// Apparently an error occured...

		// Apparently an error occurred...

		$this->add_to_log('Error: open_socket() - ' . $errorstr);
return false;
}

		$this->add_to_log('Error: open_socket() - ' . $errorstr);
return false;
}

Line 286Line 301
			$read = trim(fread($this->connection, 4096));
$data .= $read;
}

			$read = trim(fread($this->connection, 4096));
$data .= $read;
}

		while (time() <= $start + $timeout && ($wait || $data == '' || $read != '' || (substr(rtrim($data), -1) != '>')));

		while (time() <= $start + $timeout && !feof($this->connection) && ($wait || $data == '' || $read != '' || (substr(rtrim($data), -1) != '>')));


if ($data != '')
{


if ($data != '')
{

Line 385Line 400
		{
case 'stream:stream':
// Connection initialised (or after authentication). Not much to do here...

		{
case 'stream:stream':
// Connection initialised (or after authentication). Not much to do here...

				$this->session['id'] = $xml['stream:stream'][0]['@']['id'];

 

if (isset($xml['stream:stream'][0]['#']['stream:features']))
{


if (isset($xml['stream:stream'][0]['#']['stream:features']))
{

Line 395Line 409
				else
{
$this->features = $this->listen();

				else
{
$this->features = $this->listen();

 
				}

$second_time = isset($this->session['id']);
$this->session['id'] = $xml['stream:stream'][0]['@']['id'];

if ($second_time)
{
// If we are here for the second time after TLS, we need to continue logging in
return $this->login();

				}

// go on with authentication?

				}

// go on with authentication?

Line 453Line 476
					}
else if (in_array('PLAIN', $methods) && ($this->session['ssl'] || !empty($this->session['tls'])))
{

					}
else if (in_array('PLAIN', $methods) && ($this->session['ssl'] || !empty($this->session['tls'])))
{

 
						// http://www.ietf.org/rfc/rfc4616.txt (PLAIN SASL Mechanism)

						$this->send("<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>"

						$this->send("<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>"

							. base64_encode(chr(0) . $this->username . '@' . $this->server . chr(0) . $this->password) .

							. base64_encode($this->username . '@' . $this->server . chr(0) . $this->username . chr(0) . $this->password) .

							'</auth>');
}
else if (in_array('ANONYMOUS', $methods))

							'</auth>');
}
else if (in_array('ANONYMOUS', $methods))

Line 491Line 515
				}

// better generate a cnonce, maybe it's needed

				}

// better generate a cnonce, maybe it's needed

				$str = '';
mt_srand((double)microtime()*10000000);

for ($i = 0; $i < 32; $i++)
{
$str .= chr(mt_rand(0, 255));
}
$decoded['cnonce'] = base64_encode($str);

				$decoded['cnonce'] = base64_encode(md5(uniqid(mt_rand(), true)));









// second challenge?
if (isset($decoded['rspauth']))


// second challenge?
if (isset($decoded['rspauth']))

Line 519Line 536
						'response'	=> $this->encrypt_password(array_merge($decoded, array('nc' => '00000001'))),
'charset' => 'utf-8',
'nc' => '00000001',

						'response'	=> $this->encrypt_password(array_merge($decoded, array('nc' => '00000001'))),
'charset' => 'utf-8',
'nc' => '00000001',

 
						'qop'		=> 'auth',			// only auth being supported

					);


					);


					foreach (array('nonce', 'qop', 'digest-uri', 'realm', 'cnonce') as $key)

					foreach (array('nonce', 'digest-uri', 'realm', 'cnonce') as $key)

					{
if (isset($decoded[$key]))
{

					{
if (isset($decoded[$key]))
{