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