mirror of
https://github.com/phpbb/phpbb.git
synced 2025-01-18 22:58:10 +01:00
[ticket/11854] Move captcha stuff to phpbb/ and use DI for plugins
PHPBB3-11854
This commit is contained in:
parent
e0d377bca7
commit
160ff7b912
43
phpBB/config/captcha.yml
Normal file
43
phpBB/config/captcha.yml
Normal file
@ -0,0 +1,43 @@
|
||||
services:
|
||||
captchas.factory:
|
||||
class: phpbb\captcha\factory
|
||||
arguments:
|
||||
- @service_container
|
||||
- @captchas.plugins.service_collection
|
||||
|
||||
captchas.plugins.service_collection:
|
||||
class: phpbb\di\service_collection
|
||||
arguments:
|
||||
- @service_container
|
||||
tags:
|
||||
- { name: service_collection, tag: captchas.plugins }
|
||||
|
||||
core.captcha.plugins.gd:
|
||||
class: phpbb\captcha\plugins\gd
|
||||
scope: prototype # scope MUST be prototype for this to work! # scope MUST be prototype for this to work!
|
||||
tags:
|
||||
- { name: captchas.plugins }
|
||||
|
||||
core.captcha.plugins.gd_wave:
|
||||
class: phpbb\captcha\plugins\gd_wave
|
||||
scope: prototype # scope MUST be prototype for this to work! # scope MUST be prototype for this to work!
|
||||
tags:
|
||||
- { name: captchas.plugins }
|
||||
|
||||
core.captcha.plugins.nogd:
|
||||
class: phpbb\captcha\plugins\nogd
|
||||
scope: prototype # scope MUST be prototype for this to work! # scope MUST be prototype for this to work!
|
||||
tags:
|
||||
- { name: captchas.plugins }
|
||||
|
||||
core.captcha.plugins.qa:
|
||||
class: phpbb\captcha\plugins\qa
|
||||
scope: prototype # scope MUST be prototype for this to work! # scope MUST be prototype for this to work!
|
||||
tags:
|
||||
- { name: captchas.plugins }
|
||||
|
||||
core.captcha.plugins.recaptcha:
|
||||
class: phpbb\captcha\plugins\recaptcha
|
||||
scope: prototype # scope MUST be prototype for this to work! # scope MUST be prototype for this to work!
|
||||
tags:
|
||||
- { name: captchas.plugins }
|
@ -10,6 +10,7 @@ imports:
|
||||
- { resource: mimetype_guessers.yml }
|
||||
- { resource: passwords.yml }
|
||||
- { resource: profilefields.yml }
|
||||
- { resource: captcha.yml }
|
||||
- { resource: parameters.yml }
|
||||
|
||||
services:
|
||||
|
@ -26,12 +26,11 @@ class acp_captcha
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $db, $user, $auth, $template;
|
||||
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
|
||||
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container;
|
||||
|
||||
$user->add_lang('acp/board');
|
||||
|
||||
include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
|
||||
$factory = new phpbb_captcha_factory();
|
||||
$factory = $phpbb_container->get('captchas.factory');
|
||||
$captchas = $factory->get_captcha_types();
|
||||
|
||||
$selected = request_var('select_captcha', $config['captcha_plugin']);
|
||||
@ -47,7 +46,7 @@ class acp_captcha
|
||||
// Delegate
|
||||
if ($configure)
|
||||
{
|
||||
$config_captcha = phpbb_captcha_factory::get_instance($selected);
|
||||
$config_captcha = $factory->get_instance($selected);
|
||||
$config_captcha->acp_page($id, $this);
|
||||
}
|
||||
else
|
||||
@ -79,11 +78,11 @@ class acp_captcha
|
||||
// sanity check
|
||||
if (isset($captchas['available'][$selected]))
|
||||
{
|
||||
$old_captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
|
||||
$old_captcha = $factory->get_instance($config['captcha_plugin']);
|
||||
$old_captcha->uninstall();
|
||||
|
||||
set_config('captcha_plugin', $selected);
|
||||
$new_captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
|
||||
$new_captcha = $factory->get_instance($config['captcha_plugin']);
|
||||
$new_captcha->install();
|
||||
|
||||
add_log('admin', 'LOG_CONFIG_VISUAL');
|
||||
@ -114,7 +113,7 @@ class acp_captcha
|
||||
$captcha_select .= '<option value="' . $value . '"' . $current . ' class="disabled-option">' . $user->lang($title) . '</option>';
|
||||
}
|
||||
|
||||
$demo_captcha = phpbb_captcha_factory::get_instance($selected);
|
||||
$demo_captcha = $factory->get_instance($selected);
|
||||
|
||||
foreach ($config_vars as $config_var => $options)
|
||||
{
|
||||
@ -137,9 +136,9 @@ class acp_captcha
|
||||
*/
|
||||
function deliver_demo($selected)
|
||||
{
|
||||
global $db, $user, $config;
|
||||
global $db, $user, $config, $phpbb_container;
|
||||
|
||||
$captcha = phpbb_captcha_factory::get_instance($selected);
|
||||
$captcha = $phpbb_container->get('captchas.factory')->get_instance($selected);
|
||||
$captcha->init(CONFIRM_REG);
|
||||
$captcha->execute_demo();
|
||||
|
||||
|
@ -1,100 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* A small class for 3.0.x (no autoloader in 3.0.x)
|
||||
*/
|
||||
class phpbb_captcha_factory
|
||||
{
|
||||
/**
|
||||
* return an instance of class $name in file $name_plugin.php
|
||||
*/
|
||||
static public function get_instance($name)
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
$name = basename($name);
|
||||
if (!class_exists($name))
|
||||
{
|
||||
include($phpbb_root_path . "includes/captcha/plugins/{$name}_plugin." . $phpEx);
|
||||
}
|
||||
$instance = call_user_func(array($name, 'get_instance'));
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the garbage collector
|
||||
*/
|
||||
function garbage_collect($name)
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
$name = basename($name);
|
||||
if (!class_exists($name))
|
||||
{
|
||||
include($phpbb_root_path . "includes/captcha/plugins/{$name}_plugin." . $phpEx);
|
||||
}
|
||||
$captcha = self::get_instance($name);
|
||||
$captcha->garbage_collect(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* return a list of all discovered CAPTCHA plugins
|
||||
*/
|
||||
function get_captcha_types()
|
||||
{
|
||||
global $phpbb_root_path, $phpEx, $phpbb_extension_manager;
|
||||
|
||||
$captchas = array(
|
||||
'available' => array(),
|
||||
'unavailable' => array(),
|
||||
);
|
||||
|
||||
$finder = $phpbb_extension_manager->get_finder();
|
||||
$captcha_plugin_classes = $finder
|
||||
->extension_directory('/captcha')
|
||||
->suffix('_plugin')
|
||||
->core_path('includes/captcha/plugins/')
|
||||
->get_classes();
|
||||
|
||||
foreach ($captcha_plugin_classes as $class)
|
||||
{
|
||||
// check if this class needs to be loaded in legacy mode
|
||||
$old_class = preg_replace('/^phpbb_captcha_plugins_/', '', $class);
|
||||
if (file_exists($phpbb_root_path . "includes/captcha/plugins/$old_class.$phpEx") && !class_exists($old_class))
|
||||
{
|
||||
include($phpbb_root_path . "includes/captcha/plugins/$old_class.$phpEx");
|
||||
$class = preg_replace('/_plugin$/', '', $old_class);
|
||||
}
|
||||
|
||||
if (call_user_func(array($class, 'is_available')))
|
||||
{
|
||||
$captchas['available'][$class] = call_user_func(array($class, 'get_name'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$captchas['unavailable'][$class] = call_user_func(array($class, 'get_name'));
|
||||
}
|
||||
}
|
||||
|
||||
return $captchas;
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Placeholder for autoload
|
||||
*/
|
||||
if (!class_exists('phpbb_default_captcha', false))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
|
||||
}
|
||||
|
||||
class phpbb_captcha_gd_wave extends phpbb_default_captcha
|
||||
{
|
||||
|
||||
function phpbb_captcha_gd_wave()
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
if (!class_exists('captcha'))
|
||||
{
|
||||
include_once($phpbb_root_path . 'includes/captcha/captcha_gd_wave.' . $phpEx);
|
||||
}
|
||||
}
|
||||
|
||||
static public function get_instance()
|
||||
{
|
||||
return new phpbb_captcha_gd_wave();
|
||||
}
|
||||
|
||||
static public function is_available()
|
||||
{
|
||||
return @extension_loaded('gd');
|
||||
}
|
||||
|
||||
static public function get_name()
|
||||
{
|
||||
return 'CAPTCHA_GD_3D';
|
||||
}
|
||||
|
||||
function get_class_name()
|
||||
{
|
||||
return 'phpbb_captcha_gd_wave';
|
||||
}
|
||||
|
||||
function acp_page($id, &$module)
|
||||
{
|
||||
global $config, $db, $template, $user;
|
||||
|
||||
trigger_error($user->lang['CAPTCHA_NO_OPTIONS'] . adm_back_link($module->u_action));
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Placeholder for autoload
|
||||
*/
|
||||
if (!class_exists('phpbb_default_captcha', false))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
|
||||
}
|
||||
|
||||
class phpbb_captcha_nogd extends phpbb_default_captcha
|
||||
{
|
||||
|
||||
function phpbb_captcha_nogd()
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
if (!class_exists('captcha'))
|
||||
{
|
||||
include_once($phpbb_root_path . 'includes/captcha/captcha_non_gd.' . $phpEx);
|
||||
}
|
||||
}
|
||||
|
||||
static public function get_instance()
|
||||
{
|
||||
$instance = new phpbb_captcha_nogd();
|
||||
return $instance;
|
||||
}
|
||||
|
||||
static public function is_available()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static public function get_name()
|
||||
{
|
||||
return 'CAPTCHA_NO_GD';
|
||||
}
|
||||
|
||||
function get_class_name()
|
||||
{
|
||||
return 'phpbb_captcha_nogd';
|
||||
}
|
||||
|
||||
function acp_page($id, &$module)
|
||||
{
|
||||
global $user;
|
||||
|
||||
trigger_error($user->lang['CAPTCHA_NO_OPTIONS'] . adm_back_link($module->u_action));
|
||||
}
|
||||
}
|
@ -2730,11 +2730,6 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
|
||||
global $db, $user, $template, $auth, $phpEx, $phpbb_root_path, $config;
|
||||
global $request, $phpbb_container;
|
||||
|
||||
if (!class_exists('phpbb_captcha_factory', false))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
|
||||
}
|
||||
|
||||
$err = '';
|
||||
|
||||
// Make sure user->setup() has been called
|
||||
@ -2844,7 +2839,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
|
||||
{
|
||||
case LOGIN_ERROR_ATTEMPTS:
|
||||
|
||||
$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
|
||||
$captcha = $phpbb_container->get('captchas.factory')->get_instance($config['captcha_plugin']);
|
||||
$captcha->init(CONFIRM_LOGIN);
|
||||
// $captcha->reset();
|
||||
|
||||
|
@ -36,10 +36,9 @@ class ucp_confirm
|
||||
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $db, $user, $phpbb_root_path, $config, $phpEx;
|
||||
global $db, $user, $phpbb_root_path, $config, $phpEx, $phpbb_container;
|
||||
|
||||
include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
|
||||
$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
|
||||
$captcha = $phpbb_container->get('captchas.factory')->get_instance($config['captcha_plugin']);
|
||||
$captcha->init(request_var('type', 0));
|
||||
$captcha->execute();
|
||||
|
||||
|
@ -181,7 +181,7 @@ class ucp_login_link
|
||||
*/
|
||||
protected function process_login_result($result)
|
||||
{
|
||||
global $config, $request, $template, $user;
|
||||
global $config, $request, $template, $user, $phpbb_container;
|
||||
|
||||
$login_error = null;
|
||||
|
||||
@ -197,7 +197,7 @@ class ucp_login_link
|
||||
{
|
||||
case LOGIN_ERROR_ATTEMPTS:
|
||||
|
||||
$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
|
||||
$captcha = $phpbb_container->get('captchas.factory')->get_instance($config['captcha_plugin']);
|
||||
$captcha->init(CONFIRM_LOGIN);
|
||||
|
||||
$template->assign_vars(array(
|
||||
|
@ -182,8 +182,7 @@ class ucp_register
|
||||
// The CAPTCHA kicks in here. We can't help that the information gets lost on language change.
|
||||
if ($config['enable_confirm'])
|
||||
{
|
||||
include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
|
||||
$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
|
||||
$captcha = $phpbb_container->get('captchas.factory')->get_instance($config['captcha_plugin']);
|
||||
$captcha->init(CONFIRM_REG);
|
||||
}
|
||||
|
||||
|
@ -146,13 +146,7 @@ class db extends \phpbb\auth\provider\base
|
||||
// Every auth module is able to define what to do by itself...
|
||||
if ($show_captcha)
|
||||
{
|
||||
// Visual Confirmation handling
|
||||
if (!class_exists('phpbb_captcha_factory', false))
|
||||
{
|
||||
include ($this->phpbb_root_path . 'includes/captcha/captcha_factory.' . $this->php_ext);
|
||||
}
|
||||
|
||||
$captcha = \phpbb_captcha_factory::get_instance($this->config['captcha_plugin']);
|
||||
$captcha = $this->captchas_manager->get_instance($this->config['captcha_plugin']);
|
||||
$captcha->init(CONFIRM_LOGIN);
|
||||
$vc_response = $captcha->validate($row);
|
||||
if ($vc_response)
|
||||
|
83
phpBB/phpbb/captcha/factory.php
Normal file
83
phpBB/phpbb/captcha/factory.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\captcha;
|
||||
|
||||
/**
|
||||
* A small class for 3.0.x (no autoloader in 3.0.x)
|
||||
*/
|
||||
class factory
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
||||
*/
|
||||
private $container;
|
||||
|
||||
/**
|
||||
* @var \phpbb\di\service_collection
|
||||
*/
|
||||
private $plugins;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
|
||||
* @param \phpbb\di\service_collection $plugins
|
||||
*/
|
||||
public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container,\phpbb\di\service_collection $plugins)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->plugins = $plugins;
|
||||
}
|
||||
|
||||
//static public function get_instance($name)
|
||||
|
||||
public function get_instance($name)
|
||||
{
|
||||
return $this->container->get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the garbage collector
|
||||
*/
|
||||
function garbage_collect($name)
|
||||
{
|
||||
$captcha = $this->get_instance($name);
|
||||
$captcha->garbage_collect(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* return a list of all registered CAPTCHA plugins
|
||||
*/
|
||||
function get_captcha_types()
|
||||
{
|
||||
$captchas = array(
|
||||
'available' => array(),
|
||||
'unavailable' => array(),
|
||||
);
|
||||
|
||||
foreach ($this->plugins as $plugin => $plugin_instance)
|
||||
{
|
||||
if ($plugin_instance->is_available())
|
||||
{
|
||||
$captchas['available'][$plugin] = $plugin_instance->get_name();
|
||||
}
|
||||
else
|
||||
{
|
||||
$captchas['unavailable'][$plugin] = $plugin_instance->get_name();
|
||||
}
|
||||
}
|
||||
|
||||
return $captchas;
|
||||
}
|
||||
}
|
@ -11,15 +11,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
namespace phpbb\captcha;
|
||||
|
||||
class captcha
|
||||
class gd
|
||||
{
|
||||
var $width = 360;
|
||||
var $height = 96;
|
@ -11,10 +11,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\captcha;
|
||||
|
||||
/**
|
||||
* Wave3D CAPTCHA
|
||||
*/
|
||||
class captcha
|
||||
class gd_wave
|
||||
{
|
||||
var $width = 360;
|
||||
var $height = 96;
|
@ -11,19 +11,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
namespace phpbb\captcha;
|
||||
|
||||
/**
|
||||
* Main non-gd captcha class
|
||||
* @ignore
|
||||
*/
|
||||
class captcha
|
||||
class non_gd
|
||||
{
|
||||
var $filtered_pngs;
|
||||
var $width = 320;
|
@ -11,18 +11,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
namespace phpbb\captcha\plugins;
|
||||
|
||||
/**
|
||||
* This class holds the code shared by the two default 3.0.x CAPTCHAs.
|
||||
*/
|
||||
class phpbb_captcha_plugins_captcha_abstract
|
||||
abstract class captcha_abstract
|
||||
{
|
||||
var $confirm_id;
|
||||
var $confirm_code;
|
||||
@ -65,7 +59,8 @@ class phpbb_captcha_plugins_captcha_abstract
|
||||
// compute $seed % 0x7fffffff
|
||||
$this->seed -= 0x7fffffff * floor($this->seed / 0x7fffffff);
|
||||
|
||||
$captcha = new captcha();
|
||||
$generator = $this->get_generator_class();
|
||||
$captcha = new $generator();
|
||||
define('IMAGE_OUTPUT', 1);
|
||||
$captcha->execute($this->code, $this->seed);
|
||||
}
|
||||
@ -80,7 +75,8 @@ class phpbb_captcha_plugins_captcha_abstract
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$captcha = new captcha();
|
||||
$generator = $this->get_generator_class();
|
||||
$captcha = new $generator();
|
||||
define('IMAGE_OUTPUT', 1);
|
||||
$captcha->execute($this->code, $this->seed);
|
||||
}
|
||||
@ -130,7 +126,7 @@ class phpbb_captcha_plugins_captcha_abstract
|
||||
|
||||
// acp_captcha has a delivery function; let's use it
|
||||
$template->assign_vars(array(
|
||||
'CONFIRM_IMAGE' => append_sid($phpbb_admin_path . 'index.' . $phpEx, 'captcha_demo=1&mode=visual&i=' . $id . '&select_captcha=' . $this->get_class_name()) . $variables,
|
||||
'CONFIRM_IMAGE' => append_sid($phpbb_admin_path . 'index.' . $phpEx, 'captcha_demo=1&mode=visual&i=' . $id . '&select_captcha=' . $this->get_service_name()) . $variables,
|
||||
'CONFIRM_ID' => $this->confirm_id,
|
||||
));
|
||||
|
||||
@ -364,11 +360,13 @@ class phpbb_captcha_plugins_captcha_abstract
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @return string the name of the service corresponding to the plugin
|
||||
*/
|
||||
abstract function get_service_name();
|
||||
|
||||
/**
|
||||
* Old class name for legacy use. The new class name is auto loadable.
|
||||
*/
|
||||
class phpbb_default_captcha extends phpbb_captcha_plugins_captcha_abstract
|
||||
{
|
||||
/**
|
||||
* @return string the name of the class used to generate the captcha
|
||||
*/
|
||||
abstract function get_generator_class();
|
||||
}
|
@ -11,25 +11,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
namespace phpbb\captcha\plugins;
|
||||
|
||||
/**
|
||||
* Placeholder for autoload
|
||||
*/
|
||||
if (!class_exists('phpbb_default_captcha', false))
|
||||
class gd extends captcha_abstract
|
||||
{
|
||||
include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
|
||||
}
|
||||
|
||||
class phpbb_captcha_gd extends phpbb_default_captcha
|
||||
{
|
||||
|
||||
var $captcha_vars = array(
|
||||
'captcha_gd_x_grid' => 'CAPTCHA_GD_X_GRID',
|
||||
'captcha_gd_y_grid' => 'CAPTCHA_GD_Y_GRID',
|
||||
@ -40,27 +25,27 @@ class phpbb_captcha_gd extends phpbb_default_captcha
|
||||
'captcha_gd_fonts' => 'CAPTCHA_GD_FONTS',
|
||||
);
|
||||
|
||||
function phpbb_captcha_gd()
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
if (!class_exists('captcha'))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/captcha/captcha_gd.' . $phpEx);
|
||||
}
|
||||
}
|
||||
|
||||
static public function get_instance()
|
||||
{
|
||||
$instance = new phpbb_captcha_gd();
|
||||
return $instance;
|
||||
}
|
||||
|
||||
static public function is_available()
|
||||
public function is_available()
|
||||
{
|
||||
return @extension_loaded('gd');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of the service corresponding to the plugin
|
||||
*/
|
||||
function get_service_name()
|
||||
{
|
||||
return 'core.captcha.plugins.gd';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of the class used to generate the captcha
|
||||
*/
|
||||
function get_generator_class()
|
||||
{
|
||||
return '\\phpbb\\captcha\\gd';
|
||||
}
|
||||
|
||||
/**
|
||||
* API function
|
||||
*/
|
||||
@ -69,16 +54,11 @@ class phpbb_captcha_gd extends phpbb_default_captcha
|
||||
return true;
|
||||
}
|
||||
|
||||
static public function get_name()
|
||||
public function get_name()
|
||||
{
|
||||
return 'CAPTCHA_GD';
|
||||
}
|
||||
|
||||
function get_class_name()
|
||||
{
|
||||
return 'phpbb_captcha_gd';
|
||||
}
|
||||
|
||||
function acp_page($id, &$module)
|
||||
{
|
||||
global $db, $user, $auth, $template;
|
||||
@ -129,7 +109,7 @@ class phpbb_captcha_gd extends phpbb_default_captcha
|
||||
|
||||
$template->assign_vars(array(
|
||||
'CAPTCHA_PREVIEW' => $this->get_demo_template($id),
|
||||
'CAPTCHA_NAME' => $this->get_class_name(),
|
||||
'CAPTCHA_NAME' => $this->get_service_name(),
|
||||
'U_ACTION' => $module->u_action,
|
||||
));
|
||||
}
|
50
phpBB/phpbb/captcha/plugins/gd_wave.php
Normal file
50
phpBB/phpbb/captcha/plugins/gd_wave.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\captcha\plugins;
|
||||
|
||||
class gd_wave extends captcha_abstract
|
||||
{
|
||||
public function is_available()
|
||||
{
|
||||
return @extension_loaded('gd');
|
||||
}
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return 'CAPTCHA_GD_3D';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of the service corresponding to the plugin
|
||||
*/
|
||||
function get_service_name()
|
||||
{
|
||||
return 'core.captcha.plugins.gd_wave';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of the class used to generate the captcha
|
||||
*/
|
||||
function get_generator_class()
|
||||
{
|
||||
return '\\phpbb\\captcha\\gd_wave';
|
||||
}
|
||||
|
||||
function acp_page($id, &$module)
|
||||
{
|
||||
global $config, $db, $template, $user;
|
||||
|
||||
trigger_error($user->lang['CAPTCHA_NO_OPTIONS'] . adm_back_link($module->u_action));
|
||||
}
|
||||
}
|
50
phpBB/phpbb/captcha/plugins/nogd.php
Normal file
50
phpBB/phpbb/captcha/plugins/nogd.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\captcha\plugins;
|
||||
|
||||
class nogd extends captcha_abstract
|
||||
{
|
||||
public function is_available()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return 'CAPTCHA_NO_GD';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of the service corresponding to the plugin
|
||||
*/
|
||||
function get_service_name()
|
||||
{
|
||||
return 'core.captcha.plugins.nogd';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of the class used to generate the captcha
|
||||
*/
|
||||
function get_generator_class()
|
||||
{
|
||||
return '\\phpbb\\captcha\\non_gd';
|
||||
}
|
||||
|
||||
function acp_page($id, &$module)
|
||||
{
|
||||
global $user;
|
||||
|
||||
trigger_error($user->lang['CAPTCHA_NO_OPTIONS'] . adm_back_link($module->u_action));
|
||||
}
|
||||
}
|
@ -11,13 +11,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
namespace phpbb\captcha\plugins;
|
||||
|
||||
global $table_prefix;
|
||||
|
||||
@ -29,7 +23,7 @@ define('CAPTCHA_QA_CONFIRM_TABLE', $table_prefix . 'qa_confirm');
|
||||
* And now to something completely different. Let's make a captcha without extending the abstract class.
|
||||
* QA CAPTCHA sample implementation
|
||||
*/
|
||||
class phpbb_captcha_qa
|
||||
class qa
|
||||
{
|
||||
var $confirm_id;
|
||||
var $answer;
|
||||
@ -97,20 +91,10 @@ class phpbb_captcha_qa
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API function
|
||||
*/
|
||||
static public function get_instance()
|
||||
{
|
||||
$instance = new phpbb_captcha_qa();
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* See if the captcha has created its tables.
|
||||
*/
|
||||
static public function is_installed()
|
||||
public function is_installed()
|
||||
{
|
||||
global $db;
|
||||
|
||||
@ -122,14 +106,14 @@ class phpbb_captcha_qa
|
||||
/**
|
||||
* API function - for the captcha to be available, it must have installed itself and there has to be at least one question in the board's default lang
|
||||
*/
|
||||
static public function is_available()
|
||||
public function is_available()
|
||||
{
|
||||
global $config, $db, $phpbb_root_path, $phpEx, $user;
|
||||
|
||||
// load language file for pretty display in the ACP dropdown
|
||||
$user->add_lang('captcha_qa');
|
||||
|
||||
if (!self::is_installed())
|
||||
if (!$this->is_installed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -163,9 +147,9 @@ class phpbb_captcha_qa
|
||||
/**
|
||||
* API function
|
||||
*/
|
||||
function get_class_name()
|
||||
function get_service_name()
|
||||
{
|
||||
return 'phpbb_captcha_qa';
|
||||
return 'core.captcha.plugins.qa';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -621,12 +605,12 @@ class phpbb_captcha_qa
|
||||
$action = request_var('action', '');
|
||||
|
||||
// we have two pages, so users might want to navigate from one to the other
|
||||
$list_url = $module->u_action . "&configure=1&select_captcha=" . $this->get_class_name();
|
||||
$list_url = $module->u_action . "&configure=1&select_captcha=" . $this->get_service_name();
|
||||
|
||||
$template->assign_vars(array(
|
||||
'U_ACTION' => $module->u_action,
|
||||
'QUESTION_ID' => $question_id ,
|
||||
'CLASS' => $this->get_class_name(),
|
||||
'CLASS' => $this->get_service_name(),
|
||||
));
|
||||
|
||||
// show the list?
|
||||
@ -636,7 +620,7 @@ class phpbb_captcha_qa
|
||||
}
|
||||
else if ($question_id && $action == 'delete')
|
||||
{
|
||||
if ($this->get_class_name() !== $config['captcha_plugin'] || !$this->acp_is_last($question_id))
|
||||
if ($this->get_service_name() !== $config['captcha_plugin'] || !$this->acp_is_last($question_id))
|
||||
{
|
||||
if (confirm_box(true))
|
||||
{
|
||||
@ -650,7 +634,7 @@ class phpbb_captcha_qa
|
||||
'question_id' => $question_id,
|
||||
'action' => $action,
|
||||
'configure' => 1,
|
||||
'select_captcha' => $this->get_class_name(),
|
||||
'select_captcha' => $this->get_service_name(),
|
||||
))
|
||||
);
|
||||
}
|
||||
@ -759,7 +743,7 @@ class phpbb_captcha_qa
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$url = $module->u_action . "&question_id={$row['question_id']}&configure=1&select_captcha=" . $this->get_class_name() . '&';
|
||||
$url = $module->u_action . "&question_id={$row['question_id']}&configure=1&select_captcha=" . $this->get_service_name() . '&';
|
||||
|
||||
$template->assign_block_vars('questions', array(
|
||||
'QUESTION_TEXT' => $row['question_text'],
|
@ -11,21 +11,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
namespace phpbb\captcha\plugins;
|
||||
|
||||
if (!class_exists('phpbb_default_captcha', false))
|
||||
{
|
||||
// we need the classic captcha code for tracking solutions and attempts
|
||||
include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
|
||||
}
|
||||
|
||||
class phpbb_recaptcha extends phpbb_default_captcha
|
||||
class recaptcha extends \phpbb\captcha\plugins\captcha_abstract
|
||||
{
|
||||
var $recaptcha_server = 'http://www.google.com/recaptcha/api';
|
||||
var $recaptcha_server_secure = 'https://www.google.com/recaptcha/api'; // class constants :(
|
||||
@ -55,13 +43,7 @@ class phpbb_recaptcha extends phpbb_default_captcha
|
||||
$this->response = request_var('recaptcha_response_field', '');
|
||||
}
|
||||
|
||||
static public function get_instance()
|
||||
{
|
||||
$instance = new phpbb_recaptcha();
|
||||
return $instance;
|
||||
}
|
||||
|
||||
static public function is_available()
|
||||
public function is_available()
|
||||
{
|
||||
global $config, $user;
|
||||
$user->add_lang('captcha_recaptcha');
|
||||
@ -81,9 +63,20 @@ class phpbb_recaptcha extends phpbb_default_captcha
|
||||
return 'CAPTCHA_RECAPTCHA';
|
||||
}
|
||||
|
||||
function get_class_name()
|
||||
/**
|
||||
* @return string the name of the service corresponding to the plugin
|
||||
*/
|
||||
function get_service_name()
|
||||
{
|
||||
return 'phpbb_recaptcha';
|
||||
return 'core.captcha.plugins.recaptcha';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of the class used to generate the captcha
|
||||
*/
|
||||
function get_generator_class()
|
||||
{
|
||||
throw new \Exception('Go out devil!');
|
||||
}
|
||||
|
||||
function acp_page($id, &$module)
|
||||
@ -131,7 +124,7 @@ class phpbb_recaptcha extends phpbb_default_captcha
|
||||
|
||||
$template->assign_vars(array(
|
||||
'CAPTCHA_PREVIEW' => $this->get_demo_template($id),
|
||||
'CAPTCHA_NAME' => $this->get_class_name(),
|
||||
'CAPTCHA_NAME' => $this->get_service_name(),
|
||||
'U_ACTION' => $module->u_action,
|
||||
));
|
||||
|
@ -962,7 +962,7 @@ class session
|
||||
*/
|
||||
function session_gc()
|
||||
{
|
||||
global $db, $config, $phpbb_root_path, $phpEx;
|
||||
global $db, $config, $phpbb_root_path, $phpEx, $phpbb_container;
|
||||
|
||||
$batch_size = 10;
|
||||
|
||||
@ -1022,11 +1022,7 @@ class session
|
||||
}
|
||||
|
||||
// only called from CRON; should be a safe workaround until the infrastructure gets going
|
||||
if (!class_exists('phpbb_captcha_factory', false))
|
||||
{
|
||||
include($phpbb_root_path . "includes/captcha/captcha_factory." . $phpEx);
|
||||
}
|
||||
$captcha_factory = new \phpbb_captcha_factory();
|
||||
$captcha_factory = $phpbb_container->get('captchas.factory');
|
||||
$captcha_factory->garbage_collect($config['captcha_plugin']);
|
||||
|
||||
$sql = 'DELETE FROM ' . LOGIN_ATTEMPT_TABLE . '
|
||||
|
@ -241,8 +241,7 @@ $user->setup(array('posting', 'mcp', 'viewtopic'), $post_data['forum_style']);
|
||||
|
||||
if ($config['enable_post_confirm'] && !$user->data['is_registered'])
|
||||
{
|
||||
include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
|
||||
$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
|
||||
$captcha = $phpbb_container->get('captchas.factory')->get_instance($config['captcha_plugin']);
|
||||
$captcha->init(CONFIRM_POST);
|
||||
}
|
||||
|
||||
|
@ -151,8 +151,7 @@ else
|
||||
|
||||
if ($config['enable_post_confirm'] && !$user->data['is_registered'])
|
||||
{
|
||||
include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
|
||||
$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
|
||||
$captcha = $phpbb_container->get('captchas.factory')->get_instance($config['captcha_plugin']);
|
||||
$captcha->init(CONFIRM_REPORT);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user