Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 72
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
acp_jabber
0.00% covered (danger)
0.00%
0 / 70
0.00% covered (danger)
0.00%
0 / 1
182
0.00% covered (danger)
0.00%
0 / 1
 main
0.00% covered (danger)
0.00%
0 / 70
0.00% covered (danger)
0.00%
0 / 1
182
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14/**
15* @todo Check/enter/update transport info
16*/
17
18/**
19* @ignore
20*/
21if (!defined('IN_PHPBB'))
22{
23    exit;
24}
25
26class acp_jabber
27{
28    var $u_action;
29
30    function main($id, $mode)
31    {
32        global $db, $user, $template, $phpbb_log, $request;
33        global $config, $phpbb_root_path, $phpEx;
34
35        $user->add_lang('acp/board');
36
37        if (!class_exists('jabber'))
38        {
39            include($phpbb_root_path . 'includes/functions_jabber.' . $phpEx);
40        }
41
42        $submit = (isset($_POST['submit'])) ? true : false;
43
44        if ($mode != 'settings')
45        {
46            return;
47        }
48
49        $this->tpl_name = 'acp_jabber';
50        $this->page_title = 'ACP_JABBER_SETTINGS';
51
52        $jab_enable                = $request->variable('jab_enable',            (bool) $config['jab_enable']);
53        $jab_host                = $request->variable('jab_host',            (string) $config['jab_host']);
54        $jab_port                = $request->variable('jab_port',            (int) $config['jab_port']);
55        $jab_username            = $request->variable('jab_username',        (string) $config['jab_username']);
56        $jab_password            = $request->variable('jab_password',        (string) $config['jab_password']);
57        $jab_package_size        = $request->variable('jab_package_size',    (int) $config['jab_package_size']);
58        $jab_use_ssl            = $request->variable('jab_use_ssl',        (bool) $config['jab_use_ssl']);
59        $jab_verify_peer        = $request->variable('jab_verify_peer',        (bool) $config['jab_verify_peer']);
60        $jab_verify_peer_name    = $request->variable('jab_verify_peer_name',    (bool) $config['jab_verify_peer_name']);
61        $jab_allow_self_signed    = $request->variable('jab_allow_self_signed',    (bool) $config['jab_allow_self_signed']);
62
63        $form_name = 'acp_jabber';
64        add_form_key($form_name);
65
66        if ($submit)
67        {
68            if (!check_form_key($form_name))
69            {
70                trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
71            }
72
73            $message = $user->lang['JAB_SETTINGS_CHANGED'];
74            $log = 'JAB_SETTINGS_CHANGED';
75
76            // Is this feature enabled? Then try to establish a connection
77            if ($jab_enable)
78            {
79                $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);
80
81                if (!$jabber->connect())
82                {
83                    trigger_error($user->lang['ERR_JAB_CONNECT'] . '<br /><br />' . $jabber->get_log() . adm_back_link($this->u_action), E_USER_WARNING);
84                }
85
86                // We'll try to authorise using this account
87                if (!$jabber->login())
88                {
89                    trigger_error($user->lang['ERR_JAB_AUTH'] . '<br /><br />' . $jabber->get_log() . adm_back_link($this->u_action), E_USER_WARNING);
90                }
91
92                $jabber->disconnect();
93            }
94            else
95            {
96                // This feature is disabled.
97                // We update the user table to be sure all users that have IM as notify type are set to both as notify type
98                // 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.
99                $sql_ary = array(
100                    'user_notify_type'        => NOTIFY_BOTH,
101                );
102
103                $sql = 'UPDATE ' . USERS_TABLE . '
104                    SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
105                    WHERE user_notify_type = ' . NOTIFY_IM;
106                $db->sql_query($sql);
107            }
108
109            $config->set('jab_enable', $jab_enable);
110            $config->set('jab_host', $jab_host);
111            $config->set('jab_port', $jab_port);
112            $config->set('jab_username', $jab_username);
113            if ($jab_password !== '********')
114            {
115                $config->set('jab_password', $jab_password);
116            }
117            $config->set('jab_package_size', $jab_package_size);
118            $config->set('jab_use_ssl', $jab_use_ssl);
119            $config->set('jab_verify_peer', $jab_verify_peer);
120            $config->set('jab_verify_peer_name', $jab_verify_peer_name);
121            $config->set('jab_allow_self_signed', $jab_allow_self_signed);
122
123            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_' . $log);
124            trigger_error($message . adm_back_link($this->u_action));
125        }
126
127        $template->assign_vars(array(
128            'U_ACTION'                => $this->u_action,
129            'JAB_ENABLE'            => $jab_enable,
130            'L_JAB_SERVER_EXPLAIN'    => sprintf($user->lang['JAB_SERVER_EXPLAIN'], '<a href="http://www.jabber.org/">', '</a>'),
131            'JAB_HOST'                => $jab_host,
132            'JAB_PORT'                => ($jab_port) ? $jab_port : '',
133            'JAB_USERNAME'            => $jab_username,
134            'JAB_PASSWORD'            => $jab_password !== '' ? '********' : '',
135            'JAB_PACKAGE_SIZE'        => $jab_package_size,
136            'JAB_USE_SSL'            => $jab_use_ssl,
137            'JAB_VERIFY_PEER'        => $jab_verify_peer,
138            'JAB_VERIFY_PEER_NAME'    => $jab_verify_peer_name,
139            'JAB_ALLOW_SELF_SIGNED'    => $jab_allow_self_signed,
140            'S_CAN_USE_SSL'            => jabber::can_use_ssl(),
141            'S_GTALK_NOTE'            => (!@function_exists('dns_get_record')) ? true : false,
142        ));
143    }
144}