Posted by をかもと at 2008年11月4日 火曜日
livedoor が提供する「スパムちゃんぷるー」のデータに基づく DNSBL を利用して、コメント投稿者の IP アドレスをチェックする WordPress 用プラグインを作成しました。
と言っても、中身は単純。スパムちゃんぷるーDNSBLに対して、DNS問い合わせしてるだけです。
で、SPAM と判定されたら問答無用で拒否します。
以下にソースを掲載しますので、利用なさりたい方はご自由に。
適当なファイル名を付けて /wp-content/plugins/ に保存して有効化すれば、使えるようになるはずです。
なお、ライセンスは明記していませんが GPL とさせてください。
<?php
/*
Plugin Name: SPAM Champuru for WordPress
Plugin URI:
Description: スパムちゃんぷるーのDNSブラックリストに含まれるIPアドレスの場合、拒否します。
Author: wokamoto
Version: 0.3.1
Author URI: http://dogmap.jp/
*/
function reject_spam_IP($ip, $email, $date) {
$spam_IP = '127.0.0.2';
$host = "dnsbl.spam-champuru.livedoor.com";
$pattern = '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/';
$check_IP = trim(preg_match($pattern, $ip) ? $ip : $_SERVER['REMOTE_ADDR']);
$spam = false;
if (preg_match($pattern, $check_IP)) {
$host = implode('.',array_reverse(split('\.',$check_IP))) . '.' . $host;
if (function_exists('dns_get_record')) {
$check_recs = dns_get_record($host, DNS_A);
if (isset($check_recs[0]['ip'])) $spam = ($check_recs[0]['ip'] === $spam_IP);
unset($check_recs);
} elseif (function_exists('gethostbyname')) {
$checked = (gethostbyname($host) === $spam_IP);
} elseif (class_exists('Net_DNS_Resolver')) {
$resolver = new Net_DNS_Resolver();
$response = $resolver->query($host, 'A');
if ($response) {
foreach ($response->answer as $rr) {
if ($rr->type === 'A') {
$spam = ($rr->address === $spam_IP);
break;
}
}
}
unset($response);
unset($resolver);
} elseif (function_exists('checkdnsrr')) {
$spam = (checkdnsrr($host, "A") === true);
}
}
if ($spam) {
wp_die('Error: Your IP Address is registered in the DNSBL (http://spam-champuru.livedoor.com/dnsbl/).');
}
}
add_action('check_comment_flood', 'reject_spam_IP', 10, 3);
?>
また、WordPress Plugins/JSeries でも配布しておりますので、そちらからダウンロードもできます。
配布ページ:
WordPress Plugins/JSeries » SPAM Champuru for WordPress (コメントSPAM判定)
つぶやく
トラックバック & ピンバック » 表示する
コメント