最近、POST SPAM がうざい鬱陶しいので、ちょっと対策を考えてみました。
面倒なので、XOOPS全体でPOST時にチェックをかけてみます。
<a>タグの数、BBコードの[URL=]の数、URLの数をカウントします。
汎用関数の get_postspam_avr() で POSTデータ中に含まれる合計を取得できます。
// POST SPAM Check
function PostSpam_Check($post)
{
static $filters = NULL;
if (is_null($filters)) {$filters = HypCommonFunc::PostSpam_filter();}
$counts = array();
$counts[0] = $counts[1] = $counts[2] = $counts[3] = 0;
foreach($post as $dat)
{
$tmp = array();
$tmp['a'] = $tmp['bb'] = $tmp['url'] = $tmp['filter'] = 0;
if (is_array($dat))
{
list($tmp['a'],$tmp['bb'],$tmp['url'],$tmp['filter']) = HypCommonFunc::PostSpam_Check($dat);
}
else
{
// <a> タグの個数
$tmp['a'] = count(preg_split("/<a.+?\/a>/i",$dat)) - 1;
// [url] タグの個数
$tmp['bb'] = count(preg_split("/\[url=.+?\/url\]/i",$dat)) - 1;
// URL の個数
$tmp['url'] = count(preg_split("/(ht|f)tps?:\/\/[^\s]+/i",$dat)) - 1;
// フィルター
if ($filters)
{
foreach($filters as $reg => $point)
{
$counts[3] += (count(preg_split($reg,$dat)) - 1) * $point;
//echo $dat."<br>".$reg.": ".$counts[3]."<hr>";
}
}
}
$counts[0] += $tmp['a'];
$counts[1] += $tmp['bb'];
$counts[2] += $tmp['url'];
$counts[3] += $tmp['filter'];
}
return $counts;
}
// POST SPAM フィルター
function PostSpam_filter($reg="", $point=1)
{
static $regs = array();
if (empty($reg)) {return $regs;}
$regs[$reg] = $point;
}
// POST SPAM Check 汎用関数
function get_postspam_avr($alink=1,$bb=1,$url=1)
{
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
list($a_p,$bb_p,$url_p,$filter_p) = HypCommonFunc::PostSpam_Check($_POST);
return $a_p * $alink + $bb_p * $bb + $url_p * $url + $filter_p;
}
else
{
return 0;
}
}
この例では、ゲストは 15ポイント超、ログインユーザーは 30ポイント超で、弾かれます。
// PostSpam をチェック by nao-pon
HypCommonFunc::PostSpam_filter("/((?:ht|f)tps?:\/\/[!~*'();\/?:\@&=+\$,%#\w.-]+).*?<a.+?\\1.+?\/a>.*?\[url=\\1.+?\/url\]/is", 11);
if (!is_object($xoopsUser))
{
if (HypCommonFunc::get_postspam_avr() > 15)
{
header("Location: ".XOOPS_URL."/");
exit();
}
}
else if (!$xoopsUserIsAdmin)
{
if (HypCommonFunc::get_postspam_avr() > 30)
{
header("Location: ".XOOPS_URL."/");
exit();
}
}
しばらく、これで様子を見てみて調子がいいようなら CVS に投入します。
| Page name: | 徒然日記/2006-08-28 [ Sended pings(7) ] | |
| Author: | nao-pon | - 2006/08/29 10:51:32 JST(732d) |
| Last edit: | nao-pon | - 2006/08/29 10:51:32 JST(732d) |
| Editers: | nao-pon | |
| Back Link: | nao-pon(144d) CVS(318d) t_miyabi(789d) XOOPS(812d) HypCommonFunc(876d) nao-pon(1058d) 徒然日記(1470d) | |
ログイン
アクティブメニュー
"ぽちっ"としてね☆
最新のページ
ブックマーク
新着トラックバック
サイト内 Wiki
☆ 検索 ☆
オンライン状況
サイト情報
現在ページのQRコード
参照元情報