1<cfsetting enablecfoutputonly="Yes"> 2<!--- 3 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 4 * Copyright (C) 2003-2007 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="false"> 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)> 197 <cfset SendError( 102, "" )> 198 </cfif> 199 200 <cfreturn sCurrentFolder> 201</cffunction> 202 203<cffunction name="SanitizeFolderName" returntype="String" output="false"> 204 <cfargument name="sNewFolderName" required="true"> 205 206 <!--- Do a cleanup of the folder name to avoid possible problems ---> 207 <!--- Remove . \ / | : ? * " < > ---> 208 <cfset sNewFolderName = rereplace( sNewFolderName, '\.+|\\+|\/+|\|+|\:+|\?+|\*+|"+|<+|>+', "_", "all" )> 209 210 <cfreturn sNewFolderName> 211</cffunction> 212 213<cffunction name="BinaryFileRead" returntype="String" output="true"> 214 <cfargument name="fileName" required="true" type="string"> 215 <cfargument name="bytes" required="true" type="Numeric"> 216 217 <cfscript> 218 var chunk = ""; 219 var fileReaderClass = ""; 220 var fileReader = ""; 221 var file = ""; 222 var done = false; 223 var counter = 0; 224 var byteArray = ""; 225 226 if( not fileExists( ARGUMENTS.fileName ) ) 227 { 228 return "" ; 229 } 230 231 if (REQUEST.CFVersion gte 8) 232 { 233 file = FileOpen( ARGUMENTS.fileName, "readbinary" ) ; 234 byteArray = FileRead( file, 1024 ) ; 235 chunk = toString( toBinary( toBase64( byteArray ) ) ) ; 236 FileClose( file ) ; 237 } 238 else 239 { 240 fileReaderClass = createObject("java", "java.io.FileInputStream"); 241 fileReader = fileReaderClass.init(fileName); 242 243 while(not done) 244 { 245 char = fileReader.read(); 246 counter = counter + 1; 247 if ( char eq -1 or counter eq ARGUMENTS.bytes) 248 { 249 done = true; 250 } 251 else 252 { 253 chunk = chunk & chr(char) ; 254 } 255 } 256 } 257 </cfscript> 258 259 <cfreturn chunk> 260</cffunction> 261 262<cffunction name="SendUploadResults" returntype="String" output="true"> 263 <cfargument name="errorNumber" required="true" type="Numeric"> 264 <cfargument name="fileUrl" required="false" type="String" default=""> 265 <cfargument name="fileName" required="false" type="String" default=""> 266 <cfargument name="customMsg" required="false" type="String" default=""> 267 268 <cfoutput> 269 <script type="text/javascript"> 270 window.parent.OnUploadCompleted( #errorNumber#, "#JSStringFormat(fileUrl)#", "#JSStringFormat(fileName)#", "#JSStringFormat(customMsg)#" ); 271 </script> 272 </cfoutput> 273 <cfabort> 274</cffunction> 275 276<cffunction name="SanitizeFileName" returntype="String" output="false"> 277 <cfargument name="sNewFileName" required="true"> 278 279 <cfif isDefined("REQUEST.Config.ForceSingleExtension") and REQUEST.Config.ForceSingleExtension> 280 <cfset sNewFileName = rereplace( sNewFileName, '\.(?![^.]*$)', "_", "all" )> 281 </cfif> 282 283 <!--- Do a cleanup of the file name to avoid possible problems ---> 284 <!--- Remove \ / | : ? * " < > ---> 285 <cfset sNewFileName = rereplace( sNewFileName, '\\[.]+|\\+|\/+|\|+|\:+|\?+|\*+|"+|<+|>+', "_", "all" )> 286 287 <cfreturn sNewFileName> 288</cffunction> 289