[ Index ]
 

Code source de FCKeditor 2.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/editor/filemanager/browser/default/connectors/cfm/ -> connector.cfm (source)

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


Généré le : Sun Feb 25 15:28:05 2007 par Balluche grâce à PHPXref 0.7