diff --git a/README.markdown b/README.markdown index 96d9152..04902d3 100644 --- a/README.markdown +++ b/README.markdown @@ -1,17 +1,22 @@ # reCAPTCHA ## Installation -1. Get reCAPTCHA API keys from http://recaptcha.net/whyrecaptcha.html +1. Get reCAPTCHA API keys from https://www.google.com/recaptcha/intro/index.html 2. Upload the 'recaptcha' folder in this archive to your Symphony 'extensions' folder. 3. Enable it at System > Extensions. 4. Go to System > Preferences and enter your reCAPTCHA private/public API key pair. 5. Add the "reCAPTCHA Verification" filter rule to your Event via Blueprints > Events 6. Save the Event. 7. Add "reCAPTCHA: Public Key" Data Source to your page. -8. Add the following line to your form: +8. Add the following script to your site: ```HTML - + ``` +8. Add the following html where you want your recaptcha to appear: -See http://recaptcha.net/apidocs/captcha/client.html for information about customisation of the reCAPTCHA box. +```HTML +
+``` + +See https://developers.google.com/recaptcha/intro for additional reCAPTCHA information / customization. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..6b4bb1f --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "google/recaptcha": "~1.1" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..add973a --- /dev/null +++ b/composer.lock @@ -0,0 +1,64 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "098e79dcc291a46e21d6c302fdadda1f", + "content-hash": "8af575921824e2407c70af936e4311f4", + "packages": [ + { + "name": "google/recaptcha", + "version": "1.1.2", + "source": { + "type": "git", + "url": "https://github.com/google/recaptcha.git", + "reference": "2b7e00566afca82a38a1d3adb8e42c118006296e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/google/recaptcha/zipball/2b7e00566afca82a38a1d3adb8e42c118006296e", + "reference": "2b7e00566afca82a38a1d3adb8e42c118006296e", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "4.5.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "ReCaptcha\\": "src/ReCaptcha" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Client library for reCAPTCHA, a free service that protect websites from spam and abuse.", + "homepage": "http://www.google.com/recaptcha/", + "keywords": [ + "Abuse", + "captcha", + "recaptcha", + "spam" + ], + "time": "2015-09-02 17:23:59" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/extension.driver.php b/extension.driver.php index 59cd028..dbf4c28 100755 --- a/extension.driver.php +++ b/extension.driver.php @@ -2,17 +2,6 @@ Class extension_recaptcha extends Extension{ - public function about(){ - return array('name' => 'reCAPTCHA', - 'version' => '1.0', - 'release-date' => '2008-05-07', - 'author' => array( 'name' => 'Symphony Team', - 'website' => 'http://symphony21.com', - 'email' => 'team@symphony21.com'), - 'description' => 'This is an event that uses the reCAPTCHA service to help prevent spam.' - ); - } - public function getSubscribedDelegates(){ return array( array( @@ -64,11 +53,11 @@ public function appendPreferences($context){ $div = new XMLElement('div', NULL, array('class' => 'group')); $label = Widget::Label('Public Key'); - $label->appendChild(Widget::Input('settings[recaptcha][public-key]', General::Sanitize($this->_Parent->Configuration->get('public-key', 'recaptcha')))); + $label->appendChild(Widget::Input('settings[recaptcha][public-key]', General::Sanitize(Symphony::Configuration()->get('public-key', 'recaptcha')))); $div->appendChild($label); $label = Widget::Label('Private Key'); - $label->appendChild(Widget::Input('settings[recaptcha][private-key]', General::Sanitize($this->_Parent->Configuration->get('private-key', 'recaptcha')))); + $label->appendChild(Widget::Input('settings[recaptcha][private-key]', General::Sanitize(Symphony::Configuration()->get('private-key', 'recaptcha')))); $div->appendChild($label); $group->appendChild($div); @@ -99,30 +88,33 @@ public function processEventData($context){ if(!in_array('recaptcha', $context['event']->eParamFILTERS)) return; - include_once(EXTENSIONS . '/recaptcha/lib/recaptchalib.php'); - $resp = recaptcha_check_answer($this->getPrivateKey(), - $_SERVER['REMOTE_ADDR'], - $_POST['recaptcha_challenge_field'], - $_POST['recaptcha_response_field']); + include_once(EXTENSIONS . '/recaptcha/vendor/autoload.php'); + + $recaptcha = new \ReCaptcha\ReCaptcha(Symphony::Configuration()->get('private-key', 'recaptcha')); + $resp = $recaptcha->verify($_POST['g-captcha-response'], $_SERVER['REMOTE_ADDR']); + + // $resp = recaptcha_check_answer($this->getPrivateKey(), + // $_SERVER['REMOTE_ADDR'], + // $_POST['recaptcha_challenge_field'], + // $_POST['recaptcha_response_field']); + + $success = $resp->isSuccess(); - $context['messages'][] = array('recaptcha', $resp->is_valid, (!$resp->is_valid ? 'Challenge words entered were invalid.' : NULL)); + $context['messages'][] = array('recaptcha', $success, (!$success ? 'Challenge words entered were invalid.' : NULL)); } public function uninstall(){ - //ConfigurationAccessor::remove('recaptcha'); - $this->_Parent->Configuration->remove('recaptcha'); + Symphony::Configuration()->remove('recaptcha'); $this->_Parent->saveConfig(); } public function getPublicKey(){ - //return ConfigurationAccessor::get('public-key', 'recaptcha'); - return $this->_Parent->Configuration->get('public-key', 'recaptcha'); + return Symphony::Configuration()->get('public-key', 'recaptcha'); } public function getPrivateKey(){ - //return ConfigurationAccessor::get('private-key', 'recaptcha'); - return $this->_Parent->Configuration->get('private-key', 'recaptcha'); + return Symphony::Configuration()->get('private-key', 'recaptcha'); } } diff --git a/extension.meta.xml b/extension.meta.xml index ddfc6fe..c96db17 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -1,5 +1,5 @@ - + reCAPTCHA reCAPTCHA spam prevention https://github.com/symphonists/recaptcha @@ -14,6 +14,9 @@ + + - Update to new Google reCaptcha Code + \ No newline at end of file diff --git a/lib/README b/lib/README deleted file mode 100644 index 21f1a27..0000000 --- a/lib/README +++ /dev/null @@ -1,7 +0,0 @@ -reCAPTCHA README -================ - -The reCAPTCHA PHP Lirary helps you use the reCAPTCHA API. Documentation -for this library can be found at - - http://recaptcha.net/plugins/php diff --git a/lib/recaptchalib.php b/lib/recaptchalib.php deleted file mode 100644 index 897c509..0000000 --- a/lib/recaptchalib.php +++ /dev/null @@ -1,277 +0,0 @@ - $value ) - $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; - - // Cut the last '&' - $req=substr($req,0,strlen($req)-1); - return $req; -} - - - -/** - * Submits an HTTP POST to a reCAPTCHA server - * @param string $host - * @param string $path - * @param array $data - * @param int port - * @return array response - */ -function _recaptcha_http_post($host, $path, $data, $port = 80) { - - $req = _recaptcha_qsencode ($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) ) ) { - die ('Could not open socket'); - } - - 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; -} - - - -/** - * Gets the challenge HTML (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. - * @param string $pubkey A public key for reCAPTCHA - * @param string $error The error given by reCAPTCHA (optional, default is null) - * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false) - - * @return string - The HTML to be embedded in the user's form. - */ -function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false) -{ - if ($pubkey == null || $pubkey == '') { - die ("To use reCAPTCHA you must get an API key from http://recaptcha.net/api/getkey"); - } - - if ($use_ssl) { - $server = RECAPTCHA_API_SECURE_SERVER; - } else { - $server = RECAPTCHA_API_SERVER; - } - - $errorpart = ""; - if ($error) { - $errorpart = "&error=" . $error; - } - return ' - - '; -} - - - - -/** - * A ReCaptchaResponse is returned from recaptcha_check_answer() - */ -class ReCaptchaResponse { - var $is_valid; - var $error; -} - - -/** - * Calls an HTTP POST function to verify if the user's guess was correct - * @param string $privkey - * @param string $remoteip - * @param string $challenge - * @param string $response - * @param array $extra_params an array of extra variables to post to the server - * @return ReCaptchaResponse - */ -function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array()) -{ - if ($privkey == null || $privkey == '') { - die ("To use reCAPTCHA you must get an API key from http://recaptcha.net/api/getkey"); - } - - if ($remoteip == null || $remoteip == '') { - die ("For security reasons, you must pass the remote ip to reCAPTCHA"); - } - - - - //discard spam submissions - if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) { - $recaptcha_response = new ReCaptchaResponse(); - $recaptcha_response->is_valid = false; - $recaptcha_response->error = 'incorrect-captcha-sol'; - return $recaptcha_response; - } - - $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/verify", - array ( - 'privatekey' => $privkey, - 'remoteip' => $remoteip, - 'challenge' => $challenge, - 'response' => $response - ) + $extra_params - ); - - $answers = explode ("\n", $response [1]); - $recaptcha_response = new ReCaptchaResponse(); - - if (trim ($answers [0]) == 'true') { - $recaptcha_response->is_valid = true; - } - else { - $recaptcha_response->is_valid = false; - $recaptcha_response->error = $answers [1]; - } - return $recaptcha_response; - -} - -/** - * 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. - * @param string $domain The domain where the page is hosted - * @param string $appname The name of your application - */ -function recaptcha_get_signup_url ($domain = null, $appname = null) { - return "http://recaptcha.net/api/getkey?" . _recaptcha_qsencode (array ('domain' => $domain, 'app' => $appname)); -} - -function _recaptcha_aes_pad($val) { - $block_size = 16; - $numpad = $block_size - (strlen ($val) % $block_size); - return str_pad($val, strlen ($val) + $numpad, chr($numpad)); -} - -/* Mailhide related code */ - -function _recaptcha_aes_encrypt($val,$ky) { - if (! function_exists ("mcrypt_encrypt")) { - die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."); - } - $mode=MCRYPT_MODE_CBC; - $enc=MCRYPT_RIJNDAEL_128; - $val=_recaptcha_aes_pad($val); - return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); -} - - -function _recaptcha_mailhide_urlbase64 ($x) { - return strtr(base64_encode ($x), '+/', '-_'); -} - -/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */ -function recaptcha_mailhide_url($pubkey, $privkey, $email) { - if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) { - die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " . - "you can do so at http://mailhide.recaptcha.net/apikey"); - } - - - $ky = pack('H*', $privkey); - $cryptmail = _recaptcha_aes_encrypt ($email, $ky); - - return "http://mailhide.recaptcha.net/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail); -} - -/** - * gets the parts of the email to expose to the user. - * eg, given johndoe@example,com return ["john", "example.com"]. - * the email is then displayed as john...@example.com - */ -function _recaptcha_mailhide_email_parts ($email) { - $arr = preg_split("/@/", $email ); - - if (strlen ($arr[0]) <= 4) { - $arr[0] = substr ($arr[0], 0, 1); - } else if (strlen ($arr[0]) <= 6) { - $arr[0] = substr ($arr[0], 0, 3); - } else { - $arr[0] = substr ($arr[0], 0, 4); - } - return $arr; -} - -/** - * Gets html to display an email address given a public an private key. - * to get a key, go to: - * - * http://mailhide.recaptcha.net/apikey - */ -function recaptcha_mailhide_html($pubkey, $privkey, $email) { - $emailparts = _recaptcha_mailhide_email_parts ($email); - $url = recaptcha_mailhide_url ($pubkey, $privkey, $email); - - return htmlentities($emailparts[0]) . "...@" . htmlentities ($emailparts [1]); - -} - - -?> diff --git a/vendor/autoload.php b/vendor/autoload.php new file mode 100644 index 0000000..a074bd9 --- /dev/null +++ b/vendor/autoload.php @@ -0,0 +1,7 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + * @see http://www.php-fig.org/psr/psr-0/ + * @see http://www.php-fig.org/psr/psr-4/ + */ +class ClassLoader +{ + // PSR-4 + private $prefixLengthsPsr4 = array(); + private $prefixDirsPsr4 = array(); + private $fallbackDirsPsr4 = array(); + + // PSR-0 + private $prefixesPsr0 = array(); + private $fallbackDirsPsr0 = array(); + + private $useIncludePath = false; + private $classMap = array(); + + private $classMapAuthoritative = false; + + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', $this->prefixesPsr0); + } + + return array(); + } + + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 base directories + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + /** + * Unregisters this instance as an autoloader. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return bool|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + includeFile($file); + + return true; + } + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 + if ('\\' == $class[0]) { + $class = substr($class, 1); + } + + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative) { + return false; + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if ($file === null && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if ($file === null) { + // Remember that this class does not exist. + return $this->classMap[$class] = false; + } + + return $file; + } + + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { + if (0 === strpos($class, $prefix)) { + foreach ($this->prefixDirsPsr4[$prefix] as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + */ +function includeFile($file) +{ + include $file; +} diff --git a/lib/LICENSE b/vendor/composer/LICENSE similarity index 80% rename from lib/LICENSE rename to vendor/composer/LICENSE index b612f71..1a28124 100644 --- a/lib/LICENSE +++ b/vendor/composer/LICENSE @@ -1,17 +1,15 @@ -Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net -AUTHORS: - Mike Crawford - Ben Maurer + +Copyright (c) 2016 Nils Adermann, Jordi Boggiano Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, @@ -20,3 +18,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php new file mode 100644 index 0000000..7a91153 --- /dev/null +++ b/vendor/composer/autoload_classmap.php @@ -0,0 +1,9 @@ + array($vendorDir . '/google/recaptcha/src/ReCaptcha'), +); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php new file mode 100644 index 0000000..bf005b9 --- /dev/null +++ b/vendor/composer/autoload_real.php @@ -0,0 +1,52 @@ += 50600 && !defined('HHVM_VERSION'); + if ($useStaticLoader) { + require_once __DIR__ . '/autoload_static.php'; + + call_user_func(\Composer\Autoload\ComposerStaticInit2f858869b81a712dd819a735347c4725::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + } + + $loader->register(true); + + return $loader; + } +} diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php new file mode 100644 index 0000000..3a239d1 --- /dev/null +++ b/vendor/composer/autoload_static.php @@ -0,0 +1,31 @@ + + array ( + 'ReCaptcha\\' => 10, + ), + ); + + public static $prefixDirsPsr4 = array ( + 'ReCaptcha\\' => + array ( + 0 => __DIR__ . '/..' . '/google/recaptcha/src/ReCaptcha', + ), + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->prefixLengthsPsr4 = ComposerStaticInit2f858869b81a712dd819a735347c4725::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit2f858869b81a712dd819a735347c4725::$prefixDirsPsr4; + + }, null, ClassLoader::class); + } +} diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json new file mode 100644 index 0000000..8813981 --- /dev/null +++ b/vendor/composer/installed.json @@ -0,0 +1,49 @@ +[ + { + "name": "google/recaptcha", + "version": "1.1.2", + "version_normalized": "1.1.2.0", + "source": { + "type": "git", + "url": "https://github.com/google/recaptcha.git", + "reference": "2b7e00566afca82a38a1d3adb8e42c118006296e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/google/recaptcha/zipball/2b7e00566afca82a38a1d3adb8e42c118006296e", + "reference": "2b7e00566afca82a38a1d3adb8e42c118006296e", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "4.5.*" + }, + "time": "2015-09-02 17:23:59", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "ReCaptcha\\": "src/ReCaptcha" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Client library for reCAPTCHA, a free service that protect websites from spam and abuse.", + "homepage": "http://www.google.com/recaptcha/", + "keywords": [ + "Abuse", + "captcha", + "recaptcha", + "spam" + ] + } +] diff --git a/vendor/google/recaptcha/.gitignore b/vendor/google/recaptcha/.gitignore new file mode 100644 index 0000000..436384a --- /dev/null +++ b/vendor/google/recaptcha/.gitignore @@ -0,0 +1,3 @@ +/composer.lock +/nbproject/private/ +/vendor/ diff --git a/vendor/google/recaptcha/.travis.yml b/vendor/google/recaptcha/.travis.yml new file mode 100644 index 0000000..fb25bad --- /dev/null +++ b/vendor/google/recaptcha/.travis.yml @@ -0,0 +1,18 @@ +language: php + +sudo: false + +php: + - 5.3 + - 5.4 + - 5.5 + - 5.6 + - hhvm + +before_script: + - composer install + - phpenv version-name | grep ^5.[34] && echo "extension=apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true + - phpenv version-name | grep ^5.[34] && echo "apc.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true + +script: + - vendor/bin/phpunit diff --git a/vendor/google/recaptcha/CONTRIBUTING.md b/vendor/google/recaptcha/CONTRIBUTING.md new file mode 100644 index 0000000..1ba8539 --- /dev/null +++ b/vendor/google/recaptcha/CONTRIBUTING.md @@ -0,0 +1,24 @@ +Want to contribute? Great! First, read this page (including the small print at the end). + +### Before you contribute +Before we can use your code, you must sign the +[Google Individual Contributor License Agreement](https://developers.google.com/open-source/cla/individual?csw=1) +(CLA), which you can do online. The CLA is necessary mainly because you own the +copyright to your changes, even after your contribution becomes part of our +codebase, so we need your permission to use and distribute your code. We also +need to be sure of various other things—for instance that you'll tell us if you +know that your code infringes on other people's patents. You don't have to sign +the CLA until after you've submitted your code for review and a member has +approved it, but you must do it before we can put your code into our codebase. +Before you start working on a larger contribution, you should get in touch with +us first through the issue tracker with your idea so that we can help out and +possibly guide you. Coordinating up front makes it much easier to avoid +frustration later on. + +### Code reviews +All submissions, including submissions by project members, require review. We +use Github pull requests for this purpose. + +### The small print +Contributions made by corporations are covered by a different agreement than +the one above, the Software Grant and Corporate Contributor License Agreement. diff --git a/vendor/google/recaptcha/LICENSE b/vendor/google/recaptcha/LICENSE new file mode 100644 index 0000000..f641232 --- /dev/null +++ b/vendor/google/recaptcha/LICENSE @@ -0,0 +1,29 @@ +Copyright 2014, Google Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/vendor/google/recaptcha/README.md b/vendor/google/recaptcha/README.md new file mode 100644 index 0000000..6e81a8e --- /dev/null +++ b/vendor/google/recaptcha/README.md @@ -0,0 +1,113 @@ +# reCAPTCHA PHP client library + +[![Build Status](https://travis-ci.org/google/recaptcha.svg)](https://travis-ci.org/google/recaptcha) +[![Latest Stable Version](https://poser.pugx.org/google/recaptcha/v/stable.svg)](https://packagist.org/packages/google/recaptcha) +[![Total Downloads](https://poser.pugx.org/google/recaptcha/downloads.svg)](https://packagist.org/packages/google/recaptcha) + +* Project page: http://www.google.com/recaptcha/ +* Repository: https://github.com/google/recaptcha +* Version: 1.1.2 +* License: BSD, see [LICENSE](LICENSE) + +## Description + +reCAPTCHA is a free CAPTCHA service that protect websites from spam and abuse. +This is Google authored code that provides plugins for third-party integration +with reCAPTCHA. + +## Installation + +### Composer (Recommended) + +[Composer](https://getcomposer.org/) is a widely used dependency manager for PHP +packages. This reCAPTCHA client is available on Packagist as +[`google/recaptcha`](https://packagist.org/packages/google/recaptcha) and can be +installed either by running the `composer require` command or adding the library +to your `composer.json`. To enable Composer for you project, refer to the +project's [Getting Started](https://getcomposer.org/doc/00-intro.md) +documentation. + +To add this dependency using the command, run the following from within your +project directory: +``` +composer require google/recaptcha "~1.1" +``` + +Alternatively, add the dependency directly to your `composer.json` file: +```json +"require": { + "google/recaptcha": "~1.1" +} +``` + +### Direct download (no Composer) + +If you wish to install the library manually (i.e. without Composer), then you +can use the links on the main project page to either clone the repo or download +the [ZIP file](https://github.com/google/recaptcha/archive/master.zip). For +convenience, an autoloader script is provided in `src/autoload.php` which you +can require into your script instead of Composer's `vendor/autoload.php`. For +example: + +```php +require('/path/to/recaptcha/src/autoload.php'); +$recaptcha = new \ReCaptcha\ReCaptcha($secret); +``` + +The classes in the project are structured according to the +[PSR-4](http://www.php-fig.org/psr/psr-4/) standard, so you may of course also +use your own autoloader or require the needed files directly in your code. + +### Development install + +If you would like to contribute to this project or run the unit tests on within +your own environment you will need to install the development dependencies, in +this case that means [PHPUnit](https://phpunit.de/). If you clone the repo and +run `composer install` from within the repo, this will also grab PHPUnit and all +its dependencies for you. If you only need the autoloader installed, then you +can always specify to Composer not to run in development mode, e.g. `composer +install --no-dev`. + +*Note:* These dependencies are only required for development, there's no +requirement for them to be included in your production code. + +## Usage + +First, register keys for your site at https://www.google.com/recaptcha/admin + +When your app receives a form submission containing the `g-recaptcha-response` +field, you can verify it using: +```php +verify($gRecaptchaResponse, $remoteIp); +if ($resp->isSuccess()) { + // verified! +} else { + $errors = $resp->getErrorCodes(); +} +``` + +You can see an end-to-end working example in +[examples/example-captcha.php](examples/example-captcha.php) + +## Upgrading + +### From 1.0.0 + +The previous version of this client is still available on the `1.0.0` tag [in +this repo](https://github.com/google/recaptcha/tree/1.0.0) but it is purely for +reference and will not receive any updates. + +The major changes in 1.1.0 are: +* installation now via Composer; +* class loading also via Composer; +* classes now namespaced; +* old method call was `$rc->verifyResponse($remoteIp, $response)`, new call is + `$rc->verify($response, $remoteIp)` + +## Contributing + +We accept contributions via GitHub Pull Requests, but all contributors need to +be covered by the standard Google Contributor License Agreement. You can find +instructions for this in [CONTRIBUTING](CONTRIBUTING.md) diff --git a/vendor/google/recaptcha/composer.json b/vendor/google/recaptcha/composer.json new file mode 100644 index 0000000..63b751c --- /dev/null +++ b/vendor/google/recaptcha/composer.json @@ -0,0 +1,28 @@ +{ + "name": "google/recaptcha", + "description": "Client library for reCAPTCHA, a free service that protect websites from spam and abuse.", + "type": "library", + "keywords": ["recaptcha", "captcha", "spam", "abuse"], + "homepage": "http://www.google.com/recaptcha/", + "license": "BSD-3-Clause", + "support": { + "forum": "https://groups.google.com/forum/#!forum/recaptcha", + "source": "https://github.com/google/recaptcha" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "4.5.*" + }, + "autoload": { + "psr-4": { + "ReCaptcha\\": "src/ReCaptcha" + } + }, + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + } +} diff --git a/vendor/google/recaptcha/examples/example-captcha.php b/vendor/google/recaptcha/examples/example-captcha.php new file mode 100644 index 0000000..8875171 --- /dev/null +++ b/vendor/google/recaptcha/examples/example-captcha.php @@ -0,0 +1,130 @@ + + + + + reCAPTCHA Example + + + + +

reCAPTCHA Example

+ +

Add your keys

+

If you do not have keys already then visit + + https://www.google.com/recaptcha/admin to generate them. + Edit this file and set the respective keys in $siteKey and + $secret. Reload the page after this.

+ +

POST data

+
+ verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']); + + if ($resp->isSuccess()): +// If the response is a success, that's it! + ?> +

Success!

+

That's it. Everything is working. Go integrate this into your real project.

+

Try again

+ +

Something went wrong

+

The following error was returned: getErrorCodes() as $code) { + echo '' , $code , ' '; + } + ?>

