LLM 應用開發工作坊心得

防制發廣告機器人的檢核碼

每隔一段會有廣告機器人濫貼迴響(spam comment), jsen寫的檢核碼外掛(SCode plugin, security code plugin)可以要求張貼迴響前,需要輸入亂數產生圖形中的數字,來達到防制廣告機器人的效果。但是這個方法的缺點是降低網頁的親和力(Accessibility),使得有視覺障礙的網友無法發表迴響。



1. 先確定主機安裝了GD模組,可以讓程式產生圖形,GD的安裝請自行聯絡主機的網站人員。
2. 到jsen的檢核碼外掛網頁,下載SCode plugin,解壓縮後,編輯SCode.pm
* 設定暫存目錄的位置 (my $tmpdir) ,並設定該目錄可寫
* 設定檢核碼的長度(my $scode_length),預設值為6個數字,我設定成4
* 設定暫存檔的檔案數量(my $scode_maxtmp),預設值為50個暫存檔,如果你的網誌常有人進行迴響,請增加暫存檔的檔案數量。
* 調整自動產生的圖形與文字的顏色:$c_background, $c_border, $c_line and $c_code.
3. 將SCode.pm 上傳到 lib/MT/ 目錄 (MT::SCode)
4. 將mt-scode.cgi上傳到MT放置CGI的目錄,並設定該檔案為可執行
5. 將scode.pl上傳到plugins/
6. 修改檔案前請記得先備份!更改lib/MT/App/Comments.pm (MT::App:Comments),如果已經安裝 mt-Blacklist 不要修改 cgi-bin/lib/MT/App/Comments.pm 而是修改 cgi-bin/extlib/jayallen /MTBlPost.pm 這個檔案。(From 酋長的說明)

if (!$q->param('text')) {
return $app->handle_error($app->translate("Comment text is required."));
}
之後加上以下段落

#

# SecurityCode hack start

#

require MT::SCode;

my $code = $q->param('code');

my $scode = $q->param('scode');

my $sscode = MT::SCode::scode_get($code);

if ($scode ne $sscode) {

return $app->handle_error($app->translate(

"Wrong or missing Security Code."));

}

MT::SCode::scode_delete($code);

MT::SCode::scode_create($code);

#

# Security hack ends

#

7. 登入MT的管理介面,修改以下4個模版
- 單篇彙整(Individual Entry Template)
- 迴響清單模版(Comment Listing Template)
- 迴響預覽模版(Comment Preview Template)
- 迴響出錯模版(Comment Error Template)

<label for="url">網址:</label><br />

<input tabindex="3" id="url" name="url" /><br/><br />

之後加入以下段落

<!-- 檢核碼檢查開始 -->

<input type="hidden" id="code" name="code" value="<$MTSecurityCode$>">

<img border="0" src="<$MTCGIPath$><$MTSecurityImage$>?code=<$MTSecurityCode$>"><br
/>

<label for="code">請依上圖輸入檢核碼:</label><br />

<input tabindex="3" id="scode" name="scode" /><br
/><br />

<!-- 檢核碼檢查結束 -->

儲存修改後重建網站檔案,就OK了。
* 其他防制廣告機器人的方法
* 中文翻譯參考Jedi的網誌上的用語。
* 關於檢核碼技術,可參考Wikipedia對於Captcha(Completely Automated Public Turing Test to Tell Computers and Humans Apart)的說明。(英文)
* Blog 有問題,去哪邊問問題?

留言

