forked from leftypol/leftypol
Add dynamic captcha support
This commit is contained in:
parent
81f5c70681
commit
483d553fc0
4 changed files with 60 additions and 7 deletions
26
post.php
26
post.php
|
@ -74,14 +74,21 @@ function strip_markup($post_body)
|
|||
*/
|
||||
function check_recaptcha($secret, $response, $remote_ip)
|
||||
{
|
||||
$resp = json_decode(file_get_contents(
|
||||
sprintf(
|
||||
if ($remote_ip !== null) {
|
||||
$req = sprintf(
|
||||
'https://www.google.com/recaptcha/api/siteverify?secret=%s&response=%s&remoteip=%s',
|
||||
$secret,
|
||||
urlencode($response),
|
||||
$remote_ip
|
||||
)
|
||||
), true);
|
||||
);
|
||||
} else {
|
||||
$req = sprintf(
|
||||
'https://www.google.com/recaptcha/api/siteverify?secret=%s&response=%s&remoteip=%s',
|
||||
$secret,
|
||||
urlencode($response),
|
||||
);
|
||||
}
|
||||
$resp = json_decode(file_get_contents($req), true);
|
||||
return !!$resp['success'];
|
||||
}
|
||||
|
||||
|
@ -683,8 +690,17 @@ function handle_post()
|
|||
|
||||
|
||||
if (!$dropped_post) {
|
||||
if ($config['dynamic_captcha'] && $_SERVER['REMOTE_ADDR'] === '127.0.0.1' && $config['recaptcha']) {
|
||||
if (!isset($_POST['g-recaptcha-response'])) {
|
||||
error($config['error']['bot']);
|
||||
}
|
||||
if (!check_recaptcha($config['recaptcha_private'], $_POST['g-recaptcha-response'], null)) {
|
||||
error($config['error']['captcha']);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for CAPTCHA right after opening the board so the "return" link is in there.
|
||||
if ($config['recaptcha']) {
|
||||
if (!$config['dynamic_captcha'] && $config['recaptcha']) {
|
||||
if (!isset($_POST['g-recaptcha-response'])) {
|
||||
error($config['error']['bot']);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue