[763] | 1 | <cfsetting enablecfoutputonly="yes" showdebugoutput="no">
|
---|
| 2 | <!---
|
---|
| 3 | * FCKeditor - The text editor for internet
|
---|
| 4 | * Copyright (C) 2003-2006 Frederico Caldeira Knabben
|
---|
| 5 | *
|
---|
| 6 | * Licensed under the terms of the GNU Lesser General Public License:
|
---|
| 7 | * http://www.opensource.org/licenses/lgpl-license.php
|
---|
| 8 | *
|
---|
| 9 | * For further information visit:
|
---|
| 10 | * http://www.fckeditor.net/
|
---|
| 11 | *
|
---|
| 12 | * "Support Open Source software. What about a donation today?"
|
---|
| 13 | *
|
---|
| 14 | * File Name: connector.cfm
|
---|
| 15 | * File Browser connector for ColdFusion.
|
---|
| 16 | * (based on the original CF connector by Hendrik Kramer - hk@lwd.de)
|
---|
| 17 | *
|
---|
| 18 | * Note:
|
---|
| 19 | * FCKeditor requires that the connector responds with UTF-8 encoded XML.
|
---|
| 20 | * As ColdFusion 5 does not fully support UTF-8 encoding, we force ASCII
|
---|
| 21 | * file and folder names in this connector to allow CF5 send a UTF-8
|
---|
| 22 | * encoded response - code points under 127 in UTF-8 are stored using a
|
---|
| 23 | * single byte, using the same encoding as ASCII, which is damn handy.
|
---|
| 24 | * This is all grand for the English speakers, like meself, but I dunno
|
---|
| 25 | * how others are gonna take to it. Well, the previous version of this
|
---|
| 26 | * connector already did this with file names and nobody seemed to mind,
|
---|
| 27 | * so fingers-crossed nobody will mind their folder names being munged too.
|
---|
| 28 | *
|
---|
| 29 | *
|
---|
| 30 | * File Authors:
|
---|
| 31 | * Mark Woods (mark@thickpaddy.com)
|
---|
| 32 | * Wim Lemmens (didgiman@gmail.com)
|
---|
| 33 | --->
|
---|
| 34 |
|
---|
| 35 | <cfparam name="url.command">
|
---|
| 36 | <cfparam name="url.type">
|
---|
| 37 | <cfparam name="url.currentFolder">
|
---|
| 38 | <!--- note: no serverPath url parameter - see config.cfm if you need to set the serverPath manually --->
|
---|
| 39 |
|
---|
| 40 | <cfinclude template="config.cfm">
|
---|
| 41 |
|
---|
| 42 | <cfscript>
|
---|
| 43 | userFilesPath = config.userFilesPath;
|
---|
| 44 | lAllowedExtensions = config.allowedExtensions[url.type];
|
---|
| 45 | lDeniedExtensions = config.deniedExtensions[url.type];
|
---|
| 46 |
|
---|
| 47 | // make sure the user files path is correctly formatted
|
---|
| 48 | userFilesPath = replace(userFilesPath, "\", "/", "ALL");
|
---|
| 49 | userFilesPath = replace(userFilesPath, '//', '/', 'ALL');
|
---|
| 50 | if ( right(userFilesPath,1) neq "/" ) {
|
---|
| 51 | userFilesPath = userFilesPath & "/";
|
---|
| 52 | }
|
---|
| 53 | if ( left(userFilesPath,1) neq "/" ) {
|
---|
| 54 | userFilesPath = "/" & userFilesPath;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | // make sure the current folder is correctly formatted
|
---|
| 58 | url.currentFolder = replace(url.currentFolder, "\", "/", "ALL");
|
---|
| 59 | url.currentFolder = replace(url.currentFolder, '//', '/', 'ALL');
|
---|
| 60 | if ( right(url.currentFolder,1) neq "/" ) {
|
---|
| 61 | url.currentFolder = url.currentFolder & "/";
|
---|
| 62 | }
|
---|
| 63 | if ( left(url.currentFolder,1) neq "/" ) {
|
---|
| 64 | url.currentFolder = "/" & url.currentFolder;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | if ( find("/",getBaseTemplatePath()) neq 0 ) {
|
---|
| 68 | fs = "/";
|
---|
| 69 | } else {
|
---|
| 70 | fs = "\";
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | // Get the base physical path to the web root for this application. The code to determine the path automatically assumes that
|
---|
| 74 | // the "FCKeditor" directory in the http request path is directly off the web root for the application and that it's not a
|
---|
| 75 | // virtual directory or a symbolic link / junction. Use the serverPath config setting to force a physical path if necessary.
|
---|
| 76 | if ( len(config.serverPath) ) {
|
---|
| 77 | serverPath = config.serverPath;
|
---|
| 78 | } else {
|
---|
| 79 | serverPath = replaceNoCase(getBaseTemplatePath(),replace(cgi.script_name,"/",fs,"all"),"");
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | // map the user files path to a physical directory
|
---|
| 83 | userFilesServerPath = serverPath & replace(userFilesPath,"/",fs,"all");
|
---|
| 84 |
|
---|
| 85 | xmlContent = ""; // append to this string to build content
|
---|
| 86 | </cfscript>
|
---|
| 87 |
|
---|
| 88 | <cfif not config.enabled>
|
---|
| 89 |
|
---|
| 90 | <cfset xmlContent = "<Error number=""1"" text=""This connector is disabled. Please check the 'editor/filemanager/browser/default/connectors/cfm/config.cfm' file"" />">
|
---|
| 91 |
|
---|
| 92 | <cfelseif find("..",url.currentFolder)>
|
---|
| 93 |
|
---|
| 94 | <cfset xmlContent = "<Error number=""102"" />">
|
---|
| 95 |
|
---|
| 96 | </cfif>
|
---|
| 97 |
|
---|
| 98 | <cfif not len(xmlContent)>
|
---|
| 99 |
|
---|
| 100 | <!--- create directories in physical path if they don't already exist --->
|
---|
| 101 | <cfset currentPath = serverPath>
|
---|
| 102 | <cftry>
|
---|
| 103 |
|
---|
| 104 | <cfloop list="#userFilesPath#" index="name" delimiters="/">
|
---|
| 105 |
|
---|
| 106 | <cfif not directoryExists(currentPath & fs & name)>
|
---|
| 107 | <cfdirectory action="create" directory="#currentPath##fs##name#" mode="755">
|
---|
| 108 | </cfif>
|
---|
| 109 |
|
---|
| 110 | <cfset currentPath = currentPath & fs & name>
|
---|
| 111 |
|
---|
| 112 | </cfloop>
|
---|
| 113 |
|
---|
| 114 | <!--- create sub-directory for file type if it doesn't already exist --->
|
---|
| 115 | <cfif not directoryExists(userFilesServerPath & url.type)>
|
---|
| 116 | <cfdirectory action="create" directory="#userFilesServerPath##url.type#" mode="755">
|
---|
| 117 | </cfif>
|
---|
| 118 |
|
---|
| 119 | <cfcatch>
|
---|
| 120 |
|
---|
| 121 | <!--- this should only occur as a result of a permissions problem --->
|
---|
| 122 | <cfset xmlContent = "<Error number=""103"" />">
|
---|
| 123 |
|
---|
| 124 | </cfcatch>
|
---|
| 125 | </cftry>
|
---|
| 126 |
|
---|
| 127 | </cfif>
|
---|
| 128 |
|
---|
| 129 | <cfif not len(xmlContent)>
|
---|
| 130 |
|
---|
| 131 | <!--- no errors thus far - run command --->
|
---|
| 132 |
|
---|
| 133 | <!--- we need to know the physical path to the current folder for all commands --->
|
---|
| 134 | <cfset currentFolderPath = userFilesServerPath & url.type & replace(url.currentFolder,"/",fs,"all")>
|
---|
| 135 |
|
---|
| 136 | <cfswitch expression="#url.command#">
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | <cfcase value="FileUpload">
|
---|
| 140 |
|
---|
| 141 | <cfset fileName = "">
|
---|
| 142 | <cfset fileExt = "">
|
---|
| 143 |
|
---|
| 144 | <cftry>
|
---|
| 145 |
|
---|
| 146 | <!--- TODO: upload to a temp directory and move file if extension is allowed --->
|
---|
| 147 |
|
---|
| 148 | <!--- first upload the file with an unique filename --->
|
---|
| 149 | <cffile action="upload"
|
---|
| 150 | fileField="NewFile"
|
---|
| 151 | destination="#currentFolderPath#"
|
---|
| 152 | nameConflict="makeunique"
|
---|
| 153 | mode="644"
|
---|
| 154 | attributes="normal">
|
---|
| 155 |
|
---|
| 156 | <cfif cffile.fileSize EQ 0>
|
---|
| 157 | <cfthrow>
|
---|
| 158 | </cfif>
|
---|
| 159 |
|
---|
| 160 | <cfif ( len(lAllowedExtensions) and not listFindNoCase(lAllowedExtensions,cffile.ServerFileExt) )
|
---|
| 161 | or ( len(lDeniedExtensions) and listFindNoCase(lDeniedExtensions,cffile.ServerFileExt) )>
|
---|
| 162 |
|
---|
| 163 | <cfset errorNumber = "202">
|
---|
| 164 | <cffile action="delete" file="#cffile.ServerDirectory##fs##cffile.ServerFile#">
|
---|
| 165 |
|
---|
| 166 | <cfelse>
|
---|
| 167 |
|
---|
| 168 | <cfscript>
|
---|
| 169 | errorNumber = 0;
|
---|
| 170 | fileName = cffile.ClientFileName;
|
---|
| 171 | fileExt = cffile.ServerFileExt;
|
---|
| 172 |
|
---|
| 173 | // munge filename for html download. Only a-z, 0-9, _, - and . are allowed
|
---|
| 174 | if( reFind("[^A-Za-z0-9_\-\.]", fileName) ) {
|
---|
| 175 | fileName = reReplace(fileName, "[^A-Za-z0-9\-\.]", "_", "ALL");
|
---|
| 176 | fileName = reReplace(fileName, "_{2,}", "_", "ALL");
|
---|
| 177 | fileName = reReplace(fileName, "([^_]+)_+$", "\1", "ALL");
|
---|
| 178 | fileName = reReplace(fileName, "$_([^_]+)$", "\1", "ALL");
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | // When the original filename already exists, add numbers (0), (1), (2), ... at the end of the filename.
|
---|
| 182 | if( compare( cffile.ServerFileName, fileName ) ) {
|
---|
| 183 | counter = 0;
|
---|
| 184 | tmpFileName = fileName;
|
---|
| 185 | while( fileExists("#currentFolderPath##fileName#.#fileExt#") ) {
|
---|
| 186 | counter = counter + 1;
|
---|
| 187 | fileName = tmpFileName & '(#counter#)';
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
| 190 | </cfscript>
|
---|
| 191 |
|
---|
| 192 | <!--- Rename the uploaded file, if neccessary --->
|
---|
| 193 | <cfif compare(cffile.ServerFileName,fileName)>
|
---|
| 194 |
|
---|
| 195 | <cfset errorNumber = "201">
|
---|
| 196 | <cffile
|
---|
| 197 | action="rename"
|
---|
| 198 | source="#currentFolderPath##cffile.ServerFileName#.#cffile.ServerFileExt#"
|
---|
| 199 | destination="#currentFolderPath##fileName#.#fileExt#"
|
---|
| 200 | mode="644"
|
---|
| 201 | attributes="normal">
|
---|
| 202 |
|
---|
| 203 | </cfif>
|
---|
| 204 |
|
---|
| 205 | </cfif>
|
---|
| 206 |
|
---|
| 207 | <cfcatch type="Any">
|
---|
| 208 |
|
---|
| 209 | <cfset errorNumber = "202">
|
---|
| 210 |
|
---|
| 211 | </cfcatch>
|
---|
| 212 |
|
---|
| 213 | </cftry>
|
---|
| 214 |
|
---|
| 215 |
|
---|
| 216 | <cfif errorNumber eq 201>
|
---|
| 217 |
|
---|
| 218 | <!--- file was changed (201), submit the new filename --->
|
---|
| 219 | <cfoutput>
|
---|
| 220 | <script type="text/javascript">
|
---|
| 221 | window.parent.frames['frmUpload'].OnUploadCompleted(#errorNumber#,'#replace( fileName & "." & fileExt, "'", "\'", "ALL")#');
|
---|
| 222 | </script>
|
---|
| 223 | </cfoutput>
|
---|
| 224 |
|
---|
| 225 | <cfelse>
|
---|
| 226 |
|
---|
| 227 | <!--- file was uploaded succesfully(0) or an error occured(202). Submit only the error code. --->
|
---|
| 228 | <cfoutput>
|
---|
| 229 | <script type="text/javascript">
|
---|
| 230 | window.parent.frames['frmUpload'].OnUploadCompleted(#errorNumber#);
|
---|
| 231 | </script>
|
---|
| 232 | </cfoutput>
|
---|
| 233 |
|
---|
| 234 | </cfif>
|
---|
| 235 |
|
---|
| 236 | <cfabort>
|
---|
| 237 |
|
---|
| 238 | </cfcase>
|
---|
| 239 |
|
---|
| 240 |
|
---|
| 241 | <cfcase value="GetFolders">
|
---|
| 242 |
|
---|
| 243 | <!--- Sort directories first, name ascending --->
|
---|
| 244 | <cfdirectory
|
---|
| 245 | action="list"
|
---|
| 246 | directory="#currentFolderPath#"
|
---|
| 247 | name="qDir"
|
---|
| 248 | sort="type,name">
|
---|
| 249 |
|
---|
| 250 | <cfscript>
|
---|
| 251 | i=1;
|
---|
| 252 | folders = "";
|
---|
| 253 | while( i lte qDir.recordCount ) {
|
---|
| 254 | if( not compareNoCase( qDir.type[i], "FILE" ))
|
---|
| 255 | break;
|
---|
| 256 | if( not listFind(".,..", qDir.name[i]) )
|
---|
| 257 | folders = folders & '<Folder name="#qDir.name[i]#" />';
|
---|
| 258 | i=i+1;
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | xmlContent = xmlContent & '<Folders>' & folders & '</Folders>';
|
---|
| 262 | </cfscript>
|
---|
| 263 |
|
---|
| 264 | </cfcase>
|
---|
| 265 |
|
---|
| 266 |
|
---|
| 267 | <cfcase value="GetFoldersAndFiles">
|
---|
| 268 |
|
---|
| 269 | <!--- Sort directories first, name ascending --->
|
---|
| 270 | <cfdirectory
|
---|
| 271 | action="list"
|
---|
| 272 | directory="#currentFolderPath#"
|
---|
| 273 | name="qDir"
|
---|
| 274 | sort="type,name">
|
---|
| 275 |
|
---|
| 276 | <cfscript>
|
---|
| 277 | i=1;
|
---|
| 278 | folders = "";
|
---|
| 279 | files = "";
|
---|
| 280 | while( i lte qDir.recordCount ) {
|
---|
| 281 | if( not compareNoCase( qDir.type[i], "DIR" ) and not listFind(".,..", qDir.name[i]) ) {
|
---|
| 282 | folders = folders & '<Folder name="#qDir.name[i]#" />';
|
---|
| 283 | } else if( not compareNoCase( qDir.type[i], "FILE" ) ) {
|
---|
| 284 | fileSizeKB = round(qDir.size[i] / 1024);
|
---|
| 285 | files = files & '<File name="#qDir.name[i]#" size="#IIf( fileSizeKB GT 0, DE( fileSizeKB ), 1)#" />';
|
---|
| 286 | }
|
---|
| 287 | i=i+1;
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | xmlContent = xmlContent & '<Folders>' & folders & '</Folders>';
|
---|
| 291 | xmlContent = xmlContent & '<Files>' & files & '</Files>';
|
---|
| 292 | </cfscript>
|
---|
| 293 |
|
---|
| 294 | </cfcase>
|
---|
| 295 |
|
---|
| 296 |
|
---|
| 297 | <cfcase value="CreateFolder">
|
---|
| 298 |
|
---|
| 299 | <cfparam name="url.newFolderName" default="">
|
---|
| 300 |
|
---|
| 301 | <cfscript>
|
---|
| 302 | newFolderName = url.newFolderName;
|
---|
| 303 | if( reFind("[^A-Za-z0-9_\-\.]", newFolderName) ) {
|
---|
| 304 | // Munge folder name same way as we do the filename
|
---|
| 305 | // This means folder names are always US-ASCII so we don't have to worry about CF5 and UTF-8
|
---|
| 306 | newFolderName = reReplace(newFolderName, "[^A-Za-z0-9\-\.]", "_", "all");
|
---|
| 307 | newFolderName = reReplace(newFolderName, "_{2,}", "_", "all");
|
---|
| 308 | newFolderName = reReplace(newFolderName, "([^_]+)_+$", "\1", "all");
|
---|
| 309 | newFolderName = reReplace(newFolderName, "$_([^_]+)$", "\1", "all");
|
---|
| 310 | }
|
---|
| 311 | </cfscript>
|
---|
| 312 |
|
---|
| 313 | <cfif not len(newFolderName) or len(newFolderName) gt 255>
|
---|
| 314 | <cfset errorNumber = 102>
|
---|
| 315 | <cfelseif directoryExists(currentFolderPath & newFolderName)>
|
---|
| 316 | <cfset errorNumber = 101>
|
---|
| 317 | <cfelseif reFind("^\.\.",newFolderName)>
|
---|
| 318 | <cfset errorNumber = 103>
|
---|
| 319 | <cfelse>
|
---|
| 320 | <cfset errorNumber = 0>
|
---|
| 321 |
|
---|
| 322 | <cftry>
|
---|
| 323 | <cfdirectory
|
---|
| 324 | action="create"
|
---|
| 325 | directory="#currentFolderPath##newFolderName#"
|
---|
| 326 | mode="755">
|
---|
| 327 | <cfcatch>
|
---|
| 328 | <!---
|
---|
| 329 | un-resolvable error numbers in ColdFusion:
|
---|
| 330 | * 102 : Invalid folder name.
|
---|
| 331 | * 103 : You have no permissions to create the folder.
|
---|
| 332 | --->
|
---|
| 333 | <cfset errorNumber = 110>
|
---|
| 334 | </cfcatch>
|
---|
| 335 | </cftry>
|
---|
| 336 | </cfif>
|
---|
| 337 |
|
---|
| 338 | <cfset xmlContent = xmlContent & '<Error number="#errorNumber#" />'>
|
---|
| 339 |
|
---|
| 340 | </cfcase>
|
---|
| 341 |
|
---|
| 342 |
|
---|
| 343 | <cfdefaultcase>
|
---|
| 344 |
|
---|
| 345 | <cfthrow type="fckeditor.connector" message="Illegal command: #url.command#">
|
---|
| 346 |
|
---|
| 347 | </cfdefaultcase>
|
---|
| 348 |
|
---|
| 349 |
|
---|
| 350 | </cfswitch>
|
---|
| 351 |
|
---|
| 352 | </cfif>
|
---|
| 353 |
|
---|
| 354 | <cfscript>
|
---|
| 355 | xmlHeader = '<?xml version="1.0" encoding="utf-8" ?><Connector command="#url.command#" resourceType="#url.type#">';
|
---|
| 356 | xmlHeader = xmlHeader & '<CurrentFolder path="#url.currentFolder#" url="#userFilesPath##url.type##url.currentFolder#" />';
|
---|
| 357 | xmlFooter = '</Connector>';
|
---|
| 358 | </cfscript>
|
---|
| 359 |
|
---|
| 360 | <cfheader name="Expires" value="#GetHttpTimeString(Now())#">
|
---|
| 361 | <cfheader name="Pragma" value="no-cache">
|
---|
| 362 | <cfheader name="Cache-Control" value="no-cache, no-store, must-revalidate">
|
---|
| 363 | <cfcontent reset="true" type="text/xml; charset=UTF-8">
|
---|
| 364 | <cfoutput>#xmlHeader##xmlContent##xmlFooter#</cfoutput> |
---|