phpBB

Code Changes

File: includes/functions_jabber.php

  Unmodified   Added   Modified   Removed
Line 41Line 41
	var $username;
var $password;
var $use_ssl;

	var $username;
var $password;
var $use_ssl;

 
	var $verify_peer;
var $verify_peer_name;
var $allow_self_signed;

	var $resource = 'functions_jabber.phpbb.php';

var $enable_logging;

	var $resource = 'functions_jabber.phpbb.php';

var $enable_logging;

Line 49Line 52
	var $features = array();

/**

	var $features = array();

/**

 
	* Constructor
*
* @param string $server Jabber server
* @param int $port Jabber server port
* @param string $username Jabber username or JID
* @param string $password Jabber password
* @param boold $use_ssl Use ssl
* @param bool $verify_peer Verify SSL certificate
* @param bool $verify_peer_name Verify Jabber peer name
* @param bool $allow_self_signed Allow self signed certificates

	*/

	*/

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

	function __construct($server, $port, $username, $password, $use_ssl = false, $verify_peer = true, $verify_peer_name = true, $allow_self_signed = false)

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

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

Line 71Line 84

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


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

 
		$this->verify_peer			= $verify_peer;
$this->verify_peer_name = $verify_peer_name;
$this->allow_self_signed = $allow_self_signed;


// Change port if we use SSL
if ($this->port == 5222 && $this->use_ssl)


// Change port if we use SSL
if ($this->port == 5222 && $this->use_ssl)

Line 95Line 111
	*/
static public function can_use_tls()
{

	*/
static public function can_use_tls()
{

		if (!@extension_loaded('openssl') || !function_exists('stream_socket_enable_crypto') || !function_exists('stream_get_meta_data') || !function_exists('socket_set_blocking') || !function_exists('stream_get_wrappers'))

		if (!@extension_loaded('openssl') || !function_exists('stream_socket_enable_crypto') || !function_exists('stream_get_meta_data') || !function_exists('stream_set_blocking') || !function_exists('stream_get_wrappers'))

		{
return false;
}

		{
return false;
}

Line 138Line 154

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



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


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

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

		{
$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 191Line 207
	*/
function login()
{

	*/
function login()
{

		if (!sizeof($this->features))

		if (!count($this->features))

		{
$this->add_to_log('Error: No feature information from server available.');
return false;

		{
$this->add_to_log('Error: No feature information from server available.');
return false;

Line 226Line 242
	* @param string $server host to connect to
* @param int $port port number
* @param bool $use_ssl use ssl or not

	* @param string $server host to connect to
* @param int $port port number
* @param bool $use_ssl use ssl or not

 
	* @param bool $verify_peer verify ssl certificate
* @param bool $verify_peer_name verify peer name
* @param bool $allow_self_signed allow self-signed ssl certificates

	* @access public
* @return bool
*/

	* @access public
* @return bool
*/

	function open_socket($server, $port, $use_ssl = false)

	function open_socket($server, $port, $use_ssl, $verify_peer, $verify_peer_name, $allow_self_signed)

	{
if (@function_exists('dns_get_record'))
{

	{
if (@function_exists('dns_get_record'))
{

Line 240Line 259
			}
}


			}
}


		$server = $use_ssl ? 'ssl://' . $server : $server;

		$options = array();





		if ($this->connection = @fsockopen($server, $port, $errorno, $errorstr, $this->timeout))

		if ($use_ssl)

		{

		{

			socket_set_blocking($this->connection, 0);
socket_set_timeout($this->connection, 60);















			$remote_socket = 'ssl://' . $server . ':' . $port;

// Set ssl context options, see http://php.net/manual/en/context.ssl.php
$options['ssl'] = array('verify_peer' => $verify_peer, 'verify_peer_name' => $verify_peer_name, 'allow_self_signed' => $allow_self_signed);
}
else
{
$remote_socket = $server . ':' . $port;
}

$socket_context = stream_context_create($options);

if ($this->connection = @stream_socket_client($remote_socket, $errorno, $errorstr, $this->timeout, STREAM_CLIENT_CONNECT, $socket_context))
{
stream_set_blocking($this->connection, 0);
stream_set_timeout($this->connection, 60);


return true;
}


return true;
}

Line 260Line 293
	*/
function get_log()
{

	*/
function get_log()
{

		if ($this->enable_logging && sizeof($this->log_array))

		if ($this->enable_logging && count($this->log_array))

		{
return implode("<br /><br />", $this->log_array);
}

		{
return implode("<br /><br />", $this->log_array);
}

Line 367Line 400
	*/
function response($xml)
{

	*/
function response($xml)
{

		if (!is_array($xml) || !sizeof($xml))

		if (!is_array($xml) || !count($xml))

		{
return false;
}

// did we get multiple elements? do one after another
// array('message' => ..., 'presence' => ...)

		{
return false;
}

// did we get multiple elements? do one after another
// array('message' => ..., 'presence' => ...)

		if (sizeof($xml) > 1)

		if (count($xml) > 1)

		{
foreach ($xml as $key => $value)
{

		{
foreach ($xml as $key => $value)
{

Line 386Line 419
		{
// or even multiple elements of the same type?
// array('message' => array(0 => ..., 1 => ...))

		{
// or even multiple elements of the same type?
// array('message' => array(0 => ..., 1 => ...))

			if (sizeof(reset($xml)) > 1)

			if (count(reset($xml)) > 1)

			{
foreach (reset($xml) as $value)
{

			{
foreach (reset($xml) as $value)
{

Line 562Line 595
			case 'proceed':
// continue switching to TLS
$meta = stream_get_meta_data($this->connection);

			case 'proceed':
// continue switching to TLS
$meta = stream_get_meta_data($this->connection);

				socket_set_blocking($this->connection, 1);

				stream_set_blocking($this->connection, 1);


if (!stream_socket_enable_crypto($this->connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
{


if (!stream_socket_enable_crypto($this->connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
{

Line 570Line 603
					return false;
}


					return false;
}


				socket_set_blocking($this->connection, $meta['blocked']);

				stream_set_blocking($this->connection, $meta['blocked']);

				$this->session['tls'] = true;

// new stream

				$this->session['tls'] = true;

// new stream

Line 825Line 858
			array_push($children, $vals[$i]['value']);
}


			array_push($children, $vals[$i]['value']);
}


		while (++$i < sizeof($vals))

		while (++$i < count($vals))

		{
switch ($vals[$i]['type'])
{
case 'open':

$tagname = (isset($vals[$i]['tag'])) ? $vals[$i]['tag'] : '';

		{
switch ($vals[$i]['type'])
{
case 'open':

$tagname = (isset($vals[$i]['tag'])) ? $vals[$i]['tag'] : '';

					$size = (isset($children[$tagname])) ? sizeof($children[$tagname]) : 0;

					$size = (isset($children[$tagname])) ? count($children[$tagname]) : 0;


if (isset($vals[$i]['attributes']))
{


if (isset($vals[$i]['attributes']))
{

Line 850Line 883
				case 'complete':

$tagname = $vals[$i]['tag'];

				case 'complete':

$tagname = $vals[$i]['tag'];

					$size = (isset($children[$tagname])) ? sizeof($children[$tagname]) : 0;

					$size = (isset($children[$tagname])) ? count($children[$tagname]) : 0;

					$children[$tagname][$size]['#'] = (isset($vals[$i]['value'])) ? $vals[$i]['value'] : array();

if (isset($vals[$i]['attributes']))

					$children[$tagname][$size]['#'] = (isset($vals[$i]['value'])) ? $vals[$i]['value'] : array();

if (isset($vals[$i]['attributes']))