Version 3.2.3

This commit is contained in:
Neo committed 2025-12-19 00:34:03 -08:00
1 parent ae5c01cc78
commit 78706903a2
2641 files changed
+228363 -201264

No files matched your search

@@ -39,68 +39,83 @@
*/
define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
define("RECAPTCHA_VERIFY_SERVER", "www.google.com");
define("RECAPTCHA_VERIFY_SERVER", "http://www.google.com");
/**
* @file recaptcha.php Plugin for reCAPTCHA
*~TERABYTE_DOC_READY~
* $Copyright: (c) 2001 - 2011 Invision Power Services, Inc.$
* $License: This is NULLED!
* $Author: bfarber $
* @since Friday 19th May 2006 17:33
* $LastChangedDate: 2011-03-09 18:12:09 -0500 (Wed, 09 Mar 2011) $
* @version v3.2.3
* $Revision: 8004 $
*/
/**
*
* @class captchaPlugin
* @brief Plugin for reCAPTCHA
* @note This plugin is automatically loaded by classCaptcha class based on the CAPTCHA setting
*
*/
class captchaPlugin
{
/**#@+
* Registry objects
/**
* Registry Object Shortcuts
*
* @var object
* @var $registry
* @var $DB
* @var $settings
* @var $member
*/
public $registry;
public $DB;
public $settings;
public $request;
public $lang;
public $member;
public $memberData;
/**#@-*/
/**
* Error code from reCAPTCHA
* String that stores the error code from reCAPTCHA (if any)
*
* @var string
* @var $error
*/
public $error;
/**
* reCAPTCHA public key
* String that stores reCAPTCHA public key
*
* @var string
* @var $public_key
*/
public $public_key;
/**
* reCAPTCHA private key
* String that stores reCAPTCHA private key
*
* @var string
* @var $private_key
*/
public $private_key;
/**
* Flag whether to use SSL or not
* Integer flag that stores whether to use SSL or not for the connection
*
* @var string
* @var $private_key
*/
public $useSSL;
/**
* Constructor
*
* @access public
* @param object Registry Object
* @return void
* @param object $registry Registry Object
* @return @e void
*/
public function __construct( ipsRegistry $registry )
{
$this->registry = $registry;
$this->DB = $this->registry->DB();
$this->settings =& $this->registry->fetchSettings();
$this->request =& $this->registry->fetchRequest();
$this->lang = $this->registry->getClass('class_localization');
$this->member = $this->registry->member();
$this->memberData =& $this->registry->member()->fetchMemberData();
/* Settings */
$this->public_key = trim( $this->settings['recaptcha_public_key'] );
@@ -109,12 +124,16 @@ class captchaPlugin
}
/**
* Gets the challenge HTML (javascript and non-javascript version).
* Returns the reCAPTCHA template (javascript and non-javascript version).
* This is called from the browser, and the resulting reCAPTCHA HTML widget
* is embedded within the HTML form it was called from.
*
* @access public
* @return string Form HTML to display
* @return @e string HTML template for reCAPTCHA form
*
* <b>Example Usage:</b>
* @code
* $recaptchaForm = $this->getTemplate();
* @endcode
*/
public function getTemplate()
{
@@ -155,17 +174,21 @@ class captchaPlugin
}
/**
* Validate the input code
* Validates the entered captcha code
*
* @access public
* @return boolean Validation successful
* @since 1.0
* @return @e boolean TRUE if the code is valid otherwise FALSE
*
* <b>Example Usage:</b>
* @code
* $isValid = $this->validate();
* @endcode
*/
public function validate()
{
if ( !$this->private_key )
{
return '';
$this->error = 'no_private_key';
return FALSE;
}
$captcha_unique_id = $_REQUEST['recaptcha_challenge_field'];
@@ -176,16 +199,17 @@ class captchaPlugin
return false;
}
$response = $this->_recaptchaPost( RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
array (
'privatekey' => $this->private_key,
'remoteip' => $this->member->ip_address,
'challenge' => $captcha_unique_id,
'response' => $captcha_input
)
);
$classToLoad = IPSLib::loadLibrary( IPS_KERNEL_PATH . '/classFileManagement.php', 'classFileManagement' );
$communication = new $classToLoad();
$answers = explode( "\n", $response[1] );
$response = $communication->postFileContents( RECAPTCHA_VERIFY_SERVER . "/recaptcha/api/verify", array(
'privatekey' => $this->private_key,
'remoteip' => $this->member->ip_address,
'challenge' => $captcha_unique_id,
'response' => $captcha_input
) );
$answers = explode( "\n", $response );
if ( trim($answers[0]) == 'true' )
{
@@ -196,88 +220,8 @@ class captchaPlugin
/**
* It's an error
*/
$this->error = $answers[1];
$this->error = $answers[1];
return FALSE;
}
}
/**
* Gets a URL where the user can sign up for reCAPTCHA. If your application
* has a configuration page where you enter a key, you should provide a link
* using this function.
*
* @access public
* @param string $domain The domain where the page is hosted
* @param string $appname The name of your application
*/
public function getSignupUrl( $domain = null, $appname = null )
{
return "https://www.google.com/recaptcha/admin/create?" . $this->_encodeQueryString( array( 'domain' => $domain, 'app' => $appname ) );
}
/**
* Submits an HTTP POST to a reCAPTCHA server
*
* @access private
* @param string $host
* @param string $path
* @param array $data
* @param int port
* @return array response
*/
private function _recaptchaPost( $host, $path, $data, $port = 80 )
{
$req = $this->_encodeQueryString( $data );
$http_request = "POST $path HTTP/1.0\r\n";
$http_request .= "Host: $host\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
$http_request .= "Content-Length: " . strlen($req) . "\r\n";
$http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
$http_request .= "\r\n";
$http_request .= $req;
$response = '';
if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) )
{
return false;
}
fwrite($fs, $http_request);
while ( !feof($fs) )
{
$response .= fgets($fs, 1160); // One TCP-IP packet
}
fclose($fs);
$response = explode( "\r\n\r\n", $response, 2 );
return $response;
}
/**
* Encode array of data into a query string
*
* @access private
* @param array $data
* @return string query string
*/
private function _encodeQueryString( $data )
{
$req = "";
foreach ( $data as $key => $value )
{
$req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
}
// Cut the last '&'
$req = substr( $req, 0, strlen($req)-1 );
return $req;
}
}
}