hypweb.net
XOOPSマニア  最新情報のRSS(サイト全体)
[ 自宅サーバーWebRing |ID=54 前後5表示乱移動サイト一覧 ]

TOP » UsersWiki » nao-pon » blog » 2006-08-28

POST SPAM 対策を考える anchor.png

最近、POST SPAM がうざい鬱陶しいので、ちょっと対策を考えてみました。

面倒なので、XOOPS全体でPOST時にチェックをかけてみます。

Page Top

HypCommonFunc に関数を追加。 anchor.png

<a>タグの数、BBコードの[URL=]の数、URLの数をカウントします。

汎用関数の get_postspam_avr() で POSTデータ中に含まれる合計を取得できます。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
	// 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&#x7c;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;
		}
	}
Page Top

XOOPS_ROOT/include/common.php の最後に次の内容を書き加えます。 anchor.png

この例では、ゲストは 15ポイント超、ログインユーザーは 30ポイント超で、弾かれます。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
	// PostSpam をチェック by nao-pon
	HypCommonFunc::PostSpam_filter("/((?:ht&#x7c;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 に投入します。


  • おおおおおぉぉぉぉぉぉ!!はじくテキストパターンも簡単に追加できるようになるといいなぁ。でもこのままでも最高! -- t_miyabi 2006-08-28 (月) 16:12:15
  • そうですね。テキストパターンフィルターも必要ですね。ということで上記のコードを修正しました。
    正規表現のフィルターとその加算ポイントを追加できます。
    とりあえず追加したフィルターは、
    HypCommonFunc::PostSpam_filter("/((?:ht|f)tps?:\/\/[!~*'();\/?:\@&=+\$,%#\w.-]+).*?<a.+?\\1.+?\/a>.*?\[url=\\1.+?\/url\]/is", 11);
    です。
    -- nao-pon&trip("iq8llSWq9g"); 2006-08-29 (火) 10:51:32



トップ   凍結 差分 バックアップ 複製 名前変更 リロード印刷に適した表示   ページ新規作成 全ページ一覧 単語検索 最新ページの一覧   ヘルプ   最新ページのRSS 1.0 最新ページのRSS 2.0 最新ページのRSS Atom Powered by xpWiki
Counter: 303, today: 1, yesterday: 0
初版日時: 2006-08-28 (月) 09:11:29
最終更新: 2006-08-29 (火) 10:51:32 (JST) (6412d) by nao-pon
このページのTopへ
メインメニュー
ログイン

ユーザー名:


パスワード:





パスワード紛失  |新規登録
最近の更新
オンライン状況
22 人のユーザが現在オンラインです。 (1 人のユーザが UsersWiki を参照しています。)

登録ユーザ: 0
ゲスト: 22

もっと...
サイト情報