some corrections, only very minor things.

git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9554 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2009-06-07 11:34:01 +00:00
parent 711f482cb6
commit a539fca62b
19 changed files with 264 additions and 257 deletions

View file

@ -32,6 +32,11 @@ if (!defined('PHPBB_ACM_MEMCACHE_COMPRESS'))
define('PHPBB_ACM_MEMCACHE_COMPRESS', false);
}
if (!defined('PHPBB_ACM_MEMCACHE_HOST'))
{
define('PHPBB_ACM_MEMCACHE_HOST', 'localhost');
}
/**
* ACM for Memcached
* @package acm
@ -48,11 +53,6 @@ class acm extends acm_memory
// Call the parent constructor
parent::acm_memory();
if (!defined('PHPBB_ACM_MEMCACHE_HOST'))
{
trigger_error('Missing required constant [PHPBB_ACM_MEMCACHE_HOST] for memcache ACM module.', E_USER_ERROR);
}
$this->memcache = new Memcache;
$this->memcache->connect(PHPBB_ACM_MEMCACHE_HOST, PHPBB_ACM_MEMCACHE_PORT);
$this->flags = (PHPBB_ACM_MEMCACHE_COMPRESS) ? MEMCACHE_COMPRESSED : 0;

View file

@ -156,7 +156,7 @@ class acm_memory
while (($entry = readdir($dir)) !== false)
{
if (strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0)
if (strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0)
{
continue;
}
@ -415,7 +415,7 @@ class acm_memory
* @access protected
* @param string $var Cache key
* @return bool True if it exists, otherwise false
*/
*/
function _isset($var)
{
// Most caches don't need to check

View file

@ -27,7 +27,6 @@ class acm
*/
function acm()
{
}
/**
@ -43,7 +42,6 @@ class acm
*/
function unload()
{
}
/**
@ -51,7 +49,6 @@ class acm
*/
function save()
{
}
/**
@ -76,7 +73,6 @@ class acm
*/
function put($var_name, $var, $ttl = 0)
{
}
/**
@ -84,7 +80,6 @@ class acm
*/
function purge()
{
}
/**
@ -92,7 +87,6 @@ class acm
*/
function destroy($var_name, $table = '')
{
}
/**
@ -116,7 +110,6 @@ class acm
*/
function sql_save($query, &$query_result, $ttl)
{
}
/**

View file

@ -10,8 +10,6 @@
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
@ -35,13 +33,13 @@ class acp_captcha
$selected = request_var('select_captcha', $config['captcha_plugin']);
$configure = request_var('configure', false);
// Oh, they are just here for the view
if (isset($_GET['captcha_demo']))
{
$this->deliver_demo($selected);
}
// Delegate
if ($configure)
{
@ -52,6 +50,7 @@ class acp_captcha
else
{
$captchas = phpbb_captcha_factory::get_captcha_types();
$config_vars = array(
'enable_confirm' => 'REG_ENABLE',
'enable_post_confirm' => 'POST_ENABLE',
@ -68,10 +67,12 @@ class acp_captcha
if ($submit && check_form_key($form_key))
{
$config_vars = array_keys($config_vars);
foreach ($config_vars as $config_var)
{
set_config($config_var, request_var($config_var, false));
}
if ($selected !== $config['captcha_plugin'])
{
// sanity check
@ -79,9 +80,11 @@ class acp_captcha
{
$old_captcha = phpbb_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']);
$old_captcha->install();
$new_captcha->install();
add_log('admin', 'LOG_CONFIG_VISUAL');
}
else
@ -103,14 +106,15 @@ class acp_captcha
$current = ($selected !== false && $value == $selected) ? ' selected="selected"' : '';
$captcha_select .= '<option value="' . $value . '"' . $current . '>' . $user->lang[$title] . '</option>';
}
foreach ($captchas['unavailable'] as $value => $title)
{
$current = ($selected !== false && $value == $selected) ? ' selected="selected"' : '';
$captcha_select .= '<option value="' . $value . '"' . $current . ' class="disabled-option" >' . $user->lang[$title] . '</option>';
$captcha_select .= '<option value="' . $value . '"' . $current . ' class="disabled-option">' . $user->lang[$title] . '</option>';
}
$demo_captcha = phpbb_captcha_factory::get_instance($selected);
foreach ($config_vars as $config_var => $template_var)
{
$template->assign_var($template_var, (isset($_REQUEST[$config_var])) ? request_var($config_var, '') : $config[$config_var]) ;
@ -121,28 +125,23 @@ class acp_captcha
'CAPTCHA_SELECT' => $captcha_select,
));
}
}
}
/**
* Entry point for delivering image CAPTCHAs in the ACP.
*/
function deliver_demo($selected)
{
global $db, $user, $config;
$captcha = phpbb_captcha_factory::get_instance($selected);
$captcha->init(CONFIRM_REG);
$captcha->execute_demo();
garbage_collection();
exit_handler();
}
}
?>

