<!-- #include file="conn.asp" -->
<!-- #include file="cls_main.asp" -->
<%
     dim obj
     set obj = New Download
     obj.AspInit()
     set obj = nothing

Class Download

	Private ID, i, ishion
	Private Sub Class_Initialize()
		Set ishion = New Cls_Main
	End Sub
	Private Sub Class_Terminate()
		Set ishion = Nothing
	End Sub
	Public Sub AspInit()
	
		If Request.QueryString("ID") = "" Then
			Response.Write "非法操作！指定的参数不正确。"
			Response.End
		ElseIf IsNumeric(Request.QueryString("ID")) = False Then
			Response.Write "非法操作！指定的参数不正确。"
			Response.End
		Else
			ID = CLng(Request.QueryString("ID"))
			'response.write ID
			'response.end
		End If
		Call ishion.LoadSetting
		Call Main
	
	End Sub
	Private Sub Main()
		
		If ishion.Setting(24) Then
			Dim strReferer, isHttp, strHostName
			isHttp = False
			strReferer = Request.ServerVariables("HTTP_REFERER")
			strHostName = Split(ishion.Setting(10), "|")
			For i = 0 To UBound(strHostName)
				If InStr(strReferer, Trim(strHostName(i))) > 0 Then isHttp = True
			Next
			If IsNull(strReferer) Or isHttp = False Then
				Response.Write "非法操作！系统启用防盗链机制，你的下载链接来自于非法盗链页面，请访问<a href=""" & ishion.Setting(2) & """>本站页面</a>下载软件。"
				'response.redirect "../"
				Exit Sub
			End If
		End If
		
		Dim Rs, ResID, SiteID, URL
		Set Rs = ishion.Execute("select * from ishion_Down_Address where ID=" & ID)
		If Rs.EOF And Rs.BOF Then
			Response.Write ("Sorry，下载地址无效，可能已经被删除！")
			Set Rs = Nothing
			Exit Sub
		Else
			ResID = Rs("ResourceID")
			Name=Rs("Name")
			SiteID = Rs("SiteID")
			URL = Rs("URL")
		End If

		Set Rs = Nothing
		Call UpdateHits(ResID)
		'获得下载地址
		If Trim(Request.QueryString("URL1")) <> "" Then
			Response.Redirect (Trim(Request.QueryString("URL1")))
			url=Trim(Request.QueryString("URL1"))
		Else
			Response.Redirect (GetURL(SiteID, URL))
			url=GetURL(SiteID, URL)
		End If
    End Sub
	
	Private Sub UpdateHits(ResID)
		Dim Rs
		Set Rs = ishion.Execute("select HitsTotal,DateMonth,DateWeek,DateToday from ishion_Down_Resource where ID=" & ResID)
		'更新软件下载次数
		
		ishion.Execute ("update ishion_Down_Address set Hits=Hits+1 where ID=" & ID)
		ishion.Execute ("update ishion_Down_Resource set HitsTotal=HitsTotal+1,HitsMonth=HitsMonth+1,HitsWeek=HitsWeek+1,HitsToday=HitsToday+1 where ID=" & ResID)

		If DateDiff("H", Rs(3), Now) >= 24 Then ishion.Execute ("update ishion_Down_Resource set DateToday=" & SqlNowString & ",HitsToday=1 where ID=" & ResID)
		If DateDiff("D", Rs(2), Now) >= 8 Then ishion.Execute ("update ishion_Down_Resource set DateWeek=" & SqlNowString & ",HitsWeek=1 where ID=" & ResID)
		If DateDiff("D", Rs(1), Now) >= 31 Then ishion.Execute ("update ishion_Down_Resource set DateMonth=" & SqlNowString & ",HitsMonth=1 where ID=" & ResID)
		
Set Rs = Nothing
	End Sub
	Private Function GetURL(SiteID, URL)
		If SiteID = 0 Then
			GetURL = URL
			Exit Function
		Else
			Dim arrDownloadName, arrDownloadURL
			arrd=split(split(URL,"$")(Request.QueryString("sID")), ",")
			
			arrDownloadURL = arrd(0)
			GetURL = arrDownloadURL
			'response.write GetURL
			'response.end
		End If
	End Function

End Class %>

