我們在某些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,麻煩一些,也同樣可以實現程序批量設置。
评论1
$d vset image_captcha
$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的設置