phpBB jabber

Created Diff never expires
78 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
144 lines
156 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
207 lines
<?php
<?php
/**
/**
*
*
* This file is part of the phpBB Forum Software package.
* This file is part of the phpBB Forum Software package.
*
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
* @license GNU General Public License, version 2 (GPL-2.0)
*
*
* For full copyright and license information, please see
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
* the docs/CREDITS.txt file.
*
*
*/
*/


/**
namespace phpbb\acp\controller;
* @todo Check/enter/update transport info
*/


/**
/**
* @ignore
* @todo Check/enter/update transport info
*/
*/
if (!defined('IN_PHPBB'))
class jabber
{
{
exit;
/** @var \phpbb\config\config */
}
protected $config;


class acp_jabber
/** @var \phpbb\db\driver\driver_interface */
{
protected $db;
var $u_action;


function main($id, $mode)
/** @var \phpbb\acp\helper\controller */
protected $helper;

/** @var \phpbb\language\language */
protected $language;

/** @var \phpbb\log\log */
protected $log;

/** @var \phpbb\request\request */
protected $request;

/** @var \phpbb\template\template */
protected $template;

/** @var \phpbb\user */
protected $user;

/** @var string phpBB root path */
protected $root_path;

/** @var string php File extension */
protected $php_ext;

/** @var array phpBB tables */
protected $tables;

/**
* Constructor.
*
* @param \phpbb\config\config $config Config object
* @param \phpbb\db\driver\driver_interface $db Database object
* @param \phpbb\acp\helper\controller $helper ACP Controller helper object
* @param \phpbb\language\language $language Language object
* @param \phpbb\log\log $log Log object
* @param \phpbb\request\request $request Request object
* @param \phpbb\template\template $template Template object
* @param \phpbb\user $user User object
* @param string $root_path phpBB root path
* @param string $php_ext php File extension
* @param array $tables phpBB tables
*/
public function __construct(
\phpbb\config\config $config,
\phpbb\db\driver\driver_interface $db,
\phpbb\acp\helper\controller $helper,
\phpbb\language\language $language,
\phpbb\log\log $log,
\phpbb\request\request $request,
\phpbb\template\template $template,
\phpbb\user $user,
$root_path,
$php_ext,
$tables
)
{
{
global $db, $user, $template, $phpbb_log, $request;
$this->config = $config;
global $config, $phpbb_root_path, $phpEx;
$this->db = $db;
$this->helper = $helper;
$this->language = $language;
$this->log = $log;
$this->request = $request;
$this->template = $template;
$this->user = $user;


$user->add_lang('acp/board');
$this->root_path = $root_path;
$this->php_ext = $php_ext;
$this->tables = $tables;
}

public function main()
{
$this->language->add_lang('acp/board');


if (!class_exists('jabber'))
if (!class_exists('jabber'))
{
{
include($phpbb_root_path . 'includes/functions_jabber.' . $phpEx);
include($this->root_path . 'includes/functions_jabber.' . $this->php_ext);
}

$submit = (isset($_POST['submit'])) ? true : false;

if ($mode != 'settings')
{
return;
}
}


$this->tpl_name = 'acp_jabber';
$submit = $this->request->is_set_post('submit');
$this->page_title = 'ACP_JABBER_SETTINGS';


$jab_enable = $request->variable('jab_enable', (bool) $config['jab_enable']);
$jab_enable = $this->request->variable('jab_enable', (bool) $this->config['jab_enable']);
$jab_host = $request->variable('jab_host', (string) $config['jab_host']);
$jab_host = $this->request->variable('jab_host', (string) $this->config['jab_host']);
$jab_port = $request->variable('jab_port', (int) $config['jab_port']);
$jab_port = $this->request->variable('jab_port', (int) $this->config['jab_port']);
$jab_username = $request->variable('jab_username', (string) $config['jab_username']);
$jab_username = $this->request->variable('jab_username', (string) $this->config['jab_username']);
$jab_password = $request->variable('jab_password', (string) $config['jab_password']);
$jab_password = $this->request->variable('jab_password', (string) $this->config['jab_password']);
$jab_package_size = $request->variable('jab_package_size', (int) $config['jab_package_size']);
$jab_package_size = $this->request->variable('jab_package_size', (int) $this->config['jab_package_size']);
$jab_use_ssl = $request->variable('jab_use_ssl', (bool) $config['jab_use_ssl']);
$jab_use_ssl = $this->request->variable('jab_use_ssl', (bool) $this->config['jab_use_ssl']);
$jab_verify_peer = $request->variable('jab_verify_peer', (bool) $config['jab_verify_peer']);
$jab_verify_peer = $this->request->variable('jab_verify_peer', (bool) $this->config['jab_verify_peer']);
$jab_verify_peer_name = $request->variable('jab_verify_peer_name', (bool) $config['jab_verify_peer_name']);
$jab_verify_peer_name = $this->request->variable('jab_verify_peer_name', (bool) $this->config['jab_verify_peer_name']);
$jab_allow_self_signed = $request->variable('jab_allow_self_signed', (bool) $config['jab_allow_self_signed']);
$jab_allow_self_signed = $this->request->variable('jab_allow_self_signed', (bool) $this->config['jab_allow_self_signed']);


$form_name = 'acp_jabber';
$form_key = 'acp_jabber';
add_form_key($form_name);
add_form_key($form_key);


if ($submit)
if ($submit)
{
{
if (!check_form_key($form_name))
if (!check_form_key($form_key))
{
{
trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
return trigger_error($this->language->lang('FORM_INVALID'). $this->helper->adm_back_route('acp_settings_jabber'), E_USER_WARNING);
}
}


$message = $user->lang['JAB_SETTINGS_CHANGED'];
$log = 'JAB_SETTINGS_CHANGED';

// Is this feature enabled? Then try to establish a connection
// Is this feature enabled? Then try to establish a connection
if ($jab_enable)
if ($jab_enable)
{
{
$jabber = new jabber($jab_host, $jab_port, $jab_username, $jab_password, $jab_use_ssl, $jab_verify_peer, $jab_verify_peer_name, $jab_allow_self_signed);
$jabber = new \jabber($jab_host, $jab_port, $jab_username, $jab_password, $jab_use_ssl, $jab_verify_peer, $jab_verify_peer_name, $jab_allow_self_signed);


if (!$jabber->connect())
if (!$jabber->connect())
{
{
trigger_error($user->lang['ERR_JAB_CONNECT'] . '<br /><br />' . $jabber->get_log() . adm_back_link($this->u_action), E_USER_WARNING);
return trigger_error($this->language->lang('ERR_JAB_CONNECT') . '<br /><br />' . $jabber->get_log() . $this->helper->adm_back_route('acp_settings_jabber'), E_USER_WARNING);
}
}


// We'll try to authorise using this account
// We'll try to authorise using this account
if (!$jabber->login())
if (!$jabber->login())
{
{
trigger_error($user->lang['ERR_JAB_AUTH'] . '<br /><br />' . $jabber->get_log() . adm_back_link($this->u_action), E_USER_WARNING);
return trigger_error($this->language->lang('ERR_JAB_AUTH') . '<br /><br />' . $jabber->get_log() . $this->helper->adm_back_route('acp_settings_jabber'), E_USER_WARNING);
}
}


$jabber->disconnect();
$jabber->disconnect();
}
}
else
else
{
{
// This feature is disabled.
/**
// We update the user table to be sure all users that have IM as notify type are set to both as notify type
* This feature is disabled.
// We set this to both because users still have their jabber address entered and may want to receive jabber notifications again once it is re-enabled.
* We update the users table to be sure all users that have IM as notify type
$sql_ary = array(
* are set to both as notify type.
* We set this to both because users still have their jabber address entered
* and may want to receive jabber notifications again once it is re-enabled.
*/
$sql_ary = [
'user_notify_type' => NOTIFY_BOTH,
'user_notify_type' => NOTIFY_BOTH,
);
];


$sql = 'UPDATE ' . USERS_TABLE . '
$sql = 'UPDATE ' . $this->tables['users'] . '
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
WHERE user_notify_type = ' . NOTIFY_IM;
WHERE user_notify_type = ' . NOTIFY_IM;
$db->sql_query($sql);
$this->db->sql_query($sql);
}
}


$config->set('jab_enable', $jab_enable);
$this->config->set('jab_enable', $jab_enable);
$config->set('jab_host', $jab_host);
$this->config->set('jab_host', $jab_host);
$config->set('jab_port', $jab_port);
$this->config->set('jab_port', $jab_port);
$config->set('jab_username', $jab_username);
$this->config->set('jab_username', $jab_username);
if ($jab_password !== '********')
if ($jab_password !== '********')
{
{
$config->set('jab_password', $jab_password);
$this->config->set('jab_password', $jab_password);
}
}
$config->set('jab_package_size', $jab_package_size);
$this->config->set('jab_package_size', $jab_package_size);
$config->set('jab_use_ssl', $jab_use_ssl);
$this->config->set('jab_use_ssl', $jab_use_ssl);
$config->set('jab_verify_peer', $jab_verify_peer);
$this->config->set('jab_verify_peer', $jab_verify_peer);
$config->set('jab_verify_peer_name', $jab_verify_peer_name);
$this->config->set('jab_verify_peer_name', $jab_verify_peer_name);
$config->set('jab_allow_self_signed', $jab_allow_self_signed);
$this->config->set('jab_allow_self_signed', $jab_allow_self_signed);


$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_' . $log);
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_JAB_SETTINGS_CHANGED');
trigger_error($message . adm_back_link($this->u_action));

return $this->helper->message_back('JAB_SETTINGS_CHANGED', 'acp_settings_jabber');
}
}


$template->assign_vars(array(
$this->template->assign_vars([
'U_ACTION' => $this->u_action,
'JAB_ENABLE' => $jab_enable,
'JAB_ENABLE' => $jab_enable,
'L_JAB_SERVER_EXPLAIN' => sprintf($user->lang['JAB_SERVER_EXPLAIN'], '<a href="http://www.jabber.org/">', '</a>'),
'JAB_HOST' => $jab_host,
'JAB_HOST' => $jab_host,
'JAB_PORT' => ($jab_port) ? $jab_port : '',
'JAB_PORT' => $jab_port ? $jab_port : '',
'JAB_USERNAME' => $jab_username,
'JAB_USERNAME' => $jab_username,
'JAB_PASSWORD' => $jab_password !== '' ? '********' : '',
'JAB_PASSWORD' => $jab_password !== '' ? '********' : '',
'JAB_PACKAGE_SIZE' => $jab_package_size,
'JAB_PACKAGE_SIZE' => $jab_package_size,
'JAB_USE_SSL' => $jab_use_ssl,
'JAB_USE_SSL' => $jab_use_ssl,
'JAB_VERIFY_PEER' => $jab_verify_peer,
'JAB_VERIFY_PEER' => $jab_verify_peer,
'JAB_VERIFY_PEER_NAME' => $jab_verify_peer_name,
'JAB_VERIFY_PEER_NAME' => $jab_verify_peer_name,
'JAB_ALLOW_SELF_SIGNED' => $jab_allow_self_signed,
'JAB_ALLOW_SELF_SIGNED' => $jab_allow_self_signed,
'S_CAN_USE_SSL' => jabber::can_use_ssl(),

'S_GTALK_NOTE' => (!@function_exists('dns_get_record')) ? true : false,
'L_JAB_SERVER_EXPLAIN' => $this->language->lang('JAB_SERVER_EXPLAIN', '<a href="http://www.jabber.org/">', '</a>'),
));

'S_CAN_USE_SSL' => \jabber::can_use_ssl(),
'S_GTALK_NOTE' => !@function_exists('dns_get_record') ? true : false,

'U_ACTION' => $this->helper->route('acp_settings_jabber'),
]);

return $this->helper->render('acp_jabber.html', 'ACP_SETTINGS_JABBER');
}
}
}
}