1
|
<cfsetting enablecfoutputonly="Yes">
|
2
|
<!---
|
3
|
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
|
4
|
* Copyright (C) 2003-2009 Frederico Caldeira Knabben
|
5
|
*
|
6
|
* == BEGIN LICENSE ==
|
7
|
*
|
8
|
* Licensed under the terms of any of the following licenses at your
|
9
|
* choice:
|
10
|
*
|
11
|
* - GNU General Public License Version 2 or later (the "GPL")
|
12
|
* http://www.gnu.org/licenses/gpl.html
|
13
|
*
|
14
|
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
|
15
|
* http://www.gnu.org/licenses/lgpl.html
|
16
|
*
|
17
|
* - Mozilla Public License Version 1.1 or later (the "MPL")
|
18
|
* http://www.mozilla.org/MPL/MPL-1.1.html
|
19
|
*
|
20
|
* == END LICENSE ==
|
21
|
*
|
22
|
* This file include IO specific functions used by the ColdFusion Connector (MX 6.0 and above).
|
23
|
*
|
24
|
--->
|
25
|
|
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, '/' )>
|
32
|
</cffunction>
|
33
|
|
34
|
<cffunction name="GetResourceTypePath" returntype="String" output="false">
|
35
|
<cfargument name="resourceType" required="true">
|
36
|
<cfargument name="sCommand" required="true">
|
37
|
|
38
|
<cfif ARGUMENTS.sCommand eq "QuickUpload">
|
39
|
<cfreturn REQUEST.Config['QuickUploadPath'][ARGUMENTS.resourceType]>
|
40
|
<cfelse>
|
41
|
<cfreturn REQUEST.Config['FileTypesPath'][ARGUMENTS.resourceType]>
|
42
|
</cfif>
|
43
|
</cffunction>
|
44
|
|
45
|
<cffunction name="GetResourceTypeDirectory" returntype="String" output="false">
|
46
|
<cfargument name="resourceType" required="true">
|
47
|
<cfargument name="sCommand" required="true">
|
48
|
|
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]>
|
54
|
</cfif>
|
55
|
|
56
|
<cfreturn expandpath( REQUEST.Config.QuickUploadPath[ARGUMENTS.resourceType] )>
|
57
|
<cfelse>
|
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]>
|
62
|
</cfif>
|
63
|
|
64
|
<cfreturn expandpath( REQUEST.Config.FileTypesPath[ARGUMENTS.resourceType] )>
|
65
|
</cfif>
|
66
|
</cffunction>
|
67
|
|
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">
|
72
|
|
73
|
<cfreturn CombinePaths( GetResourceTypePath( ARGUMENTS.resourceType, ARGUMENTS.sCommand ), ARGUMENTS.folderPath )>
|
74
|
</cffunction>
|
75
|
|
76
|
<cffunction name="RemoveExtension" output="false" returntype="String">
|
77
|
<cfargument name="fileName" required="true">
|
78
|
<cfset var pos = find( ".", reverse ( ARGUMENTS.fileName ) )>
|
79
|
|
80
|
<cfreturn mid( ARGUMENTS.fileName, 1, Len( ARGUMENTS.fileName ) - pos ) >
|
81
|
</cffunction>
|
82
|
|
83
|
<cffunction name="GetExtension" output="false" returntype="String">
|
84
|
<cfargument name="fileName" required="true">
|
85
|
<cfset var pos = find( ".", reverse ( ARGUMENTS.fileName ) )>
|
86
|
|
87
|
<cfif not pos>
|
88
|
<cfreturn "">
|
89
|
</cfif>
|
90
|
|
91
|
<cfreturn mid( ARGUMENTS.fileName, pos, Len( ARGUMENTS.fileName ) - pos ) >
|
92
|
</cffunction>
|
93
|
|
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">
|
98
|
|
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 ) >
|
103
|
|
104
|
<cfif sErrorMsg neq ''>
|
105
|
<cfset SendError( 1, 'Error creating folder "' & sResourceTypePath & '" (' & sErrorMsg & ')' )>
|
106
|
</cfif>
|
107
|
|
108
|
<!--- Return the resource type directory combined with the required path. --->
|
109
|
<cfreturn CombinePaths( sResourceTypePath , ARGUMENTS.folderPath )>
|
110
|
</cffunction>
|
111
|
|
112
|
<cffunction name="GetParentFolder" returntype="string" output="false">
|
113
|
<cfargument name="folderPath" required="true">
|
114
|
|
115
|
<cfreturn rereplace(ARGUMENTS.folderPath, "[/\\\\][^/\\\\]+[/\\\\]?$", "")>
|
116
|
</cffunction>
|
117
|
|
118
|
<cffunction name="CreateServerFolder" returntype="String" output="false">
|
119
|
<cfargument name="folderPath">
|
120
|
|
121
|
<!--- Ensure the folder path has no double-slashes, or mkdir may fail on certain platforms --->
|
122
|
<cfset folderPath = rereplace(ARGUMENTS.folderPath, "//+", "/", "all")>
|
123
|
|
124
|
<cfif directoryexists(ARGUMENTS.folderPath) or fileexists(ARGUMENTS.folderPath)>
|
125
|
<cfreturn "">
|
126
|
<cfelse>
|
127
|
<cftry>
|
128
|
<cfdirectory action="create" mode="0755" directory="#ARGUMENTS.folderPath#">
|
129
|
<cfcatch type="any">
|
130
|
<cfreturn CFCATCH.Message>
|
131
|
</cfcatch>
|
132
|
</cftry>
|
133
|
</cfif>
|
134
|
|
135
|
<cfreturn "">
|
136
|
</cffunction>
|
137
|
|
138
|
<cffunction name="IsAllowedExt" returntype="boolean" output="false">
|
139
|
<cfargument name="sExtension" required="true">
|
140
|
<cfargument name="resourceType" required="true">
|
141
|
|
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 )>
|
145
|
<cfreturn false>
|
146
|
</cfif>
|
147
|
|
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 )>
|
151
|
<cfreturn false>
|
152
|
</cfif>
|
153
|
|
154
|
<cfreturn true>
|
155
|
</cffunction>
|
156
|
|
157
|
<cffunction name="IsAllowedType" returntype="boolean" output="false">
|
158
|
<cfargument name="resourceType">
|
159
|
|
160
|
<cfif not listFindNoCase( REQUEST.Config.ConfigAllowedTypes, ARGUMENTS.resourceType )>
|
161
|
<cfreturn false>
|
162
|
</cfif>
|
163
|
|
164
|
<cfreturn true>
|
165
|
</cffunction>
|
166
|
|
167
|
<cffunction name="IsAllowedCommand" returntype="boolean" output="true">
|
168
|
<cfargument name="sCommand" required="true" type="String">
|
169
|
|
170
|
<cfif not listFindNoCase( REQUEST.Config.ConfigAllowedCommands, ARGUMENTS.sCommand )>
|
171
|
<cfreturn false>
|
172
|
</cfif>
|
173
|
|
174
|
<cfreturn true>
|
175
|
</cffunction>
|
176
|
|
177
|
<cffunction name="GetCurrentFolder" returntype="String" output="true">
|
178
|
<cfset var sCurrentFolder = "/">
|
179
|
|
180
|
<cfif isDefined( "URL.CurrentFolder" )>
|
181
|
<cfset sCurrentFolder = URL.CurrentFolder>
|
182
|
</cfif>
|
183
|
|
184
|
<!--- Check the current folder syntax (must begin and start with a slash). --->
|
185
|
<cfif not refind( "/$", sCurrentFolder)>
|
186
|
<cfset sCurrentFolder = sCurrentFolder & "/">
|
187
|
</cfif>
|
188
|
|
189
|
<cfif not refind( "^/", sCurrentFolder )>
|
190
|
<cfset sCurrentFolder = "/" & sCurrentFolder>
|
191
|
</cfif>
|
192
|
|
193
|
<!--- Ensure the folder path has no double-slashes, or mkdir may fail on certain platforms --->
|
194
|
<cfset sCurrentFolder = rereplace( sCurrentFolder, "//+", "/", "all" )>
|
195
|
|
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, "", "", "") >
|
199
|
<cfelse>
|
200
|
<cfset SendError( 102, "" )>
|
201
|
</cfif>
|
202
|
</cfif>
|
203
|
|
204
|
<cfreturn sCurrentFolder>
|
205
|
</cffunction>
|
206
|
|
207
|
<cffunction name="SanitizeFolderName" returntype="String" output="false">
|
208
|
<cfargument name="sNewFolderName" required="true">
|
209
|
|
210
|
<!--- Do a cleanup of the folder name to avoid possible problems --->
|
211
|
<!--- Remove . \ / | : ? * " < > and control characters --->
|
212
|
<cfset sNewFolderName = rereplace( sNewFolderName, '\.+|\\+|\/+|\|+|\:+|\?+|\*+|"+|<+|>+|[[:cntrl:]]+', "_", "all" )>
|
213
|
|
214
|
<cfreturn sNewFolderName>
|
215
|
</cffunction>
|
216
|
|
217
|
<cffunction name="BinaryFileRead" returntype="String" output="true">
|
218
|
<cfargument name="fileName" required="true" type="string">
|
219
|
<cfargument name="bytes" required="true" type="Numeric">
|
220
|
|
221
|
<cfscript>
|
222
|
var chunk = "";
|
223
|
var fileReaderClass = "";
|
224
|
var fileReader = "";
|
225
|
var file = "";
|
226
|
var done = false;
|
227
|
var counter = 0;
|
228
|
var byteArray = "";
|
229
|
|
230
|
if( not fileExists( ARGUMENTS.fileName ) )
|
231
|
{
|
232
|
return "" ;
|
233
|
}
|
234
|
|
235
|
if (REQUEST.CFVersion gte 8)
|
236
|
{
|
237
|
file = FileOpen( ARGUMENTS.fileName, "readbinary" ) ;
|
238
|
byteArray = FileRead( file, 1024 ) ;
|
239
|
chunk = toString( toBinary( toBase64( byteArray ) ) ) ;
|
240
|
FileClose( file ) ;
|
241
|
}
|
242
|
else
|
243
|
{
|
244
|
fileReaderClass = createObject("java", "java.io.FileInputStream");
|
245
|
fileReader = fileReaderClass.init(fileName);
|
246
|
|
247
|
while(not done)
|
248
|
{
|
249
|
char = fileReader.read();
|
250
|
counter = counter + 1;
|
251
|
if ( char eq -1 or counter eq ARGUMENTS.bytes)
|
252
|
{
|
253
|
done = true;
|
254
|
}
|
255
|
else
|
256
|
{
|
257
|
chunk = chunk & chr(char) ;
|
258
|
}
|
259
|
}
|
260
|
}
|
261
|
</cfscript>
|
262
|
|
263
|
<cfreturn chunk>
|
264
|
</cffunction>
|
265
|
|
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="">
|
271
|
|
272
|
<cfif errorNumber and errorNumber neq 201>
|
273
|
<cfset fileUrl = "">
|
274
|
<cfset fileName = "">
|
275
|
</cfif>
|
276
|
<!--- Minified version of the document.domain automatic fix script (#1919).
|
277
|
The original script can be found at _dev/domain_fix_template.js --->
|
278
|
<cfoutput>
|
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)#" );
|
282
|
</script>
|
283
|
</cfoutput>
|
284
|
<cfabort>
|
285
|
</cffunction>
|
286
|
|
287
|
<cffunction name="SanitizeFileName" returntype="String" output="false">
|
288
|
<cfargument name="sNewFileName" required="true">
|
289
|
|
290
|
<cfif isDefined("REQUEST.Config.ForceSingleExtension") and REQUEST.Config.ForceSingleExtension>
|
291
|
<cfset sNewFileName = rereplace( sNewFileName, '\.(?![^.]*$)', "_", "all" )>
|
292
|
</cfif>
|
293
|
|
294
|
<!--- Do a cleanup of the file name to avoid possible problems --->
|
295
|
<!--- Remove \ / | : ? * " < > and control characters --->
|
296
|
<cfset sNewFileName = rereplace( sNewFileName, '\\[.]+|\\+|\/+|\|+|\:+|\?+|\*+|"+|<+|>+|[[:cntrl:]]+', "_", "all" )>
|
297
|
|
298
|
<cfreturn sNewFileName>
|
299
|
</cffunction>
|