io.asp
上传用户:ah_jiwei
上传日期:2022-07-24
资源大小:54044k
文件大小:6k
源码类别:

数据库编程

开发平台:

Visual C++

  1. <%
  2.  ' FCKeditor - The text editor for Internet - http://www.fckeditor.net
  3.  ' Copyright (C) 2003-2007 Frederico Caldeira Knabben
  4.  '
  5.  ' == BEGIN LICENSE ==
  6.  '
  7.  ' Licensed under the terms of any of the following licenses at your
  8.  ' choice:
  9.  '
  10.  '  - GNU General Public License Version 2 or later (the "GPL")
  11.  '    http://www.gnu.org/licenses/gpl.html
  12.  '
  13.  '  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  14.  '    http://www.gnu.org/licenses/lgpl.html
  15.  '
  16.  '  - Mozilla Public License Version 1.1 or later (the "MPL")
  17.  '    http://www.mozilla.org/MPL/MPL-1.1.html
  18.  '
  19.  ' == END LICENSE ==
  20.  '
  21.  ' This file include IO specific functions used by the ASP Connector.
  22. %>
  23. <%
  24. function CombinePaths( sBasePath, sFolder)
  25. CombinePaths =  RemoveFromEnd( sBasePath, "/" ) & "/" & RemoveFromStart( sFolder, "/" )
  26. end function
  27. Function GetResourceTypePath( resourceType, sCommand )
  28. if ( sCommand = "QuickUpload") then
  29. GetResourceTypePath = ConfigQuickUploadPath.Item( resourceType )
  30. else
  31. GetResourceTypePath = ConfigFileTypesPath.Item( resourceType )
  32. end if
  33. end Function
  34. Function GetResourceTypeDirectory( resourceType, sCommand )
  35. if ( sCommand = "QuickUpload") then
  36. if ( ConfigQuickUploadAbsolutePath.Item( resourceType ) <> "" ) then
  37. GetResourceTypeDirectory = ConfigQuickUploadAbsolutePath.Item( resourceType )
  38. else
  39. ' Map the "UserFiles" path to a local directory.
  40. GetResourceTypeDirectory = Server.MapPath( ConfigQuickUploadPath.Item( resourceType ) ) 
  41. end if
  42. else
  43. if ( ConfigFileTypesAbsolutePath.Item( resourceType ) <> "" ) then 
  44. GetResourceTypeDirectory = ConfigFileTypesAbsolutePath.Item( resourceType )
  45. else
  46. ' Map the "UserFiles" path to a local directory.
  47. GetResourceTypeDirectory = Server.MapPath( ConfigFileTypesPath.Item( resourceType ) ) 
  48. end if
  49. end if
  50. end Function
  51. Function GetUrlFromPath( resourceType, folderPath, sCommand )
  52. GetUrlFromPath = CombinePaths( GetResourceTypePath( resourceType, sCommand ), folderPath )
  53. End Function
  54. Function RemoveExtension( fileName )
  55. RemoveExtension = Left( fileName, InStrRev( fileName, "." ) - 1 )
  56. End Function
  57. Function ServerMapFolder( resourceType, folderPath, sCommand )
  58. Dim sResourceTypePath
  59. ' Get the resource type directory.
  60. sResourceTypePath = GetResourceTypeDirectory( resourceType, sCommand ) 
  61. ' Ensure that the directory exists.
  62. CreateServerFolder sResourceTypePath
  63. ' Return the resource type directory combined with the required path.
  64. ServerMapFolder = CombinePaths( sResourceTypePath, folderPath )
  65. End Function
  66. Sub CreateServerFolder( folderPath )
  67. Dim oFSO
  68. Set oFSO = Server.CreateObject( "Scripting.FileSystemObject" )
  69. Dim sParent
  70. sParent = oFSO.GetParentFolderName( folderPath )
  71. ' Check if the parent exists, or create it.
  72. If ( NOT oFSO.FolderExists( sParent ) ) Then CreateServerFolder( sParent )
  73. If ( oFSO.FolderExists( folderPath ) = False ) Then
  74. On Error resume next
  75. oFSO.CreateFolder( folderPath )
  76. if err.number<>0 then
  77. dim sErrorNumber
  78. Dim iErrNumber, sErrDescription
  79. iErrNumber = err.number
  80. sErrDescription = err.Description
  81. On Error Goto 0
  82. Select Case iErrNumber
  83. Case 52
  84. sErrorNumber = "102" ' Invalid Folder Name.
  85. Case 70
  86. sErrorNumber = "103" ' Security Error.
  87. Case 76
  88. sErrorNumber = "102" ' Path too long.
  89. Case Else
  90. sErrorNumber = "110"
  91. End Select
  92. SendError sErrorNumber, "CreateServerFolder(" & folderPath & ") : " & sErrDescription
  93. end if
  94. End If
  95. Set oFSO = Nothing
  96. End Sub
  97. Function IsAllowedExt( extension, resourceType )
  98. Dim oRE
  99. Set oRE = New RegExp
  100. oRE.IgnoreCase = True
  101. oRE.Global = True
  102. Dim sAllowed, sDenied
  103. sAllowed = ConfigAllowedExtensions.Item( resourceType )
  104. sDenied = ConfigDeniedExtensions.Item( resourceType )
  105. IsAllowedExt = True
  106. If sDenied <> "" Then
  107. oRE.Pattern = sDenied
  108. IsAllowedExt = Not oRE.Test( extension )
  109. End If
  110. If IsAllowedExt And sAllowed <> "" Then
  111. oRE.Pattern = sAllowed
  112. IsAllowedExt = oRE.Test( extension )
  113. End If
  114. Set oRE = Nothing
  115. End Function
  116. Function IsAllowedType( resourceType )
  117. Dim oRE
  118. Set oRE = New RegExp
  119. oRE.IgnoreCase = True
  120. oRE.Global = True
  121. oRE.Pattern = "^(" & ConfigAllowedTypes & ")$"
  122. IsAllowedType = oRE.Test( resourceType )
  123. Set oRE = Nothing
  124. End Function
  125. Function IsAllowedCommand( sCommand )
  126. Dim oRE
  127. Set oRE = New RegExp
  128. oRE.IgnoreCase = True
  129. oRE.Global = True
  130. oRE.Pattern = "^(" & ConfigAllowedCommands & ")$"
  131. IsAllowedCommand = oRE.Test( sCommand )
  132. Set oRE = Nothing
  133. End Function
  134. function GetCurrentFolder()
  135. dim sCurrentFolder
  136. sCurrentFolder = Request.QueryString("CurrentFolder")
  137. If ( sCurrentFolder = "" ) Then sCurrentFolder = "/"
  138. ' Check the current folder syntax (must begin and start with a slash).
  139. If ( Right( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = sCurrentFolder & "/"
  140. If ( Left( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = "/" & sCurrentFolder
  141. ' Check for invalid folder paths (..)
  142. If ( InStr( 1, sCurrentFolder, ".." ) <> 0 ) Then
  143. SendError 102, ""
  144. End If
  145. GetCurrentFolder = sCurrentFolder
  146. end function
  147. ' Do a cleanup of the folder name to avoid possible problems
  148. function SanitizeFolderName( sNewFolderName )
  149. Dim oRegex
  150. Set oRegex = New RegExp
  151. oRegex.Global = True
  152. ' remove .  / | : ? *  " < >
  153. oRegex.Pattern = "(.|\|/|||:|?|*|""|<|>)"
  154. SanitizeFolderName = oRegex.Replace( sNewFolderName, "_" )
  155. Set oRegex = Nothing
  156. end function
  157. ' Do a cleanup of the file name to avoid possible problems
  158. function SanitizeFileName( sNewFileName )
  159. Dim oRegex
  160. Set oRegex = New RegExp
  161. oRegex.Global = True
  162. if ( ConfigForceSingleExtension = True ) then
  163. oRegex.Pattern = ".(?![^.]*$)"
  164. sNewFileName = oRegex.Replace( sNewFileName, "_" )
  165. end if
  166. ' remove  / | : ? *  " < >
  167. oRegex.Pattern = "(\|/|||:|?|*|""|<|>)"
  168. SanitizeFileName = oRegex.Replace( sNewFileName, "_" )
  169. Set oRegex = Nothing
  170. end function
  171. ' This is the function that sends the results of the uploading process.
  172. Sub SendUploadResults( errorNumber, fileUrl, fileName, customMsg )
  173. Response.Clear
  174. Response.Write "<script type=""text/javascript"">"
  175. Response.Write "window.parent.OnUploadCompleted(" & errorNumber & ",""" & Replace( fileUrl, """", """" ) & """,""" & Replace( fileName, """", """" ) & """,""" & Replace( customMsg , """", """" ) & """) ;"
  176. Response.Write "</script>"
  177. Response.End
  178. End Sub
  179. %>