aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php')
-rw-r--r--phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php150
1 files changed, 77 insertions, 73 deletions
diff --git a/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php b/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php
index 2593f1259c..f9bd345f02 100644
--- a/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php
+++ b/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php
@@ -1,8 +1,8 @@
-<?
+<?php
/**
*
* @package VC
-* @version $Id: $
+* @version $Id: constants.php 8818 2008-09-04 14:06:43Z acydburn $
* @copyright (c) 2006 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
@@ -16,9 +16,8 @@ if (!defined('IN_PHPBB'))
exit;
}
-
// 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
{
@@ -27,18 +26,17 @@ class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plu
protected $challenge;
protected $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', '');
}
-
-
+
public static function get_instance()
{
return new phpbb_recaptcha();
@@ -46,25 +44,25 @@ class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plu
static function is_available()
{
- global $config, $user;
+ global $config, $user;
$user->add_lang('recaptcha');
return (isset($config['recaptcha_pubkey']) && !empty($config['recaptcha_pubkey']));
}
-
+
static function get_name()
{
return 'CAPTCHA_RECAPTCHA';
}
-
+
static 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',
@@ -108,47 +106,47 @@ class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plu
}
}
-
-
+
+
// 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' => self::recaptcha_server,
'RECAPTCHA_PUBKEY' => isset($config['recaptcha_pubkey']) ? $config['recaptcha_pubkey'] : '',
'RECAPTCHA_ERRORGET' => '',
'S_RECAPTCHA_AVAILABLE' => self::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)
{
@@ -157,17 +155,17 @@ class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plu
$hidden_fields['confirm_id'] = $this->confirm_id;
return $hidden_fields;
}
-
+
function uninstall()
{
self::garbage_collect(0);
}
-
+
function install()
{
return;
}
-
+
function validate()
{
if (!parent::validate())
@@ -179,7 +177,7 @@ class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plu
return $this->recaptcha_check_answer();
}
}
-
+
// 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
- * @param string $host
- * @param string $path
- * @param array $data
- * @param int port
- * @return array response
- */
- protected 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
+ */
+ protected function _recaptcha_http_post($host, $path, $data, $port = 80)
{
$req = $this->_recaptcha_qsencode ($data);
@@ -236,52 +234,56 @@ class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plu
$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
- */
- protected 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
+ */
+ protected 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)
+
+ // 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",
- 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')
+ $response = $this->_recaptcha_http_post(self::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')
{
$this->solved = true;
return false;
}
- else
+ else
{
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
- * @param $data - array of string elements to be encoded
- * @return string - encoded request
- */
- protected 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
+ */
+ protected 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;
}
}
+?> \ No newline at end of file