- 2004年11月28日 13:58
- Movable Type
Movable Type Ver 3.x に対応。(たぶん)
・コメント通知メールから直接ブラックリスト行きのリンク
・ブラックリストへの追加と同時にそのコメントの削除
コメントの事前確認を有効にしている場合
・メール通知で「コメントを受け入れる」を掲載許可へ直接リンク
参考サイト
Hacking the Hack: MT コメントSPAM Blacklist ファイル更新 : NDO::Weblog
MT コメントSPAM対策: blog.bulknews.net
MT コメントSPAM Blacklist ファイル更新: blog.bulknews.net
[MT]/lib/MT/App/Comments.pm
155行目付近 太字の部分を追加
use FileHandle;
my %banned_url;
my $blacklist = "/CGI-PATH/mt/blacklist.txt";
my $fh = FileHandle->new($blacklist) or die "$blacklist: $!";
while (<$fh>) {
chomp;
$banned_url{$_} = 1;
}
if ($banned_url{$q->param('url')}) {
return $app->handle_error('Banned');
}
require MT::IPBanList;
my $iter = MT::IPBanList->load_iter({ blog_id => $entry->blog_id });
while (my $ban = $iter->()) {
my $banned_ip = $ban->ip;
if ($user_ip =~ /$banned_ip/) {
return $app->handle_error($app->translate(
"You are not allowed to post comments."));
}
}
[MT]/lib/MT/App/Comments.pm
440行目付近 パスワードの設定をお忘れなく(secret の所)
my %param = (
blog_name => $blog->name,
entry_id => $entry->id,
entry_title => $entry->title,
view_url => $comment_link,
edit_url => $base . '?__mode=view&blog_id=' . $blog->id
. '&_type=comment&id=' . $comment->id,
ban_url => $base . '?__mode=save&_type=banlist&blog_id='
. $blog->id . '&ip=' . $comment->ip,
approve_url => $base . '?__mode=approve_comment&blog_id='
. $blog->id . '&id=' . $comment->id,
blacklist_url => $app->base . $app->path . 'mt-blacklist-append.cgi?password='
. 'secret' . '&url=' . MT::Util::encode_url($comment->url) . '&id=' . $comment->id,
comment_ip => $comment->ip,
comment_name => $comment->author,
(is_valid_email($comment->email)?
(comment_email => $comment->email):()),
comment_url => $comment->url,
comment_text => $comment->text,
unapproved => !$comment->visible(),
);
[MT]/tmpl/email/new-comment.tmpl
全部コピペしても問題無いと思います。
<TMPL_IF NAME="UNAPPROVED"><MT_TRANS phrase="An unapproved user has posted a comment on [_1], on entry #[_2] ([_3]). You need to approve this commenter before the comments will appear on your site." params="<TMPL_VAR NAME=BLOG_NAME ESCAPE=HTML>%%<TMPL_VAR NAME=ENTRY_ID>%%<TMPL_VAR NAME=ENTRY_TITLE>">
<MT_TRANS phrase="Approve this commenter:"> <<TMPL_VAR NAME=approve_url>><TMPL_ELSE><MT_TRANS phrase="A new comment has been posted on your blog [_1], on entry #[_2] ([_3])." params="<TMPL_VAR NAME=BLOG_NAME ESCAPE=HTML>%%<TMPL_VAR NAME=ENTRY_ID>%%<TMPL_VAR NAME=ENTRY_TITLE>">
</TMPL_IF NAME="UNAPPROVED">
<TMPL_UNLESS NAME="UNAPPROVED"><MT_TRANS phrase="View this comment:"> <<TMPL_VAR NAME=VIEW_URL>>
</TMPL_UNLESS><MT_TRANS phrase="Edit this comment:"> <<TMPL_VAR NAME=EDIT_URL>>
<TMPL_IF NAME="COMMENT_URL"><MT_TRANS phrase="Add URL Blacklist & delete this comment:"> <<TMPL_VAR NAME=blacklist_url>>
</TMPL_IF NAME="COMMENT_URL">
<MT_TRANS phrase="Name:"> <TMPL_VAR NAME=COMMENT_NAME>
<MT_TRANS phrase="URL:"> <TMPL_VAR NAME=COMMENT_URL>
<MT_TRANS phrase="Comments:">
<TMPL_VAR NAME=COMMENT_TEXT>
<MT_TRANS phrase="Email Address:"> <TMPL_VAR NAME=COMMENT_EMAIL>
<MT_TRANS phrase="IP Address:"> <TMPL_VAR NAME=COMMENT_IP>
[MT]/mt-blacklist-append.cgi
Permission 755
#!/usr/local/bin/perl -w
# mt-blacklist-append.cgi
# written by Tatsuhiko Miyagawa (http://blog.bulknews.net/mt/archives/000910.html/)
# modified by Naoya Ito <naoya@naoya.dyndns.org>
use strict;
use CGI;
use FileHandle;
use lib qw(/CGI-PATH/mt/lib);
use MT;
use MT::Entry;
use MT::Comment;
my $mt_cfg = "/CGI-PATH/mt/mt.cfg";
my $blacklist = "/CGI-PATH/mt/blacklist.txt";
my $password = "secret";
do_task(CGI->new);
sub do_task {
my $q = shift;
$q->param('password') eq $password
or return show_error($q, "Password mismatch");
my $out = FileHandle->new(">>$blacklist")
or return show_erorr($q, "$blacklist: $!");
$out->print($q->param('url'), "\n");
$out->close;
## deleting a spammed comment from your database and rebuild the entry.
my $mt = MT->new( Config => $mt_cfg );
my $comment = MT::Comment->load($q->param('id'))
or return show_error($q, "Comment not found");
my $entry = MT::Entry->load($comment->entry_id)
or return show_error($q, "Entry not found");
$comment->remove
or return show_erorr($q, "Removing comment failed: " . $comment->errstr);
$mt->rebuild_entry( Entry => $entry )
or return show_error($q, "Rebuliding entry failed: " . $mt->errstr);
$mt->rebuild_indexes( BlogID => $entry->blog_id)
or return show_error($q, "Rebuilding index failed: " . $mt->errstr);
print $q->header, "Blacklist appended successfully.";
}
sub show_error {
my($q, $msg) = @_;
print $q->header, "Error: $msg";
}
[MT]/blacklist.txt
Permission 666
- Newer: ラップトップはラップトップで使わないように。
- Older: Yahoo! は www がお好き?

