diff --git a/includes/common.php b/includes/common.php index c51acef..b19826c 100644 --- a/includes/common.php +++ b/includes/common.php @@ -45,5 +45,39 @@ $iso639[$data[0]] = $data[1]; } fclose($handle); - + + function render_captcha($site_key) { + return '
' . + ''; + } + + function confirm_captcha_response($secret_key, $response) { + // do not check invalid responses + if ($response == null || strlen($response) == 0) { + return false; + } + + $response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret_key . + '&remoteip=' . $_SERVER["REMOTE_ADDR"] . + '&response=' . $response); + + $answer = json_decode($response); + return $answer->success == 'true'; + } ?> diff --git a/includes/header.php b/includes/header.php index 3e2069f..2c21cb9 100644 --- a/includes/header.php +++ b/includes/header.php @@ -16,6 +16,7 @@ + "; } ?> diff --git a/includes/settings.example.php b/includes/settings.example.php index 135be46..77b8946 100644 --- a/includes/settings.example.php +++ b/includes/settings.example.php @@ -14,5 +14,10 @@ $frommail = ''; $askforemail = TRUE; $requireemail = FALSE; - + + // reCAPTCHA settings + $requirecaptcha = FALSE; + $recaptcha_site_key = ''; + $recaptcha_secret_key = ''; + ?> diff --git a/translation.php b/translation.php index 03e61dd..b774624 100644 --- a/translation.php +++ b/translation.php @@ -61,7 +61,12 @@ die('Please enter a name and valid email address. You can use the back button of the browser to recover your translations.'); } } - + + // Check captcha + if ($requirecaptcha && !confirm_captcha_response($recaptcha_secret_key, $_POST["g-recaptcha-response"])) { + die('Error validating the security response. You can use the back button of the browser to recover your translations.'); + } + // Traverse through the lines of the original strings file $lines = file($basedir . '/values/strings.xml'); $outfile = ""; @@ -221,6 +226,13 @@ function requireNameAndEmail() { alert(\'Please enter a name and valid e-mail address.\'); return false; } + function requireCaptcha() { + if (!grecaptcha.getResponse()) { + alert("Please confirm the captcha first."); + return false; + } + return true; + }No translation for this language currently exists. When saving for the first time, it will create a directory and the first strings.{timestamp}.xml for this new language.
'; } - // Require the input of a name and email address? - $requireemailhtml = $requireemail? 'return(requireNameAndEmail());"': ''; + // Require the input of a name and email address and/or captcha? + if ($requireemail && $requireCaptcha) { + $requirehtml = 'return(requireNameAndEmail() && requireCaptcha());'; + } else if ($requireemail) { + $requirehtml = 'return(requireNameAndEmail());'; + } else if ($requirecaptcha) { + $requirehtml = 'return(requireCaptcha());'; + } else { + $requirehtml = ''; + } echo ' -