Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 70
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 / 68
0.00% covered (danger)
0.00%
0 / 1
156
0.00% covered (danger)
0.00%
0 / 1
 main
0.00% covered (danger)
0.00%
0 / 68
0.00% covered (danger)
0.00%
0 / 1
156
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_container, $phpbb_root_path, $phpEx;
34
35        $jabber = $phpbb_container->get('messenger.method.jabber');
36
37        $user->add_lang('acp/board');
38
39        $submit = (isset($_POST['submit'])) ? true : false;
40
41        if ($mode != 'settings')
42        {
43            return;
44        }
45
46        $this->tpl_name = 'acp_jabber';
47        $this->page_title = 'ACP_JABBER_SETTINGS';
48
49        $jab_enable                = $request->variable('jab_enable',            (bool) $config['jab_enable']);
50        $jab_host                = $request->variable('jab_host',            (string) $config['jab_host']);
51        $jab_port                = $request->variable('jab_port',            (int) $config['jab_port']);
52        $jab_username            = $request->variable('jab_username',        (string) $config['jab_username']);
53        $jab_password            = $request->variable('jab_password',        (string) $config['jab_password']);
54        $jab_package_size        = $request->variable('jab_package_size',    (int) $config['jab_package_size']);
55        $jab_use_ssl            = $request->variable('jab_use_ssl',        (bool) $config['jab_use_ssl']);
56        $jab_verify_peer        = $request->variable('jab_verify_peer',        (bool) $config['jab_verify_peer']);
57        $jab_verify_peer_name    = $request->variable('jab_verify_peer_name',    (bool) $config['jab_verify_peer_name']);
58        $jab_allow_self_signed    = $request->variable('jab_allow_self_signed',    (bool) $config['jab_allow_self_signed']);
59
60        $form_name = 'acp_jabber';
61        add_form_key($form_name);
62
63        if ($submit)
64        {
65            if (!check_form_key($form_name))
66            {
67                trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
68            }
69
70            $message = $user->lang['JAB_SETTINGS_CHANGED'];
71            $log = 'JAB_SETTINGS_CHANGED';
72
73            // Is this feature enabled? Then try to establish a connection
74            if ($jabber->is_enabled())
75            {
76                if (!$jabber->connect())
77                {
78                    trigger_error($user->lang['ERR_JAB_CONNECT'] . '<br /><br />' . $jabber->get_log() . adm_back_link($this->u_action), E_USER_WARNING);
79                }
80
81                // We'll try to authorise using this account
82                if (!$jabber->login())
83                {
84                    trigger_error($user->lang['ERR_JAB_AUTH'] . '<br /><br />' . $jabber->get_log() . adm_back_link($this->u_action), E_USER_WARNING);
85                }
86
87                $jabber->disconnect();
88            }
89            else
90            {
91                // This feature is disabled.
92                // We update the user table to be sure all users that have IM as notify type are set to both as notify type
93                // 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.
94                $sql_ary = array(
95                    'user_notify_type'        => $jabber::NOTIFY_BOTH,
96                );
97
98                $sql = 'UPDATE ' . USERS_TABLE . '
99                    SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
100                    WHERE user_notify_type = ' . $jabber::NOTIFY_IM;
101                $db->sql_query($sql);
102            }
103
104            $config->set('jab_enable', $jab_enable);
105            $config->set('jab_host', $jab_host);
106            $config->set('jab_port', $jab_port);
107            $config->set('jab_username', $jab_username);
108            if ($jab_password !== '********')
109            {
110                $config->set('jab_password', $jab_password);
111            }
112            $config->set('jab_package_size', $jab_package_size);
113            $config->set('jab_use_ssl', $jab_use_ssl);
114            $config->set('jab_verify_peer', $jab_verify_peer);
115            $config->set('jab_verify_peer_name', $jab_verify_peer_name);
116            $config->set('jab_allow_self_signed', $jab_allow_self_signed);
117
118            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_' . $log);
119            trigger_error($message . adm_back_link($this->u_action));
120        }
121
122        $template->assign_vars(array(
123            'U_ACTION'                => $this->u_action,
124            'JAB_ENABLE'            => $jab_enable,
125            'L_JAB_SERVER_EXPLAIN'    => sprintf($user->lang['JAB_SERVER_EXPLAIN'], '<a href="http://www.jabber.org/">', '</a>'),
126            'JAB_HOST'                => $jab_host,
127            'JAB_PORT'                => ($jab_port) ? $jab_port : '',
128            'JAB_USERNAME'            => $jab_username,
129            'JAB_PASSWORD'            => $jab_password !== '' ? '********' : '',
130            'JAB_PACKAGE_SIZE'        => $jab_package_size,
131            'JAB_USE_SSL'            => $jab_use_ssl,
132            'JAB_VERIFY_PEER'        => $jab_verify_peer,
133            'JAB_VERIFY_PEER_NAME'    => $jab_verify_peer_name,
134            'JAB_ALLOW_SELF_SIGNED'    => $jab_allow_self_signed,
135            'S_CAN_USE_SSL'            => $jabber::can_use_ssl(),
136            'S_GTALK_NOTE'            => (!@function_exists('dns_get_record')) ? true : false,
137        ));
138    }
139}