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); define('PHPBB_ACM_MEMCACHE_COMPRESS', false);
} }
if (!defined('PHPBB_ACM_MEMCACHE_HOST'))
{
define('PHPBB_ACM_MEMCACHE_HOST', 'localhost');
}
/** /**
* ACM for Memcached * ACM for Memcached
* @package acm * @package acm
@ -48,11 +53,6 @@ class acm extends acm_memory
// Call the parent constructor // Call the parent constructor
parent::acm_memory(); 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 = new Memcache;
$this->memcache->connect(PHPBB_ACM_MEMCACHE_HOST, PHPBB_ACM_MEMCACHE_PORT); $this->memcache->connect(PHPBB_ACM_MEMCACHE_HOST, PHPBB_ACM_MEMCACHE_PORT);
$this->flags = (PHPBB_ACM_MEMCACHE_COMPRESS) ? MEMCACHE_COMPRESSED : 0; $this->flags = (PHPBB_ACM_MEMCACHE_COMPRESS) ? MEMCACHE_COMPRESSED : 0;

View file

@ -156,7 +156,7 @@ class acm_memory
while (($entry = readdir($dir)) !== false) 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; continue;
} }

View file

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

View file

@ -10,8 +10,6 @@
/** /**
* @ignore * @ignore
*/ */
if (!defined('IN_PHPBB')) if (!defined('IN_PHPBB'))
{ {
exit; exit;
@ -52,6 +50,7 @@ class acp_captcha
else else
{ {
$captchas = phpbb_captcha_factory::get_captcha_types(); $captchas = phpbb_captcha_factory::get_captcha_types();
$config_vars = array( $config_vars = array(
'enable_confirm' => 'REG_ENABLE', 'enable_confirm' => 'REG_ENABLE',
'enable_post_confirm' => 'POST_ENABLE', 'enable_post_confirm' => 'POST_ENABLE',
@ -68,10 +67,12 @@ class acp_captcha
if ($submit && check_form_key($form_key)) if ($submit && check_form_key($form_key))
{ {
$config_vars = array_keys($config_vars); $config_vars = array_keys($config_vars);
foreach ($config_vars as $config_var) foreach ($config_vars as $config_var)
{ {
set_config($config_var, request_var($config_var, false)); set_config($config_var, request_var($config_var, false));
} }
if ($selected !== $config['captcha_plugin']) if ($selected !== $config['captcha_plugin'])
{ {
// sanity check // sanity check
@ -79,9 +80,11 @@ class acp_captcha
{ {
$old_captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']); $old_captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
$old_captcha->uninstall(); $old_captcha->uninstall();
set_config('captcha_plugin', $selected); set_config('captcha_plugin', $selected);
$new_captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']); $new_captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
$old_captcha->install(); $new_captcha->install();
add_log('admin', 'LOG_CONFIG_VISUAL'); add_log('admin', 'LOG_CONFIG_VISUAL');
} }
else else
@ -103,10 +106,11 @@ class acp_captcha
$current = ($selected !== false && $value == $selected) ? ' selected="selected"' : ''; $current = ($selected !== false && $value == $selected) ? ' selected="selected"' : '';
$captcha_select .= '<option value="' . $value . '"' . $current . '>' . $user->lang[$title] . '</option>'; $captcha_select .= '<option value="' . $value . '"' . $current . '>' . $user->lang[$title] . '</option>';
} }
foreach ($captchas['unavailable'] as $value => $title) foreach ($captchas['unavailable'] as $value => $title)
{ {
$current = ($selected !== false && $value == $selected) ? ' selected="selected"' : ''; $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); $demo_captcha = phpbb_captcha_factory::get_instance($selected);
@ -121,11 +125,9 @@ class acp_captcha
'CAPTCHA_SELECT' => $captcha_select, 'CAPTCHA_SELECT' => $captcha_select,
)); ));
} }
} }
} }
/** /**
* Entry point for delivering image CAPTCHAs in the ACP. * Entry point for delivering image CAPTCHAs in the ACP.
*/ */
@ -136,13 +138,10 @@ class acp_captcha
$captcha = phpbb_captcha_factory::get_instance($selected); $captcha = phpbb_captcha_factory::get_instance($selected);
$captcha->init(CONFIRM_REG); $captcha->init(CONFIRM_REG);
$captcha->execute_demo(); $captcha->execute_demo();
garbage_collection(); garbage_collection();
exit_handler(); 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']) if ($config['max_login_attempts'] && $row['user_login_attempts'] >= $config['max_login_attempts'])
{ {
$confirm_id = request_var('confirm_id', ''); $confirm_id = request_var('confirm_id', '');
$confirm_code = request_var('confirm_code', '');
// Visual Confirmation handling // Visual Confirmation handling
if (!$confirm_id) if (!$confirm_id)
@ -84,12 +83,13 @@ function login_db(&$username, &$password)
$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']); $captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
$captcha->init(CONFIRM_LOGIN); $captcha->init(CONFIRM_LOGIN);
$vc_response = $captcha->validate(); $vc_response = $captcha->validate();
if ($vc_response) if ($vc_response)
{ {
return array( return array(
'status' => LOGIN_ERROR_ATTEMPTS, 'status' => LOGIN_ERROR_ATTEMPTS,
'error_msg' => 'LOGIN_ERROR_ATTEMPTS', 'error_msg' => 'LOGIN_ERROR_ATTEMPTS',
'user_row' => $row, 'user_row' => $row,
); );
} }
} }

