1
<cfsetting enablecfoutputonly="Yes">
3
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
4
* Copyright (C) 2003-2010 Frederico Caldeira Knabben
8
* Licensed under the terms of any of the following licenses at your
11
* - GNU General Public License Version 2 or later (the "GPL")
12
* http://www.gnu.org/licenses/gpl.html
14
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
15
* http://www.gnu.org/licenses/lgpl.html
17
* - Mozilla Public License Version 1.1 or later (the "MPL")
18
* http://www.mozilla.org/MPL/MPL-1.1.html
22
* This file include IO specific functions used by the ColdFusion Connector (MX 6.0 and above).
26
<cffunction name="CombinePaths" returntype="String" output="true">
27
<cfargument name="sBasePath" required="true">
28
<cfargument name="sFolder" required="true">
29
<cfset sBasePath = RemoveFromEnd( sBasePath, "/" )>
30
<cfset sBasePath = RemoveFromEnd( sBasePath, "\" )>
31
<cfreturn sBasePath & "/" & RemoveFromStart( ARGUMENTS.sFolder, '/' )>
34
<cffunction name="GetResourceTypePath" returntype="String" output="false">
35
<cfargument name="resourceType" required="true">
36
<cfargument name="sCommand" required="true">
38
<cfif ARGUMENTS.sCommand eq "QuickUpload">
39
<cfreturn REQUEST.Config['QuickUploadPath'][ARGUMENTS.resourceType]>
41
<cfreturn REQUEST.Config['FileTypesPath'][ARGUMENTS.resourceType]>
45
<cffunction name="GetResourceTypeDirectory" returntype="String" output="false">
46
<cfargument name="resourceType" required="true">
47
<cfargument name="sCommand" required="true">
49
<cfif ARGUMENTS.sCommand eq "QuickUpload">
50
<cfif isDefined( "REQUEST.Config.QuickUploadAbsolutePath" )
51
and structkeyexists( REQUEST.Config.QuickUploadAbsolutePath, ARGUMENTS.resourceType )
52
and Len( REQUEST.Config.QuickUploadAbsolutePath[ARGUMENTS.resourceType] )>
53
<cfreturn REQUEST.Config.QuickUploadAbsolutePath[ARGUMENTS.resourceType]>
56
<cfreturn expandpath( REQUEST.Config.QuickUploadPath[ARGUMENTS.resourceType] )>
58
<cfif isDefined( "REQUEST.Config.FileTypesAbsolutePath" )
59
and structkeyexists( REQUEST.Config.FileTypesAbsolutePath, ARGUMENTS.resourceType )
60
and Len( REQUEST.Config.FileTypesAbsolutePath[ARGUMENTS.resourceType] )>
61
<cfreturn REQUEST.Config.FileTypesAbsolutePath[ARGUMENTS.resourceType]>
64
<cfreturn expandpath( REQUEST.Config.FileTypesPath[ARGUMENTS.resourceType] )>
68
<cffunction name="GetUrlFromPath" returntype="String" output="false">
69
<cfargument name="resourceType" required="true">
70
<cfargument name="folderPath" required="true">
71
<cfargument name="sCommand" required="true">
73
<cfreturn CombinePaths( GetResourceTypePath( ARGUMENTS.resourceType, ARGUMENTS.sCommand ), ARGUMENTS.folderPath )>
76
<cffunction name="RemoveExtension" output="false" returntype="String">
77
<cfargument name="fileName" required="true">
78
<cfset var pos = find( ".", reverse ( ARGUMENTS.fileName ) )>
80
<cfreturn mid( ARGUMENTS.fileName, 1, Len( ARGUMENTS.fileName ) - pos ) >
83
<cffunction name="GetExtension" output="false" returntype="String">
84
<cfargument name="fileName" required="true">
85
<cfset var pos = find( ".", reverse ( ARGUMENTS.fileName ) )>
91
<cfreturn mid( ARGUMENTS.fileName, pos, Len( ARGUMENTS.fileName ) - pos ) >
94
<cffunction name="ServerMapFolder" returntype="String" output="false">
95
<cfargument name="resourceType" required="true">
96
<cfargument name="folderPath" required="true">
97
<cfargument name="sCommand" required="true">
99
<!--- Get the resource type directory. --->
100
<cfset var sResourceTypePath = GetResourceTypeDirectory( ARGUMENTS.resourceType, ARGUMENTS.sCommand ) >
101
<!--- Ensure that the directory exists. --->
102
<cfset var sErrorMsg = CreateServerFolder( sResourceTypePath ) >
104
<cfif sErrorMsg neq ''>
105
<cfset SendError( 1, 'Error creating folder "' & sResourceTypePath & '" (' & sErrorMsg & ')' )>
108
<!--- Return the resource type directory combined with the required path. --->
109
<cfreturn CombinePaths( sResourceTypePath , ARGUMENTS.folderPath )>
112
<cffunction name="GetParentFolder" returntype="string" output="false">
113
<cfargument name="folderPath" required="true">
115
<cfreturn rereplace(ARGUMENTS.folderPath, "[/\\\\][^/\\\\]+[/\\\\]?$", "")>
118
<cffunction name="CreateServerFolder" returntype="String" output="false">
119
<cfargument name="folderPath">
121
<!--- Ensure the folder path has no double-slashes, or mkdir may fail on certain platforms --->
122
<cfset folderPath = rereplace(ARGUMENTS.folderPath, "//+", "/", "all")>
124
<cfif directoryexists(ARGUMENTS.folderPath) or fileexists(ARGUMENTS.folderPath)>
128
<cfdirectory action="create" mode="0755" directory="#ARGUMENTS.folderPath#">
130
<cfreturn CFCATCH.Message>
138
<cffunction name="IsAllowedExt" returntype="boolean" output="false">
139
<cfargument name="sExtension" required="true">
140
<cfargument name="resourceType" required="true">
142
<cfif isDefined( "REQUEST.Config.AllowedExtensions." & ARGUMENTS.resourceType )
143
and listLen( REQUEST.Config.AllowedExtensions[ARGUMENTS.resourceType] )
144
and not listFindNoCase( REQUEST.Config.AllowedExtensions[ARGUMENTS.resourceType], ARGUMENTS.sExtension )>
148
<cfif isDefined( "REQUEST.Config.DeniedExtensions." & ARGUMENTS.resourceType )
149
and listLen( REQUEST.Config.DeniedExtensions[ARGUMENTS.resourceType] )
150
and listFindNoCase( REQUEST.Config.DeniedExtensions[ARGUMENTS.resourceType], ARGUMENTS.sExtension )>
157
<cffunction name="IsAllowedType" returntype="boolean" output="false">
158
<cfargument name="resourceType">
160
<cfif not listFindNoCase( REQUEST.Config.ConfigAllowedTypes, ARGUMENTS.resourceType )>
167
<cffunction name="IsAllowedCommand" returntype="boolean" output="true">
168
<cfargument name="sCommand" required="true" type="String">
170
<cfif not listFindNoCase( REQUEST.Config.ConfigAllowedCommands, ARGUMENTS.sCommand )>
177
<cffunction name="GetCurrentFolder" returntype="String" output="true">
178
<cfset var sCurrentFolder = "/">
180
<cfif isDefined( "URL.CurrentFolder" )>
181
<cfset sCurrentFolder = URL.CurrentFolder>
184
<!--- Check the current folder syntax (must begin and start with a slash). --->
185
<cfif not refind( "/$", sCurrentFolder)>
186
<cfset sCurrentFolder = sCurrentFolder & "/">
189
<cfif not refind( "^/", sCurrentFolder )>
190
<cfset sCurrentFolder = "/" & sCurrentFolder>
193
<!--- Ensure the folder path has no double-slashes, or mkdir may fail on certain platforms --->
194
<cfset sCurrentFolder = rereplace( sCurrentFolder, "//+", "/", "all" )>
196
<cfif find( "..", sCurrentFolder) or find( "\", sCurrentFolder) or REFind('(/\.)|(//)|[[:cntrl:]]|([\\:\*\?\"<>])', sCurrentFolder)>
197
<cfif URL.Command eq "FileUpload" or URL.Command eq "QuickUpload">
198
<cfset SendUploadResults( 102, "", "", "") >
200
<cfset SendError( 102, "" )>
204
<cfreturn sCurrentFolder>
207
<cffunction name="SanitizeFolderName" returntype="String" output="false">
208
<cfargument name="sNewFolderName" required="true">
210
<!--- Do a cleanup of the folder name to avoid possible problems --->
211
<!--- Remove . \ / | : ? * " < > and control characters --->
212
<cfset sNewFolderName = rereplace( sNewFolderName, '\.+|\\+|\/+|\|+|\:+|\?+|\*+|"+|<+|>+|[[:cntrl:]]+', "_", "all" )>
214
<cfreturn sNewFolderName>
217
<cffunction name="BinaryFileRead" returntype="String" output="true">
218
<cfargument name="fileName" required="true" type="string">
219
<cfargument name="bytes" required="true" type="Numeric">
223
var fileReaderClass = "";
230
if( not fileExists( ARGUMENTS.fileName ) )
235
if (REQUEST.CFVersion gte 8)
237
file = FileOpen( ARGUMENTS.fileName, "readbinary" ) ;
238
byteArray = FileRead( file, 1024 ) ;
239
chunk = toString( toBinary( toBase64( byteArray ) ) ) ;
244
fileReaderClass = createObject("java", "java.io.FileInputStream");
245
fileReader = fileReaderClass.init(fileName);
249
char = fileReader.read();
250
counter = counter + 1;
251
if ( char eq -1 or counter eq ARGUMENTS.bytes)
257
chunk = chunk & chr(char) ;
266
<cffunction name="SendUploadResults" returntype="String" output="true">
267
<cfargument name="errorNumber" required="true" type="Numeric">
268
<cfargument name="fileUrl" required="false" type="String" default="">
269
<cfargument name="fileName" required="false" type="String" default="">
270
<cfargument name="customMsg" required="false" type="String" default="">
272
<cfif errorNumber and errorNumber neq 201>
274
<cfset fileName = "">
276
<!--- Minified version of the document.domain automatic fix script (#1919).
277
The original script can be found at _dev/domain_fix_template.js --->
279
<script type="text/javascript">
280
(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;}}})();
281
window.parent.OnUploadCompleted( #errorNumber#, "#JSStringFormat(fileUrl)#", "#JSStringFormat(fileName)#", "#JSStringFormat(customMsg)#" );
287
<cffunction name="SanitizeFileName" returntype="String" output="false">
288
<cfargument name="sNewFileName" required="true">
290
<cfif isDefined("REQUEST.Config.ForceSingleExtension") and REQUEST.Config.ForceSingleExtension>
291
<cfset sNewFileName = rereplace( sNewFileName, '\.(?![^.]*$)', "_", "all" )>
294
<!--- Do a cleanup of the file name to avoid possible problems --->
295
<!--- Remove \ / | : ? * " < > and control characters --->
296
<cfset sNewFileName = rereplace( sNewFileName, '\\[.]+|\\+|\/+|\|+|\:+|\?+|\*+|"+|<+|>+|[[:cntrl:]]+', "_", "all" )>
298
<cfreturn sNewFileName>