当前位置

Drupal验证码Captcha模块批量设置

James Qi 在 2015年3月13日 - 10:59 提交
内容摘要:我们在某些Drupal网站上安装了验证码Captcha模块后,发现依然有一些垃圾信息漏网发出,而我的这个博客安装验证码模块后这半年几乎都没遇到过垃圾信息了,对比发现我的博客网站中对验证码选用了图像方式......

  我们在某些Drupal网站上安装了验证码Captcha模块后,发现依然有一些垃圾信息漏网发出,而我的这个博客安装验证码模块后这半年几乎都没遇到过垃圾信息了,对比发现我的博客网站中对验证码选用了图像方式,而且对图像进行了一些字符扭曲、添加噪点、添加斜线等变形,不容易被机器人自动识别,而新安装的Drupal网站中验证码模块基本上没有修改过,使用的图像也是白底无变形,容易被识别出来,需要进行修改加强保护。

  而多个系列网站的子网站数量太大,人工设置容易出错,以后也很不方便修改,还是得想办法程序批量修改,我还是用老办法,先在一个例子网站的数据库中找到两个相关的表:variable和captcha_points,需要对这两个表中的一些数据进行修改、添加操作,下面是我的办法:

1、对于variable表

  先在phpmyadmin中过滤列出与captcha相关的行:

SELECT * FROM `variable` WHERE `name` LIKE '%captcha%'

  执行结果:

captcha_administration_mode
    i:0;
captcha_allow_on_admin_pages
    i:0;
captcha_default_challenge
    s:12:"captcha/Math";
captcha_add_captcha_description
    i:1;
captcha_description_zh-hans
    s:102:"此问题用于识别是否为人类访问者,以屏蔽自动发送垃圾信息的机器人程序。";
captcha_description_en
    s:103:"This question is for testing whether you ar...
captcha_default_validation
    s:1:"1";
captcha_persistence
    s:1:"1";
captcha_log_wrong_responses
    i:1;
captcha_placement_map_cache
    a:4:{s:12:"comment_form";a:3:{s:4:"path";a:0:{}s:3...
captcha_wrong_response_counter
    i:1933;
image_captcha_fonts_preview_map_cache
    a:3:{s:32:"2d0e63850e91ee2c999b22e41eb0b20c";O:8:"...
image_captcha_font_size
    s:2:"30";
image_captcha_character_spacing
    s:3:"1.2";
image_captcha_background_color
    s:7:"#ffffff";
image_captcha_foreground_color
    s:7:"#000000";
image_captcha_foreground_color_randomness
    s:3:"100";
image_captcha_file_format
    s:1:"1";
image_captcha_image_allowed_chars
    s:39:"aAbBCdEeFfGHhijKLMmNPQRrSTtWXYZ23456789";
image_captcha_code_length
    s:1:"5";
captcha_sid
    i:17229;
captcha_token
    s:32:"722f3232afc2e6ed81a95c45d9a3217d";
captcha_response
    s:5:"dfRfA";
image_captcha_fonts
    a:2:{s:61:"sites/all/modules/captcha/image_captcha...
image_captcha_distortion_amplitude
    s:1:"5";

  这些都是与验证码、图形验证码模块相关的变量,可以使用drush vset命令来修改、设置,例如:

# 添加噪点
drush vset image_captcha_dot_noise 1

# 设置默认验证方式为图形验证
drush vset captcha_default_challenge "image_captcha/Image"

# 设置默认验证方式为算术题验证
drush vset captcha_default_challenge "captcha/Math" 

  更多变量都可以逐一测试、设置。

  补充:获得vget/设置vset验证码描述的多语言翻译内容(其中部分语言没有翻译,还是默认的英语):

drush vset captcha_description_af 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_ar 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_az 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_bg 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_ca 'Aquesta pregunta és per comprovar que sou un visitant humà i prevenir els enviaments automàtics de correu brossa.'
drush vset captcha_description_cs 'Tato otázka je pro ověření, zda jste opravdový návštěvník a ne automatizovaný spamový robot.'
drush vset captcha_description_cy 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_da 'Dette spørgsmål tester hvorvidt du er et menneske og forhindrer automatisk indsendelse af spam.'
drush vset captcha_description_de 'Diese Frage soll automatisierten Spam verhindern und überprüft, ob Sie ein menschlicher Besucher sind.'
drush vset captcha_description_el 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_en 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_eo 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_es 'Esta pregunta se hace para comprobar que es usted una persona real e impedir el envío automatizado de mensajes basura.'
drush vset captcha_description_et 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_fa 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_fi 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.' 'Tämä kysymys esitetään, jotta lomakkeen automatisoitu käyttö voitaisiin estää.'
drush vset captcha_description_fil 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_fr 'Cette question permet de s\'assurer que vous êtes un utilisateur humain et non un logiciel automatisé de pollupostage (spam).'
drush vset captcha_description_ga 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_gl 'Esta pregunta é para comprobar que vostede é unha persoa e prever o envío automático de lixo.'
drush vset captcha_description_hr 'Navedeno pitanje je test da li ste spam program ili stvarna osoba.'
drush vset captcha_description_hu 'A kérdés azt vizsgálja, hogy valós látogató vagy robot szeretné az űrlapot beküldeni.'
drush vset captcha_description_hy 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_is 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_it 'Questa domanda serve a verificare che il form non venga inviato da procedure automatizzate'
drush vset captcha_description_ja 'この質問はあなたが人間かどうかをテストし、自動化されたスパム投稿を防ぐためのものです。'
drush vset captcha_description_ka 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_ko '이 질문은 당신이 정말 사람인지 아니면 기계인지의 여부를 확인하기 위해 자동화된 스팸 제출을 방지하기 위한 테스트를 위한 것입니다.'
drush vset captcha_description_lt 'Šis klausimas yra testas, ar jūs esate žmogus, tai skirta apsaugoti svetainę nuo automatinių nepageidaujamų įrašų.'
drush vset captcha_description_lv 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_mk 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_ms 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_mt 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_nl 'Deze vraag wordt gebruikt om te controleren of u een menselijke bezoeker bent om zo spam te voorkomen.'
drush vset captcha_description_pl 'Poniższe zadanie ma na celu stwierdzenie, czy jesteś człowiekiem, a tym samym przeciwdziałanie spamowi.'
drush vset captcha_description_pt 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_ro 'Această întrebare este pentru a testa dacă sunteţi un vizitator uman şi pentru a preveni spam-ul automat la trimiteri.'
drush vset captcha_description_ru 'Этот вопрос задается для того, чтобы выяснить, являетесь ли Вы  человеком или представляете из себя автоматическую спам-рассылку.'
drush vset captcha_description_sk 'Táto otázka je kvôli testu, či ste ľudský návštevník, aby sa predišlo automatickým odoslaniam spamu.'
drush vset captcha_description_sl 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_sq 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_sr 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_sv 'Denna fråga är för att testa om du är en människa och används för att hindra automatiska spaminlägg.'
drush vset captcha_description_sw 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_th 'This question is for testing whether you are a human visitor and to prevent automated spam submissions.'
drush vset captcha_description_tr 'Bu soru sizin bir insan olup olmadığınızı denetlemek ve otomatik spam gönderilerini önlemek içindir.'
drush vset captcha_description_uk 'Ціль цього запитання - довести, що ви є реальним відвідувачем і запобігти автоматизованим розсилкам спаму.'
drush vset captcha_description_vi 'Nhập các mã nhìn thấy dưới đây hoặc trả lời câu hỏi được đưa ra. Việc này để ngăn chặn việc tự động Spam.'
drush vset captcha_description_zh-hans '这个问题检测是否是人为访问,以防止自动的垃圾提交行为。'
drush vset captcha_description_zh-hant '這個問題是要驗證您是不是一個人類訪客,以防止這個網垃被自動化程式貼入大量的垃圾資訊。'

2、对于captcha_points表

  打开此表查看内容:

form_id    module    captcha_type
comment_form    NULL    NULL
contact_mail_user    NULL    default
contact_mail_page    NULL    default
user_register    NULL    default
user_pass    NULL    NULL
user_login    NULL    NULL
user_login_block    captcha    Math
forum_node_form    image_captcha    Image

  很明显是各种表单对应选用什么验证方式,有四种:无、默认、图形、算术,不过这个表内容的增加、修改就比variable表麻烦一点,没有drush vset这样的方式,需要运行sql命令,例如:

  修改:

drush sql-query "UPDATE captcha_points SET module = NULL, captcha_type = 'default' WHERE form_id = 'comment_node_gongshang_form';"

  新增:

drush sql-query "INSERT INTO captcha_points (form_id, module, captcha_type) VALUES ('comment_node_gongshang_form', NULL, 'default');" 

  如果不确定是否有此行,可以“修改”、“新增”都运行,反正只可能有一种运行成功。

  上面我都是用了drush来进行变量设置、数据库更改的,如果没有安装drush,也可以做个php程序来进行,只要要进行一些初始化、调用drupal API,麻烦一些,也同样可以实现程序批量设置。

 

评论

-- 发自IP地址: 58.49.21.84 (位置 | 谁是)

$d vset image_captcha_distortion_amplitude 3 //Distortion level选为3

$d vset image_captcha_dot_noise 1 //将Add salt and pepper noise选取

$d vset image_captcha_line_noise 1 //Add line noise选取

$d vset image_captcha_noise_level 3 //Add line noise选取以后对Noise level的设置