mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
short php open tags should not be used. :) A lot of users (including myself) do not allow them.
git-svn-id: file:///svn/phpbb/trunk@8907 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
08428f8fa1
commit
aa9dbcec3c
6 changed files with 186 additions and 173 deletions
|
@ -1,4 +1,4 @@
|
||||||
<?
|
<?php
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @package VC
|
* @package VC
|
||||||
|
@ -18,10 +18,12 @@ if (!defined('IN_PHPBB'))
|
||||||
|
|
||||||
if (!interface_exists('phpbb_captcha_plugin'))
|
if (!interface_exists('phpbb_captcha_plugin'))
|
||||||
{
|
{
|
||||||
include(PHPBB_ROOT_PATH . "includes/captcha/captcha_plugin." . PHP_EXT);
|
include(PHPBB_ROOT_PATH . 'includes/captcha/captcha_plugin.' . PHP_EXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A small class until we get the autoloader done */
|
/**
|
||||||
|
* A small class until we get the autoloader done
|
||||||
|
*/
|
||||||
class phpbb_captcha_factory
|
class phpbb_captcha_factory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -36,7 +38,7 @@ class phpbb_captcha_factory
|
||||||
}
|
}
|
||||||
return call_user_func(array($name, 'get_instance'));
|
return call_user_func(array($name, 'get_instance'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call the garbage collector
|
* Call the garbage collector
|
||||||
*/
|
*/
|
||||||
|
@ -49,16 +51,17 @@ class phpbb_captcha_factory
|
||||||
}
|
}
|
||||||
call_user_func(array($name, 'garbage_collect'), 0);
|
call_user_func(array($name, 'garbage_collect'), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return a list of all discovered CAPTCHA plugins
|
* return a list of all discovered CAPTCHA plugins
|
||||||
*/
|
*/
|
||||||
public static function get_captcha_types()
|
public static function get_captcha_types()
|
||||||
{
|
{
|
||||||
$captchas = array();
|
$captchas = array(
|
||||||
$captchas['available'] = array();
|
'available' => array(),
|
||||||
$captchas['unavailable'] = array();
|
'unavailable' => array(),
|
||||||
|
);
|
||||||
|
|
||||||
$dp = @opendir(PHPBB_ROOT_PATH . 'includes/captcha/plugins');
|
$dp = @opendir(PHPBB_ROOT_PATH . 'includes/captcha/plugins');
|
||||||
|
|
||||||
if ($dp)
|
if ($dp)
|
||||||
|
@ -87,4 +90,6 @@ class phpbb_captcha_factory
|
||||||
|
|
||||||
return $captchas;
|
return $captchas;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -1,9 +1,9 @@
|
||||||
<?
|
<?php
|
||||||
|
|
||||||
interface phpbb_captcha_plugin
|
interface phpbb_captcha_plugin
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Initiates the CAPTCHA to validate codes.
|
* Initiates the CAPTCHA to validate codes.
|
||||||
* @param int $type the type as defined in constants.php
|
* @param int $type the type as defined in constants.php
|
||||||
*/
|
*/
|
||||||
function init($type);
|
function init($type);
|
||||||
|
@ -13,17 +13,17 @@ interface phpbb_captcha_plugin
|
||||||
* Returns true if the captcha will work on the current install
|
* Returns true if the captcha will work on the current install
|
||||||
*/
|
*/
|
||||||
static function is_available();
|
static function is_available();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the translated pretty name of the captcha.
|
* Returns the translated pretty name of the captcha.
|
||||||
*/
|
*/
|
||||||
static function get_name();
|
static function get_name();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the class name of the captcha.
|
* Returns the class name of the captcha.
|
||||||
*/
|
*/
|
||||||
static function get_class_name();
|
static function get_class_name();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an instance; does not have to be the same instance twice.
|
* Returns an instance; does not have to be the same instance twice.
|
||||||
*/
|
*/
|
||||||
|
@ -33,65 +33,66 @@ interface phpbb_captcha_plugin
|
||||||
* Returns the HTML needed to embed the captcha in another template
|
* Returns the HTML needed to embed the captcha in another template
|
||||||
*/
|
*/
|
||||||
function get_template();
|
function get_template();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delivers the image of image based captchas; not required for text/remote etc CAPTCHAs
|
* Delivers the image of image based captchas; not required for text/remote etc CAPTCHAs
|
||||||
*/
|
*/
|
||||||
function execute();
|
function execute();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the HTML needed to display a demo of the captcha
|
* Returns the HTML needed to display a demo of the captcha
|
||||||
*/
|
*/
|
||||||
function get_demo_template($id);
|
function get_demo_template($id);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delivers the demo image of image based captchas; not required for text/remote etc CAPTCHAs
|
* Delivers the demo image of image based captchas; not required for text/remote etc CAPTCHAs
|
||||||
*/
|
*/
|
||||||
function execute_demo();
|
function execute_demo();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears leftover entries in the database.
|
* Clears leftover entries in the database.
|
||||||
*/
|
*/
|
||||||
static function garbage_collect($type);
|
static function garbage_collect($type);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears all entries from the database if the CAPTCHA is replaced
|
* Clears all entries from the database if the CAPTCHA is replaced
|
||||||
*/
|
*/
|
||||||
function uninstall();
|
function uninstall();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the CAPTCHA when it is selected in the ACP.
|
* Sets up the CAPTCHA when it is selected in the ACP.
|
||||||
*/
|
*/
|
||||||
function install();
|
function install();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the captcha; returns false if the code was correct; a translated error string otherwise
|
* Checks the captcha; returns false if the code was correct; a translated error string otherwise
|
||||||
*/
|
*/
|
||||||
function validate();
|
function validate();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the captcha to ask a new question; required call on failed answers
|
* Prepares the captcha to ask a new question; required call on failed answers
|
||||||
*/
|
*/
|
||||||
function reset();
|
function reset();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the configuration options in the ACP
|
* Displays the configuration options in the ACP
|
||||||
*/
|
*/
|
||||||
function acp_page($id, &$module);
|
function acp_page($id, &$module);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the entries for the hidden field array needed to preserve the current state.
|
* Returns the entries for the hidden field array needed to preserve the current state.
|
||||||
*/
|
*/
|
||||||
function get_hidden_fields();
|
function get_hidden_fields();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of solving attempts of the current user
|
* Returns the number of solving attempts of the current user
|
||||||
*/
|
*/
|
||||||
function get_attempt_count();
|
function get_attempt_count();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
?>
|
|
@ -1,8 +1,8 @@
|
||||||
<?
|
<?php
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @package VC
|
* @package VC
|
||||||
* @version $Id: $
|
* @version $Id$
|
||||||
* @copyright (c) 2006 2008 phpBB Group
|
* @copyright (c) 2006 2008 phpBB Group
|
||||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||||
*
|
*
|
||||||
|
@ -33,33 +33,33 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
|
||||||
function init($type)
|
function init($type)
|
||||||
{
|
{
|
||||||
global $config, $db, $user;
|
global $config, $db, $user;
|
||||||
|
|
||||||
// read input
|
// read input
|
||||||
$this->confirm_id = request_var('confirm_id', '');
|
$this->confirm_id = request_var('confirm_id', '');
|
||||||
$this->confirm_code = request_var('confirm_code', '');
|
$this->confirm_code = request_var('confirm_code', '');
|
||||||
$this->type = (int) $type;
|
$this->type = (int) $type;
|
||||||
|
|
||||||
if (!strlen($this->confirm_id))
|
if (!strlen($this->confirm_id))
|
||||||
{
|
{
|
||||||
// we have no confirm ID, better get ready to display something
|
// we have no confirm ID, better get ready to display something
|
||||||
$this->generate_code();
|
$this->generate_code();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function execute_demo()
|
function execute_demo()
|
||||||
{
|
{
|
||||||
global $user;
|
global $user;
|
||||||
|
|
||||||
$this->code = gen_rand_string(mt_rand(5, 8));
|
$this->code = gen_rand_string(mt_rand(5, 8));
|
||||||
$this->seed = hexdec(substr(unique_id(), 4, 10));
|
$this->seed = hexdec(substr(unique_id(), 4, 10));
|
||||||
|
|
||||||
// compute $seed % 0x7fffffff
|
// compute $seed % 0x7fffffff
|
||||||
$this->seed -= 0x7fffffff * floor($this->seed / 0x7fffffff);
|
$this->seed -= 0x7fffffff * floor($this->seed / 0x7fffffff);
|
||||||
|
|
||||||
captcha::execute($this->code, $this->seed);
|
captcha::execute($this->code, $this->seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function execute()
|
function execute()
|
||||||
{
|
{
|
||||||
if (empty($this->code))
|
if (empty($this->code))
|
||||||
|
@ -72,28 +72,28 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
|
||||||
}
|
}
|
||||||
captcha::execute($this->code, $this->seed);
|
captcha::execute($this->code, $this->seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function get_template()
|
function get_template()
|
||||||
{
|
{
|
||||||
global $config, $user, $template;
|
global $config, $user, $template;
|
||||||
|
|
||||||
$template->set_filenames(array(
|
$template->set_filenames(array(
|
||||||
'captcha' => 'captcha_default.html')
|
'captcha' => 'captcha_default.html')
|
||||||
);
|
);
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'CONFIRM_IMAGE' => append_sid('ucp', 'mode=confirm&confirm_id=' . $this->confirm_id . '&type=' . $this->type),
|
'CONFIRM_IMAGE' => append_sid('ucp', 'mode=confirm&confirm_id=' . $this->confirm_id . '&type=' . $this->type),
|
||||||
'CONFIRM_ID' => $this->confirm_id,
|
'CONFIRM_ID' => $this->confirm_id,
|
||||||
));
|
));
|
||||||
|
|
||||||
return $template->assign_display('captcha');
|
return $template->assign_display('captcha');
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_demo_template($id)
|
function get_demo_template($id)
|
||||||
{
|
{
|
||||||
global $config, $user, $template;
|
global $config, $user, $template;
|
||||||
|
|
||||||
$template->set_filenames(array(
|
$template->set_filenames(array(
|
||||||
'captcha_demo' => 'captcha_default_acp_demo.html')
|
'captcha_demo' => 'captcha_default_acp_demo.html')
|
||||||
);
|
);
|
||||||
|
@ -102,14 +102,14 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
|
||||||
'CONFIRM_IMAGE' => append_sid(PHPBB_ADMIN_PATH . 'index.' . PHP_EXT, 'captcha_demo=1&mode=visual&i=' . $id . '&select_captcha=' . $this->get_class_name()),
|
'CONFIRM_IMAGE' => append_sid(PHPBB_ADMIN_PATH . 'index.' . PHP_EXT, 'captcha_demo=1&mode=visual&i=' . $id . '&select_captcha=' . $this->get_class_name()),
|
||||||
'CONFIRM_ID' => $this->confirm_id,
|
'CONFIRM_ID' => $this->confirm_id,
|
||||||
));
|
));
|
||||||
|
|
||||||
return $template->assign_display('captcha_demo');
|
return $template->assign_display('captcha_demo');
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_hidden_fields()
|
function get_hidden_fields()
|
||||||
{
|
{
|
||||||
$hidden_fields = array();
|
$hidden_fields = array();
|
||||||
|
|
||||||
// this is required for postig.php - otherwise we would forget about the captcha being already solved
|
// this is required for postig.php - otherwise we would forget about the captcha being already solved
|
||||||
if ($this->solved)
|
if ($this->solved)
|
||||||
{
|
{
|
||||||
|
@ -118,7 +118,7 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
|
||||||
$hidden_fields['confirm_id'] = $this->confirm_id;
|
$hidden_fields['confirm_id'] = $this->confirm_id;
|
||||||
return $hidden_fields;
|
return $hidden_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function garbage_collect($type)
|
static function garbage_collect($type)
|
||||||
{
|
{
|
||||||
global $db, $config;
|
global $db, $config;
|
||||||
|
@ -148,23 +148,23 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
|
||||||
}
|
}
|
||||||
$db->sql_freeresult($result);
|
$db->sql_freeresult($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
function uninstall()
|
function uninstall()
|
||||||
{
|
{
|
||||||
self::garbage_collect(0);
|
self::garbage_collect(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function install()
|
function install()
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate()
|
function validate()
|
||||||
{
|
{
|
||||||
global $config, $db, $user;
|
global $config, $db, $user;
|
||||||
|
|
||||||
$this->confirm_code = request_var('confirm_code', '');
|
$this->confirm_code = request_var('confirm_code', '');
|
||||||
|
|
||||||
if (!$this->confirm_id)
|
if (!$this->confirm_id)
|
||||||
{
|
{
|
||||||
$error = $user->lang['CONFIRM_CODE_WRONG'];
|
$error = $user->lang['CONFIRM_CODE_WRONG'];
|
||||||
|
@ -181,7 +181,7 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
|
||||||
$error = $user->lang['CONFIRM_CODE_WRONG'];
|
$error = $user->lang['CONFIRM_CODE_WRONG'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($error))
|
if (strlen($error))
|
||||||
{
|
{
|
||||||
// okay, inorect answer. Let's ask a new question
|
// okay, inorect answer. Let's ask a new question
|
||||||
|
@ -193,15 +193,15 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The old way to generate code, suitable for GD and non-GD. Resets the internal state.
|
* The old way to generate code, suitable for GD and non-GD. Resets the internal state.
|
||||||
*/
|
*/
|
||||||
protected function generate_code()
|
protected function generate_code()
|
||||||
{
|
{
|
||||||
global $db, $user;
|
global $db, $user;
|
||||||
|
|
||||||
$this->code = gen_rand_string(mt_rand(5, 8));
|
$this->code = gen_rand_string(mt_rand(5, 8));
|
||||||
$this->confirm_id = md5(unique_id($user->ip));
|
$this->confirm_id = md5(unique_id($user->ip));
|
||||||
$this->seed = hexdec(substr(unique_id(), 4, 10));
|
$this->seed = hexdec(substr(unique_id(), 4, 10));
|
||||||
|
@ -218,9 +218,9 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
|
||||||
);
|
);
|
||||||
$db->sql_query($sql);
|
$db->sql_query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look up everything we need for painting&checking.
|
* Look up everything we need for painting&checking.
|
||||||
*/
|
*/
|
||||||
protected function load_code()
|
protected function load_code()
|
||||||
{
|
{
|
||||||
|
@ -240,13 +240,13 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function check_code()
|
protected function check_code()
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
if (empty($this->code))
|
if (empty($this->code))
|
||||||
{
|
{
|
||||||
if (!$this->load_code())
|
if (!$this->load_code())
|
||||||
|
@ -256,22 +256,22 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
|
||||||
}
|
}
|
||||||
return (strcasecmp($this->code, $this->confirm_code) === 0);
|
return (strcasecmp($this->code, $this->confirm_code) === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function delete_code()
|
protected function delete_code()
|
||||||
{
|
{
|
||||||
global $db, $user;
|
global $db, $user;
|
||||||
|
|
||||||
$sql = 'DELETE FROM ' . CONFIRM_TABLE . "
|
$sql = 'DELETE FROM ' . CONFIRM_TABLE . "
|
||||||
WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
|
WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
|
||||||
AND session_id = '" . $db->sql_escape($user->session_id) . "'
|
AND session_id = '" . $db->sql_escape($user->session_id) . "'
|
||||||
AND confirm_type = " . $this->type;
|
AND confirm_type = " . $this->type;
|
||||||
$db->sql_query($sql);
|
$db->sql_query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_attempt_count()
|
function get_attempt_count()
|
||||||
{
|
{
|
||||||
global $db, $user;
|
global $db, $user;
|
||||||
|
|
||||||
$sql = 'SELECT COUNT(session_id) AS attempts
|
$sql = 'SELECT COUNT(session_id) AS attempts
|
||||||
FROM ' . CONFIRM_TABLE . "
|
FROM ' . CONFIRM_TABLE . "
|
||||||
WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
|
WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
|
||||||
|
@ -279,23 +279,24 @@ abstract class phpbb_default_captcha implements phpbb_captcha_plugin
|
||||||
$result = $db->sql_query($sql);
|
$result = $db->sql_query($sql);
|
||||||
$attempts = (int) $db->sql_fetchfield('attempts');
|
$attempts = (int) $db->sql_fetchfield('attempts');
|
||||||
$db->sql_freeresult($result);
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
return $attempts;
|
return $attempts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function reset()
|
function reset()
|
||||||
{
|
{
|
||||||
global $db, $user;
|
global $db, $user;
|
||||||
|
|
||||||
$sql = 'DELETE FROM ' . CONFIRM_TABLE . "
|
$sql = 'DELETE FROM ' . CONFIRM_TABLE . "
|
||||||
WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
|
WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
|
||||||
AND confirm_type = " . (int) $this->type;
|
AND confirm_type = " . (int) $this->type;
|
||||||
$db->sql_query($sql);
|
$db->sql_query($sql);
|
||||||
|
|
||||||
// we leave the class usable by generating a new question
|
// we leave the class usable by generating a new question
|
||||||
$this->generate_code();
|
$this->generate_code();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -1,8 +1,8 @@
|
||||||
<?
|
<?php
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @package VC
|
* @package VC
|
||||||
* @version $Id: $
|
* @version $Id$
|
||||||
* @copyright (c) 2006 2008 phpBB Group
|
* @copyright (c) 2006 2008 phpBB Group
|
||||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||||
*
|
*
|
||||||
|
@ -15,19 +15,19 @@ if (!defined('IN_PHPBB'))
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Placeholder for autoload
|
* Placeholder for autoload
|
||||||
*/
|
*/
|
||||||
include_once(PHPBB_ROOT_PATH . "includes/captcha/plugins/captcha_abstract." . PHP_EXT);
|
include_once(PHPBB_ROOT_PATH . 'includes/captcha/plugins/captcha_abstract.' . PHP_EXT);
|
||||||
|
|
||||||
class phpbb_captcha_gd extends phpbb_default_captcha implements phpbb_captcha_plugin
|
class phpbb_captcha_gd extends phpbb_default_captcha implements phpbb_captcha_plugin
|
||||||
{
|
{
|
||||||
|
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
include_once(PHPBB_ROOT_PATH . "includes/captcha/captcha_gd." . PHP_EXT);
|
include_once(PHPBB_ROOT_PATH . 'includes/captcha/captcha_gd.' . PHP_EXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_instance()
|
public static function get_instance()
|
||||||
{
|
{
|
||||||
return new phpbb_captcha_gd();
|
return new phpbb_captcha_gd();
|
||||||
|
@ -37,21 +37,21 @@ class phpbb_captcha_gd extends phpbb_default_captcha implements phpbb_captcha_pl
|
||||||
{
|
{
|
||||||
return (@extension_loaded('gd') || can_load_dll('gd'));
|
return (@extension_loaded('gd') || can_load_dll('gd'));
|
||||||
}
|
}
|
||||||
|
|
||||||
static function get_name()
|
static function get_name()
|
||||||
{
|
{
|
||||||
return 'CAPTCHA_GD';
|
return 'CAPTCHA_GD';
|
||||||
}
|
}
|
||||||
|
|
||||||
static function get_class_name()
|
static function get_class_name()
|
||||||
{
|
{
|
||||||
return 'phpbb_captcha_gd';
|
return 'phpbb_captcha_gd';
|
||||||
}
|
}
|
||||||
|
|
||||||
function acp_page($id, &$module)
|
function acp_page($id, &$module)
|
||||||
{
|
{
|
||||||
global $config, $db, $template, $user;
|
global $config, $db, $template, $user;
|
||||||
|
|
||||||
$captcha_vars = array(
|
$captcha_vars = array(
|
||||||
'captcha_gd_x_grid' => 'CAPTCHA_GD_X_GRID',
|
'captcha_gd_x_grid' => 'CAPTCHA_GD_X_GRID',
|
||||||
'captcha_gd_y_grid' => 'CAPTCHA_GD_Y_GRID',
|
'captcha_gd_y_grid' => 'CAPTCHA_GD_Y_GRID',
|
||||||
|
@ -99,3 +99,4 @@ class phpbb_captcha_gd extends phpbb_default_captcha implements phpbb_captcha_pl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -1,8 +1,8 @@
|
||||||
<?
|
<?php
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @package VC
|
* @package VC
|
||||||
* @version $Id: $
|
* @version $Id$
|
||||||
* @copyright (c) 2006 2008 phpBB Group
|
* @copyright (c) 2006 2008 phpBB Group
|
||||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||||
*
|
*
|
||||||
|
@ -15,16 +15,16 @@ if (!defined('IN_PHPBB'))
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once(PHPBB_ROOT_PATH . "includes/captcha/plugins/captcha_abstract." . PHP_EXT);
|
include_once(PHPBB_ROOT_PATH . 'includes/captcha/plugins/captcha_abstract.' . PHP_EXT);
|
||||||
|
|
||||||
class phpbb_captcha_nogd extends phpbb_default_captcha implements phpbb_captcha_plugin
|
class phpbb_captcha_nogd extends phpbb_default_captcha implements phpbb_captcha_plugin
|
||||||
{
|
{
|
||||||
|
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
include_once(PHPBB_ROOT_PATH . "includes/captcha/captcha_non_gd." . PHP_EXT);
|
include_once(PHPBB_ROOT_PATH . 'includes/captcha/captcha_non_gd.' . PHP_EXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_instance()
|
public static function get_instance()
|
||||||
{
|
{
|
||||||
return new phpbb_captcha_nogd();
|
return new phpbb_captcha_nogd();
|
||||||
|
@ -34,25 +34,26 @@ class phpbb_captcha_nogd extends phpbb_default_captcha implements phpbb_captcha_
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function get_name()
|
static function get_name()
|
||||||
{
|
{
|
||||||
global $user;
|
global $user;
|
||||||
|
|
||||||
return 'CAPTCHA_NO_GD';
|
return 'CAPTCHA_NO_GD';
|
||||||
}
|
}
|
||||||
|
|
||||||
static function get_class_name()
|
static function get_class_name()
|
||||||
{
|
{
|
||||||
return 'phpbb_captcha_nogd';
|
return 'phpbb_captcha_nogd';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function acp_page($id, &$module)
|
function acp_page($id, &$module)
|
||||||
{
|
{
|
||||||
global $user;
|
global $user;
|
||||||
|
|
||||||
trigger_error($user->lang['CAPTCHA_NO_OPTIONS'] . adm_back_link($module->u_action));
|
trigger_error($user->lang['CAPTCHA_NO_OPTIONS'] . adm_back_link($module->u_action));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -1,8 +1,8 @@
|
||||||
<?
|
<?php
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @package VC
|
* @package VC
|
||||||
* @version $Id: $
|
* @version $Id: constants.php 8818 2008-09-04 14:06:43Z acydburn $
|
||||||
* @copyright (c) 2006 2008 phpBB Group
|
* @copyright (c) 2006 2008 phpBB Group
|
||||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||||
*
|
*
|
||||||
|
@ -16,9 +16,8 @@ if (!defined('IN_PHPBB'))
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// we need the classic captcha code for tracking solutions and attempts
|
// we need the classic captcha code for tracking solutions and attempts
|
||||||
include_once(PHPBB_ROOT_PATH . "includes/captcha/plugins/captcha_abstract." . PHP_EXT);
|
include_once(PHPBB_ROOT_PATH . 'includes/captcha/plugins/captcha_abstract.' . PHP_EXT);
|
||||||
|
|
||||||
class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plugin
|
class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plugin
|
||||||
{
|
{
|
||||||
|
@ -27,18 +26,17 @@ class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plu
|
||||||
protected $challenge;
|
protected $challenge;
|
||||||
protected $response;
|
protected $response;
|
||||||
|
|
||||||
|
|
||||||
function init($type)
|
function init($type)
|
||||||
{
|
{
|
||||||
global $config, $db, $user;
|
global $config, $db, $user;
|
||||||
|
|
||||||
$user->add_lang('recaptcha');
|
$user->add_lang('recaptcha');
|
||||||
parent::init($type);
|
parent::init($type);
|
||||||
|
|
||||||
$this->challenge = request_var('recaptcha_challenge_field', '');
|
$this->challenge = request_var('recaptcha_challenge_field', '');
|
||||||
$this->response = request_var('recaptcha_response_field', '');
|
$this->response = request_var('recaptcha_response_field', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function get_instance()
|
public static function get_instance()
|
||||||
{
|
{
|
||||||
return new phpbb_recaptcha();
|
return new phpbb_recaptcha();
|
||||||
|
@ -46,25 +44,25 @@ class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plu
|
||||||
|
|
||||||
static function is_available()
|
static function is_available()
|
||||||
{
|
{
|
||||||
global $config, $user;
|
global $config, $user;
|
||||||
$user->add_lang('recaptcha');
|
$user->add_lang('recaptcha');
|
||||||
return (isset($config['recaptcha_pubkey']) && !empty($config['recaptcha_pubkey']));
|
return (isset($config['recaptcha_pubkey']) && !empty($config['recaptcha_pubkey']));
|
||||||
}
|
}
|
||||||
|
|
||||||
static function get_name()
|
static function get_name()
|
||||||
{
|
{
|
||||||
return 'CAPTCHA_RECAPTCHA';
|
return 'CAPTCHA_RECAPTCHA';
|
||||||
}
|
}
|
||||||
|
|
||||||
static function get_class_name()
|
static function get_class_name()
|
||||||
{
|
{
|
||||||
return 'phpbb_recaptcha';
|
return 'phpbb_recaptcha';
|
||||||
}
|
}
|
||||||
|
|
||||||
function acp_page($id, &$module)
|
function acp_page($id, &$module)
|
||||||
{
|
{
|
||||||
global $config, $db, $template, $user;
|
global $config, $db, $template, $user;
|
||||||
|
|
||||||
$captcha_vars = array(
|
$captcha_vars = array(
|
||||||
'recaptcha_pubkey' => 'RECAPTCHA_PUBKEY',
|
'recaptcha_pubkey' => 'RECAPTCHA_PUBKEY',
|
||||||
'recaptcha_privkey' => 'RECAPTCHA_PRIVKEY',
|
'recaptcha_privkey' => 'RECAPTCHA_PRIVKEY',
|
||||||
|
@ -108,47 +106,47 @@ class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plu
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// not needed
|
// not needed
|
||||||
function execute_demo()
|
function execute_demo()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// not needed
|
// not needed
|
||||||
function execute()
|
function execute()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function get_template()
|
function get_template()
|
||||||
{
|
{
|
||||||
global $config, $user, $template;
|
global $config, $user, $template;
|
||||||
|
|
||||||
$template->set_filenames(array(
|
$template->set_filenames(array(
|
||||||
'captcha' => 'captcha_recaptcha.html')
|
'captcha' => 'captcha_recaptcha.html')
|
||||||
);
|
);
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'RECAPTCHA_SERVER' => self::recaptcha_server,
|
'RECAPTCHA_SERVER' => self::recaptcha_server,
|
||||||
'RECAPTCHA_PUBKEY' => isset($config['recaptcha_pubkey']) ? $config['recaptcha_pubkey'] : '',
|
'RECAPTCHA_PUBKEY' => isset($config['recaptcha_pubkey']) ? $config['recaptcha_pubkey'] : '',
|
||||||
'RECAPTCHA_ERRORGET' => '',
|
'RECAPTCHA_ERRORGET' => '',
|
||||||
'S_RECAPTCHA_AVAILABLE' => self::is_available(),
|
'S_RECAPTCHA_AVAILABLE' => self::is_available(),
|
||||||
));
|
));
|
||||||
|
|
||||||
return $template->assign_display('captcha');
|
return $template->assign_display('captcha');
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_demo_template($id)
|
function get_demo_template($id)
|
||||||
{
|
{
|
||||||
return $this->get_template();
|
return $this->get_template();
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_hidden_fields()
|
function get_hidden_fields()
|
||||||
{
|
{
|
||||||
$hidden_fields = array();
|
$hidden_fields = array();
|
||||||
|
|
||||||
// this is required for postig.php - otherwise we would forget about the captcha being already solved
|
// this is required for postig.php - otherwise we would forget about the captcha being already solved
|
||||||
if ($this->solved)
|
if ($this->solved)
|
||||||
{
|
{
|
||||||
|
@ -157,17 +155,17 @@ class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plu
|
||||||
$hidden_fields['confirm_id'] = $this->confirm_id;
|
$hidden_fields['confirm_id'] = $this->confirm_id;
|
||||||
return $hidden_fields;
|
return $hidden_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
function uninstall()
|
function uninstall()
|
||||||
{
|
{
|
||||||
self::garbage_collect(0);
|
self::garbage_collect(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function install()
|
function install()
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate()
|
function validate()
|
||||||
{
|
{
|
||||||
if (!parent::validate())
|
if (!parent::validate())
|
||||||
|
@ -179,7 +177,7 @@ class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plu
|
||||||
return $this->recaptcha_check_answer();
|
return $this->recaptcha_check_answer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Code from here on is based on recaptchalib.php
|
// Code from here on is based on recaptchalib.php
|
||||||
/*
|
/*
|
||||||
|
@ -216,14 +214,14 @@ class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plu
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submits an HTTP POST to a reCAPTCHA server
|
* Submits an HTTP POST to a reCAPTCHA server
|
||||||
* @param string $host
|
* @param string $host
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @param int port
|
* @param int port
|
||||||
* @return array response
|
* @return array response
|
||||||
*/
|
*/
|
||||||
protected function _recaptcha_http_post($host, $path, $data, $port = 80)
|
protected function _recaptcha_http_post($host, $path, $data, $port = 80)
|
||||||
{
|
{
|
||||||
$req = $this->_recaptcha_qsencode ($data);
|
$req = $this->_recaptcha_qsencode ($data);
|
||||||
|
|
||||||
|
@ -236,52 +234,56 @@ class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plu
|
||||||
$http_request .= $req;
|
$http_request .= $req;
|
||||||
|
|
||||||
$response = '';
|
$response = '';
|
||||||
if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
|
if (false == ($fs = @fsockopen($host, $port, $errno, $errstr, 10)))
|
||||||
die ('Could not open socket');
|
{
|
||||||
|
trigger_error('Could not open socket', E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
fwrite($fs, $http_request);
|
fwrite($fs, $http_request);
|
||||||
|
|
||||||
while ( !feof($fs) )
|
while (!feof($fs))
|
||||||
$response .= fgets($fs, 1160); // One TCP-IP packet
|
{
|
||||||
|
// One TCP-IP packet
|
||||||
|
$response .= fgets($fs, 1160);
|
||||||
|
}
|
||||||
fclose($fs);
|
fclose($fs);
|
||||||
|
|
||||||
$response = explode("\r\n\r\n", $response, 2);
|
$response = explode("\r\n\r\n", $response, 2);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls an HTTP POST function to verify if the user's guess was correct
|
* Calls an HTTP POST function to verify if the user's guess was correct
|
||||||
* @param array $extra_params an array of extra variables to post to the server
|
* @param array $extra_params an array of extra variables to post to the server
|
||||||
* @return ReCaptchaResponse
|
* @return ReCaptchaResponse
|
||||||
*/
|
*/
|
||||||
protected function recaptcha_check_answer ($extra_params = array())
|
protected function recaptcha_check_answer($extra_params = array())
|
||||||
{
|
{
|
||||||
global $config, $user;
|
global $config, $user;
|
||||||
//discard spam submissions
|
|
||||||
if ($this->challenge == null || strlen($this->challenge) == 0 || $this->response == null || strlen($this->response) == 0)
|
// discard spam submissions
|
||||||
|
if ($this->challenge == null || strlen($this->challenge) == 0 || $this->response == null || strlen($this->response) == 0)
|
||||||
{
|
{
|
||||||
return $user->lang['RECAPTCHA_INCORRECT'];
|
return $user->lang['RECAPTCHA_INCORRECT'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = $this->_recaptcha_http_post (self::recaptcha_verify_server, "/verify",
|
$response = $this->_recaptcha_http_post(self::recaptcha_verify_server, '/verify', array(
|
||||||
array (
|
'privatekey' => $config['recaptcha_privkey'],
|
||||||
'privatekey' => $config['recaptcha_privkey'],
|
'remoteip' => $user->ip,
|
||||||
'remoteip' => $user->ip,
|
'challenge' => $this->challenge,
|
||||||
'challenge' => $this->challenge,
|
'response' => $this->response,
|
||||||
'response' => $this->response
|
) + $extra_params
|
||||||
) + $extra_params
|
);
|
||||||
);
|
|
||||||
|
|
||||||
$answers = explode ("\n", $response[1]);
|
$answers = explode("\n", $response[1]);
|
||||||
|
|
||||||
if (trim ($answers[0]) === 'true')
|
if (trim($answers[0]) === 'true')
|
||||||
{
|
{
|
||||||
$this->solved = true;
|
$this->solved = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($answers[1] === 'incorrect-captcha-sol')
|
if ($answers[1] === 'incorrect-captcha-sol')
|
||||||
{
|
{
|
||||||
|
@ -289,22 +291,24 @@ class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encodes the given data into a query string format
|
* Encodes the given data into a query string format
|
||||||
* @param $data - array of string elements to be encoded
|
* @param $data - array of string elements to be encoded
|
||||||
* @return string - encoded request
|
* @return string - encoded request
|
||||||
*/
|
*/
|
||||||
protected function _recaptcha_qsencode ($data)
|
protected function _recaptcha_qsencode($data)
|
||||||
{
|
{
|
||||||
$req = '';
|
$req = '';
|
||||||
foreach ( $data as $key => $value )
|
|
||||||
|
foreach ($data as $key => $value)
|
||||||
{
|
{
|
||||||
$req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
|
$req .= $key . '=' . urlencode(stripslashes($value)) . '&';
|
||||||
}
|
}
|
||||||
// Cut the last '&'
|
// Cut the last '&'
|
||||||
$req=substr($req,0,strlen($req)-1);
|
$req = substr($req, 0, strlen($req) - 1);
|
||||||
return $req;
|
return $req;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Add table
Reference in a new issue