2
' FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
' Copyright (C) 2003-2010 Frederico Caldeira Knabben
7
' Licensed under the terms of any of the following licenses at your
10
' - GNU General Public License Version 2 or later (the "GPL")
11
' http://www.gnu.org/licenses/gpl.html
13
' - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
' http://www.gnu.org/licenses/lgpl.html
16
' - Mozilla Public License Version 1.1 or later (the "MPL")
17
' http://www.mozilla.org/MPL/MPL-1.1.html
21
' This file include IO specific functions used by the ASP Connector.
24
function CombinePaths( sBasePath, sFolder)
25
sFolder = replace(sFolder, "\", "/")
26
CombinePaths = RemoveFromEnd( sBasePath, "/" ) & "/" & RemoveFromStart( sFolder, "/" )
29
function CombineLocalPaths( sBasePath, sFolder)
30
sFolder = replace(sFolder, "/", "\")
31
' The RemoveFrom* functions use RegExp, so we must escape the \
32
CombineLocalPaths = RemoveFromEnd( sBasePath, "\\" ) & "\" & RemoveFromStart( sFolder, "\\" )
35
Function GetResourceTypePath( resourceType, sCommand )
36
if ( sCommand = "QuickUpload") then
37
GetResourceTypePath = ConfigQuickUploadPath.Item( resourceType )
39
GetResourceTypePath = ConfigFileTypesPath.Item( resourceType )
43
Function GetResourceTypeDirectory( resourceType, sCommand )
44
if ( sCommand = "QuickUpload") then
46
if ( ConfigQuickUploadAbsolutePath.Item( resourceType ) <> "" ) then
47
GetResourceTypeDirectory = ConfigQuickUploadAbsolutePath.Item( resourceType )
49
' Map the "UserFiles" path to a local directory.
50
GetResourceTypeDirectory = Server.MapPath( ConfigQuickUploadPath.Item( resourceType ) )
53
if ( ConfigFileTypesAbsolutePath.Item( resourceType ) <> "" ) then
54
GetResourceTypeDirectory = ConfigFileTypesAbsolutePath.Item( resourceType )
56
' Map the "UserFiles" path to a local directory.
57
GetResourceTypeDirectory = Server.MapPath( ConfigFileTypesPath.Item( resourceType ) )
62
Function GetUrlFromPath( resourceType, folderPath, sCommand )
63
GetUrlFromPath = CombinePaths( GetResourceTypePath( resourceType, sCommand ), folderPath )
66
Function RemoveExtension( fileName )
67
RemoveExtension = Left( fileName, InStrRev( fileName, "." ) - 1 )
70
Function ServerMapFolder( resourceType, folderPath, sCommand )
72
' Get the resource type directory.
73
sResourceTypePath = GetResourceTypeDirectory( resourceType, sCommand )
75
' Ensure that the directory exists.
76
CreateServerFolder sResourceTypePath
78
' Return the resource type directory combined with the required path.
79
ServerMapFolder = CombineLocalPaths( sResourceTypePath, folderPath )
82
Sub CreateServerFolder( folderPath )
84
Set oFSO = Server.CreateObject( "Scripting.FileSystemObject" )
87
sParent = oFSO.GetParentFolderName( folderPath )
89
' If folderPath is a network path (\\server\folder\) then sParent is an empty string.
91
if (sParent = "") then exit sub
93
' Check if the parent exists, or create it.
94
If ( NOT oFSO.FolderExists( sParent ) ) Then CreateServerFolder( sParent )
96
If ( oFSO.FolderExists( folderPath ) = False ) Then
98
oFSO.CreateFolder( folderPath )
100
if err.number<>0 then
102
Dim iErrNumber, sErrDescription
103
iErrNumber = err.number
104
sErrDescription = err.Description
108
Select Case iErrNumber
110
sErrorNumber = "102" ' Invalid Folder Name.
112
sErrorNumber = "103" ' Security Error.
114
sErrorNumber = "102" ' Path too long.
119
SendError sErrorNumber, "CreateServerFolder(" & folderPath & ") : " & sErrDescription
127
Function IsAllowedExt( extension, resourceType )
130
oRE.IgnoreCase = True
133
Dim sAllowed, sDenied
134
sAllowed = ConfigAllowedExtensions.Item( resourceType )
135
sDenied = ConfigDeniedExtensions.Item( resourceType )
139
If sDenied <> "" Then
140
oRE.Pattern = sDenied
141
IsAllowedExt = Not oRE.Test( extension )
144
If IsAllowedExt And sAllowed <> "" Then
145
oRE.Pattern = sAllowed
146
IsAllowedExt = oRE.Test( extension )
152
Function IsAllowedType( resourceType )
155
oRE.IgnoreCase = False
157
oRE.Pattern = "^(" & ConfigAllowedTypes & ")$"
159
IsAllowedType = oRE.Test( resourceType )
164
Function IsAllowedCommand( sCommand )
167
oRE.IgnoreCase = True
169
oRE.Pattern = "^(" & ConfigAllowedCommands & ")$"
171
IsAllowedCommand = oRE.Test( sCommand )
176
function GetCurrentFolder()
180
sCurrentFolder = Request.QueryString("CurrentFolder")
181
If ( sCurrentFolder = "" ) Then sCurrentFolder = "/"
183
' Check the current folder syntax (must begin and start with a slash).
184
If ( Right( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = sCurrentFolder & "/"
185
If ( Left( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = "/" & sCurrentFolder
187
' Check for invalid folder paths (..)
188
If ( InStr( 1, sCurrentFolder, ".." ) <> 0 OR InStr( 1, sCurrentFolder, "\" ) <> 0) Then
192
Set oRegex = New RegExp
194
oRegex.Pattern = "(/\.)|(//)|([\\:\*\?\""\<\>\|]|[\u0000-\u001F]|\u007F)"
196
if (oRegex.Test(sCurrentFolder)) Then
200
GetCurrentFolder = sCurrentFolder
203
' Do a cleanup of the folder name to avoid possible problems
204
function SanitizeFolderName( sNewFolderName )
206
Set oRegex = New RegExp
209
' remove . \ / | : ? * " < > and control characters
210
oRegex.Pattern = "(\.|\\|\/|\||:|\?|\*|""|\<|\>|[\u0000-\u001F]|\u007F)"
211
SanitizeFolderName = oRegex.Replace( sNewFolderName, "_" )
216
' Do a cleanup of the file name to avoid possible problems
217
function SanitizeFileName( sNewFileName )
219
Set oRegex = New RegExp
222
if ( ConfigForceSingleExtension = True ) then
223
oRegex.Pattern = "\.(?![^.]*$)"
224
sNewFileName = oRegex.Replace( sNewFileName, "_" )
227
' remove \ / | : ? * " < > and control characters
228
oRegex.Pattern = "(\\|\/|\||:|\?|\*|""|\<|\>|[\u0000-\u001F]|\u007F)"
229
SanitizeFileName = oRegex.Replace( sNewFileName, "_" )
234
' This is the function that sends the results of the uploading process.
235
Sub SendUploadResults( errorNumber, fileUrl, fileName, customMsg )
237
Response.Write "<script type=""text/javascript"">"
238
' Minified version of the document.domain automatic fix script (#1919).
239
' The original script can be found at _dev/domain_fix_template.js
240
Response.Write "(function(){var d=document.domain;while (true){try{var A=window.parent.document.domain;break;}catch(e) {};d=d.replace(/.*?(?:\.|$)/,'');if (d.length==0) break;try{document.domain=d;}catch (e){break;}}})();"
242
Response.Write "window.parent.OnUploadCompleted(" & errorNumber & ",""" & Replace( fileUrl, """", "\""" ) & """,""" & Replace( fileName, """", "\""" ) & """,""" & Replace( customMsg , """", "\""" ) & """) ;"
243
Response.Write "</script>"