Down.asp
上传用户:jisenq
上传日期:2014-06-29
资源大小:7216k
文件大小:6k
源码类别:

数据库编程

开发平台:

ASP/ASPX

  1. <% Option Explicit %>
  2. <!--#include file="FS_Inc/Const.asp" -->
  3. <!--#include file="FS_Inc/Function.asp" -->
  4. <!--#include file="FS_InterFace/MF_Function.asp" -->
  5. <%
  6. Dim Conn
  7. MF_Default_Conn
  8. Dim DownCacheNameStr
  9. DownCacheNameStr = "Http://"&Get_MF_Domain()
  10. Dim ResponseBodyStr,ResponseStr,ErrorStr,RsAddressObj,FileURL
  11. Dim Server_Name,Server_V1,Server_V2
  12. Dim OnlyFileUrlTF '只有文件地址
  13. OnlyFileUrlTF = False     
  14. ResponseBodyStr = "<title>下载</title>" & Chr(13)
  15. ResponseBodyStr = ResponseBodyStr & "<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>" & Chr(13)
  16. ResponseBodyStr = ResponseBodyStr & "<style>body{font-size:9pt;line-height:140%}</style>" & Chr(13)
  17. ResponseBodyStr = ResponseBodyStr & "<body>" & Chr(13)
  18. ErrorStr = "<meta http-equiv='Refresh' content='5; URL="&DownCacheNameStr&"'>" & Chr(13)
  19. ErrorStr = ErrorStr & ResponseBodyStr & Chr(13)
  20. ErrorStr = ErrorStr & "<b>错误!&nbsp;</b>读取地址时出错&nbsp;5秒后自动<a href="&DownCacheNameStr&">返回首页</a>..." & Chr(13)
  21. FileURL = Request("FileUrl")
  22. if (Request("DownLoadID")="" or Request("ID")="" or not isnumeric(Request("ID"))) And FileURL = "" then
  23. Response.Write ErrorStr
  24. Set Conn = Nothing
  25. Response.End
  26. end if
  27. if FileUrl = "" then
  28. set RsAddressObj=Conn.execute("Select Url from FS_DS_Address where ID=" & NoSqlHack(request("ID")))
  29. if Not RsAddressObj.Eof then
  30. FileURL = RsAddressObj("Url")
  31. else
  32. RsAddressObj.Close
  33. Set RsAddressObj = Nothing
  34. Set Conn = Nothing
  35. Response.Write ErrorStr
  36. Response.End
  37. end if
  38. RsAddressObj.Close
  39. OnlyFileUrlTF = False
  40. else
  41. OnlyFileUrlTF = True
  42. end if
  43. '防盗链
  44. Dim DownLoadConfigObj
  45. Set DownLoadConfigObj = Conn.execute("select top 1 Lock,IPType,IPList,OverDueMode from FS_DS_SysPara")
  46. if DownLoadConfigObj.eof then response.Write("系统错误"): Set DownLoadConfigObj = Nothing:Set Conn = Nothing: response.End()
  47. if DownLoadConfigObj("Lock") = 1 then
  48. Server_Name = Len(Request.ServerVariables("SERVER_NAME"))
  49. Server_V1 = Left(Replace(Cstr(Request.ServerVariables("HTTP_REFERER")),"http://",""),Server_Name)
  50. Server_V2 = Left(Cstr(Request.ServerVariables("SERVER_NAME")),Server_Name)
  51. if Server_V1 <> Server_V2 and Server_V1 <> "" and Server_V2 <> "" then
  52. Set DownLoadConfigObj = Nothing
  53. Set Conn = Nothing
  54. response.Redirect(DownCacheNameStr)
  55. Response.End
  56. end if
  57. end if
  58. '判断过期
  59. if DownLoadConfigObj("OverDueMode") = 2 then
  60. set RsAddressObj=Conn.execute("Select ID from FS_DS_List where OverDue>0 and datediff('d',AddTime,'"&date()&"') > OverDue) and DownLoadID='" & NoSqlHack(Request("DownLoadID")) & "'")
  61. if not RsAddressObj.eof then 
  62. RsAddressObj.close
  63. Response.write("<script>alert('该下载已经过期!');history.back();</script>")
  64. Response.End
  65. else
  66. Set RsAddressObj = Nothing
  67. end if
  68. end if
  69. '判断IP限制
  70. Dim RequestIPAddress,IPList,IPType,Flag,DownLoadTF
  71. RequestIPAddress = Request.ServerVariables("REMOTE_ADDR")
  72. IPList = DownLoadConfigObj("IPList")
  73. IPType = DownLoadConfigObj("IPType")
  74. Flag = CheckIPAddress(IPList,RequestIPAddress)
  75. 'Response.Write(Flag)
  76. 'Response.End
  77. if Not IsNull(IPList) And IPList <> "" then
  78. if Flag = True then
  79. if IPType = 1 then 
  80. DownLoadTF = False
  81. else
  82. DownLoadTF = True
  83. end if
  84. else
  85. if IPType = 1 then 
  86. DownLoadTF = True
  87. else
  88. DownLoadTF = False
  89. end if
  90. end if
  91. else
  92. DownLoadTF = True
  93. end if
  94. if DownLoadTF then
  95. if OnlyFileUrlTF = False then
  96. RsAddressObj.Open "Select ClickNum from FS_DS_List where DownLoadID='" & NoSqlHack(Request("DownLoadID")) & "'",Conn,1,2
  97. if Not RsAddressObj.eof then
  98. RsAddressObj("ClickNum") = CLng(RsAddressObj("ClickNum")) + 1
  99. RsAddressObj.UpDate
  100. else
  101. RsAddressObj.Close
  102. Set RsAddressObj = Nothing
  103. Set Conn = Nothing
  104. Response.Write ErrorStr
  105. Response.End
  106. end if
  107. end if
  108. Set RsAddressObj = Nothing
  109. if InStr(LCase(FileURl),"://") = 0 then
  110. FileURl = DownCacheNameStr & FileUrl
  111. end if
  112. Response.Redirect FileURL
  113. else
  114. Response.write("<script>alert('没有权限,或者IP被锁定');history.back();</script>")
  115. end if
  116. Response.End
  117. Set DownLoadConfigObj = Nothing
  118. Set Conn = Nothing
  119. Function CheckIPAddress(IPList,IPAddress)
  120. Dim TempArray,i,j,AddressArray,BeginAddressArray,EndAddressArray,IPAddressArray
  121. IPAddressArray = Split(IPAddress,".")
  122. if UBound(IPAddressArray) <> 3 then
  123. CheckIPAddress = False
  124. Exit Function
  125. end if
  126. if IsNull(IPList) then
  127. CheckIPAddress = False
  128. else
  129. if IPList <> "" then
  130. TempArray = Split(IPList,"$")
  131. for i = LBound(TempArray) to UBound(TempArray)
  132. AddressArray = Split(TempArray(i),"-")
  133. if UBound(AddressArray) = 1 then
  134. BeginAddressArray = Split(AddressArray(0),".")
  135. EndAddressArray = Split(AddressArray(1),".")
  136. if (UBound(BeginAddressArray) = 3) and (UBound(EndAddressArray) = 3) then
  137. for j = LBound(BeginAddressArray) to UBound(BeginAddressArray)
  138. 'Response.Write(EndAddressArray(j) = BeginAddressArray(j))
  139. if (EndAddressArray(j) = BeginAddressArray(j)) then
  140. if EndAddressArray(j) <> IPAddressArray(j) then
  141. if (CInt(IPAddressArray(j)) >= CInt(BeginAddressArray(j))) And (CInt(IPAddressArray(j)) <= CInt(EndAddressArray(j))) then
  142. CheckIPAddress = True
  143. Exit Function
  144. end if
  145. end if
  146. else
  147. if (CInt(IPAddressArray(j)) >= CInt(BeginAddressArray(j))) And (CInt(IPAddressArray(j)) <= CInt(EndAddressArray(j))) then
  148. CheckIPAddress = True
  149. Exit Function
  150. end if
  151. end if
  152. Next
  153. end if
  154. end if
  155. 'Response.End
  156. Next
  157. CheckIPAddress = False
  158. else
  159. CheckIPAddress = False
  160. end if
  161. end if
  162. End Function
  163. %>