dAb寫道…
好呀~suno大哥
最近正為我的Blog充滿了機器人留言而困擾
不過我覺得台灣人已經夠吝於發表迴響了, 如果加了個檢核碼
究竟會不會有影響, 我可要思考一下
不過像您這樣輸入完個人資料以後, 多個檢核碼, 其實感覺蠻OK^^
helenna寫道…
請問,
奇怪...我安裝好了以後....同樣可以看見檢核碼...但是就算不輸入該Scode ,一樣可以comment...是哪裡設定沒改到嗎?
http://www.redeyekinda.org/hblog/000274.php#more
helenna寫道…
成功了!!^^
planetoid表示…
恭喜啊 :)
藍方寫道…
你好 我想請問一下 我安裝好了
但是就算輸入檢核碼輸對他仍會有錯誤訊息出現
MT::App::Comments=HASH(0x813237c) print() on closed filehandle OUTFILE at lib/MT/SCode.pm line 51.
這是什麼意思呢??
planetoid表示…
藍方: 檢查暫存檔目錄可否寫入
藍方寫道…
ok 了 感謝 :)
WeiChou表示…
感謝您的分享!!!
最近才遇到垃圾迴響的問題,啟用 black-list 好像沒啥用處,
只好再加上這個方法試試看了... ^^"
Andy寫道…
我依照你描述的方式安裝了!但是一直有問題,我的檢查碼的圖形怪怪的,有出現類似方格紙的圖形,但是卻沒有數字,檢查httpd的error_log中有兩個錯誤訊息:Use of uninitialized value in concatenation (.) or string at /var/www/mt/lib/MT/SCode.pm line 46以及Use of uninitialized value in subroutine entry at /var/www/mt/mt-scode.cgi line 52.
Andy寫道…
已經可以了!只有一篇文章無法正常顯示檢查碼,正好我一直使用該文章測試,所以一直無法得到正常結果,其他的文章都可以正常顯示了!
Paul寫道…
What does 將SCode.pm 上傳到 lib/MT/ 目錄 (MT::SCode) mean?
does it mean uploading scode.pm to lib/mt/ or lib/mt/scode/??
Thanks
planetoid表示…
Dear Paul:
將SCode.pm 上傳到 lib/MT/ 目錄 (MT::SCode)
不用在lib/MT/下再建立SCode子目錄
chientai表示…
我的問題是在 rebuide site 的時候﹐會出現 MT::App::Comments=HASH(0x813237c) print() on closed filehandle OUTFILE at lib/MT/SCode.pm line 50。這個問題要怎麼解決?
planetoid表示…
Dear chientai
樓上的藍方問了同樣的問題,請爬文。
Paul表示…
Hello planetoid,
我的圖形似乎出不來. (其實功能已經在那邊了, 可是看不到圖形) 我查看了 temp 檔案夾, 他有755的權限, 而且裡面也有檔案, 不過沒有副檔名... 每個檔案的size大概是 4bytes. 我download temmp folder 裡面的檔案下來 我也沒有辦法開啟. 妳覺得這個問題是我的安裝有問題嗎 還是我在哪一個步驟有出錯?? 還是server上就是沒有 GD plig-in?? 可是我有問過我的hosting company, 他說 GD libary 有在server 上.... 我已經不知道還有什麼需要check的了... 請指教 :)
planetoid表示…
Paul:
James Seng 在scode 0.1c版中有附上提供測試用的程式scodetest.cgi( http://james.seng.cc/archives/000145.html ),可以用來檢查。不過如果你的虛擬主機廠商是totalchoice,目前無解。
先前我的檢查結果是
Step 1.1 OK : GD.pm is installed
Step 1.2 OK : GD is installed
Step 1.3 OK : GD has PNG support
Step 3.0 OK : SCode.pm is installed
ERROR 2.0 : $tmpdir defined in SCode.pm is not writable by web engine!
然而$tmpdir其實已經設定成可寫入,廠商也說他們有重新安裝過GD,所以目前SCode無法運作的狀況還是無解。
阿醜寫道…
您好
設定暫存目錄的位置 (my $tmpdir) ,並設定該目錄可寫
這個部分是否可以解釋清楚一點?
小弟使用的是虛擬主機>O<
主機商說已經有灌GD模組
但我還是不太明天暫存目錄的位置意思
如果我想要存在archives的資料夾中
是指要key入網頁位置(ex:http://gaspar.info/blog/archives/ )還是直接打temp/archives/呢?
又3.15的迴響模版都沒有
<label for="url">網址:</label><br />
<input tabindex="3" id="url" name="url" /><br/><br />
的語法,是否要將模版改為舊的迴響模版?
感恩
Trago表示…
有個小問題想請教一下,
我是自己架設的伺服器。
我在PHPMYADMIN裡查PHP狀態,
GD是已經安裝啟用的,
可是用SCODETEST時,
它卻說我的GD沒有INSTALL,
請問這是什麼情況?
planetoid表示…
Trango:
記得另一個GD是屬於Perl的
大頭鼠寫道…
您好:
想請問我跑完scodetest.cgi後,出現以下訊息,似乎是正常。
但我依據4567去檢查後,
我目前的圖片仍沒出現,打了個叉。
請問還有什麼地方可能是小弟我沒注意到的?
請賜教,謝謝!!!
Step 1.1 OK : GD.pm is installed
Step 1.2 OK : GD is installed
Step 1.3 OK : GD has PNG support
Step 3.0 OK : SCode.pm is installed
Step 2.0 OK : $tmpdir in SCode.pm is defined properly
NOTE: This script does not test the Step 4 to 7 of the installation guide, namely
4. mt-scode.cgi is installed in the main directory and executable
5. scode.pl is installed in plugins directory
6. Comments.pm is patch properly with the neccessary testing
7. template is patch properly with the neccessary tags
Please also note you have to additional installation if you are using MT 3.x. See README for more details
Carrie寫道…
您好,我在裝上檢核碼之後,自行測試的結果,卻出現了以下錯誤訊息↓
迴響提交錯誤
您的迴響無法提交是因為以下原因:
為防止氾濫的垃圾評論,我開啟了如下功能,即評論人發表評論後,需要等待一小段時間才能夠再次發表評論。請嘗試等待一段時間後再發表評論,謝謝你的耐心。
請以以下方式更正錯誤,然後再發表您的迴響。
��===============
可是,在預覽的時候是正常的,但只要按下發表就會出線上頭的錯誤訊息,不知道是哪裏出了差錯呢?
又,我的檔案都已經設為755可寫入了。
planetoid表示…
Carrie:
jsen提供的程式中有一支是可以自行檢測環境的測試程式,建議透過測試程式了解,然後再回報Blog服務提供者。
寫道…
planetoid您好,
我依照貴站教學的資料,
成功顯示出檢核碼,
但是,
http://tooru.lolipop.jp/cgi-bin/mt/tooru/archives/001136.html
確有不需要輸入檢核碼就可留言的情形,
請教我需要修正那些地方呢?
planetoid寫道…
TO: 徹
到Scode作者網頁下載SCode plugin壓縮檔(檔名:scode-0.1c.tar.gz),解開後請可查看Readme內後面的FAQ第3點:作者提到SCode與另一個黑名單外掛的相容問題。
3. I got it installed, image display fine but it does not work!
Comments still gets through without keying the right code!
If you are using MT-blacklist, then you have to disable it.
(Read http://james.seng.cc/archives/000156.html )
If disabling MT-blacklist is not an option to you, then you have a bit
more work to do. You also have to apply the Step 6 hacks to MTBlPost.pm
in additional to Comment.pm. (Read http://www.muhajabah.com/islamicblog/mt-tips/archives/plugins/dealing_with_crapflooding_part_two.php )
If you are not using MT-blacklist and it still don't work, then make
sure you have apply Step 6 properly. If you are using MT 3.x, then make
sure you follow the MT 3.x installaiton guide above.