View file

@ -68,7 +68,6 @@ function login_db(&$username, &$password)
if ($config['max_login_attempts'] && $row['user_login_attempts'] >= $config['max_login_attempts'])
{
$confirm_id = request_var('confirm_id', '');
$confirm_code = request_var('confirm_code', '');
// Visual Confirmation handling
if (!$confirm_id)
@ -84,12 +83,13 @@ function login_db(&$username, &$password)
$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
$captcha->init(CONFIRM_LOGIN);
$vc_response = $captcha->validate();
if ($vc_response)
{
return array(
'status' => LOGIN_ERROR_ATTEMPTS,
'error_msg' => 'LOGIN_ERROR_ATTEMPTS',
'user_row' => $row,
'status' => LOGIN_ERROR_ATTEMPTS,
'error_msg' => 'LOGIN_ERROR_ATTEMPTS',
'user_row' => $row,
);
}
}
@ -130,7 +130,7 @@ function login_db(&$username, &$password)
$row['user_pass_convert'] = 0;
$row['user_password'] = $hash;
}
else
else
{
// Although we weren't able to convert this password we have to
// increase login attempt count to make sure this cannot be exploited

View file

@ -16,8 +16,11 @@ if (!defined('IN_PHPBB'))
exit;
}
/** A small class until we get the autoloader done */
/**
* A small class for 3.0.x (no autoloader in 3.0.x)
*
* @package VC
*/
class phpbb_captcha_factory
{
/**
@ -26,7 +29,7 @@ class phpbb_captcha_factory
function get_instance($name)
{
global $phpbb_root_path, $phpEx;
$name = basename($name);
if (!class_exists($name))
{
@ -34,7 +37,7 @@ class phpbb_captcha_factory
}
return call_user_func(array($name, 'get_instance'));
}
/**
* Call the garbage collector
*/
@ -49,18 +52,19 @@ class phpbb_captcha_factory
}
call_user_func(array($name, 'garbage_collect'), 0);
}
/**
* return a list of all discovered CAPTCHA plugins
*/
function get_captcha_types()
{
global $phpbb_root_path, $phpEx;
$captchas = array();
$captchas['available'] = array();
$captchas['unavailable'] = array();
$captchas = array(
'available' => array(),
'unavailable' => array(),
);
$dp = @opendir($phpbb_root_path . 'includes/captcha/plugins');
if ($dp)
@ -74,6 +78,7 @@ class phpbb_captcha_factory
{
include($phpbb_root_path . "includes/captcha/plugins/$file");
}
if (call_user_func(array($name, 'is_available')))
{
$captchas['available'][$name] = call_user_func(array($name, 'get_name'));

View file

@ -1,16 +1,18 @@
<?php
/**
/**
*
* @package VC
* @version $Id$
* @copyright (c) 2006 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @copyright (c) 2006 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* Wave3D CAPTCHA by Robert Hetzler
/**
* Wave3D CAPTCHA
*
* @author Robert Hetzler
* @package VC
*/
class captcha
{
@ -20,10 +22,10 @@ class captcha
function execute($code, $seed)
{
global $starttime;
// seed the random generator
mt_srand($seed);
// set height and width
$img_x = $this->width;
$img_y = $this->height;
@ -32,7 +34,7 @@ class captcha
$img = imagecreatetruecolor($img_x, $img_y);
$x_grid = mt_rand(6, 10);
$y_grid = mt_rand(6, 10);
// Ok, so lets cut to the chase. We could accurately represent this in 3d and
// do all the appropriate linear transforms. my questions is... why bother?
// The computational overhead is unnecessary when you consider the simple fact:
@ -47,27 +49,28 @@ class captcha
$plane_x = 100;
$plane_y = 30;
$subdivision_factor = 3;
$subdivision_factor = 3;
// $box is the 4 points in img_space that correspond to the corners of the plane in 3-space
$box = array(
'upper_left' => array(
'x' => mt_rand(5, 15),
'y' => mt_rand(10, 15)
),
),
'upper_right' => array(
'x' => mt_rand($img_x - 35, $img_x - 19),
'y' => mt_rand(10, 17)
),
),
'lower_left' => array(
'x' => mt_rand($img_x - 5, $img_x - 45),
'y' => mt_rand($img_y - 0, $img_y - 15)
),
);
$box['lower_right'] = array(
'x' => $box['lower_left']['x'] + $box['upper_left']['x'] - $box['upper_right']['x'],
'y' => $box['lower_left']['y'] + $box['upper_left']['y'] - $box['upper_right']['y'],
),
);
$box['lower_right'] = array(
'x' => $box['lower_left']['x'] + $box['upper_left']['x'] - $box['upper_right']['x'],
'y' => $box['lower_left']['y'] + $box['upper_left']['y'] - $box['upper_right']['y'],
);
// TODO
$background = imagecolorallocate($img, mt_rand(155, 255), mt_rand(155, 255), mt_rand(155, 255));
@ -83,7 +86,7 @@ class captcha
}
$fontcolors[0] = imagecolorallocate($img, mt_rand(0, 120), mt_rand(0, 120), mt_rand(0, 120));
$colors = array();
$minr = mt_rand(20, 30);
@ -159,7 +162,7 @@ class captcha
$cur_height = $this->wave_height($x, 0, $subdivision_factor);
$offset = $cur_height - $prev_height;
$img_pos_cur = array($img_pos_prev[0] + $dxx, $img_pos_prev[1] + $dxy + $offset);
$img_buffer[0][$x] = $img_pos_cur;
$img_pos_prev = $img_pos_cur;
$prev_height = $cur_height;
@ -170,7 +173,7 @@ class captcha
// swap buffers
$buffer_cur = $y & 1;
$buffer_prev = 1 - $buffer_cur;
$prev_height = $this->wave_height(0, $y, $subdivision_factor);
$offset = $prev_height - $this->wave_height(0, $y - 1, $subdivision_factor);
$img_pos_cur = array($img_buffer[$buffer_prev][0][0] + $dyx, min($img_buffer[$buffer_prev][0][1] + $dyy + $offset, $img_y - 1));
@ -179,7 +182,7 @@ class captcha
$img_pos_prev = $img_pos_cur;
$img_buffer[$buffer_cur][0] = $img_pos_cur;
for ($x = 1; $x <= $full_x; ++$x)
{
$cur_height = $this->wave_height($x, $y, $subdivision_factor) + $this->grid_height($x, $y, 1, $x_grid, $y_grid);
@ -496,7 +499,7 @@ class captcha
array(0,0,0,0,0,0,0,0,0),
array(0,0,0,0,0,0,0,0,0),
array(0,0,0,0,0,0,0,0,0),
),
),
'O' => array(
array(0,0,0,1,1,1,0,0,0),
array(0,0,1,0,0,0,1,0,0),

View file

@ -18,7 +18,9 @@ if (!defined('IN_PHPBB'))
/**
* This class holds the code shared by the two default 3.0 CAPTCHAs.
* This class holds the code shared by the two default 3.0.x CAPTCHAs.
*
* @package VC
*/
class phpbb_default_captcha
{
@ -29,18 +31,17 @@ class phpbb_default_captcha
var $type;
var $solved = false;
function init($type)
{
global $config, $db, $user;
// read input
$this->confirm_id = request_var('confirm_id', '');
$this->confirm_code = request_var('confirm_code', '');
$refresh = request_var('refresh_vc', false) && $config['confirm_refresh'];
$this->type = (int) $type;
if (!strlen($this->confirm_id))
{
// we have no confirm ID, better get ready to display something
@ -50,24 +51,22 @@ class phpbb_default_captcha
{
$this->regenerate_code();
}
}
function execute_demo()
{
global $user;
$this->code = gen_rand_string(mt_rand(5, 8));
$this->code = gen_rand_string(mt_rand(CAPTCHA_MIN_CHARS, CAPTCHA_MAX_CHARS));
$this->seed = hexdec(substr(unique_id(), 4, 10));
// compute $seed % 0x7fffffff
$this->seed -= 0x7fffffff * floor($this->seed / 0x7fffffff);
$captcha = new captcha();
$captcha->execute($this->code, $this->seed);
}
function execute()
{
if (empty($this->code))
@ -81,46 +80,46 @@ class phpbb_default_captcha
$captcha = new captcha();
$captcha->execute($this->code, $this->seed);
}
function get_template()
{
global $config, $user, $template, $phpEx, $phpbb_root_path;
$template->set_filenames(array(
'captcha' => 'captcha_default.html')
);
$template->assign_vars(array(
'CONFIRM_IMAGE' => append_sid($phpbb_root_path . 'ucp.' . $phpEx . '?mode=confirm&amp;confirm_id=' . $this->confirm_id . '&amp;type=' . $this->type),
'CONFIRM_ID' => $this->confirm_id,
'CONFIRM_ID' => $this->confirm_id,
'S_REFRESH' => (bool) $config['confirm_refresh'],
));
return $template->assign_display('captcha');
}
function get_demo_template($id)
{
global $config, $user, $template, $phpbb_admin_path, $phpEx;
$template->set_filenames(array(
'captcha_demo' => 'captcha_default_acp_demo.html')
);
// 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&amp;mode=visual&amp;i=' . $id . '&amp;select_captcha=' . $this->get_class_name()),
'CONFIRM_ID' => $this->confirm_id,
));
return $template->assign_display('captcha_demo');
}
function get_hidden_fields()
{
$hidden_fields = array();
// this is required for postig.php - otherwise we would forget about the captcha being already solved
if ($this->solved)
{
@ -129,16 +128,16 @@ class phpbb_default_captcha
$hidden_fields['confirm_id'] = $this->confirm_id;
return $hidden_fields;
}
function garbage_collect($type)
{
global $db, $config;
$sql = 'SELECT DISTINCT c.session_id
FROM ' . CONFIRM_TABLE . ' c
LEFT JOIN ' . SESSIONS_TABLE . ' s ON (c.session_id = s.session_id)
WHERE s.session_id IS NULL' .
((empty($type)) ? '' : ' AND c.confirm_type = ' . (int) $type);
FROM ' . CONFIRM_TABLE . ' c
LEFT JOIN ' . SESSIONS_TABLE . ' s ON (c.session_id = s.session_id)
WHERE s.session_id IS NULL' .
((empty($type)) ? '' : ' AND c.confirm_type = ' . (int) $type);
$result = $db->sql_query($sql);
if ($row = $db->sql_fetchrow($result))
@ -159,21 +158,21 @@ class phpbb_default_captcha
}
$db->sql_freeresult($result);
}
function uninstall()
{
self::garbage_collect(0);
$this->garbage_collect(0);
}
function install()
{
return;
}
function validate()
{
global $config, $db, $user;
$this->confirm_code = request_var('confirm_code', '');
if (!$this->confirm_id)
{
@ -191,10 +190,10 @@ class phpbb_default_captcha
$error = $user->lang['CONFIRM_CODE_WRONG'];
}
}
if (strlen($error))
{
// okay, inorect answer. Let's ask a new question
// okay, incorrect answer. Let's ask a new question.
$this->generate_code();
return $error;
}
@ -203,16 +202,15 @@ class phpbb_default_captcha
return false;
}
}
/**
* The old way to generate code, suitable for GD and non-GD. Resets the internal state.
*/
function generate_code()
{
global $db, $user;
$this->code = gen_rand_string(mt_rand(5, 8));
$this->code = gen_rand_string(mt_rand(CAPTCHA_MIN_CHARS, CAPTCHA_MAX_CHARS));
$this->confirm_id = md5(unique_id($user->ip));
$this->seed = hexdec(substr(unique_id(), 4, 10));
$this->solved = false;
@ -228,19 +226,20 @@ class phpbb_default_captcha
);
$db->sql_query($sql);
}
/**
* New Question, if desired.
*/
function regenerate_code()
{
global $db, $user;
$this->code = gen_rand_string(mt_rand(5, 8));
$this->code = gen_rand_string(mt_rand(CAPTCHA_MIN_CHARS, CAPTCHA_MAX_CHARS));
$this->seed = hexdec(substr(unique_id(), 4, 10));
$this->solved = false;
// compute $seed % 0x7fffffff
$this->seed -= 0x7fffffff * floor($this->seed / 0x7fffffff);
$sql = 'UPDATE ' . CONFIRM_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array(
'code' => (string) $this->code,
'seed' => (int) $this->seed)) . '
@ -249,35 +248,37 @@ class phpbb_default_captcha
session_id = \'' . $db->sql_escape($user->session_id) . '\'';
$db->sql_query($sql);
}
/**
* Look up everything we need for painting&checking.
* Look up everything we need for painting&checking.
*/
function load_code()
{
global $db, $user;
$sql = 'SELECT code, seed
FROM ' . CONFIRM_TABLE . "
WHERE confirm_id = '" . $db->sql_escape($this->confirm_id) . "'
AND session_id = '" . $db->sql_escape($user->session_id) . "'
AND confirm_type = " . $this->type;
FROM ' . CONFIRM_TABLE . "
WHERE confirm_id = '" . $db->sql_escape($this->confirm_id) . "'
AND session_id = '" . $db->sql_escape($user->session_id) . "'
AND confirm_type = " . $this->type;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row)
{
$this->code = $row['code'];
$this->seed = $row['seed'];
return true;
}
return false;
}
function check_code()
{
global $db;
if (empty($this->code))
{
if (!$this->load_code())
@ -287,47 +288,45 @@ class phpbb_default_captcha
}
return (strcasecmp($this->code, $this->confirm_code) === 0);
}
function delete_code()
{
global $db, $user;
$sql = 'DELETE FROM ' . CONFIRM_TABLE . "
WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
AND session_id = '" . $db->sql_escape($user->session_id) . "'
AND confirm_type = " . $this->type;
WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
AND session_id = '" . $db->sql_escape($user->session_id) . "'
AND confirm_type = " . $this->type;
$db->sql_query($sql);
}
function get_attempt_count()
{
global $db, $user;
$sql = 'SELECT COUNT(session_id) AS attempts
FROM ' . CONFIRM_TABLE . "
WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
AND confirm_type = " . $this->type;
FROM ' . CONFIRM_TABLE . "
WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
AND confirm_type = " . $this->type;
$result = $db->sql_query($sql);
$attempts = (int) $db->sql_fetchfield('attempts');
$db->sql_freeresult($result);
return $attempts;
}
function reset()
{
global $db, $user;
$sql = 'DELETE FROM ' . CONFIRM_TABLE . "
WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
AND confirm_type = " . (int) $this->type;
WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
AND confirm_type = " . (int) $this->type;
$db->sql_query($sql);
// we leave the class usable by generating a new question
$this->generate_code();
}
}
?>

