From 061524de15ef004e2a798c1d6a865d05ef30d820 Mon Sep 17 00:00:00 2001 From: Mathew May Date: Wed, 29 May 2019 11:41:19 +0800 Subject: [PATCH] MDL-65754 libraries: Remove unused v1 recaptcha --- .eslintignore | 1 - .stylelintignore | 1 - lang/en/auth.php | 5 - lib/recaptchalib.php | 343 ----------------------------------------- lib/thirdpartylibs.xml | 7 - 5 files changed, 357 deletions(-) delete mode 100644 lib/recaptchalib.php diff --git a/.eslintignore b/.eslintignore index a262404db97a1..77b4a7f17dcfa 100644 --- a/.eslintignore +++ b/.eslintignore @@ -42,7 +42,6 @@ lib/yuilib/gallery/ lib/jquery/ lib/html2text/ lib/markdown/ -lib/recaptchalib.php lib/xhprof/ lib/horde/ lib/requirejs/ diff --git a/.stylelintignore b/.stylelintignore index 6bcaefed8cf0a..16fceadd990e3 100644 --- a/.stylelintignore +++ b/.stylelintignore @@ -43,7 +43,6 @@ lib/yuilib/gallery/ lib/jquery/ lib/html2text/ lib/markdown/ -lib/recaptchalib.php lib/xhprof/ lib/horde/ lib/requirejs/ diff --git a/lang/en/auth.php b/lang/en/auth.php index 1233c20838d18..0b395a791145d 100644 --- a/lang/en/auth.php +++ b/lang/en/auth.php @@ -82,8 +82,6 @@ {$a->url}'; $string['emailupdatesuccess'] = 'Email address of user {$a->fullname} was successfully updated to {$a->email}.'; $string['emailupdatetitle'] = 'Confirmation of email update at {$a->site}'; -$string['enterthenumbersyouhear'] = 'Enter the numbers you hear'; -$string['enterthewordsabove'] = 'Enter the words above'; $string['errormaxconsecutiveidentchars'] = 'Passwords must have at most {$a} consecutive identical characters.'; $string['errorminpassworddigits'] = 'Passwords must have at least {$a} digit(s).'; $string['errorminpasswordlength'] = 'Passwords must be at least {$a} characters long.'; @@ -100,9 +98,6 @@ $string['forcechangepassword_help'] = 'Force users to change password on their next login to Moodle.'; $string['forgottenpassword'] = 'If you enter a URL here, it will be used as the lost password recovery page for this site. This is intended for sites where passwords are handled entirely outside of Moodle. Leave this blank to use the default password recovery.'; $string['forgottenpasswordurl'] = 'Forgotten password URL'; -$string['getanaudiocaptcha'] = 'Get an audio CAPTCHA'; -$string['getanimagecaptcha'] = 'Get an image CAPTCHA'; -$string['getanothercaptcha'] = 'Get another CAPTCHA'; $string['getrecaptchaapi'] = 'To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin'; $string['guestloginbutton'] = 'Guest login button'; $string['changepassword'] = 'Change password URL'; diff --git a/lib/recaptchalib.php b/lib/recaptchalib.php deleted file mode 100644 index 79eb4a3fc610f..0000000000000 --- a/lib/recaptchalib.php +++ /dev/null @@ -1,343 +0,0 @@ - $value ) - $req .= $key . '=' . urlencode( $value ) . '&'; - - // Cut the last '&' - $req=substr($req,0,strlen($req)-1); - return $req; -} - - - -/** - * Submits an HTTP POST to a reCAPTCHA server - * - * @global object - * @param string $host - * @param string $path - * @param array $data - * @param int port - * @return array response - */ -function _recaptcha_http_post($host, $path, $data, $port = 80, $https=false) { - global $CFG; - $protocol = 'http'; - if ($https) { - $protocol = 'https'; - } - - require_once $CFG->libdir . '/filelib.php'; - - $req = _recaptcha_qsencode ($data); - - $headers = array(); - $headers['Host'] = $host; - $headers['Content-Type'] = 'application/x-www-form-urlencoded'; - $headers['Content-Length'] = strlen($req); - $headers['User-Agent'] = 'reCAPTCHA/PHP'; - - $results = download_file_content("$protocol://" . $host . $path, $headers, $data, false, 300, 20, true); - - if ($results) { - return array(1 => $results); - } else { - return false; - } -} - -/** - * Return the recaptcha challenge and image and javascript urls - * - * @param string $server server url - * @param string $pubkey public key - * @param string $errorpart error part to append - * @return array the challenge hash, image and javascript url - * @since Moodle 3.2 - */ -function recaptcha_get_challenge_hash_and_urls($server, $pubkey, $errorpart = '') { - global $CFG; - - require_once($CFG->libdir . '/filelib.php'); - $html = download_file_content($server . '/noscript?k=' . $pubkey . $errorpart, null, null, false, 300, 20, true); - preg_match('/image\?c\=([A-Za-z0-9\-\_]*)\"/', $html, $matches); - $challengehash = $matches[1]; - $imageurl = $server . '/image?c=' . $challengehash; - - $jsurl = $server . '/challenge?k=' . $pubkey . $errorpart; - - return array($challengehash, $imageurl, $jsurl); -} - - -/** - * 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. - * - * @global object - * @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) { - global $PAGE; - - $recaptchatype = optional_param('recaptcha', 'image', PARAM_TEXT); - - if ($pubkey == null || $pubkey == '') { - die ("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create"); - } - - if ($use_ssl) { - $server = RECAPTCHA_API_SECURE_SERVER; - } else { - $server = RECAPTCHA_API_SERVER; - } - - $errorpart = ""; - if ($error) { - $errorpart = "&error=" . $error; - } - - list($challengehash, $imageurl, $jsurl) = recaptcha_get_challenge_hash_and_urls($server, $pubkey, $errorpart); - - $strincorrectpleasetryagain = get_string('incorrectpleasetryagain', 'auth'); - $strenterthewordsabove = get_string('enterthewordsabove', 'auth'); - $strenterthenumbersyouhear = get_string('enterthenumbersyouhear', 'auth'); - $strgetanothercaptcha = get_string('getanothercaptcha', 'auth'); - $strgetanaudiocaptcha = get_string('getanaudiocaptcha', 'auth'); - $strgetanimagecaptcha = get_string('getanimagecaptcha', 'auth'); - - $return = html_writer::script('', $jsurl); - $return .= ''; - - return $return; -} - - - - -/** - * A ReCaptchaResponse is returned from recaptcha_check_answer() - * - * @package moodlecore - * @copyright (c) 2007 reCAPTCHA -- {@link http://www.google.com/recaptcha} - */ -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 - * @return ReCaptchaResponse - */ -function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $https=false) -{ - if ($privkey == null || $privkey == '') { - die ("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create"); - } - - 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, "/recaptcha/api/verify", - array ( - 'privatekey' => $privkey, - 'remoteip' => $remoteip, - 'challenge' => $challenge, - 'response' => $response - ), - $https - ); - - $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 "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $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://www.google.com/recaptcha/mailhide/apikey"); - } - - - $ky = pack('H*', $privkey); - $cryptmail = _recaptcha_aes_encrypt ($email, $ky); - - return "http://www.google.com/recaptcha/mailhide/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://www.google.com/recaptcha/mailhide/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/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml index 85d046baea289..66a3298fc2e4e 100644 --- a/lib/thirdpartylibs.xml +++ b/lib/thirdpartylibs.xml @@ -182,13 +182,6 @@ 1.7.0 - - recaptchalib.php - ReCAPTCHA - MIT - 1.10 - - xhprof XHProf