Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 95
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
acp_captcha
0.00% covered (danger)
0.00%
0 / 93
0.00% covered (danger)
0.00%
0 / 2
506
0.00% covered (danger)
0.00%
0 / 1
 main
0.00% covered (danger)
0.00%
0 / 87
0.00% covered (danger)
0.00%
0 / 1
462
 deliver_demo
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
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* @ignore
16*/
17if (!defined('IN_PHPBB'))
18{
19    exit;
20}
21
22class acp_captcha
23{
24    var $u_action;
25
26    /** @var string Template name */
27    public $tpl_name = 'acp_captcha';
28
29    /** @var string Page title language variable */
30    public $page_title = 'ACP_VC_SETTINGS';
31
32    function main($id, $mode)
33    {
34        global $user, $template, $phpbb_log, $request;
35        global $config, $phpbb_container;
36
37        $user->add_lang('acp/board');
38
39        /* @var $factory \phpbb\captcha\factory */
40        $factory = $phpbb_container->get('captcha.factory');
41        $captchas = $factory->get_captcha_types();
42
43        $selected = $request->variable('select_captcha', $config['captcha_plugin']);
44        $selected = (isset($captchas['available'][$selected]) || isset($captchas['unavailable'][$selected])) ? $selected : $config['captcha_plugin'];
45        $configure = $request->variable('configure', false);
46
47        // Oh, they are just here for the view
48        if (isset($_GET['captcha_demo']))
49        {
50            $this->deliver_demo($selected);
51        }
52
53        // Delegate
54        if ($configure)
55        {
56            $config_captcha = $factory->get_instance($selected);
57            $config_captcha->acp_page($id, $this);
58        }
59        else
60        {
61            $config_vars = array(
62                'enable_confirm'        => array(
63                    'tpl'        => 'REG_ENABLE',
64                    'default'    => false,
65                    'validate'    => 'bool',
66                    'lang'        => 'VISUAL_CONFIRM_REG',
67                ),
68                'enable_post_confirm'    => array(
69                    'tpl'        => 'POST_ENABLE',
70                    'default'    => false,
71                    'validate'    => 'bool',
72                    'lang'        => 'VISUAL_CONFIRM_POST',
73                ),
74                'confirm_refresh'        => array(
75                    'tpl'        => 'CONFIRM_REFRESH',
76                    'default'    => false,
77                    'validate'    => 'bool',
78                    'lang'        => 'VISUAL_CONFIRM_REFRESH',
79                ),
80                'max_reg_attempts'        => array(
81                    'tpl'        => 'REG_LIMIT',
82                    'default'    => 0,
83                    'validate'    => 'int:0:99999',
84                    'lang'        => 'REG_LIMIT',
85                ),
86                'max_login_attempts'    => array(
87                    'tpl'        => 'MAX_LOGIN_ATTEMPTS',
88                    'default'    => 0,
89                    'validate'    => 'int:0:99999',
90                    'lang'        => 'MAX_LOGIN_ATTEMPTS',
91                ),
92            );
93
94            $form_key = 'acp_captcha';
95            add_form_key($form_key);
96
97            $submit = $request->variable('main_submit', false);
98            $error = $cfg_array = array();
99
100            if ($submit)
101            {
102                foreach ($config_vars as $config_var => $options)
103                {
104                    $cfg_array[$config_var] = $request->variable($config_var, $options['default']);
105                }
106                validate_config_vars($config_vars, $cfg_array, $error);
107
108                if (!check_form_key($form_key))
109                {
110                    $error[] = $user->lang['FORM_INVALID'];
111                }
112                if ($error)
113                {
114                    $submit = false;
115                }
116            }
117
118            if ($submit)
119            {
120                foreach ($cfg_array as $key => $value)
121                {
122                    $config->set($key, $value);
123                }
124
125                if ($selected !== $config['captcha_plugin'])
126                {
127                    // sanity check
128                    if (isset($captchas['available'][$selected]))
129                    {
130                        $old_captcha = $factory->get_instance($config['captcha_plugin']);
131                        $old_captcha->uninstall();
132
133                        $config->set('captcha_plugin', $selected);
134                        $new_captcha = $factory->get_instance($config['captcha_plugin']);
135                        $new_captcha->install();
136
137                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_VISUAL');
138                    }
139                    else
140                    {
141                        trigger_error($user->lang['CAPTCHA_UNAVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
142                    }
143                }
144                trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
145            }
146            else
147            {
148                $captcha_select = '';
149                foreach ($captchas['available'] as $value => $title)
150                {
151                    $current = ($selected !== false && $value == $selected) ? ' selected="selected"' : '';
152                    $captcha_select .= '<option value="' . $value . '"' . $current . '>' . $user->lang($title) . '</option>';
153                }
154
155                foreach ($captchas['unavailable'] as $value => $title)
156                {
157                    $current = ($selected !== false && $value == $selected) ? ' selected="selected"' : '';
158                    $captcha_select .= '<option value="' . $value . '"' . $current . ' class="disabled-option">' . $user->lang($title) . '</option>';
159                }
160
161                $demo_captcha = $factory->get_instance($selected);
162
163                foreach ($config_vars as $config_var => $options)
164                {
165                    $template->assign_var($options['tpl'], (isset($_POST[$config_var])) ? $request->variable($config_var, $options['default']) : $config[$config_var]) ;
166                }
167
168                $template->assign_vars(array(
169                    'CAPTCHA_PREVIEW_TPL'    => $demo_captcha->get_demo_template($id),
170                    'S_CAPTCHA_HAS_CONFIG'    => $demo_captcha->has_config(),
171                    'CAPTCHA_SELECT'        => $captcha_select,
172                    'ERROR_MSG'                => implode('<br />', $error),
173
174                    'U_ACTION'                => $this->u_action,
175                ));
176            }
177        }
178    }
179
180    /**
181    * Entry point for delivering image CAPTCHAs in the ACP.
182    */
183    function deliver_demo($selected)
184    {
185        global $phpbb_container;
186
187        $captcha = $phpbb_container->get('captcha.factory')->get_instance($selected);
188        $captcha->init(CONFIRM_REG);
189        $captcha->execute_demo();
190
191        garbage_collection();
192        exit_handler();
193    }
194}