<%
'****************************************************
'函数名：Checktgzcm
'作  用：检查管理员是否登录
'参  数：True/False
'****************************************************
Function Checktgzcm()
	SiteManageCode=tgzcm(3)
	'检查管理员是否登录
	Site_Sn=Replace(Replace(LCase(Request.ServerVariables("SERVER_NAME") & GetScriptPath(Trim(Request.ServerVariables("SCRIPT_NAME")), 1)), "/", ""), ".", "")
	AdminName = ReplaceBadChar(Trim(Request.Cookies(Site_Sn)("AdminName")))
	AdminPassword = ReplaceBadChar(Trim(Request.Cookies(Site_Sn)("AdminPassword")))
	RndPassword = ReplaceBadChar(Trim(Request.Cookies(Site_Sn)("RndPassword")))
	AdminLoginCode = ReplaceBadChar(Trim(Request.Cookies(Site_Sn)("AdminLoginCode")))
	If AdminName = "" Or AdminPassword = "" Or RndPassword = ""  Or AdminLoginCode <> SiteManageCode Then
		Checktgzcm=False
	Else
	    Checktgzcm=True
	End If
End Function

'**************************************************
'函数名：GetRndPassword
'作  用：生成随机
'**************************************************
Function GetRndPassword(PasswordLen)
    Dim Ran, i, strPassword
    strPassword = ""
    For i = 1 To PasswordLen
        Randomize
        Ran = CInt(Rnd * 2)
        Randomize
        If Ran = 0 Then
            Ran = CInt(Rnd * 25) + 97
            strPassword = strPassword & UCase(Chr(Ran))
        ElseIf Ran = 1 Then
            Ran = CInt(Rnd * 9)
            strPassword = strPassword & Ran
        ElseIf Ran = 2 Then
            Ran = CInt(Rnd * 25) + 97
            strPassword = strPassword & Chr(Ran)
        End If
    Next
    GetRndPassword = strPassword
End Function

Function GetScriptPath(ByVal ScriptName, ParentLevel)
    Dim i
    GetScriptPath = "/"
    If ScriptName = "" Or IsNull(ScriptName) Then Exit Function
    If ParentLevel > 1 Then ParentLevel = 1
    If ParentLevel = 0 Then
        GetScriptPath = Left(ScriptName, InStrRev(ScriptName, "/"))
    ElseIf ParentLevel = 1 Then
        i = InStrRev(ScriptName, "/") - 1
        If i < 1 Then i = 1
        GetScriptPath = Left(ScriptName, InStrRev(ScriptName, "/", i))
    End If
    If Right(GetScriptPath, 1) <> "/" Then GetScriptPath = GetScriptPath & "/"
End Function

'**************************************************
'函数名：ReplaceBadChar
'作  用：过滤非法的SQL字符
'参  数：strChar-----要过滤的字符
'返回值：过滤后的字符
'**************************************************
Function ReplaceBadChar(strChar)
    If strChar = "" Or IsNull(strChar) Then
        ReplaceBadChar = ""
        Exit Function
    End If
    Dim strBadChar, arrBadChar, tempChar, i
    strBadChar = "+,',--,%,^,&,?,(,),<,>,[,],{,},/,\,;,:," & Chr(34) & "," & Chr(0) & ""
    arrBadChar = Split(strBadChar, ",")
    tempChar = strChar
    For i = 0 To UBound(arrBadChar)
        tempChar = Replace(tempChar, arrBadChar(i), "")
    Next
    tempChar = Replace(tempChar, "@@", "@")
    ReplaceBadChar = tempChar
End Function


'****************************************************
'函数名：Replacehtml
'作  用：清理html
'参  数：tstr ----字符串
'****************************************************
Function ReplaceHtml(str)
	Dim re
	Set re=new RegExp
	re.IgnoreCase =True
	re.Global=True
	re.Pattern="<(p|\/p|br)>"
	str=re.Replace(str,vbNewLine)
	re.Pattern="<img.[^>]*src(=| )(.[^>]*)>"
	str=re.replace(str,"[img]$2[/img]")
	re.Pattern="<(.[^>]*)>"
	str=re.Replace(str,"")
	Set Re=Nothing
	ReplaceHtml=str
End Function

