Zeile 41 | Zeile 41 |
---|
* 1 = Default CAPTCHA * 2 = reCAPTCHA * 3 = Are You a Human
|
* 1 = Default CAPTCHA * 2 = reCAPTCHA * 3 = Are You a Human
|
| * 4 = NoCATPCHA reCAPTCHA
|
* * @var int */
| * * @var int */
|
Zeile 59 | Zeile 60 |
---|
* @var string */ public $server = '';
|
* @var string */ public $server = '';
|
/** * CAPTCHA Secure Server URL * * @var string */ public $secure_server = '';
| |
/** * CAPTCHA Verify Server
| /** * CAPTCHA Verify Server
|
Zeile 73 | Zeile 67 |
---|
* @var string */ public $verify_server = '';
|
* @var string */ public $verify_server = '';
|
|
|
/** * Are You a Human configuration *
| /** * Are You a Human configuration *
|
Zeile 84 | Zeile 78 |
---|
public $ayah_scoring_key = ''; public $ayah_debug_mode = ''; public $ayah_use_curl = '';
|
public $ayah_scoring_key = ''; public $ayah_debug_mode = ''; public $ayah_use_curl = '';
|
|
|
/** * HTML of the built CAPTCHA *
| /** * HTML of the built CAPTCHA *
|
Zeile 99 | Zeile 93 |
---|
*/ public $errors = array();
|
*/ public $errors = array();
|
| /** * @param bool $build * @param string $template */
|
function __construct($build = false, $template = "") {
|
function __construct($build = false, $template = "") {
|
global $mybb;
| global $mybb, $plugins;
|
$this->type = $mybb->settings['captchaimage'];
|
$this->type = $mybb->settings['captchaimage'];
|
| $args = array( 'this' => &$this, 'build' => &$build, 'template' => &$template, );
$plugins->run_hooks('captcha_build_start', $args);
|
// Prepare the build template if($template) { $this->captcha_template = $template;
|
// Prepare the build template if($template) { $this->captcha_template = $template;
|
|
|
if($this->type == 2) { $this->captcha_template .= "_recaptcha"; } else if($this->type == 3)
|
if($this->type == 2) { $this->captcha_template .= "_recaptcha"; } else if($this->type == 3)
|
{
| {
|
$this->captcha_template .= "_ayah";
|
$this->captcha_template .= "_ayah";
|
| } else if($this->type == 4){ $this->captcha_template .= "_nocaptcha";
|
} }
| } }
|
Zeile 138 | Zeile 147 |
---|
else if($this->type == 2 && $mybb->settings['captchapublickey'] && $mybb->settings['captchaprivatekey']) { // We want to use reCAPTCHA, set the server options
|
else if($this->type == 2 && $mybb->settings['captchapublickey'] && $mybb->settings['captchaprivatekey']) { // We want to use reCAPTCHA, set the server options
|
$this->server = "http://www.google.com/recaptcha/api"; $this->secure_server = "https://www.google.com/recaptcha/api";
| $this->server = "//www.google.com/recaptcha/api";
|
$this->verify_server = "www.google.com";
|
$this->verify_server = "www.google.com";
|
| if($build == true) { $this->build_recaptcha(); } } else if($this->type == 4 && $mybb->settings['captchapublickey'] && $mybb->settings['captchaprivatekey']) { // We want to use reCAPTCHA, set the server options $this->server = "//www.google.com/recaptcha/api.js"; $this->verify_server = "https://www.google.com/recaptcha/api/siteverify";
|
if($build == true) {
| if($build == true) {
|
Zeile 152 | Zeile 171 |
---|
if(!function_exists("imagecreatefrompng")) { // We want to use the default CAPTCHA, but it's not installed
|
if(!function_exists("imagecreatefrompng")) { // We want to use the default CAPTCHA, but it's not installed
|
return false;
| return;
|
} else if($build == true) { $this->build_captcha();
|
} else if($build == true) { $this->build_captcha();
|
} }
// Plugin hook
| } }
$plugins->run_hooks('captcha_build_end', $args);
|
}
|
}
|
| /** * @param bool $return Not used */
|
function build_captcha($return = false) { global $db, $lang, $templates, $theme, $mybb;
| function build_captcha($return = false) { global $db, $lang, $templates, $theme, $mybb;
|
Zeile 189 | Zeile 211 |
---|
// This will build a reCAPTCHA $server = $this->server; $public_key = $mybb->settings['captchapublickey'];
|
// This will build a reCAPTCHA $server = $this->server; $public_key = $mybb->settings['captchapublickey'];
|
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { // Use secure server if HTTPS $server = $this->secure_server; }
| |
eval("\$this->html = \"".$templates->get($this->captcha_template, 1, 0)."\";"); //eval("\$this->html = \"".$templates->get("member_register_regimage_recaptcha")."\";");
| eval("\$this->html = \"".$templates->get($this->captcha_template, 1, 0)."\";"); //eval("\$this->html = \"".$templates->get("member_register_regimage_recaptcha")."\";");
|
Zeile 221 | Zeile 237 |
---|
} }
|
} }
|
| /** * @return string */
|
function build_hidden_captcha() { global $db, $mybb, $templates;
| function build_hidden_captcha() { global $db, $mybb, $templates;
|
Zeile 228 | Zeile 247 |
---|
$field = array();
if($this->type == 1)
|
$field = array();
if($this->type == 1)
|
{ // Names
| { // Names
|
$hash = "imagehash"; $string = "imagestring";
|
$hash = "imagehash"; $string = "imagestring";
|
// Values
| // Values
|
$field['hash'] = $db->escape_string($mybb->input['imagehash']); $field['string'] = $db->escape_string($mybb->input['imagestring']); }
| $field['hash'] = $db->escape_string($mybb->input['imagehash']); $field['string'] = $db->escape_string($mybb->input['imagestring']); }
|
Zeile 242 | Zeile 261 |
---|
// Names $hash = "recaptcha_challenge_field"; $string = "recaptcha_response_field";
|
// Names $hash = "recaptcha_challenge_field"; $string = "recaptcha_response_field";
|
|
|
// Values $field['hash'] = $mybb->input['recaptcha_challenge_field']; $field['string'] = $mybb->input['recaptcha_response_field'];
|
// Values $field['hash'] = $mybb->input['recaptcha_challenge_field']; $field['string'] = $mybb->input['recaptcha_response_field'];
|
}
| }
|
else if($this->type == 3) { // Are You a Human can't be built as a hidden captcha
|
else if($this->type == 3) { // Are You a Human can't be built as a hidden captcha
|
continue;
| return '';
|
}
eval("\$this->html = \"".$templates->get("post_captcha_hidden")."\";"); return $this->html;
|
}
eval("\$this->html = \"".$templates->get("post_captcha_hidden")."\";"); return $this->html;
|
}
| }
|
|
|
| /** * @return bool */
|
function validate_captcha() {
|
function validate_captcha() {
|
global $db, $lang, $mybb;
// Plugin hook
| global $db, $lang, $mybb, $session, $plugins;
$plugins->run_hooks('captcha_validate_start', $this);
|
if($this->type == 1) {
| if($this->type == 1) {
|
Zeile 269 | Zeile 291 |
---|
$imagehash = $db->escape_string($mybb->input['imagehash']); $imagestring = $db->escape_string(my_strtolower($mybb->input['imagestring']));
|
$imagehash = $db->escape_string($mybb->input['imagehash']); $imagestring = $db->escape_string(my_strtolower($mybb->input['imagestring']));
|
$query = $db->simple_select("captcha", "*", "imagehash = '{$imagehash}' AND LOWER(imagestring) = '{$imagestring}'");
| switch($db->type) { case 'mysql': case 'mysqli': $field = 'imagestring'; break; default: $field = 'LOWER(imagestring)'; break; }
$query = $db->simple_select("captcha", "*", "imagehash = '{$imagehash}' AND {$field} = '{$imagestring}'");
|
$imgcheck = $db->fetch_array($query);
if(!$imgcheck)
| $imgcheck = $db->fetch_array($query);
if(!$imgcheck)
|
Zeile 331 | Zeile 364 |
---|
{ // We got it wrong! Oh no... $this->set_error($lang->invalid_captcha_verify);
|
{ // We got it wrong! Oh no... $this->set_error($lang->invalid_captcha_verify);
|
| } } } } elseif($this->type == 4) { $response = $mybb->input['g-recaptcha-response']; if(!$response || strlen($response) == 0) { $this->set_error($lang->invalid_nocaptcha); } else { // We have a noCAPTCHA to handle // Contact Google and see if our reCAPTCHA was successful $response = fetch_remote_file($this->verify_server, array( 'secret' => $mybb->settings['captchaprivatekey'], 'remoteip' => $session->ipaddress, 'response' => $response ));
if($response == false) { $this->set_error($lang->invalid_nocaptcha_transmit); } else { $answer = json_decode($response, true);
if($answer['success'] != 'true') { // We got it wrong! Oh no... $this->set_error($lang->invalid_nocaptcha);
|
} } }
| } } }
|
Zeile 354 | Zeile 420 |
---|
} }
|
} }
|
// Plugin hook
| $plugins->run_hooks('captcha_validate_end', $this);
|
if(count($this->errors) > 0) {
| if(count($this->errors) > 0) {
|
Zeile 368 | Zeile 434 |
---|
function invalidate_captcha() {
|
function invalidate_captcha() {
|
global $db, $mybb;
| global $db, $mybb, $plugins;
|
if($this->type == 1) {
| if($this->type == 1) {
|
Zeile 381 | Zeile 447 |
---|
} // Not necessary for reCAPTCHA or Are You a Human
|
} // Not necessary for reCAPTCHA or Are You a Human
|
// Plugin hook
| $plugins->run_hooks('captcha_invalidate_end', $this);
|
}
/** * Add an error to the error array.
|
}
/** * Add an error to the error array.
|
*/
| * * @param string $error * @param string $data */
|
function set_error($error, $data='') { $this->errors[$error] = array(
| function set_error($error, $data='') { $this->errors[$error] = array(
|
Zeile 398 | Zeile 467 |
---|
/** * Returns the error(s) that occurred when handling data * in a format that MyBB can handle.
|
/** * Returns the error(s) that occurred when handling data * in a format that MyBB can handle.
|
* * @return An array of errors in a MyBB format. */
| * * @return array An array of errors in a MyBB format. */
|
function get_errors() { global $lang;
|
function get_errors() { global $lang;
|
| $errors = array();
|
foreach($this->errors as $error) { $lang_string = $error['error_code'];
| foreach($this->errors as $error) { $lang_string = $error['error_code'];
|
Zeile 412 | Zeile 482 |
---|
if(!$lang_string) { if($lang->invalid_captcha_verify)
|
if(!$lang_string) { if($lang->invalid_captcha_verify)
|
{
| {
|
$lang_string = 'invalid_captcha_verify'; } else
| $lang_string = 'invalid_captcha_verify'; } else
|
Zeile 446 | Zeile 516 |
---|
return $errors; }
|
return $errors; }
|
| /** * @param array $data * * @return string */
|
private function _qsencode($data) { $req = '';
| private function _qsencode($data) { $req = '';
|