From 3b06ee0d381dc1be5f40ca98ad4278046d869d21 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 17 Nov 2019 20:57:39 +0100 Subject: checked in initial customized verison for Archlinux32 --- addons/recaptcha.php | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 addons/recaptcha.php (limited to 'addons/recaptcha.php') diff --git a/addons/recaptcha.php b/addons/recaptcha.php new file mode 100644 index 0000000..668de1c --- /dev/null +++ b/addons/recaptcha.php @@ -0,0 +1,136 @@ +is_configured()) return; + + $this->get_language(); + + if ($this->enabled_location('register')) + { + $manager->bind('register_after_validation', array($this, 'hook_after_validation')); + $manager->bind('register_before_submit', array($this, 'hook_before_submit')); + } + + if ($this->enabled_location('login')) + { + $manager->bind('login_after_validation', array($this, 'hook_after_validation')); + $manager->bind('login_before_submit', array($this, 'hook_before_submit')); + } + + if ($this->enabled_location('guestpost') && $pun_user['is_guest']) + { + $manager->bind('post_after_validation', array($this, 'hook_after_validation')); + $manager->bind('post_before_submit', array($this, 'hook_before_submit')); + $manager->bind('quickpost_before_submit', array($this, 'hook_before_submit')); + } + } + + function is_configured() + { + global $pun_config; + + return !empty($pun_config['recaptcha_enabled']) && !empty($pun_config['recaptcha_site_key']) && !empty($pun_config['recaptcha_secret_key']); + } + + function enabled_location($page) + { + global $pun_config; + + return !empty($pun_config['recaptcha_location_'.$page]); + } + + function get_language() + { + global $pun_user; + + if (file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/recaptcha_addon.php')) + require PUN_ROOT.'lang/'.$pun_user['language'].'/recaptcha_addon.php'; + else + require PUN_ROOT.'lang/English/recaptcha_addon.php'; + } + + function hook_after_validation() + { + global $errors, $lang_recaptcha; + + if (empty($errors) && !$this->verify_user_response()) + { + $errors[] = $lang_recaptcha['Error']; + } + } + + function hook_before_submit() + { + global $pun_config, $lang_recaptcha; + + $site_key = $pun_config['recaptcha_site_key']; + + ?> +
+
+ +
+

+ +
+
+
+
+ send_request($url); + + return strpos($response, '"success": true') !== false; + } + + function send_request($url) + { + if (function_exists('curl_version')) + return $this->send_curl_request($url); + else + return $this->get_remote_file($url); + } + + function send_curl_request($url) + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + $response = curl_exec($ch); + curl_close($ch); + + return $response; + } + + function get_remote_file($url) + { + global $lang_recaptcha; + + $response = file_get_contents($url); + + if ($response === false) + throw new Exception($lang_recaptcha['API error']); + + return $response; + } +} -- cgit v1.2.3-54-g00ecf