Function NoSqlHack(content)
	Dim f_NoSqlHack_AllStr,f_NoSqlHack_Str,f_NoSqlHack_i,Str_InputStr
	If content = "" Or IsNull(content) Then Exit Function
	Str_InputStr=content
	f_NoSqlHack_AllStr="dbcc|alter|drop|* |and|exec|insert|select|delete|update|count|master|truncate|declare|char|mid(|chr|set |where|xp_cmdshell|tab|union|'|%"
	f_NoSqlHack_Str = Split(f_NoSqlHack_AllStr,"|")
	For f_NoSqlHack_i=LBound(f_NoSqlHack_Str) To Ubound(f_NoSqlHack_Str)
		If Instr(LCase(Str_InputStr),f_NoSqlHack_Str(f_NoSqlHack_i))<>0 Then
			If f_NoSqlHack_Str(f_NoSqlHack_i)="'" Then f_NoSqlHack_Str(f_NoSqlHack_i)=" \' "
			Response.Write "<html><title>警告</title><body bgcolor=""EEEEEE"" leftmargin=""60"" topmargin=""30""><font style=""font-size:16px;font-weight:bolder;color:blue;""><li>您提交的数据有恶意字符</li></font><font style=""font-size:14px;font-weight:bolder;color:red;""><br><li>您的数据已经被记录!</li><br><li>您的IP："&Request.ServerVariables("Remote_Addr")&"</li><br><li>操作日期："&Now&"</li></font></body></html>"
			Response.End
		End if
	Next
	NoSqlHack = Replace(Replace(Str_InputStr,"'","''"),"%27","''")
End Function

Function  FilterDirty(content)'过滤非法色情关键字
	Dim dirtyStr,dirtyStrArray,i : dirtyStr="%u80E1%u9526%u6D9B%2C%u6E29%u5BB6%u5B9D%2C%u5C3B%2C%u5C4C%2C%u64CD%u4F60%2C%u5E72%u6B7B%u4F60%2C%u8D31%u4EBA%2C%u72D7%u5A18%2C%u5A4A%u5B50%2C%u8868%u5B50%2C%u9760%u4F60%2C%u53C9%u4F60%2C%u53C9%u6B7B%2C%u63D2%u4F60%2C%u63D2%u6B7B%2C%u5E72%u4F60%2C%u5E72%u6B7B%2C%u65E5%u4F60%2C%u65E5%u6B7B%2C%u9E21%u5DF4%2C%u777E%u4E38%2C%u5305%u76AE%2C%u9F9F%u5934%2C%u5C44%2C%u8D51%2C%u59A3%2C%u808F%2C%u5976%u5B50%2C%u5976%u5934%2C%u9634%u6BDB%2C%u9634%u9053%2C%u9634%u830E%2C%u53EB%u5E8A%2C%u5F3A%u5978%2C%u7231%u6DB2%2C%u6027%u9AD8%u6F6E%2C%u505A%u7231%2C%u6027%u4EA4%2C%u53E3%u4EA4%2C%u809B%u4EA4"
	dirtyStrArray=split(unescape(dirtyStr),",")
	for i=0 to ubound(dirtyStrArray)
		content=replace(content,dirtyStrArray(i),"^v^",1,-1,1)
	next
	FilterDirty=content
End Function

Function Bad_Url(strValue)
	Set regEx = New RegExp
	regEx.IgnoreCase = True
	regEx.Global = True
	'
    Dim strCustom, strParameter
	strCustom = strValue
    'regEx.Pattern = "\.[\s\S]*"
	regEx.Pattern = "(\w+\.|\s(com.cn|net.cn|com|cn|cc|net|org|la))"
    Set Matches = regEx.Execute(strCustom)
    For Each Match In Matches
		strCustom=Replace(strCustom,Match.value,"^v^")
    Next
    Bad_Url = strCustom
End Function

Function CloseCai(str)
   Dim AppealNum,AppealCount 
   AppealNum=10 '同一IP60秒内请求限制10次 
   AppealCount=Request.Cookies("AppealCount") 
   If AppealCount="" Then 
     response.Cookies("AppealCount")=1 
     AppealCount=1 
     response.cookies("AppealCount").expires=dateadd("s",60,now()) 
   Else 
     response.Cookies("AppealCount")=AppealCount+1 
     response.cookies("AppealCount").expires=dateadd("s",60,now()) 
   End If 
   if int(AppealCount)>int(AppealNum) then 
     Response.Write("<script language=""javascript"">")
     Response.Write("alert('"&str&"')")
     Response.Write("</script>") 
     response.end 
   End If
End Function

Function Chkhttp()
Dim server_v1,server_v2,urlwww
server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
urlwww=instr(server_v1,"baidu.com")
if mid(server_v1,8,len(server_v2))<>server_v2   then
Response.Write "<BR><table width='350' border='0' align='center' cellpadding='0' cellspacing='0' style='font-size:14px; border:1px #CCCCCC dashed; text-align:center; color:#666' ><tr><td height='40'>操作错误，禁止从站点外部提交任何数据！</td></tr></table>"
response.end
end if
end Function
%>