View file

@ -16,8 +16,11 @@ if (!defined('IN_PHPBB'))
exit; 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 class phpbb_captcha_factory
{ {
/** /**
@ -57,9 +60,10 @@ class phpbb_captcha_factory
{ {
global $phpbb_root_path, $phpEx; global $phpbb_root_path, $phpEx;
$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');
@ -74,6 +78,7 @@ class phpbb_captcha_factory
{ {
include($phpbb_root_path . "includes/captcha/plugins/$file"); include($phpbb_root_path . "includes/captcha/plugins/$file");
} }
if (call_user_func(array($name, 'is_available'))) if (call_user_func(array($name, 'is_available')))
{ {
$captchas['available'][$name] = call_user_func(array($name, 'get_name')); $captchas['available'][$name] = call_user_func(array($name, 'get_name'));

View file

@ -8,9 +8,11 @@
* *
*/ */
/** /**
* Wave3D CAPTCHA by Robert Hetzler * Wave3D CAPTCHA
*
* @author Robert Hetzler
* @package VC
*/ */
class captcha class captcha
{ {
@ -47,7 +49,8 @@ class captcha
$plane_x = 100; $plane_x = 100;
$plane_y = 30; $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 is the 4 points in img_space that correspond to the corners of the plane in 3-space
$box = array( $box = array(
'upper_left' => array( 'upper_left' => array(
@ -63,11 +66,11 @@ class captcha
'y' => mt_rand($img_y - 0, $img_y - 15) '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 // TODO
$background = imagecolorallocate($img, mt_rand(155, 255), mt_rand(155, 255), mt_rand(155, 255)); $background = imagecolorallocate($img, mt_rand(155, 255), mt_rand(155, 255), mt_rand(155, 255));

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 class phpbb_default_captcha
{ {
@ -29,7 +31,6 @@ class phpbb_default_captcha
var $type; var $type;
var $solved = false; var $solved = false;
function init($type) function init($type)
{ {
global $config, $db, $user; global $config, $db, $user;
@ -50,14 +51,13 @@ class phpbb_default_captcha
{ {
$this->regenerate_code(); $this->regenerate_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(CAPTCHA_MIN_CHARS, CAPTCHA_MAX_CHARS));
$this->seed = hexdec(substr(unique_id(), 4, 10)); $this->seed = hexdec(substr(unique_id(), 4, 10));
// compute $seed % 0x7fffffff // compute $seed % 0x7fffffff
@ -67,7 +67,6 @@ class phpbb_default_captcha
$captcha->execute($this->code, $this->seed); $captcha->execute($this->code, $this->seed);
} }
function execute() function execute()
{ {
if (empty($this->code)) if (empty($this->code))
@ -82,7 +81,6 @@ class phpbb_default_captcha
$captcha->execute($this->code, $this->seed); $captcha->execute($this->code, $this->seed);
} }
function get_template() function get_template()
{ {
global $config, $user, $template, $phpEx, $phpbb_root_path; global $config, $user, $template, $phpEx, $phpbb_root_path;
@ -108,6 +106,7 @@ class phpbb_default_captcha
$template->set_filenames(array( $template->set_filenames(array(
'captcha_demo' => 'captcha_default_acp_demo.html') 'captcha_demo' => 'captcha_default_acp_demo.html')
); );
// acp_captcha has a delivery function; let's use it // acp_captcha has a delivery function; let's use it
$template->assign_vars(array( $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_IMAGE' => append_sid($phpbb_admin_path . 'index.' . $phpEx . '?captcha_demo=1&amp;mode=visual&amp;i=' . $id . '&amp;select_captcha=' . $this->get_class_name()),
@ -135,10 +134,10 @@ class phpbb_default_captcha
global $db, $config; global $db, $config;
$sql = 'SELECT DISTINCT c.session_id $sql = 'SELECT DISTINCT c.session_id
FROM ' . CONFIRM_TABLE . ' c FROM ' . CONFIRM_TABLE . ' c
LEFT JOIN ' . SESSIONS_TABLE . ' s ON (c.session_id = s.session_id) LEFT JOIN ' . SESSIONS_TABLE . ' s ON (c.session_id = s.session_id)
WHERE s.session_id IS NULL' . WHERE s.session_id IS NULL' .
((empty($type)) ? '' : ' AND c.confirm_type = ' . (int) $type); ((empty($type)) ? '' : ' AND c.confirm_type = ' . (int) $type);
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
if ($row = $db->sql_fetchrow($result)) if ($row = $db->sql_fetchrow($result))
@ -162,7 +161,7 @@ class phpbb_default_captcha
function uninstall() function uninstall()
{ {
self::garbage_collect(0); $this->garbage_collect(0);
} }
function install() function install()
@ -194,7 +193,7 @@ class phpbb_default_captcha
if (strlen($error)) if (strlen($error))
{ {
// okay, inorect answer. Let's ask a new question // okay, incorrect answer. Let's ask a new question.
$this->generate_code(); $this->generate_code();
return $error; return $error;
} }
@ -204,7 +203,6 @@ class phpbb_default_captcha
} }
} }
/** /**
* 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.
*/ */
@ -212,7 +210,7 @@ class phpbb_default_captcha
{ {
global $db, $user; 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->confirm_id = md5(unique_id($user->ip));
$this->seed = hexdec(substr(unique_id(), 4, 10)); $this->seed = hexdec(substr(unique_id(), 4, 10));
$this->solved = false; $this->solved = false;
@ -236,11 +234,12 @@ class phpbb_default_captcha
{ {
global $db, $user; 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->seed = hexdec(substr(unique_id(), 4, 10));
$this->solved = false; $this->solved = false;
// compute $seed % 0x7fffffff // compute $seed % 0x7fffffff
$this->seed -= 0x7fffffff * floor($this->seed / 0x7fffffff); $this->seed -= 0x7fffffff * floor($this->seed / 0x7fffffff);
$sql = 'UPDATE ' . CONFIRM_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array( $sql = 'UPDATE ' . CONFIRM_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array(
'code' => (string) $this->code, 'code' => (string) $this->code,
'seed' => (int) $this->seed)) . ' 'seed' => (int) $this->seed)) . '
@ -256,22 +255,24 @@ class phpbb_default_captcha
function load_code() function load_code()
{ {
global $db, $user; global $db, $user;
$sql = 'SELECT code, seed $sql = 'SELECT code, seed
FROM ' . CONFIRM_TABLE . " FROM ' . CONFIRM_TABLE . "
WHERE confirm_id = '" . $db->sql_escape($this->confirm_id) . "' WHERE confirm_id = '" . $db->sql_escape($this->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;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
if ($row) if ($row)
{ {
$this->code = $row['code']; $this->code = $row['code'];
$this->seed = $row['seed']; $this->seed = $row['seed'];
return true; return true;
} }
return false;
return false;
} }
function check_code() function check_code()
@ -293,9 +294,9 @@ class phpbb_default_captcha
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);
} }
@ -304,9 +305,9 @@ class phpbb_default_captcha
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) . "'
AND confirm_type = " . $this->type; AND confirm_type = " . $this->type;
$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);
@ -314,20 +315,18 @@ class phpbb_default_captcha
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();
} }
} }
?> ?>

View file

@ -24,6 +24,9 @@ if (!class_exists('phpbb_default_captcha'))
include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx); include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
} }
/**
* @package VC
*/
class phpbb_captcha_gd extends phpbb_default_captcha class phpbb_captcha_gd extends phpbb_default_captcha
{ {
function phpbb_captcha_gd() function phpbb_captcha_gd()
@ -80,7 +83,6 @@ class phpbb_captcha_gd extends phpbb_default_captcha
'captcha_gd' => 'CAPTCHA_GD', 'captcha_gd' => 'CAPTCHA_GD',
); );
$module->tpl_name = 'captcha_gd_acp'; $module->tpl_name = 'captcha_gd_acp';
$module->page_title = 'ACP_VC_SETTINGS'; $module->page_title = 'ACP_VC_SETTINGS';
$form_key = 'acp_captcha'; $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]; $var = (isset($_REQUEST[$captcha_var])) ? request_var($captcha_var, 0) : $config[$captcha_var];
$template->assign_var($template_var, $var); $template->assign_var($template_var, $var);
} }
$template->assign_vars(array( $template->assign_vars(array(
'CAPTCHA_PREVIEW' => $this->get_demo_template($id), 'CAPTCHA_PREVIEW' => $this->get_demo_template($id),
'CAPTCHA_NAME' => $this->get_class_name(), '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); include_once($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
} }
/**
* @package VC
*/
class phpbb_captcha_gd_wave extends phpbb_default_captcha class phpbb_captcha_gd_wave extends phpbb_default_captcha
{ {

View file

@ -24,6 +24,9 @@ if (!class_exists('phpbb_default_captcha'))
include_once($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx); include_once($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
} }
/**
* @package VC
*/
class phpbb_captcha_nogd extends phpbb_default_captcha class phpbb_captcha_nogd extends phpbb_default_captcha
{ {
@ -49,8 +52,6 @@ class phpbb_captcha_nogd extends phpbb_default_captcha
function get_name() function get_name()
{ {
global $user;
return 'CAPTCHA_NO_GD'; return 'CAPTCHA_NO_GD';
} }
@ -59,7 +60,6 @@ class phpbb_captcha_nogd extends phpbb_default_captcha
return 'phpbb_captcha_nogd'; return 'phpbb_captcha_nogd';
} }
function acp_page($id, &$module) function acp_page($id, &$module)
{ {
global $user; global $user;
@ -68,3 +68,4 @@ class phpbb_captcha_nogd extends phpbb_default_captcha
} }
} }
?>

View file

@ -22,6 +22,9 @@ if (!class_exists('phpbb_default_captcha'))
include_once($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx); include_once($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
} }
/**
* @package VC
*/
class phpbb_recaptcha extends phpbb_default_captcha class phpbb_recaptcha extends phpbb_default_captcha
{ {
var $recaptcha_server = 'http://api.recaptcha.net'; var $recaptcha_server = 'http://api.recaptcha.net';
@ -29,7 +32,6 @@ class phpbb_recaptcha extends phpbb_default_captcha
var $challenge; var $challenge;
var $response; var $response;
function init($type) function init($type)
{ {
global $config, $db, $user; global $config, $db, $user;
@ -40,7 +42,6 @@ class phpbb_recaptcha extends phpbb_default_captcha
$this->response = request_var('recaptcha_response_field', ''); $this->response = request_var('recaptcha_response_field', '');
} }
function get_instance() function get_instance()
{ {
return new phpbb_recaptcha(); return new phpbb_recaptcha();
@ -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] : ''); $var = (isset($_REQUEST[$captcha_var])) ? request_var($captcha_var, '') : ((isset($config[$captcha_var])) ? $config[$captcha_var] : '');
$template->assign_var($template_var, $var); $template->assign_var($template_var, $var);
} }
$template->assign_vars(array( $template->assign_vars(array(
'CAPTCHA_PREVIEW' => $this->get_demo_template($id), 'CAPTCHA_PREVIEW' => $this->get_demo_template($id),
'CAPTCHA_NAME' => $this->get_class_name(), 'CAPTCHA_NAME' => $this->get_class_name(),
@ -111,19 +113,16 @@ class phpbb_recaptcha extends phpbb_default_captcha
} }
} }
// 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;
@ -162,7 +161,7 @@ class phpbb_recaptcha extends phpbb_default_captcha
function uninstall() function uninstall()
{ {
self::garbage_collect(0); $this->garbage_collect(0);
} }
function install() function install()
@ -182,7 +181,6 @@ class phpbb_recaptcha extends phpbb_default_captcha
} }
} }
// Code from here on is based on recaptchalib.php // Code from here on is based on recaptchalib.php
/* /*
* This is a PHP library that handles calling reCAPTCHA. * This is a PHP library that handles calling reCAPTCHA.
@ -218,13 +216,13 @@ class phpbb_recaptcha extends phpbb_default_captcha
*/ */
/** /**
* 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
*/ */
function _recaptcha_http_post($host, $path, $data, $port = 80) function _recaptcha_http_post($host, $path, $data, $port = 80)
{ {
$req = $this->_recaptcha_qsencode ($data); $req = $this->_recaptcha_qsencode ($data);
@ -238,47 +236,51 @@ class phpbb_recaptcha extends phpbb_default_captcha
$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
*/ */
function recaptcha_check_answer ($extra_params = array()) function recaptcha_check_answer($extra_params = array())
{ {
global $config, $user; global $config, $user;
//discard spam submissions //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", $response = $this->_recaptcha_http_post($this->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;
@ -292,21 +294,23 @@ class phpbb_recaptcha extends phpbb_default_captcha
} }
} }
/** /**
* 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
*/ */
function _recaptcha_qsencode ($data) 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;
} }
} }
?>

