<%
'inc_antiSpam
'OBlog3.2 Module 
'For Reg,Post,Comment,Message
'Min AD Content(18):<a href=x.cn>x</a>
'Protect Class
'1-Base ;2-Middle;3-Advance
Function antiSpam(sContent,sMode)
	If CheckDoubtfulLinks(sContent,"1")="1" Then
		antiSpam="1"
		If C_Spam_Class<>3 Then Exit Function
	End If
	If CheckDoubtfulLinks(sContent,"2")="1" Then
		antiSpam="1"
		If C_Spam_Class<>3 Then Exit Function
	End If
	If C_Spam_30MinutesOneIp>0 Then
		If CheckDoubtfulIp(sMode)="1" Then
			antiSpam="1"
			If C_Spam_Class<>3 Then Exit Function
		End If
	End If
End Function


'检查回复频度
Function  CheckDoubtfulIp(sMode)
	'内容过滤字前面已经处理过，此处进行重复性处理
	Dim rst,rstCache
	Set rst=Server.CreateObject("Adodb.Recordset")
	If sMode="1" Then
		If is_sqldata=1 Then
			Set rst=oblog.Execute("Select count(commentid) From Oblog_Comment Where addip='" & oblog.userip & "' And datediff(n,addtime,getdate())<=30")
		Else
			Set rst=oblog.Execute("Select count(commentid) From Oblog_Comment Where addip='" & oblog.userip & "' And datediff('n',addtime,now())<=30")
		End If
	Else
		If is_sqldata=1 Then
			Set rst=oblog.Execute("Select count(messageid) From Oblog_Message Where addip='" & oblog.userip & "' And datediff(n,addtime,getdate())<=30")
		Else
			Set rst=oblog.Execute("Select count(messageid) From Oblog_Message Where addip='" & oblog.userip & "' And datediff('n',addtime,now())<=30")
		End If
	End If
	If rst(0)>C_Spam_30MinutesOneIp Then
		'加入黑名单
		Set  rstCache=Server.CreateObject("Adodb.RecordSet")
		rstCache.Open "Select * From oblog_setup where ID=1",conn,1,3
		rstCache("lockip")=rstCache("lockip") & vbcrlf & oblog.userip
		rstCache.Update
		rstCache.Close
		Set rstCache=Nothing
		oblog.reloadsetup
		CheckDoubtfulIp="1"
	End If
	rst.Close
	Set rst=Nothing
End Function
'检查可疑连接
Function CheckDoubtfulLinks(sContent,sMode) 
	Dim oRegExp,oMatch,spamCount
	Set oRegExp = New Regexp
	oRegExp.IgnoreCase = True
	oRegExp.Global = True
	CheckDoubtfulLinks="0"
	If Len(sContent)<=18 Then Exit Function
	If sMode="1" Then
		'Links
		oRegExp.Pattern = "href"
		Set oMatch=oRegExp.Execute(sContent)
		spamCount=oMatch.Count
		If spamCount>C_Spam_MaxLinks Then CheckDoubtfulLinks="1"
	Else
		If C_Spam_MaxMedias=-1 Then Exit Function
		'Image/flash/media 
		oRegExp.Pattern = "src"
		Set oMatch=oRegExp.Execute(sContent)
		spamCount= oMatch.Count
		If spamCount>C_Spam_MaxMedias Then CheckDoubtfulLinks="1"
	End If
	Set oRegExp=Nothing
End Function

%>