+

Check the error code reference at https://developers.google.com/recaptcha/docs/verify#error-code-reference. +

Note: Error code missing-input-response may mean the user just didn't complete the reCAPTCHA.

+

Try again

+ +

Complete the reCAPTCHA then submit the form.

+
+
+ An example form +

Example input A:

+

Example input B:

+ +
+ +

+
+
+ + + diff --git a/vendor/google/recaptcha/phpunit.xml.dist b/vendor/google/recaptcha/phpunit.xml.dist new file mode 100644 index 0000000..4376678 --- /dev/null +++ b/vendor/google/recaptcha/phpunit.xml.dist @@ -0,0 +1,17 @@ + + + + + tests/ReCaptcha/ + + + + + src/ReCaptcha/ + + + diff --git a/vendor/google/recaptcha/src/ReCaptcha/ReCaptcha.php b/vendor/google/recaptcha/src/ReCaptcha/ReCaptcha.php new file mode 100644 index 0000000..e2f7c34 --- /dev/null +++ b/vendor/google/recaptcha/src/ReCaptcha/ReCaptcha.php @@ -0,0 +1,97 @@ +secret = $secret; + + if (!is_null($requestMethod)) { + $this->requestMethod = $requestMethod; + } else { + $this->requestMethod = new RequestMethod\Post(); + } + } + + /** + * Calls the reCAPTCHA siteverify API to verify whether the user passes + * CAPTCHA test. + * + * @param string $response The value of 'g-recaptcha-response' in the submitted form. + * @param string $remoteIp The end user's IP address. + * @return Response Response from the service. + */ + public function verify($response, $remoteIp = null) + { + // Discard empty solution submissions + if (empty($response)) { + $recaptchaResponse = new Response(false, array('missing-input-response')); + return $recaptchaResponse; + } + + $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION); + $rawResponse = $this->requestMethod->submit($params); + return Response::fromJson($rawResponse); + } +} diff --git a/vendor/google/recaptcha/src/ReCaptcha/RequestMethod.php b/vendor/google/recaptcha/src/ReCaptcha/RequestMethod.php new file mode 100644 index 0000000..fc4dde5 --- /dev/null +++ b/vendor/google/recaptcha/src/ReCaptcha/RequestMethod.php @@ -0,0 +1,42 @@ +curl = $curl; + } else { + $this->curl = new Curl(); + } + } + + /** + * Submit the cURL request with the specified parameters. + * + * @param RequestParameters $params Request parameters + * @return string Body of the reCAPTCHA response + */ + public function submit(RequestParameters $params) + { + $handle = $this->curl->init(self::SITE_VERIFY_URL); + + $options = array( + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $params->toQueryString(), + CURLOPT_HTTPHEADER => array( + 'Content-Type: application/x-www-form-urlencoded' + ), + CURLINFO_HEADER_OUT => false, + CURLOPT_HEADER => false, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_SSL_VERIFYPEER => true + ); + $this->curl->setoptArray($handle, $options); + + $response = $this->curl->exec($handle); + $this->curl->close($handle); + + return $response; + } +} diff --git a/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/Post.php b/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/Post.php new file mode 100644 index 0000000..7770d90 --- /dev/null +++ b/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/Post.php @@ -0,0 +1,70 @@ + array( + 'header' => "Content-type: application/x-www-form-urlencoded\r\n", + 'method' => 'POST', + 'content' => $params->toQueryString(), + // Force the peer to validate (not needed in 5.6.0+, but still works + 'verify_peer' => true, + // Force the peer validation to use www.google.com + $peer_key => 'www.google.com', + ), + ); + $context = stream_context_create($options); + return file_get_contents(self::SITE_VERIFY_URL, false, $context); + } +} diff --git a/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/Socket.php b/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/Socket.php new file mode 100644 index 0000000..d3c8792 --- /dev/null +++ b/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/Socket.php @@ -0,0 +1,105 @@ +handle = fsockopen($hostname, $port, $errno, $errstr, (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout)); + + if ($this->handle != false && $errno === 0 && $errstr === '') { + return $this->handle; + } else { + return false; + } + } + + /** + * fwrite + * + * @see http://php.net/fwrite + * @param string $string + * @param int $length + * @return int | bool + */ + public function fwrite($string, $length = null) + { + return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length)); + } + + /** + * fgets + * + * @see http://php.net/fgets + * @param int $length + * @return string + */ + public function fgets($length = null) + { + return fgets($this->handle, $length); + } + + /** + * feof + * + * @see http://php.net/feof + * @return bool + */ + public function feof() + { + return feof($this->handle); + } + + /** + * fclose + * + * @see http://php.net/fclose + * @return bool + */ + public function fclose() + { + return fclose($this->handle); + } +} diff --git a/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/SocketPost.php b/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/SocketPost.php new file mode 100644 index 0000000..4754121 --- /dev/null +++ b/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/SocketPost.php @@ -0,0 +1,121 @@ +socket = $socket; + } else { + $this->socket = new Socket(); + } + } + + /** + * Submit the POST request with the specified parameters. + * + * @param RequestParameters $params Request parameters + * @return string Body of the reCAPTCHA response + */ + public function submit(RequestParameters $params) + { + $errno = 0; + $errstr = ''; + + if (false === $this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30)) { + return self::BAD_REQUEST; + } + + $content = $params->toQueryString(); + + $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; + $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; + $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; + $request .= "Content-length: " . strlen($content) . "\r\n"; + $request .= "Connection: close\r\n\r\n"; + $request .= $content . "\r\n\r\n"; + + $this->socket->fwrite($request); + $response = ''; + + while (!$this->socket->feof()) { + $response .= $this->socket->fgets(4096); + } + + $this->socket->fclose(); + + if (0 !== strpos($response, 'HTTP/1.1 200 OK')) { + return self::BAD_RESPONSE; + } + + $parts = preg_split("#\n\s*\n#Uis", $response); + + return $parts[1]; + } +} diff --git a/vendor/google/recaptcha/src/ReCaptcha/RequestParameters.php b/vendor/google/recaptcha/src/ReCaptcha/RequestParameters.php new file mode 100644 index 0000000..cb66f26 --- /dev/null +++ b/vendor/google/recaptcha/src/ReCaptcha/RequestParameters.php @@ -0,0 +1,103 @@ +secret = $secret; + $this->response = $response; + $this->remoteIp = $remoteIp; + $this->version = $version; + } + + /** + * Array representation. + * + * @return array Array formatted parameters. + */ + public function toArray() + { + $params = array('secret' => $this->secret, 'response' => $this->response); + + if (!is_null($this->remoteIp)) { + $params['remoteip'] = $this->remoteIp; + } + + if (!is_null($this->version)) { + $params['version'] = $this->version; + } + + return $params; + } + + /** + * Query string representation for HTTP request. + * + * @return string Query string formatted parameters. + */ + public function toQueryString() + { + return http_build_query($this->toArray(), '', '&'); + } +} diff --git a/vendor/google/recaptcha/src/ReCaptcha/Response.php b/vendor/google/recaptcha/src/ReCaptcha/Response.php new file mode 100644 index 0000000..d2d8a8b --- /dev/null +++ b/vendor/google/recaptcha/src/ReCaptcha/Response.php @@ -0,0 +1,102 @@ +success = $success; + $this->errorCodes = $errorCodes; + } + + /** + * Is success? + * + * @return boolean + */ + public function isSuccess() + { + return $this->success; + } + + /** + * Get error codes. + * + * @return array + */ + public function getErrorCodes() + { + return $this->errorCodes; + } +} diff --git a/vendor/google/recaptcha/src/autoload.php b/vendor/google/recaptcha/src/autoload.php new file mode 100644 index 0000000..a53cbd7 --- /dev/null +++ b/vendor/google/recaptcha/src/autoload.php @@ -0,0 +1,38 @@ +verify(''); + $this->assertFalse($response->isSuccess()); + $this->assertEquals(array('missing-input-response'), $response->getErrorCodes()); + } + + public function testVerifyReturnsResponse() + { + $method = $this->getMock('\\ReCaptcha\\RequestMethod', array('submit')); + $method->expects($this->once()) + ->method('submit') + ->with($this->callback(function ($params) { + + return true; + })) + ->will($this->returnValue('{"success": true}')); + ; + $rc = new ReCaptcha('secret', $method); + $response = $rc->verify('response'); + $this->assertTrue($response->isSuccess()); + } +} diff --git a/vendor/google/recaptcha/tests/ReCaptcha/RequestMethod/CurlPostTest.php b/vendor/google/recaptcha/tests/ReCaptcha/RequestMethod/CurlPostTest.php new file mode 100644 index 0000000..892e207 --- /dev/null +++ b/vendor/google/recaptcha/tests/ReCaptcha/RequestMethod/CurlPostTest.php @@ -0,0 +1,63 @@ +markTestSkipped( + 'The cURL extension is not available.' + ); + } + } + + public function testSubmit() + { + $curl = $this->getMock('\\ReCaptcha\\RequestMethod\\Curl', + array('init', 'setoptArray', 'exec', 'close')); + $curl->expects($this->once()) + ->method('init') + ->willReturn(new \stdClass); + $curl->expects($this->once()) + ->method('setoptArray') + ->willReturn(true); + $curl->expects($this->once()) + ->method('exec') + ->willReturn('RESPONSEBODY'); + $curl->expects($this->once()) + ->method('close'); + + $pc = new CurlPost($curl); + $response = $pc->submit(new RequestParameters("secret", "response")); + $this->assertEquals('RESPONSEBODY', $response); + } +} diff --git a/vendor/google/recaptcha/tests/ReCaptcha/RequestMethod/PostTest.php b/vendor/google/recaptcha/tests/ReCaptcha/RequestMethod/PostTest.php new file mode 100644 index 0000000..2eaabb5 --- /dev/null +++ b/vendor/google/recaptcha/tests/ReCaptcha/RequestMethod/PostTest.php @@ -0,0 +1,118 @@ +parameters = new RequestParameters("secret", "response", "remoteip", "version"); + } + + public function tearDown() + { + self::$assert = null; + } + + public function testHTTPContextOptions() + { + $req = new Post(); + self::$assert = array($this, "httpContextOptionsCallback"); + $req->submit($this->parameters); + $this->assertEquals(1, $this->runcount, "The assertion was ran"); + } + + public function testSSLContextOptions() + { + $req = new Post(); + self::$assert = array($this, "sslContextOptionsCallback"); + $req->submit($this->parameters); + $this->assertEquals(1, $this->runcount, "The assertion was ran"); + } + + public function httpContextOptionsCallback(array $args) + { + $this->runcount++; + $this->assertCommonOptions($args); + + $options = stream_context_get_options($args[2]); + $this->assertArrayHasKey('http', $options); + + $this->assertArrayHasKey('method', $options['http']); + $this->assertEquals("POST", $options['http']['method']); + + $this->assertArrayHasKey('content', $options['http']); + $this->assertEquals($this->parameters->toQueryString(), $options['http']['content']); + + $this->assertArrayHasKey('header', $options['http']); + $headers = array( + "Content-type: application/x-www-form-urlencoded", + ); + foreach ($headers as $header) { + $this->assertContains($header, $options['http']['header']); + } + } + + public function sslContextOptionsCallback(array $args) + { + $this->runcount++; + $this->assertCommonOptions($args); + + $options = stream_context_get_options($args[2]); + $this->assertArrayHasKey('http', $options); + $this->assertArrayHasKey('verify_peer', $options['http']); + $this->assertTrue($options['http']['verify_peer']); + + $key = version_compare(PHP_VERSION, "5.6.0", "<") ? "CN_name" : "peer_name"; + + $this->assertArrayHasKey($key, $options['http']); + $this->assertEquals("www.google.com", $options['http'][$key]); + } + + protected function assertCommonOptions(array $args) + { + $this->assertCount(3, $args); + $this->assertStringStartsWith("https://www.google.com/", $args[0]); + $this->assertFalse($args[1]); + $this->assertTrue(is_resource($args[2]), "The context options should be a resource"); + } +} + +function file_get_contents() +{ + if (PostTest::$assert) { + return call_user_func(PostTest::$assert, func_get_args()); + } + // Since we can't represent maxlen in userland... + return call_user_func_array('file_get_contents', func_get_args()); +} diff --git a/vendor/google/recaptcha/tests/ReCaptcha/RequestMethod/SocketPostTest.php b/vendor/google/recaptcha/tests/ReCaptcha/RequestMethod/SocketPostTest.php new file mode 100644 index 0000000..10eb7c2 --- /dev/null +++ b/vendor/google/recaptcha/tests/ReCaptcha/RequestMethod/SocketPostTest.php @@ -0,0 +1,90 @@ +getMock('\\ReCaptcha\\RequestMethod\\Socket', array('fsockopen', 'fwrite', 'fgets', 'feof', 'fclose')); + $socket->expects($this->once()) + ->method('fsockopen') + ->willReturn(true); + $socket->expects($this->once()) + ->method('fwrite'); + $socket->expects($this->once()) + ->method('fgets') + ->willReturn("HTTP/1.1 200 OK\n\nRESPONSEBODY"); + $socket->expects($this->exactly(2)) + ->method('feof') + ->will($this->onConsecutiveCalls(false, true)); + $socket->expects($this->once()) + ->method('fclose') + ->willReturn(true); + + $ps = new SocketPost($socket); + $response = $ps->submit(new RequestParameters("secret", "response", "remoteip", "version")); + $this->assertEquals('RESPONSEBODY', $response); + } + + public function testSubmitBadResponse() + { + $socket = $this->getMock('\\ReCaptcha\\RequestMethod\\Socket', array('fsockopen', 'fwrite', 'fgets', 'feof', 'fclose')); + $socket->expects($this->once()) + ->method('fsockopen') + ->willReturn(true); + $socket->expects($this->once()) + ->method('fwrite'); + $socket->expects($this->once()) + ->method('fgets') + ->willReturn("HTTP/1.1 500 NOPEn\\nBOBBINS"); + $socket->expects($this->exactly(2)) + ->method('feof') + ->will($this->onConsecutiveCalls(false, true)); + $socket->expects($this->once()) + ->method('fclose') + ->willReturn(true); + + $ps = new SocketPost($socket); + $response = $ps->submit(new RequestParameters("secret", "response", "remoteip", "version")); + $this->assertEquals(SocketPost::BAD_RESPONSE, $response); + } + + public function testSubmitBadRequest() + { + $socket = $this->getMock('\\ReCaptcha\\RequestMethod\\Socket', array('fsockopen')); + $socket->expects($this->once()) + ->method('fsockopen') + ->willReturn(false); + $ps = new SocketPost($socket); + $response = $ps->submit(new RequestParameters("secret", "response", "remoteip", "version")); + $this->assertEquals(SocketPost::BAD_REQUEST, $response); + } +} diff --git a/vendor/google/recaptcha/tests/ReCaptcha/RequestParametersTest.php b/vendor/google/recaptcha/tests/ReCaptcha/RequestParametersTest.php new file mode 100644 index 0000000..adc601b --- /dev/null +++ b/vendor/google/recaptcha/tests/ReCaptcha/RequestParametersTest.php @@ -0,0 +1,61 @@ + 'SECRET', 'response' => 'RESPONSE', 'remoteip' => 'REMOTEIP', 'version' => 'VERSION'), + 'secret=SECRET&response=RESPONSE&remoteip=REMOTEIP&version=VERSION'), + array('SECRET', 'RESPONSE', null, null, + array('secret' => 'SECRET', 'response' => 'RESPONSE'), + 'secret=SECRET&response=RESPONSE'), + ); + } + + /** + * @dataProvider provideValidData + */ + public function testToArray($secret, $response, $remoteIp, $version, $expectedArray, $expectedQuery) + { + $params = new RequestParameters($secret, $response, $remoteIp, $version); + $this->assertEquals($params->toArray(), $expectedArray); + } + + /** + * @dataProvider provideValidData + */ + public function testToQueryString($secret, $response, $remoteIp, $version, $expectedArray, $expectedQuery) + { + $params = new RequestParameters($secret, $response, $remoteIp, $version); + $this->assertEquals($params->toQueryString(), $expectedQuery); + } +} diff --git a/vendor/google/recaptcha/tests/ReCaptcha/ResponseTest.php b/vendor/google/recaptcha/tests/ReCaptcha/ResponseTest.php new file mode 100644 index 0000000..0e7eac9 --- /dev/null +++ b/vendor/google/recaptcha/tests/ReCaptcha/ResponseTest.php @@ -0,0 +1,68 @@ +assertEquals($success, $response->isSuccess()); + $this->assertEquals($errorCodes, $response->getErrorCodes()); + } + + public function provideJson() + { + return array( + array('{"success": true}', true, array()), + array('{"success": false, "error-codes": ["test"]}', false, array('test')), + array('{"success": true, "error-codes": ["test"]}', true, array()), + array('{"success": false}', false, array()), + array('BAD JSON', false, array('invalid-json')), + ); + } + + public function testIsSuccess() + { + $response = new Response(true); + $this->assertTrue($response->isSuccess()); + + $response = new Response(false); + $this->assertFalse($response->isSuccess()); + } + + public function testGetErrorCodes() + { + $errorCodes = array('test'); + $response = new Response(true, $errorCodes); + $this->assertEquals($errorCodes, $response->getErrorCodes()); + } +}