Select the types of activity you want to include in your feed.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
···11+<?php
22+33+/*
44+ * Copyright 2011 Facebook, Inc.
55+ *
66+ * Licensed under the Apache License, Version 2.0 (the "License");
77+ * you may not use this file except in compliance with the License.
88+ * You may obtain a copy of the License at
99+ *
1010+ * http://www.apache.org/licenses/LICENSE-2.0
1111+ *
1212+ * Unless required by applicable law or agreed to in writing, software
1313+ * distributed under the License is distributed on an "AS IS" BASIS,
1414+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515+ * See the License for the specific language governing permissions and
1616+ * limitations under the License.
1717+ */
1818+1919+return array(
2020+2121+ // The root URI which Phabricator is installed on.
2222+ // Example: "http://phabricator.example.com/"
2323+ 'phabricator.base-uri' => null,
2424+2525+2626+ //
2727+ 'phabricator.csrf-key' => '0b7ec0592e0a2829d8b71df2fa269b2c6172eca3',
2828+2929+3030+// -- Facebook ---------------------------------------------------------------
3131+3232+ // Can users use Facebook credentials to login to Phabricator?
3333+ 'facebook.auth-enabled' => false,
3434+3535+ // The Facebook "Application ID" to use for Facebook API access.
3636+ 'facebook.application-id' => null,
3737+3838+ // The Facebook "Application Secret" to use for Facebook API access.
3939+ 'facebook.application-secret' => null,
4040+4141+ 'recaptcha.public-key' => null,
4242+ 'recaptcha.private-key' => null,
4343+4444+4545+4646+);
+22
conf/development.conf.php
···11+<?php
22+33+/*
44+ * Copyright 2011 Facebook, Inc.
55+ *
66+ * Licensed under the Apache License, Version 2.0 (the "License");
77+ * you may not use this file except in compliance with the License.
88+ * You may obtain a copy of the License at
99+ *
1010+ * http://www.apache.org/licenses/LICENSE-2.0
1111+ *
1212+ * Unless required by applicable law or agreed to in writing, software
1313+ * distributed under the License is distributed on an "AS IS" BASIS,
1414+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515+ * See the License for the specific language governing permissions and
1616+ * limitations under the License.
1717+ */
1818+1919+return array(
2020+2121+2222+) + phabricator_read_config_file('default');
+23
conf/production.conf.php
···11+<?php
22+33+/*
44+ * Copyright 2011 Facebook, Inc.
55+ *
66+ * Licensed under the Apache License, Version 2.0 (the "License");
77+ * you may not use this file except in compliance with the License.
88+ * You may obtain a copy of the License at
99+ *
1010+ * http://www.apache.org/licenses/LICENSE-2.0
1111+ *
1212+ * Unless required by applicable law or agreed to in writing, software
1313+ * distributed under the License is distributed on an "AS IS" BASIS,
1414+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515+ * See the License for the specific language governing permissions and
1616+ * limitations under the License.
1717+ */
1818+1919+return array(
2020+2121+2222+) + phabricator_read_config_file('default');
2323+
+22
externals/recaptcha/LICENSE
···11+Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
22+AUTHORS:
33+ Mike Crawford
44+ Ben Maurer
55+66+Permission is hereby granted, free of charge, to any person obtaining a copy
77+of this software and associated documentation files (the "Software"), to deal
88+in the Software without restriction, including without limitation the rights
99+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1010+copies of the Software, and to permit persons to whom the Software is
1111+furnished to do so, subject to the following conditions:
1212+1313+The above copyright notice and this permission notice shall be included in
1414+all copies or substantial portions of the Software.
1515+1616+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1717+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1818+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1919+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2020+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222+THE SOFTWARE.
+277
externals/recaptcha/recaptchalib.php
···11+<?php
22+/*
33+ * This is a PHP library that handles calling reCAPTCHA.
44+ * - Documentation and latest version
55+ * http://recaptcha.net/plugins/php/
66+ * - Get a reCAPTCHA API Key
77+ * https://www.google.com/recaptcha/admin/create
88+ * - Discussion group
99+ * http://groups.google.com/group/recaptcha
1010+ *
1111+ * Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
1212+ * AUTHORS:
1313+ * Mike Crawford
1414+ * Ben Maurer
1515+ *
1616+ * Permission is hereby granted, free of charge, to any person obtaining a copy
1717+ * of this software and associated documentation files (the "Software"), to deal
1818+ * in the Software without restriction, including without limitation the rights
1919+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2020+ * copies of the Software, and to permit persons to whom the Software is
2121+ * furnished to do so, subject to the following conditions:
2222+ *
2323+ * The above copyright notice and this permission notice shall be included in
2424+ * all copies or substantial portions of the Software.
2525+ *
2626+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2727+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2828+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2929+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3030+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3131+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3232+ * THE SOFTWARE.
3333+ */
3434+3535+/**
3636+ * The reCAPTCHA server URL's
3737+ */
3838+define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
3939+define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
4040+define("RECAPTCHA_VERIFY_SERVER", "www.google.com");
4141+4242+/**
4343+ * Encodes the given data into a query string format
4444+ * @param $data - array of string elements to be encoded
4545+ * @return string - encoded request
4646+ */
4747+function _recaptcha_qsencode ($data) {
4848+ $req = "";
4949+ foreach ( $data as $key => $value )
5050+ $req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
5151+5252+ // Cut the last '&'
5353+ $req=substr($req,0,strlen($req)-1);
5454+ return $req;
5555+}
5656+5757+5858+5959+/**
6060+ * Submits an HTTP POST to a reCAPTCHA server
6161+ * @param string $host
6262+ * @param string $path
6363+ * @param array $data
6464+ * @param int port
6565+ * @return array response
6666+ */
6767+function _recaptcha_http_post($host, $path, $data, $port = 80) {
6868+6969+ $req = _recaptcha_qsencode ($data);
7070+7171+ $http_request = "POST $path HTTP/1.0\r\n";
7272+ $http_request .= "Host: $host\r\n";
7373+ $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
7474+ $http_request .= "Content-Length: " . strlen($req) . "\r\n";
7575+ $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
7676+ $http_request .= "\r\n";
7777+ $http_request .= $req;
7878+7979+ $response = '';
8080+ if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
8181+ die ('Could not open socket');
8282+ }
8383+8484+ fwrite($fs, $http_request);
8585+8686+ while ( !feof($fs) )
8787+ $response .= fgets($fs, 1160); // One TCP-IP packet
8888+ fclose($fs);
8989+ $response = explode("\r\n\r\n", $response, 2);
9090+9191+ return $response;
9292+}
9393+9494+9595+9696+/**
9797+ * Gets the challenge HTML (javascript and non-javascript version).
9898+ * This is called from the browser, and the resulting reCAPTCHA HTML widget
9999+ * is embedded within the HTML form it was called from.
100100+ * @param string $pubkey A public key for reCAPTCHA
101101+ * @param string $error The error given by reCAPTCHA (optional, default is null)
102102+ * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
103103+104104+ * @return string - The HTML to be embedded in the user's form.
105105+ */
106106+function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
107107+{
108108+ if ($pubkey == null || $pubkey == '') {
109109+ die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
110110+ }
111111+112112+ if ($use_ssl) {
113113+ $server = RECAPTCHA_API_SECURE_SERVER;
114114+ } else {
115115+ $server = RECAPTCHA_API_SERVER;
116116+ }
117117+118118+ $errorpart = "";
119119+ if ($error) {
120120+ $errorpart = "&error=" . $error;
121121+ }
122122+ return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
123123+124124+ <noscript>
125125+ <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
126126+ <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
127127+ <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
128128+ </noscript>';
129129+}
130130+131131+132132+133133+134134+/**
135135+ * A ReCaptchaResponse is returned from recaptcha_check_answer()
136136+ */
137137+class ReCaptchaResponse {
138138+ var $is_valid;
139139+ var $error;
140140+}
141141+142142+143143+/**
144144+ * Calls an HTTP POST function to verify if the user's guess was correct
145145+ * @param string $privkey
146146+ * @param string $remoteip
147147+ * @param string $challenge
148148+ * @param string $response
149149+ * @param array $extra_params an array of extra variables to post to the server
150150+ * @return ReCaptchaResponse
151151+ */
152152+function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
153153+{
154154+ if ($privkey == null || $privkey == '') {
155155+ die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
156156+ }
157157+158158+ if ($remoteip == null || $remoteip == '') {
159159+ die ("For security reasons, you must pass the remote ip to reCAPTCHA");
160160+ }
161161+162162+163163+164164+ //discard spam submissions
165165+ if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
166166+ $recaptcha_response = new ReCaptchaResponse();
167167+ $recaptcha_response->is_valid = false;
168168+ $recaptcha_response->error = 'incorrect-captcha-sol';
169169+ return $recaptcha_response;
170170+ }
171171+172172+ $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
173173+ array (
174174+ 'privatekey' => $privkey,
175175+ 'remoteip' => $remoteip,
176176+ 'challenge' => $challenge,
177177+ 'response' => $response
178178+ ) + $extra_params
179179+ );
180180+181181+ $answers = explode ("\n", $response [1]);
182182+ $recaptcha_response = new ReCaptchaResponse();
183183+184184+ if (trim ($answers [0]) == 'true') {
185185+ $recaptcha_response->is_valid = true;
186186+ }
187187+ else {
188188+ $recaptcha_response->is_valid = false;
189189+ $recaptcha_response->error = $answers [1];
190190+ }
191191+ return $recaptcha_response;
192192+193193+}
194194+195195+/**
196196+ * gets a URL where the user can sign up for reCAPTCHA. If your application
197197+ * has a configuration page where you enter a key, you should provide a link
198198+ * using this function.
199199+ * @param string $domain The domain where the page is hosted
200200+ * @param string $appname The name of your application
201201+ */
202202+function recaptcha_get_signup_url ($domain = null, $appname = null) {
203203+ return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
204204+}
205205+206206+function _recaptcha_aes_pad($val) {
207207+ $block_size = 16;
208208+ $numpad = $block_size - (strlen ($val) % $block_size);
209209+ return str_pad($val, strlen ($val) + $numpad, chr($numpad));
210210+}
211211+212212+/* Mailhide related code */
213213+214214+function _recaptcha_aes_encrypt($val,$ky) {
215215+ if (! function_exists ("mcrypt_encrypt")) {
216216+ die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
217217+ }
218218+ $mode=MCRYPT_MODE_CBC;
219219+ $enc=MCRYPT_RIJNDAEL_128;
220220+ $val=_recaptcha_aes_pad($val);
221221+ return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
222222+}
223223+224224+225225+function _recaptcha_mailhide_urlbase64 ($x) {
226226+ return strtr(base64_encode ($x), '+/', '-_');
227227+}
228228+229229+/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
230230+function recaptcha_mailhide_url($pubkey, $privkey, $email) {
231231+ if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
232232+ die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
233233+ "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>");
234234+ }
235235+236236+237237+ $ky = pack('H*', $privkey);
238238+ $cryptmail = _recaptcha_aes_encrypt ($email, $ky);
239239+240240+ return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
241241+}
242242+243243+/**
244244+ * gets the parts of the email to expose to the user.
245245+ * eg, given johndoe@example,com return ["john", "example.com"].
246246+ * the email is then displayed as john...@example.com
247247+ */
248248+function _recaptcha_mailhide_email_parts ($email) {
249249+ $arr = preg_split("/@/", $email );
250250+251251+ if (strlen ($arr[0]) <= 4) {
252252+ $arr[0] = substr ($arr[0], 0, 1);
253253+ } else if (strlen ($arr[0]) <= 6) {
254254+ $arr[0] = substr ($arr[0], 0, 3);
255255+ } else {
256256+ $arr[0] = substr ($arr[0], 0, 4);
257257+ }
258258+ return $arr;
259259+}
260260+261261+/**
262262+ * Gets html to display an email address given a public an private key.
263263+ * to get a key, go to:
264264+ *
265265+ * http://www.google.com/recaptcha/mailhide/apikey
266266+ */
267267+function recaptcha_mailhide_html($pubkey, $privkey, $email) {
268268+ $emailparts = _recaptcha_mailhide_email_parts ($email);
269269+ $url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
270270+271271+ return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
272272+ "' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]);
273273+274274+}
275275+276276+277277+?>
···11+<?php
22+33+/*
44+ * Copyright 2011 Facebook, Inc.
55+ *
66+ * Licensed under the Apache License, Version 2.0 (the "License");
77+ * you may not use this file except in compliance with the License.
88+ * You may obtain a copy of the License at
99+ *
1010+ * http://www.apache.org/licenses/LICENSE-2.0
1111+ *
1212+ * Unless required by applicable law or agreed to in writing, software
1313+ * distributed under the License is distributed on an "AS IS" BASIS,
1414+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515+ * See the License for the specific language governing permissions and
1616+ * limitations under the License.
1717+ */
1818+1919+class PhabricatorEmailLoginController extends PhabricatorAuthController {
2020+2121+ public function shouldRequireLogin() {
2222+ return false;
2323+ }
2424+2525+ public function processRequest() {
2626+ $request = $this->getRequest();
2727+2828+ $e_email = true;
2929+ $e_captcha = true;
3030+ $errors = array();
3131+3232+ if ($request->isFormPost()) {
3333+ $e_email = null;
3434+ $e_captcha = 'Again';
3535+3636+ $captcha_ok = AphrontFormRecaptchaControl::processCaptcha($request);
3737+ if (!$captcha_ok) {
3838+ $errors[] = "Captcha response is incorrect, try again.";
3939+ $e_captcha = 'Invalid';
4040+ }
4141+4242+ $email = $request->getStr('email');
4343+ if (!strlen($email)) {
4444+ $errors[] = "You must provide an email address.";
4545+ $e_email = 'Required';
4646+ }
4747+4848+ if (!$errors) {
4949+ // NOTE: Don't validate the email unless the captcha is good; this makes
5050+ // it expensive to fish for valid email addresses while giving the user
5151+ // a better error if they goof their email.
5252+5353+ $target_user = id(new PhabricatorUser())->loadOneWhere(
5454+ 'email = %s',
5555+ $email);
5656+5757+ if (!$target_user) {
5858+ $errors[] = "There is no account associated with that email address.";
5959+ $e_email = "Invalid";
6060+ }
6161+6262+ if (!$errors) {
6363+ $etoken = $target_user->generateEmailToken();
6464+6565+ $mail = new PhabricatorMetaMTAMail();
6666+ $mail->setSubject('Phabricator Email Authentication');
6767+ $mail->addTos(
6868+ array(
6969+ $target_user->getEmail(),
7070+ ));
7171+ $mail->setBody(
7272+ "blah blah blah ".
7373+ PhabricatorEnv::getURI('/login/etoken/'.$etoken.'/').'?email='.phutil_escape_uri($target_user->getEmail()));
7474+ $mail->save();
7575+7676+ $view = new AphrontRequestFailureView();
7777+ $view->setHeader('Check Your Email');
7878+ $view->appendChild(
7979+ '<p>An email has been sent with a link you can use to login.</p>');
8080+ return $this->buildStandardPageResponse(
8181+ $view,
8282+ array(
8383+ 'title' => 'Email Sent',
8484+ ));
8585+ }
8686+ }
8787+8888+ }
8989+9090+ $email_auth = new AphrontFormView();
9191+ $email_auth
9292+ ->setAction('/login/email/')
9393+ ->setUser($request->getUser())
9494+ ->appendChild(
9595+ id(new AphrontFormTextControl())
9696+ ->setLabel('Email')
9797+ ->setName('email')
9898+ ->setValue($request->getStr('email'))
9999+ ->setError($e_email))
100100+ ->appendChild(
101101+ id(new AphrontFormRecaptchaControl())
102102+ ->setLabel('Captcha')
103103+ ->setError($e_captcha))
104104+ ->appendChild(
105105+ id(new AphrontFormSubmitControl())
106106+ ->setValue('Send Email'));
107107+108108+ $error_view = null;
109109+ if ($errors) {
110110+ $error_view = new AphrontErrorView();
111111+ $error_view->setTitle('Login Error');
112112+ $error_view->setErrors($errors);
113113+ }
114114+115115+116116+ $panel = new AphrontPanelView();
117117+ $panel->setWidth(AphrontPanelView::WIDTH_FORM);
118118+ $panel->appendChild('<h1>Forgot Password / Email Login</h1>');
119119+ $panel->appendChild($email_auth);
120120+121121+ return $this->buildStandardPageResponse(
122122+ array(
123123+ $error_view,
124124+ $panel,
125125+ ),
126126+ array(
127127+ 'title' => 'Create New Account',
128128+ ));
129129+ }
130130+131131+}
···11+<?php
22+33+/*
44+ * Copyright 2011 Facebook, Inc.
55+ *
66+ * Licensed under the Apache License, Version 2.0 (the "License");
77+ * you may not use this file except in compliance with the License.
88+ * You may obtain a copy of the License at
99+ *
1010+ * http://www.apache.org/licenses/LICENSE-2.0
1111+ *
1212+ * Unless required by applicable law or agreed to in writing, software
1313+ * distributed under the License is distributed on an "AS IS" BASIS,
1414+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515+ * See the License for the specific language governing permissions and
1616+ * limitations under the License.
1717+ */
1818+1919+final class PhabricatorEnv {
2020+ private static $env;
2121+2222+ public static function setEnvConfig(array $config) {
2323+ self::$env = $config;
2424+ }
2525+2626+ public static function getEnvConfig($key, $default = null) {
2727+ return idx(self::$env, $key, $default);
2828+ }
2929+3030+ public static function getURI($path) {
3131+ return rtrim(self::getEnvConfig('phabricator.base-uri'), '/').$path;
3232+ }
3333+3434+}
+12
src/infrastructure/env/__init__.php
···11+<?php
22+/**
33+ * This file is automatically generated. Lint this module to rebuild it.
44+ * @generated
55+ */
66+77+88+99+phutil_require_module('phutil', 'utils');
1010+1111+1212+phutil_require_source('PhabricatorEnv.php');
···11+<?php
22+33+/*
44+ * Copyright 2011 Facebook, Inc.
55+ *
66+ * Licensed under the Apache License, Version 2.0 (the "License");
77+ * you may not use this file except in compliance with the License.
88+ * You may obtain a copy of the License at
99+ *
1010+ * http://www.apache.org/licenses/LICENSE-2.0
1111+ *
1212+ * Unless required by applicable law or agreed to in writing, software
1313+ * distributed under the License is distributed on an "AS IS" BASIS,
1414+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515+ * See the License for the specific language governing permissions and
1616+ * limitations under the License.
1717+ */
1818+1919+class AphrontFormPasswordControl extends AphrontFormControl {
2020+2121+ protected function getCustomControlClass() {
2222+ return 'aphront-form-control-password';
2323+ }
2424+2525+ protected function renderInput() {
2626+ return phutil_render_tag(
2727+ 'input',
2828+ array(
2929+ 'type' => 'password',
3030+ 'name' => $this->getName(),
3131+ 'value' => $this->getValue(),
3232+ 'disabled' => $this->getDisabled() ? 'disabled' : null,
3333+ ));
3434+ }
3535+3636+}
+14
src/view/form/control/password/__init__.php
···11+<?php
22+/**
33+ * This file is automatically generated. Lint this module to rebuild it.
44+ * @generated
55+ */
66+77+88+99+phutil_require_module('phabricator', 'view/form/control/base');
1010+1111+phutil_require_module('phutil', 'markup');
1212+1313+1414+phutil_require_source('AphrontFormPasswordControl.php');
···11+<?php
22+33+/*
44+ * Copyright 2011 Facebook, Inc.
55+ *
66+ * Licensed under the Apache License, Version 2.0 (the "License");
77+ * you may not use this file except in compliance with the License.
88+ * You may obtain a copy of the License at
99+ *
1010+ * http://www.apache.org/licenses/LICENSE-2.0
1111+ *
1212+ * Unless required by applicable law or agreed to in writing, software
1313+ * distributed under the License is distributed on an "AS IS" BASIS,
1414+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515+ * See the License for the specific language governing permissions and
1616+ * limitations under the License.
1717+ */
1818+1919+class AphrontFormRecaptchaControl extends AphrontFormControl {
2020+2121+ protected function getCustomControlClass() {
2222+ return 'aphront-form-control-recaptcha';
2323+ }
2424+2525+ protected function shouldRender() {
2626+ return self::isRecaptchaEnabled();
2727+ }
2828+2929+ private static function isRecaptchaEnabled() {
3030+ return PhabricatorEnv::getEnvConfig('recaptcha.enabled');
3131+ }
3232+3333+ private static function requireLib() {
3434+ $root = phutil_get_library_root('phabricator');
3535+ require_once dirname($root).'/externals/recaptcha/recaptchalib.php';
3636+ }
3737+3838+ public static function processCaptcha(AphrontRequest $request) {
3939+ if (!self::isRecaptchaEnabled()) {
4040+ return true;
4141+ }
4242+4343+ self::requireLib();
4444+4545+ $challenge = $request->getStr('recaptcha_challenge_field');
4646+ $response = $request->getStr('recaptcha_response_field');
4747+ $resp = recaptcha_check_answer(
4848+ PhabricatorEnv::getEnvConfig('recaptcha.private-key'),
4949+ $_SERVER['REMOTE_ADDR'],
5050+ $challenge,
5151+ $response);
5252+5353+ return (bool)@$resp->is_valid;
5454+ }
5555+5656+ protected function renderInput() {
5757+ self::requireLib();
5858+5959+ return recaptcha_get_html(
6060+ PhabricatorEnv::getEnvConfig('recaptcha.public-key'),
6161+ $error = null,
6262+ $use_ssl = false);
6363+ }
6464+6565+}
+15
src/view/form/control/recaptcha/__init__.php
···11+<?php
22+/**
33+ * This file is automatically generated. Lint this module to rebuild it.
44+ * @generated
55+ */
66+77+88+99+phutil_require_module('phabricator', 'infrastructure/env');
1010+phutil_require_module('phabricator', 'view/form/control/base');
1111+1212+phutil_require_module('phutil', 'moduleutils');
1313+1414+1515+phutil_require_source('AphrontFormRecaptchaControl.php');