View file

@ -16,7 +16,7 @@ if (!defined('IN_PHPBB'))
exit;
}
/**
/**
* Placeholder for autoload
*/
if (!class_exists('phpbb_default_captcha'))
@ -24,6 +24,9 @@ if (!class_exists('phpbb_default_captcha'))
include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
}
/**
* @package VC
*/
class phpbb_captcha_gd extends phpbb_default_captcha
{
function phpbb_captcha_gd()
@ -35,7 +38,7 @@ class phpbb_captcha_gd extends phpbb_default_captcha
include($phpbb_root_path . 'includes/captcha/captcha_gd.' . $phpEx);
}
}
function get_instance()
{
return new phpbb_captcha_gd();
@ -45,17 +48,17 @@ class phpbb_captcha_gd extends phpbb_default_captcha
{
return (@extension_loaded('gd') || can_load_dll('gd'));
}
function get_name()
{
return 'CAPTCHA_GD';
}
function get_class_name()
{
return 'phpbb_captcha_gd';
}
function acp_page($id, &$module)
{
global $db, $user, $auth, $template;
@ -80,7 +83,6 @@ class phpbb_captcha_gd extends phpbb_default_captcha
'captcha_gd' => 'CAPTCHA_GD',
);
$module->tpl_name = 'captcha_gd_acp';
$module->page_title = 'ACP_VC_SETTINGS';
$form_key = 'acp_captcha';
@ -112,11 +114,11 @@ class phpbb_captcha_gd extends phpbb_default_captcha
$var = (isset($_REQUEST[$captcha_var])) ? request_var($captcha_var, 0) : $config[$captcha_var];
$template->assign_var($template_var, $var);
}
$template->assign_vars(array(
'CAPTCHA_PREVIEW' => $this->get_demo_template($id),
'CAPTCHA_NAME' => $this->get_class_name(),
));
}
}
}

