[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\captcha\plugins; 15 16 class recaptcha extends captcha_abstract 17 { 18 var $recaptcha_server = 'http://www.google.com/recaptcha/api'; 19 var $recaptcha_server_secure = 'https://www.google.com/recaptcha/api'; // class constants :( 20 21 var $response; 22 23 /** 24 * Constructor 25 */ 26 public function __construct() 27 { 28 global $request; 29 $this->recaptcha_server = $request->is_secure() ? $this->recaptcha_server_secure : $this->recaptcha_server; 30 } 31 32 function init($type) 33 { 34 global $user, $request; 35 36 $user->add_lang('captcha_recaptcha'); 37 parent::init($type); 38 $this->response = $request->variable('g-recaptcha-response', ''); 39 } 40 41 public function is_available() 42 { 43 global $config, $user; 44 $user->add_lang('captcha_recaptcha'); 45 return (isset($config['recaptcha_pubkey']) && !empty($config['recaptcha_pubkey'])); 46 } 47 48 /** 49 * API function 50 */ 51 function has_config() 52 { 53 return true; 54 } 55 56 static public function get_name() 57 { 58 return 'CAPTCHA_RECAPTCHA'; 59 } 60 61 /** 62 * This function is implemented because required by the upper class, but is never used for reCaptcha. 63 */ 64 function get_generator_class() 65 { 66 throw new \Exception('No generator class given.'); 67 } 68 69 function acp_page($id, $module) 70 { 71 global $config, $template, $user, $phpbb_log, $request; 72 73 $captcha_vars = array( 74 'recaptcha_pubkey' => 'RECAPTCHA_PUBKEY', 75 'recaptcha_privkey' => 'RECAPTCHA_PRIVKEY', 76 ); 77 78 $module->tpl_name = 'captcha_recaptcha_acp'; 79 $module->page_title = 'ACP_VC_SETTINGS'; 80 $form_key = 'acp_captcha'; 81 add_form_key($form_key); 82 83 $submit = $request->variable('submit', ''); 84 85 if ($submit && check_form_key($form_key)) 86 { 87 $captcha_vars = array_keys($captcha_vars); 88 foreach ($captcha_vars as $captcha_var) 89 { 90 $value = $request->variable($captcha_var, ''); 91 if ($value) 92 { 93 $config->set($captcha_var, $value); 94 } 95 } 96 97 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_VISUAL'); 98 trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($module->u_action)); 99 } 100 else if ($submit) 101 { 102 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($module->u_action)); 103 } 104 else 105 { 106 foreach ($captcha_vars as $captcha_var => $template_var) 107 { 108 $var = (isset($_REQUEST[$captcha_var])) ? $request->variable($captcha_var, '') : ((isset($config[$captcha_var])) ? $config[$captcha_var] : ''); 109 $template->assign_var($template_var, $var); 110 } 111 112 $template->assign_vars(array( 113 'CAPTCHA_PREVIEW' => $this->get_demo_template($id), 114 'CAPTCHA_NAME' => $this->get_service_name(), 115 'U_ACTION' => $module->u_action, 116 )); 117 118 } 119 } 120 121 // not needed 122 function execute_demo() 123 { 124 } 125 126 // not needed 127 function execute() 128 { 129 } 130 131 function get_template() 132 { 133 global $config, $user, $template, $phpbb_root_path, $phpEx; 134 135 if ($this->is_solved()) 136 { 137 return false; 138 } 139 else 140 { 141 $contact_link = phpbb_get_board_contact_link($config, $phpbb_root_path, $phpEx); 142 $explain = $user->lang(($this->type != CONFIRM_POST) ? 'CONFIRM_EXPLAIN' : 'POST_CONFIRM_EXPLAIN', '<a href="' . $contact_link . '">', '</a>'); 143 144 $template->assign_vars(array( 145 'RECAPTCHA_SERVER' => $this->recaptcha_server, 146 'RECAPTCHA_PUBKEY' => isset($config['recaptcha_pubkey']) ? $config['recaptcha_pubkey'] : '', 147 'S_RECAPTCHA_AVAILABLE' => self::is_available(), 148 'S_CONFIRM_CODE' => true, 149 'S_TYPE' => $this->type, 150 'L_CONFIRM_EXPLAIN' => $explain, 151 )); 152 153 return 'captcha_recaptcha.html'; 154 } 155 } 156 157 function get_demo_template($id) 158 { 159 return $this->get_template(); 160 } 161 162 function get_hidden_fields() 163 { 164 $hidden_fields = array(); 165 166 // this is required for posting.php - otherwise we would forget about the captcha being already solved 167 if ($this->solved) 168 { 169 $hidden_fields['confirm_code'] = $this->code; 170 } 171 $hidden_fields['confirm_id'] = $this->confirm_id; 172 return $hidden_fields; 173 } 174 175 function uninstall() 176 { 177 $this->garbage_collect(0); 178 } 179 180 function install() 181 { 182 return; 183 } 184 185 function validate() 186 { 187 if (!parent::validate()) 188 { 189 return false; 190 } 191 else 192 { 193 return $this->recaptcha_check_answer(); 194 } 195 } 196 197 /** 198 * Calls an HTTP POST function to verify if the user's guess was correct 199 * 200 * @return bool|string Returns false on success or error string on failure. 201 */ 202 function recaptcha_check_answer() 203 { 204 global $config, $user; 205 206 //discard spam submissions 207 if ($this->response == null || strlen($this->response) == 0) 208 { 209 return $user->lang['RECAPTCHA_INCORRECT']; 210 } 211 212 $recaptcha = new \ReCaptcha\ReCaptcha($config['recaptcha_privkey']); 213 $result = $recaptcha->verify($this->response, $user->ip); 214 215 if ($result->isSuccess()) 216 { 217 $this->solved = true; 218 return false; 219 } 220 else 221 { 222 return $user->lang['RECAPTCHA_INCORRECT']; 223 } 224 } 225 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |