Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
recaptcha.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\captcha\plugins;
015
016 class recaptcha extends captcha_abstract
017 {
018 var $recaptcha_server = 'http://www.google.com/recaptcha/api';
019 var $recaptcha_server_secure = 'https://www.google.com/recaptcha/api'; // class constants :(
020
021 // We are opening a socket to port 80 of this host and send
022 // the POST request asking for verification to the path specified here.
023 var $recaptcha_verify_server = 'www.google.com';
024 var $recaptcha_verify_path = '/recaptcha/api/verify';
025
026 var $challenge;
027 var $response;
028
029 // PHP4 Constructor
030 function phpbb_recaptcha()
031 {
032 global $request;
033 $this->recaptcha_server = $request->is_secure() ? $this->recaptcha_server_secure : $this->recaptcha_server;
034 }
035
036 function init($type)
037 {
038 global $config, $db, $user;
039
040 $user->add_lang('captcha_recaptcha');
041 parent::init($type);
042 $this->challenge = request_var('recaptcha_challenge_field', '');
043 $this->response = request_var('recaptcha_response_field', '');
044 }
045
046 public function is_available()
047 {
048 global $config, $user;
049 $user->add_lang('captcha_recaptcha');
050 return (isset($config['recaptcha_pubkey']) && !empty($config['recaptcha_pubkey']));
051 }
052
053 /**
054 * API function
055 */
056 function has_config()
057 {
058 return true;
059 }
060
061 static public function get_name()
062 {
063 return 'CAPTCHA_RECAPTCHA';
064 }
065
066 /**
067 * This function is implemented because required by the upper class, but is never used for reCaptcha.
068 */
069 function get_generator_class()
070 {
071 throw new \Exception('No generator class given.');
072 }
073
074 function acp_page($id, &$module)
075 {
076 global $config, $db, $template, $user;
077
078 $captcha_vars = array(
079 'recaptcha_pubkey' => 'RECAPTCHA_PUBKEY',
080 'recaptcha_privkey' => 'RECAPTCHA_PRIVKEY',
081 );
082
083 $module->tpl_name = 'captcha_recaptcha_acp';
084 $module->page_title = 'ACP_VC_SETTINGS';
085 $form_key = 'acp_captcha';
086 add_form_key($form_key);
087
088 $submit = request_var('submit', '');
089
090 if ($submit && check_form_key($form_key))
091 {
092 $captcha_vars = array_keys($captcha_vars);
093 foreach ($captcha_vars as $captcha_var)
094 {
095 $value = request_var($captcha_var, '');
096 if ($value)
097 {
098 set_config($captcha_var, $value);
099 }
100 }
101
102 add_log('admin', 'LOG_CONFIG_VISUAL');
103 trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($module->u_action));
104 }
105 else if ($submit)
106 {
107 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($module->u_action));
108 }
109 else
110 {
111 foreach ($captcha_vars as $captcha_var => $template_var)
112 {
113 $var = (isset($_REQUEST[$captcha_var])) ? request_var($captcha_var, '') : ((isset($config[$captcha_var])) ? $config[$captcha_var] : '');
114 $template->assign_var($template_var, $var);
115 }
116
117 $template->assign_vars(array(
118 'CAPTCHA_PREVIEW' => $this->get_demo_template($id),
119 'CAPTCHA_NAME' => $this->get_service_name(),
120 'U_ACTION' => $module->u_action,
121 ));
122
123 }
124 }
125
126 // not needed
127 function execute_demo()
128 {
129 }
130
131 // not needed
132 function execute()
133 {
134 }
135
136 function get_template()
137 {
138 global $config, $user, $template, $phpbb_root_path, $phpEx;
139
140 if ($this->is_solved())
141 {
142 return false;
143 }
144 else
145 {
146 $contact_link = phpbb_get_board_contact_link($config, $phpbb_root_path, $phpEx);
147 $explain = $user->lang(($this->type != CONFIRM_POST) ? 'CONFIRM_EXPLAIN' : 'POST_CONFIRM_EXPLAIN', '<a href="' . $contact_link . '">', '</a>');
148
149 $template->assign_vars(array(
150 'RECAPTCHA_SERVER' => $this->recaptcha_server,
151 'RECAPTCHA_PUBKEY' => isset($config['recaptcha_pubkey']) ? $config['recaptcha_pubkey'] : '',
152 'RECAPTCHA_ERRORGET' => '',
153 'S_RECAPTCHA_AVAILABLE' => self::is_available(),
154 'S_CONFIRM_CODE' => true,
155 'S_TYPE' => $this->type,
156 'L_CONFIRM_EXPLAIN' => $explain,
157 ));
158
159 return 'captcha_recaptcha.html';
160 }
161 }
162
163 function get_demo_template($id)
164 {
165 return $this->get_template();
166 }
167
168 function get_hidden_fields()
169 {
170 $hidden_fields = array();
171
172 // this is required for posting.php - otherwise we would forget about the captcha being already solved
173 if ($this->solved)
174 {
175 $hidden_fields['confirm_code'] = $this->code;
176 }
177 $hidden_fields['confirm_id'] = $this->confirm_id;
178 return $hidden_fields;
179 }
180
181 function uninstall()
182 {
183 $this->garbage_collect(0);
184 }
185
186 function install()
187 {
188 return;
189 }
190
191 function validate()
192 {
193 if (!parent::validate())
194 {
195 return false;
196 }
197 else
198 {
199 return $this->recaptcha_check_answer();
200 }
201 }
202
203 // Code from here on is based on recaptchalib.php
204 /*
205 * This is a PHP library that handles calling reCAPTCHA.
206 * - Documentation and latest version
207 * http://recaptcha.net/plugins/php/
208 * - Get a reCAPTCHA API Key
209 * http://recaptcha.net/api/getkey
210 * - Discussion group
211 * http://groups.google.com/group/recaptcha
212 *
213 * Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
214 * AUTHORS:
215 * Mike Crawford
216 * Ben Maurer
217 *
218 * Permission is hereby granted, free of charge, to any person obtaining a copy
219 * of this software and associated documentation files (the "Software"), to deal
220 * in the Software without restriction, including without limitation the rights
221 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
222 * copies of the Software, and to permit persons to whom the Software is
223 * furnished to do so, subject to the following conditions:
224 *
225 * The above copyright notice and this permission notice shall be included in
226 * all copies or substantial portions of the Software.
227 *
228 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
229 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
230 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
231 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
232 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
233 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
234 * THE SOFTWARE.
235 */
236
237 /**
238 * Submits an HTTP POST to a reCAPTCHA server
239 * @param string $host
240 * @param string $path
241 * @param array $data
242 * @param int port
243 * @return array response
244 */
245 function _recaptcha_http_post($host, $path, $data, $port = 80)
246 {
247 $req = $this->_recaptcha_qsencode ($data);
248
249 $http_request = "POST $path HTTP/1.0\r\n";
250 $http_request .= "Host: $host\r\n";
251 $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
252 $http_request .= "Content-Length: " . strlen($req) . "\r\n";
253 $http_request .= "User-Agent: reCAPTCHA/PHP/phpBB\r\n";
254 $http_request .= "\r\n";
255 $http_request .= $req;
256
257 $response = '';
258 if (false == ($fs = @fsockopen($host, $port, $errno, $errstr, 10)))
259 {
260 trigger_error('RECAPTCHA_SOCKET_ERROR', E_USER_ERROR);
261 }
262
263 fwrite($fs, $http_request);
264
265 while (!feof($fs))
266 {
267 // One TCP-IP packet
268 $response .= fgets($fs, 1160);
269 }
270 fclose($fs);
271 $response = explode("\r\n\r\n", $response, 2);
272
273 return $response;
274 }
275
276 /**
277 * Calls an HTTP POST function to verify if the user's guess was correct
278 * @param array $extra_params an array of extra variables to post to the server
279 * @return ReCaptchaResponse
280 */
281 function recaptcha_check_answer($extra_params = array())
282 {
283 global $config, $user;
284
285 //discard spam submissions
286 if ($this->challenge == null || strlen($this->challenge) == 0 || $this->response == null || strlen($this->response) == 0)
287 {
288 return $user->lang['RECAPTCHA_INCORRECT'];
289 }
290
291 $response = $this->_recaptcha_http_post($this->recaptcha_verify_server, $this->recaptcha_verify_path,
292 array(
293 'privatekey' => $config['recaptcha_privkey'],
294 'remoteip' => $user->ip,
295 'challenge' => $this->challenge,
296 'response' => $this->response
297 ) + $extra_params
298 );
299
300 $answers = explode("\n", $response[1]);
301
302 if (trim($answers[0]) === 'true')
303 {
304 $this->solved = true;
305 return false;
306 }
307 else
308 {
309 return $user->lang['RECAPTCHA_INCORRECT'];
310 }
311 }
312
313 /**
314 * Encodes the given data into a query string format
315 * @param $data - array of string elements to be encoded
316 * @return string - encoded request
317 */
318 function _recaptcha_qsencode($data)
319 {
320 $req = '';
321 foreach ($data as $key => $value)
322 {
323 $req .= $key . '=' . urlencode(stripslashes($value)) . '&';
324 }
325
326 // Cut the last '&'
327 $req = substr($req, 0, strlen($req) - 1);
328 return $req;
329 }
330 }
331