View file

@ -24,6 +24,9 @@ if (!class_exists('captcha_abstract'))
include_once($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
}
/**
* @package VC
*/
class phpbb_captcha_gd_wave extends phpbb_default_captcha
{
@ -60,7 +63,7 @@ class phpbb_captcha_gd_wave extends phpbb_default_captcha
function acp_page($id, &$module)
{
global $config, $db, $template, $user;
trigger_error($user->lang['CAPTCHA_NO_OPTIONS'] . adm_back_link($module->u_action));
}
}

View file

@ -16,7 +16,7 @@ if (!defined('IN_PHPBB'))
exit;
}
/**
/**
* Placeholder for autoload
*/
if (!class_exists('phpbb_default_captcha'))
@ -24,6 +24,9 @@ if (!class_exists('phpbb_default_captcha'))
include_once($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
}
/**
* @package VC
*/
class phpbb_captcha_nogd extends phpbb_default_captcha
{
@ -36,7 +39,7 @@ class phpbb_captcha_nogd extends phpbb_default_captcha
include_once($phpbb_root_path . 'includes/captcha/captcha_non_gd.' . $phpEx);
}
}
function get_instance()
{
return new phpbb_captcha_nogd();
@ -46,25 +49,23 @@ class phpbb_captcha_nogd extends phpbb_default_captcha
{
return true;
}
function get_name()
{
global $user;
return 'CAPTCHA_NO_GD';
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));
}
}
?>