View file

@ -670,17 +670,17 @@ function phpbb_chmod($filename, $perms = CHMOD_READ)
} }
/** /**
* Test if a file/directory is writable * Test if a file/directory is writable
* *
* This function calls the native is_writable() when not running under * This function calls the native is_writable() when not running under
* Windows and it is not disabled. * Windows and it is not disabled.
* *
* @param string $file Path to perform write test on * @param string $file Path to perform write test on
* @return bool True when the path is writable, otherwise false. * @return bool True when the path is writable, otherwise false.
*/ */
function phpbb_is_writable($file) 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)) if (file_exists($file))
{ {
@ -714,7 +714,6 @@ function phpbb_is_writable($file)
else else
{ {
// file does not exist test if we can write to the directory // file does not exist test if we can write to the directory
$dir = dirname($file); $dir = dirname($file);
if (file_exists($dir) && is_dir($dir) && phpbb_is_writable($dir)) if (file_exists($dir) && is_dir($dir) && phpbb_is_writable($dir))
@ -722,6 +721,7 @@ function phpbb_is_writable($file)
return true; return true;
} }
} }
return false; return false;
} }
else else
@ -2700,14 +2700,12 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
$captcha->init(CONFIRM_LOGIN); $captcha->init(CONFIRM_LOGIN);
$captcha->reset(); $captcha->reset();
$template->assign_vars(array( $template->assign_vars(array(
'S_CONFIRM_CODE' => true, 'S_CONFIRM_CODE' => true,
'CONFIRM' => $captcha->get_template(''), 'CONFIRM' => $captcha->get_template(''),
)); ));
$err = $user->lang[$result['error_msg']]; $err = $user->lang[$result['error_msg']];
break; break;
case LOGIN_ERROR_PASSWORD_CONVERT: 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)) if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $sub_file))
{ {
$avatar_list[$file][$avatar_row_count][$avatar_col_count] = array( $avatar_list[$file][$avatar_row_count][$avatar_col_count] = array(
'file' => rawurlencode ($file) . '/' . rawurlencode ($sub_file), 'file' => rawurlencode($file) . '/' . rawurlencode($sub_file),
'filename' => rawurlencode ($sub_file), 'filename' => rawurlencode($sub_file),
'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $sub_file))), 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $sub_file))),
); );
$avatar_col_count++; $avatar_col_count++;

View file

@ -961,7 +961,6 @@ class session
return; return;
} }
/** /**
* Sets a cookie * Sets a cookie
* *

View file

@ -42,7 +42,8 @@ class ucp_register
$submit = (isset($_POST['submit'])) ? true : false; $submit = (isset($_POST['submit'])) ? true : false;
$change_lang = request_var('change_lang', ''); $change_lang = request_var('change_lang', '');
$user_lang = request_var('lang', $user->lang_name); $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) if ($agreed)
{ {
add_form_key('ucp_register'); add_form_key('ucp_register');
@ -52,7 +53,6 @@ class ucp_register
add_form_key('ucp_register_terms'); add_form_key('ucp_register_terms');
} }
if ($config['enable_confirm']) if ($config['enable_confirm'])
{ {
include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx); include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
@ -198,10 +198,12 @@ class ucp_register
'tz' => array('num', false, -14, 14), 'tz' => array('num', false, -14, 14),
'lang' => array('match', false, '#^[a-z_\-]{2,}$#i'), 'lang' => array('match', false, '#^[a-z_\-]{2,}$#i'),
)); ));
if (!check_form_key('ucp_register')) if (!check_form_key('ucp_register'))
{ {
$error[] = $user->lang['FORM_INVALID']; $error[] = $user->lang['FORM_INVALID'];
} }
// Replace "error" strings with their real, localised form // Replace "error" strings with their real, localised form
$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
@ -216,11 +218,13 @@ class ucp_register
{ {
$captcha->reset(); $captcha->reset();
} }
if ($config['max_reg_attempts'] && $captcha->get_attempt_count() > $config['max_reg_attempts']) if ($config['max_reg_attempts'] && $captcha->get_attempt_count() > $config['max_reg_attempts'])
{ {
$error[] = $user->lang['TOO_MANY_REGISTERS']; $error[] = $user->lang['TOO_MANY_REGISTERS'];
} }
} }
// DNSBL check // DNSBL check
if ($config['check_dnsbl']) if ($config['check_dnsbl'])
{ {
@ -424,7 +428,6 @@ class ucp_register
$confirm_image = ''; $confirm_image = '';
// Visual Confirmation - Show images // Visual Confirmation - Show images
if ($config['enable_confirm']) if ($config['enable_confirm'])
{ {
if ($change_lang || $confirm_refresh) if ($change_lang || $confirm_refresh)
@ -434,13 +437,12 @@ class ucp_register
else else
{ {
$str = ''; $str = '';
} }
$template->assign_vars(array( $template->assign_vars(array(
'L_CONFIRM_EXPLAIN' => sprintf($user->lang['CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>'), 'L_CONFIRM_EXPLAIN' => sprintf($user->lang['CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>'),
'S_CAPTCHA' => $captcha->get_template(), 'S_CAPTCHA' => $captcha->get_template(),
)); ));
} }
// //
@ -474,8 +476,7 @@ class ucp_register
'S_COPPA' => $coppa, 'S_COPPA' => $coppa,
'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_HIDDEN_FIELDS' => $s_hidden_fields,
'S_UCP_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register'), 'S_UCP_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register'),
) ));
);
// //
$user->profile_fields = array(); $user->profile_fields = array();

View file

@ -1016,12 +1016,11 @@ function change_database_data(&$no_updates, $version)
case '3.0.5-RC1': case '3.0.5-RC1':
break; break;
case '3.0.5': case '3.0.5':
// TODO: smarter detection here; problem without GD. // TODO: smarter detection here; problem without GD.
set_config('captcha_plugin', 'phpbb_captcha_nogd'); set_config('captcha_plugin', 'phpbb_captcha_nogd');
$no_updates = false;
break; break;
} }
} }

View file

@ -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); $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'))) if ($config['enable_post_confirm'] && !$user->data['is_registered'] && in_array($mode, array('quote', 'post', 'reply')))
{ {
$captcha->reset(); $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. // 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'])) 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(); $captcha->reset();
$template->assign_vars(array( $template->assign_vars(array(
'S_CONFIRM_CODE' => true, 'S_CONFIRM_CODE' => true,
'CONFIRM' => $captcha->get_template(), 'CONFIRM' => $captcha->get_template(),