--- /dev/null
+<%\r
+ ' FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
+ ' Copyright (C) 2003-2008 Frederico Caldeira Knabben\r
+ '\r
+ ' == BEGIN LICENSE ==\r
+ '\r
+ ' Licensed under the terms of any of the following licenses at your\r
+ ' choice:\r
+ '\r
+ ' - GNU General Public License Version 2 or later (the "GPL")\r
+ ' http://www.gnu.org/licenses/gpl.html\r
+ '\r
+ ' - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
+ ' http://www.gnu.org/licenses/lgpl.html\r
+ '\r
+ ' - Mozilla Public License Version 1.1 or later (the "MPL")\r
+ ' http://www.mozilla.org/MPL/MPL-1.1.html\r
+ '\r
+ ' == END LICENSE ==\r
+ '\r
+ ' This file include IO specific functions used by the ASP Connector.\r
+%>\r
+<%\r
+function CombinePaths( sBasePath, sFolder)\r
+ CombinePaths = RemoveFromEnd( sBasePath, "/" ) & "/" & RemoveFromStart( sFolder, "/" )\r
+end function\r
+\r
+function CombineLocalPaths( sBasePath, sFolder)\r
+ sFolder = replace(sFolder, "/", "\")\r
+ ' The RemoveFrom* functions use RegExp, so we must escape the \\r
+ CombineLocalPaths = RemoveFromEnd( sBasePath, "\\" ) & "\" & RemoveFromStart( sFolder, "\\" )\r
+end function\r
+\r
+Function GetResourceTypePath( resourceType, sCommand )\r
+ if ( sCommand = "QuickUpload") then\r
+ GetResourceTypePath = ConfigQuickUploadPath.Item( resourceType )\r
+ else\r
+ GetResourceTypePath = ConfigFileTypesPath.Item( resourceType )\r
+ end if\r
+end Function\r
+\r
+Function GetResourceTypeDirectory( resourceType, sCommand )\r
+ if ( sCommand = "QuickUpload") then\r
+\r
+ if ( ConfigQuickUploadAbsolutePath.Item( resourceType ) <> "" ) then\r
+ GetResourceTypeDirectory = ConfigQuickUploadAbsolutePath.Item( resourceType )\r
+ else\r
+ ' Map the "UserFiles" path to a local directory.\r
+ GetResourceTypeDirectory = Server.MapPath( ConfigQuickUploadPath.Item( resourceType ) )\r
+ end if\r
+ else\r
+ if ( ConfigFileTypesAbsolutePath.Item( resourceType ) <> "" ) then\r
+ GetResourceTypeDirectory = ConfigFileTypesAbsolutePath.Item( resourceType )\r
+ else\r
+ ' Map the "UserFiles" path to a local directory.\r
+ GetResourceTypeDirectory = Server.MapPath( ConfigFileTypesPath.Item( resourceType ) )\r
+ end if\r
+ end if\r
+end Function\r
+\r
+Function GetUrlFromPath( resourceType, folderPath, sCommand )\r
+ GetUrlFromPath = CombinePaths( GetResourceTypePath( resourceType, sCommand ), folderPath )\r
+End Function\r
+\r
+Function RemoveExtension( fileName )\r
+ RemoveExtension = Left( fileName, InStrRev( fileName, "." ) - 1 )\r
+End Function\r
+\r
+Function ServerMapFolder( resourceType, folderPath, sCommand )\r
+ Dim sResourceTypePath\r
+ ' Get the resource type directory.\r
+ sResourceTypePath = GetResourceTypeDirectory( resourceType, sCommand )\r
+\r
+ ' Ensure that the directory exists.\r
+ CreateServerFolder sResourceTypePath\r
+\r
+ ' Return the resource type directory combined with the required path.\r
+ ServerMapFolder = CombineLocalPaths( sResourceTypePath, folderPath )\r
+End Function\r
+\r
+Sub CreateServerFolder( folderPath )\r
+ Dim oFSO\r
+ Set oFSO = Server.CreateObject( "Scripting.FileSystemObject" )\r
+\r
+ Dim sParent\r
+ sParent = oFSO.GetParentFolderName( folderPath )\r
+\r
+ ' If folderPath is a network path (\\server\folder\) then sParent is an empty string.\r
+ ' Get out.\r
+ if (sParent = "") then exit sub\r
+\r
+ ' Check if the parent exists, or create it.\r
+ If ( NOT oFSO.FolderExists( sParent ) ) Then CreateServerFolder( sParent )\r
+\r
+ If ( oFSO.FolderExists( folderPath ) = False ) Then\r
+ On Error resume next\r
+ oFSO.CreateFolder( folderPath )\r
+\r
+ if err.number<>0 then\r
+ dim sErrorNumber\r
+ Dim iErrNumber, sErrDescription\r
+ iErrNumber = err.number\r
+ sErrDescription = err.Description\r
+\r
+ On Error Goto 0\r
+\r
+ Select Case iErrNumber\r
+ Case 52\r
+ sErrorNumber = "102" ' Invalid Folder Name.\r
+ Case 70\r
+ sErrorNumber = "103" ' Security Error.\r
+ Case 76\r
+ sErrorNumber = "102" ' Path too long.\r
+ Case Else\r
+ sErrorNumber = "110"\r
+ End Select\r
+\r
+ SendError sErrorNumber, "CreateServerFolder(" & folderPath & ") : " & sErrDescription\r
+ end if\r
+\r
+ End If\r
+\r
+ Set oFSO = Nothing\r
+End Sub\r
+\r
+Function IsAllowedExt( extension, resourceType )\r
+ Dim oRE\r
+ Set oRE = New RegExp\r
+ oRE.IgnoreCase = True\r
+ oRE.Global = True\r
+\r
+ Dim sAllowed, sDenied\r
+ sAllowed = ConfigAllowedExtensions.Item( resourceType )\r
+ sDenied = ConfigDeniedExtensions.Item( resourceType )\r
+\r
+ IsAllowedExt = True\r
+\r
+ If sDenied <> "" Then\r
+ oRE.Pattern = sDenied\r
+ IsAllowedExt = Not oRE.Test( extension )\r
+ End If\r
+\r
+ If IsAllowedExt And sAllowed <> "" Then\r
+ oRE.Pattern = sAllowed\r
+ IsAllowedExt = oRE.Test( extension )\r
+ End If\r
+\r
+ Set oRE = Nothing\r
+End Function\r
+\r
+Function IsAllowedType( resourceType )\r
+ Dim oRE\r
+ Set oRE = New RegExp\r
+ oRE.IgnoreCase = True\r
+ oRE.Global = True\r
+ oRE.Pattern = "^(" & ConfigAllowedTypes & ")$"\r
+\r
+ IsAllowedType = oRE.Test( resourceType )\r
+\r
+ Set oRE = Nothing\r
+End Function\r
+\r
+Function IsAllowedCommand( sCommand )\r
+ Dim oRE\r
+ Set oRE = New RegExp\r
+ oRE.IgnoreCase = True\r
+ oRE.Global = True\r
+ oRE.Pattern = "^(" & ConfigAllowedCommands & ")$"\r
+\r
+ IsAllowedCommand = oRE.Test( sCommand )\r
+\r
+ Set oRE = Nothing\r
+End Function\r
+\r
+function GetCurrentFolder()\r
+ dim sCurrentFolder\r
+ sCurrentFolder = Request.QueryString("CurrentFolder")\r
+ If ( sCurrentFolder = "" ) Then sCurrentFolder = "/"\r
+\r
+ ' Check the current folder syntax (must begin and start with a slash).\r
+ If ( Right( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = sCurrentFolder & "/"\r
+ If ( Left( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = "/" & sCurrentFolder\r
+\r
+ ' Check for invalid folder paths (..)\r
+ If ( InStr( 1, sCurrentFolder, ".." ) <> 0 OR InStr( 1, sCurrentFolder, "\" ) <> 0) Then\r
+ SendError 102, ""\r
+ End If\r
+\r
+ GetCurrentFolder = sCurrentFolder\r
+end function\r
+\r
+' Do a cleanup of the folder name to avoid possible problems\r
+function SanitizeFolderName( sNewFolderName )\r
+ Dim oRegex\r
+ Set oRegex = New RegExp\r
+ oRegex.Global = True\r
+\r
+' remove . \ / | : ? * " < > and control characters\r
+ oRegex.Pattern = "(\.|\\|\/|\||:|\?|\*|""|\<|\>|[\u0000-\u001F]|\u007F)"\r
+ SanitizeFolderName = oRegex.Replace( sNewFolderName, "_" )\r
+\r
+ Set oRegex = Nothing\r
+end function\r
+\r
+' Do a cleanup of the file name to avoid possible problems\r
+function SanitizeFileName( sNewFileName )\r
+ Dim oRegex\r
+ Set oRegex = New RegExp\r
+ oRegex.Global = True\r
+\r
+ if ( ConfigForceSingleExtension = True ) then\r
+ oRegex.Pattern = "\.(?![^.]*$)"\r
+ sNewFileName = oRegex.Replace( sNewFileName, "_" )\r
+ end if\r
+\r
+' remove \ / | : ? * " < > and control characters\r
+ oRegex.Pattern = "(\\|\/|\||:|\?|\*|""|\<|\>|[\u0000-\u001F]|\u007F)"\r
+ SanitizeFileName = oRegex.Replace( sNewFileName, "_" )\r
+\r
+ Set oRegex = Nothing\r
+end function\r
+\r
+' This is the function that sends the results of the uploading process.\r
+Sub SendUploadResults( errorNumber, fileUrl, fileName, customMsg )\r
+ Response.Clear\r
+ Response.Write "<script type=""text/javascript"">"\r
+ ' Minified version of the document.domain automatic fix script (#1919).\r
+ ' The original script can be found at _dev/domain_fix_template.js\r
+ 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;}}})();"\r
+\r
+ Response.Write "window.parent.OnUploadCompleted(" & errorNumber & ",""" & Replace( fileUrl, """", "\""" ) & """,""" & Replace( fileName, """", "\""" ) & """,""" & Replace( customMsg , """", "\""" ) & """) ;"\r
+ Response.Write "</script>"\r
+ Response.End\r
+End Sub\r
+\r
+%>\r