View file

@ -22,6 +22,9 @@ if (!class_exists('phpbb_default_captcha'))
include_once($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
}
/**
* @package VC
*/
class phpbb_recaptcha extends phpbb_default_captcha
{
var $recaptcha_server = 'http://api.recaptcha.net';
@ -29,18 +32,16 @@ class phpbb_recaptcha extends phpbb_default_captcha
var $challenge;
var $response;
function init($type)
{
global $config, $db, $user;
$user->add_lang('recaptcha');
parent::init($type);
$this->challenge = request_var('recaptcha_challenge_field', '');
$this->response = request_var('recaptcha_response_field', '');
}
function get_instance()
{
return new phpbb_recaptcha();
@ -48,25 +49,25 @@ class phpbb_recaptcha extends phpbb_default_captcha
function is_available()
{
global $config, $user;
global $config, $user;
$user->add_lang('recaptcha');
return (isset($config['recaptcha_pubkey']) && !empty($config['recaptcha_pubkey']));
}
function get_name()
{
return 'CAPTCHA_RECAPTCHA';
}
function get_class_name()
{
return 'phpbb_recaptcha';
}
function acp_page($id, &$module)
{
global $config, $db, $template, $user;
$captcha_vars = array(
'recaptcha_pubkey' => 'RECAPTCHA_PUBKEY',
'recaptcha_privkey' => 'RECAPTCHA_PRIVKEY',
@ -103,6 +104,7 @@ class phpbb_recaptcha extends phpbb_default_captcha
$var = (isset($_REQUEST[$captcha_var])) ? request_var($captcha_var, '') : ((isset($config[$captcha_var])) ? $config[$captcha_var] : '');
$template->assign_var($template_var, $var);
}
$template->assign_vars(array(
'CAPTCHA_PREVIEW' => $this->get_demo_template($id),
'CAPTCHA_NAME' => $this->get_class_name(),
@ -110,47 +112,44 @@ class phpbb_recaptcha extends phpbb_default_captcha
}
}
// not needed
function execute_demo()
{
}
// not needed
function execute()
{
}
function get_template()
{
global $config, $user, $template;
$template->set_filenames(array(
'captcha' => 'captcha_recaptcha.html')
);
$template->assign_vars(array(
'RECAPTCHA_SERVER' => $this->recaptcha_server,
'RECAPTCHA_PUBKEY' => isset($config['recaptcha_pubkey']) ? $config['recaptcha_pubkey'] : '',
'RECAPTCHA_ERRORGET' => '',
'S_RECAPTCHA_AVAILABLE' => $this->is_available(),
));
return $template->assign_display('captcha');
}
function get_demo_template($id)
{
return $this->get_template();
}
function get_hidden_fields()
{
$hidden_fields = array();
// this is required for postig.php - otherwise we would forget about the captcha being already solved
if ($this->solved)
{
@ -159,17 +158,17 @@ class phpbb_recaptcha extends phpbb_default_captcha
$hidden_fields['confirm_id'] = $this->confirm_id;
return $hidden_fields;
}
function uninstall()
{
self::garbage_collect(0);
$this->garbage_collect(0);
}
function install()
{
return;
}
function validate()
{
if (!parent::validate())
@ -181,7 +180,6 @@ class phpbb_recaptcha extends phpbb_default_captcha
return $this->recaptcha_check_answer();
}
}
// Code from here on is based on recaptchalib.php
/*
@ -218,14 +216,14 @@ class phpbb_recaptcha extends phpbb_default_captcha
*/
/**
* Submits an HTTP POST to a reCAPTCHA server
* @param string $host
* @param string $path
* @param array $data
* @param int port
* @return array response
*/
function _recaptcha_http_post($host, $path, $data, $port = 80)
* Submits an HTTP POST to a reCAPTCHA server
* @param string $host
* @param string $path
* @param array $data
* @param int port
* @return array response
*/
function _recaptcha_http_post($host, $path, $data, $port = 80)
{
$req = $this->_recaptcha_qsencode ($data);
@ -238,52 +236,56 @@ class phpbb_recaptcha extends phpbb_default_captcha
$http_request .= $req;
$response = '';
if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
die ('Could not open socket');
if (false == ($fs = @fsockopen($host, $port, $errno, $errstr, 10)))
{
trigger_error('Could not open socket', E_USER_ERROR);
}
fwrite($fs, $http_request);
while ( !feof($fs) )
$response .= fgets($fs, 1160); // One TCP-IP packet
while (!feof($fs))
{
// One TCP-IP packet
$response .= fgets($fs, 1160);
}
fclose($fs);
$response = explode("\r\n\r\n", $response, 2);
return $response;
}
/**
* 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
* @return ReCaptchaResponse
*/
function recaptcha_check_answer ($extra_params = array())
* 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
* @return ReCaptchaResponse
*/
function recaptcha_check_answer($extra_params = array())
{
global $config, $user;
//discard spam submissions
if ($this->challenge == null || strlen($this->challenge) == 0 || $this->response == null || strlen($this->response) == 0)
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 ($this->recaptcha_verify_server, "/verify",
array (
'privatekey' => $config['recaptcha_privkey'],
'remoteip' => $user->ip,
'challenge' => $this->challenge,
'response' => $this->response
) + $extra_params
);
$response = $this->_recaptcha_http_post($this->recaptcha_verify_server, '/verify',
array(
'privatekey' => $config['recaptcha_privkey'],
'remoteip' => $user->ip,
'challenge' => $this->challenge,
'response' => $this->response
) + $extra_params
);
$answers = explode ("\n", $response[1]);
if (trim ($answers[0]) === 'true')
$answers = explode("\n", $response[1]);
if (trim($answers[0]) === 'true')
{
$this->solved = true;
return false;
}
else
else
{
if ($answers[1] === 'incorrect-captcha-sol')
{
@ -291,22 +293,24 @@ class phpbb_recaptcha extends phpbb_default_captcha
}
}
}
/**
* Encodes the given data into a query string format
* @param $data - array of string elements to be encoded
* @return string - encoded request
*/
function _recaptcha_qsencode ($data)
/**
* Encodes the given data into a query string format
* @param $data - array of string elements to be encoded
* @return string - encoded request
*/
function _recaptcha_qsencode($data)
{
$req = '';
foreach ( $data as $key => $value )
foreach ($data as $key => $value)
{
$req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
$req .= $key . '=' . urlencode(stripslashes($value)) . '&';
}
// Cut the last '&'
$req=substr($req,0,strlen($req)-1);
$req = substr($req, 0, strlen($req) - 1);
return $req;
}
}
?>

View file

@ -670,17 +670,17 @@ function phpbb_chmod($filename, $perms = CHMOD_READ)
}
/**
* Test if a file/directory is writable
*
* This function calls the native is_writable() when not running under
* Windows and it is not disabled.
*
* @param string $file Path to perform write test on
* @return bool True when the path is writable, otherwise false.
*/
* Test if a file/directory is writable
*
* This function calls the native is_writable() when not running under
* Windows and it is not disabled.
*
* @param string $file Path to perform write test on
* @return bool True when the path is writable, otherwise false.
*/
function phpbb_is_writable($file)
{
if (substr(PHP_OS, 0, 3) === 'WIN' || !function_exists('is_writable'))
if (strtolower(substr(PHP_OS, 0, 3)) === 'win' || !function_exists('is_writable'))
{
if (file_exists($file))
{
@ -714,7 +714,6 @@ function phpbb_is_writable($file)
else
{
// file does not exist test if we can write to the directory
$dir = dirname($file);
if (file_exists($dir) && is_dir($dir) && phpbb_is_writable($dir))
@ -722,6 +721,7 @@ function phpbb_is_writable($file)
return true;
}
}
return false;
}
else
@ -2585,7 +2585,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
{
include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
}
$err = '';
// Make sure user->setup() has been called
@ -2700,14 +2700,12 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
$captcha->init(CONFIRM_LOGIN);
$captcha->reset();
$template->assign_vars(array(
'S_CONFIRM_CODE' => true,
'CONFIRM' => $captcha->get_template(''),
));
$err = $user->lang[$result['error_msg']];
break;
case LOGIN_ERROR_PASSWORD_CONVERT:

View file

@ -2077,8 +2077,8 @@ function avatar_gallery($category, $avatar_select, $items_per_column, $block_var
if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $sub_file))
{
$avatar_list[$file][$avatar_row_count][$avatar_col_count] = array(
'file' => rawurlencode ($file) . '/' . rawurlencode ($sub_file),
'filename' => rawurlencode ($sub_file),
'file' => rawurlencode($file) . '/' . rawurlencode($sub_file),
'filename' => rawurlencode($sub_file),
'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $sub_file))),
);
$avatar_col_count++;

View file

@ -949,7 +949,7 @@ class session
WHERE last_login < ' . (time() - (86400 * (int) $config['max_autologin_time']));
$db->sql_query($sql);
}
// only called from CRON; should be a safe workaround until the infrastructure gets going
if (!class_exists('captcha_factory'))
{
@ -961,7 +961,6 @@ class session
return;
}
/**
* Sets a cookie
*

View file

@ -42,7 +42,8 @@ class ucp_register
$submit = (isset($_POST['submit'])) ? true : false;
$change_lang = request_var('change_lang', '');
$user_lang = request_var('lang', $user->lang_name);
$confirm_refresh = (isset($_POST['confirm_refresh']) && $config['confirm_refresh']) ? ((!empty($_POST['confirm_refresh'])) ? 1 : 0) : false;
$confirm_refresh= (isset($_POST['confirm_refresh']) && $config['confirm_refresh']) ? ((!empty($_POST['confirm_refresh'])) ? 1 : 0) : false;
if ($agreed)
{
add_form_key('ucp_register');
@ -52,14 +53,13 @@ class ucp_register
add_form_key('ucp_register_terms');
}
if ($config['enable_confirm'])
{
include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
$captcha->init(CONFIRM_REG);
}
if ($change_lang || $user_lang != $config['default_lang'])
{
$use_lang = ($change_lang) ? basename($change_lang) : basename($user_lang);
@ -94,7 +94,7 @@ class ucp_register
{
$add_lang = ($change_lang) ? '&amp;change_lang=' . urlencode($change_lang) : '';
$add_coppa = ($coppa !== false) ? '&amp;coppa=' . $coppa : '';
$s_hidden_fields = array();
// If we change the language, we want to pass on some more possible parameter.
@ -108,7 +108,7 @@ class ucp_register
'lang' => $user->lang_name,
'tz' => request_var('tz', (float) $config['board_timezone']),
));
if ($config['enable_confirm'])
{
$s_hidden_fields = array_merge($s_hidden_fields, $captcha->get_hidden_fields());
@ -198,10 +198,12 @@ class ucp_register
'tz' => array('num', false, -14, 14),
'lang' => array('match', false, '#^[a-z_\-]{2,}$#i'),
));
if (!check_form_key('ucp_register'))
{
$error[] = $user->lang['FORM_INVALID'];
}
// Replace "error" strings with their real, localised form
$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
@ -216,11 +218,13 @@ class ucp_register
{
$captcha->reset();
}
if ($config['max_reg_attempts'] && $captcha->get_attempt_count() > $config['max_reg_attempts'])
{
$error[] = $user->lang['TOO_MANY_REGISTERS'];
}
}
// DNSBL check
if ($config['check_dnsbl'])
{
@ -424,7 +428,6 @@ class ucp_register
$confirm_image = '';
// Visual Confirmation - Show images
if ($config['enable_confirm'])
{
if ($change_lang || $confirm_refresh)
@ -434,13 +437,12 @@ class ucp_register
else
{
$str = '';
}
$template->assign_vars(array(
'L_CONFIRM_EXPLAIN' => sprintf($user->lang['CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>'),
'S_CAPTCHA' => $captcha->get_template(),
));
}
//
@ -455,7 +457,7 @@ class ucp_register
$l_reg_cond = $user->lang['UCP_ADMIN_ACTIVATE'];
break;
}
$template->assign_vars(array(
'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
'USERNAME' => $data['username'],
@ -474,8 +476,7 @@ class ucp_register
'S_COPPA' => $coppa,
'S_HIDDEN_FIELDS' => $s_hidden_fields,
'S_UCP_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register'),
)
);
));
//
$user->profile_fields = array();

View file

@ -677,7 +677,7 @@ function database_update_info()
// No changes from 3.0.5-RC1 to 3.0.5
'3.0.5-RC1' => array(),
// No changes from 3.0.5
'3.0.5' => array(),
);
@ -1015,13 +1015,12 @@ function change_database_data(&$no_updates, $version)
// No changes from 3.0.5-RC1 to 3.0.5
case '3.0.5-RC1':
break;
case '3.0.5':
// TODO: smarter detection here; problem without GD.
set_config('captcha_plugin', 'phpbb_captcha_nogd');
$no_updates = false;
break;
}
}

View file

@ -257,7 +257,7 @@ $lang = array_merge($lang, array(
'CAPTCHA_NO_GD' => 'CAPTCHA without GD',
'CAPTCHA_PREVIEW_MSG' => 'Your changes to the visual confirmation setting were not saved. This is just a preview.',
'CAPTCHA_PREVIEW_EXPLAIN' => 'The CAPTCHA as it would look like using the current selection.',
'CAPTCHA_SELECT' => 'Installed CAPTCHA plugins',
'CAPTCHA_SELECT_EXPLAIN' => 'The dropdown holds the CAPTCHA plugins recognized by the board. Gray entries are not available right now and might need configuration prior to use.',
'CAPTCHA_CONFIGURE' => 'Configure CAPTCHAs',

View file

@ -51,7 +51,7 @@ if ($config['enable_post_confirm'] && !$user->data['is_registered'])
$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
$captcha->init(CONFIRM_POST);
}
// Was cancel pressed? If so then redirect to the appropriate page
if ($cancel || ($current_time - $lastclick < 2 && $submit))
{
@ -1016,10 +1016,12 @@ if ($submit || $preview || $refresh)
}
$redirect_url = submit_post($mode, $post_data['post_subject'], $post_data['username'], $post_data['topic_type'], $poll, $data, $update_message);
if ($config['enable_post_confirm'] && !$user->data['is_registered'] && in_array($mode, array('quote', 'post', 'reply')))
{
$captcha->reset();
}
// Check the permissions for post approval, as well as the queue trigger where users are put on approval with a post count lower than specified. Moderators are not affected.
if ((($config['enable_queue_trigger'] && $user->data['user_posts'] < $config['queue_trigger_posts']) || !$auth->acl_get('f_noapprove', $data['forum_id'])) && !$auth->acl_get('m_approve', $data['forum_id']))
{
@ -1242,7 +1244,6 @@ if ($config['enable_post_confirm'] && !$user->data['is_registered'] && $solved_c
{
$captcha->reset();
$template->assign_vars(array(
'S_CONFIRM_CODE' => true,
'CONFIRM' => $captcha->get_template(),