From efac3dcc325c738271287a5522f9db580a2b7859 Mon Sep 17 00:00:00 2001 From: Sascha Grossenbacher Date: Mon, 13 Oct 2014 22:54:09 +0200 Subject: [PATCH 1/2] Updated watchdog() calls --- captcha.module | 10 ++++------ image_captcha/image_captcha.module | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/captcha.module b/captcha.module index 09001d5..bdd8903 100755 --- a/captcha.module +++ b/captcha.module @@ -571,10 +571,9 @@ function captcha_validate($element, FormStateInterface &$form_state) { // TODO: this probably never happens anymore now that there is detection // for CAPTCHA session reuse attacks in _captcha_get_posted_captcha_info(). $form_state->setErrorByName('captcha', t('CAPTCHA validation error: unknown CAPTCHA session ID. Contact the site administrator if this problem persists.')); - watchdog('CAPTCHA', + \Drupal::logger('CAPTCHA')->error( 'CAPTCHA validation error: unknown CAPTCHA session ID (%csid).', - array('%csid' => var_export($csid, TRUE)), - WATCHDOG_ERROR); + array('%csid' => var_export($csid, TRUE))); } else { // Get CAPTCHA validate function or fall back on strict equality. @@ -610,7 +609,7 @@ function captcha_validate($element, FormStateInterface &$form_state) { } if (\Drupal::config('captcha.settings')->get('log_wrong_responses', FALSE)) { - watchdog('CAPTCHA', + \Drupal::logger('CAPTCHA')->notice( '%form_id post blocked by CAPTCHA module: challenge %challenge (by module %module), user answered "@response", but the solution was "@solution".', array( '%form_id' => $form_id, @@ -618,8 +617,7 @@ function captcha_validate($element, FormStateInterface &$form_state) { '@solution' => $solution, '%challenge' => $captcha_info['captcha_type'], '%module' => $captcha_info['module'], - ), - WATCHDOG_NOTICE); + )); } } } diff --git a/image_captcha/image_captcha.module b/image_captcha/image_captcha.module index 476378b..7baeb19 100755 --- a/image_captcha/image_captcha.module +++ b/image_captcha/image_captcha.module @@ -103,7 +103,7 @@ function _image_captcha_utf8_split($str) { $width = 4; } else { - watchdog('CAPTCHA', 'Encountered an illegal byte while splitting an utf8 string in characters.', array(), WATCHDOG_ERROR); + \Drupal::logger('CAPTCHA')->error('Encountered an illegal byte while splitting an utf8 string in characters.'); return $characters; } } From 8481e8a95ec3e227ce32b1bbb625962fe8161379 Mon Sep 17 00:00:00 2001 From: Milos Date: Tue, 4 Nov 2014 21:37:49 +0100 Subject: [PATCH 2/2] Fixed hook_help() implementation --- captcha.module | 19 ++++++++++--------- captcha.routing.yml | 16 ++++++++++++++++ image_captcha/image_captcha.module | 8 +++++--- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/captcha.module b/captcha.module index bdd8903..f31c809 100755 --- a/captcha.module +++ b/captcha.module @@ -11,6 +11,7 @@ use Drupal\captcha\Entity\CaptchaPoint; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; /** @@ -42,24 +43,24 @@ define('CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE', 1); /** * Implements hook_help(). */ -function captcha_help($path, $arg) { - switch ($path) { - case 'admin/help#captcha': +function captcha_help($route_name, RouteMatchInterface $route_match) { + switch ($route_name) { + case 'help.page.captcha': $output = '

' . t('"CAPTCHA" is an acronym for "Completely Automated Public Turing test to tell Computers and Humans Apart". It is typically a challenge-response test to determine whether the user is human. The CAPTCHA module is a tool to fight automated submission by malicious users (spamming) of for example comments forms, user registration forms, guestbook forms, etc. You can extend the desired forms with an additional challenge, which should be easy for a human to solve correctly, but hard enough to keep automated scripts and spam bots out.') . '

'; $output .= '

' . t('Note that the CAPTCHA module interacts with page caching (see performance settings). Because the challenge should be unique for each generated form, the caching of the page it appears on is prevented. Make sure that these forms do not appear on too many pages or you will lose much caching efficiency. For example, if you put a CAPTCHA on the user login block, which typically appears on each page for anonymous visitors, caching will practically be disabled. The comment submission forms are another example. In this case you should set the Location of comment submission form to Display on separate page in the comment settings of the relevant content types for better caching efficiency.', array( - '!performancesettings' => url('admin/config/development/performance'), - '!contenttypes' => url('admin/structure/types'), + '!performancesettings' => \Drupal::url('system.performance_settings'), + '!contenttypes' => \Drupal::url('node.overview_types'), ) ) . '

'; $output .= '

' . t('CAPTCHA is a trademark of Carnegie Mellon University.') . '

'; return $output; - case 'admin/config/people/captcha': - case 'admin/config/people/captcha/captcha': - case 'admin/config/people/captcha/captcha/settings': + case 'captcha_settings': + case 'captcha_settings_captcha': + case 'captcha_settings_general': $output = '

' . t('A CAPTCHA can be added to virtually each Drupal form. Some default forms are already provided in the form list, but arbitrary forms can be easily added and managed when the option Add CAPTCHA administration links to forms is enabled.') . '

'; - $output .= '

' . t('Users with the Skip CAPTCHA permission won\'t be offered a challenge. Be sure to grant this permission to the trusted users (e.g. site administrators). If you want to test a protected form, be sure to do it as a user without the Skip CAPTCHA permission (e.g. as anonymous user).', array('@perm' => url('admin/people/permissions'))) . '

'; + $output .= '

' . t('Users with the Skip CAPTCHA permission won\'t be offered a challenge. Be sure to grant this permission to the trusted users (e.g. site administrators). If you want to test a protected form, be sure to do it as a user without the Skip CAPTCHA permission (e.g. as anonymous user).', array('!perm' => \Drupal::url('user.admin_permissions'))) . '

'; return $output; } } diff --git a/captcha.routing.yml b/captcha.routing.yml index fe19ded..30b1d99 100755 --- a/captcha.routing.yml +++ b/captcha.routing.yml @@ -6,6 +6,22 @@ captcha_settings: requirements: _permission: 'administer CAPTCHA settings' +captcha_settings_captcha: + path: '/admin/config/people/captcha/captcha' + defaults: + _form: '\Drupal\captcha\Form\CaptchaSettingsForm' + _title: 'CAPTCHA' + requirements: + _permission: 'administer CAPTCHA settings' + +captcha_settings_general: + path: '/admin/config/people/captcha/captcha/settings' + defaults: + _form: '\Drupal\captcha\Form\CaptchaSettingsForm' + _title: 'General settings' + requirements: + _permission: 'administer CAPTCHA settings' + captcha_examples: path: '/admin/config/people/captcha/examples/{module}/{challenge}' defaults: diff --git a/image_captcha/image_captcha.module b/image_captcha/image_captcha.module index 7baeb19..cabeea6 100755 --- a/image_captcha/image_captcha.module +++ b/image_captcha/image_captcha.module @@ -5,6 +5,8 @@ * Implements image CAPTCHA for use with the CAPTCHA module */ +use Drupal\Core\Routing\RouteMatchInterface; + define('IMAGE_CAPTCHA_ALLOWED_CHARACTERS', 'aAbBCdEeFfGHhijKLMmNPQRrSTtWXYZ23456789'); // Setup status flags. @@ -19,9 +21,9 @@ define('IMAGE_CAPTCHA_FILE_FORMAT_TRANSPARENT_PNG', 3); /** * Implements hook_help(). */ -function image_captcha_help($path, $arg) { - switch ($path) { - case 'admin/config/people/captcha/image_captcha': +function image_captcha_help($route_name, RouteMatchInterface $route_match) { + switch ($route_name) { + case 'image_captcha.settings': $output = '

' . t('The image CAPTCHA is a popular challenge where a random textual code is obfuscated in an image. The image is generated on the fly for each request, which is rather CPU intensive for the server. Be careful with the size and computation related settings.') . '

'; return $output; }