PageRenderTime 14ms CodeModel.GetById 9ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/EQT_V2/EQT/EQTWebApp/fckeditor/editor/filemanager/connectors/cfm/cf_commands.cfm

http://sgsoft-las.googlecode.com/
ColdFusion | 230 lines | 163 code | 30 blank | 37 comment | 4 complexity | 7bedac0a7ed00a646e0b2ace68702ea7 MD5 | raw file
Possible License(s): LGPL-2.1
  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 the functions that handle the Command requests
 23 * in the ColdFusion Connector (MX 6.0 and above).
 24--->
 25
 26<cffunction name="FileUpload" returntype="void" output="true">
 27	<cfargument name="resourceType" type="string" required="yes" default="">
 28	<cfargument name="currentFolder" type="string" required="yes" default="">
 29	<cfargument name="sCommand" type="string" required="yes" default="">
 30
 31	<cfset var sFileName = "">
 32	<cfset var sFilePart = "">
 33	<cfset var sFileExt = "">
 34	<cfset var sFileUrl = "">
 35	<cfset var sTempDir = "">
 36	<cfset var sTempFilePath = "">
 37	<cfset var errorNumber = 0>
 38	<cfset var customMsg = 0>
 39	<cfset var counter = 0>
 40	<cfset var destination = "">
 41
 42	<cftry>
 43		<cfif isDefined( "REQUEST.Config.TempDirectory" )>
 44			<cfset sTempDir = REQUEST.Config.TempDirectory>
 45		<cfelse>
 46			<cfset sTempDir = GetTempDirectory()>
 47		</cfif>
 48		<cfif NOT DirectoryExists (sTempDir)>
 49			<cfthrow message="Invalid temporary directory: #sTempDir#">
 50		</cfif>
 51
 52		<cffile action="UPLOAD" filefield="NewFile" destination="#sTempDir#" nameconflict="makeunique" mode="0755" />
 53		<cfset sTempFilePath = CFFILE.ServerDirectory & REQUEST.fs & CFFILE.ServerFile>
 54
 55		<!--- Map the virtual path to the local server path. --->
 56		<cfset sServerDir = ServerMapFolder( ARGUMENTS.resourceType, ARGUMENTS.currentFolder, ARGUMENTS.sCommand) >
 57		<!--- Get the uploaded file name. --->
 58		<cfset sFileName = SanitizeFileName( CFFILE.ClientFile ) >
 59		<cfset sOriginalFileName = sFileName >
 60
 61		<cfif isDefined( "REQUEST.Config.SecureImageUploads" ) and REQUEST.Config.SecureImageUploads>
 62			<cfif not IsImageValid( sTempFilePath, CFFILE.ClientFileExt )>
 63				<cftry>
 64				<cffile action="delete" file="#sTempFilePath#">
 65				<cfcatch type="any">
 66				</cfcatch>
 67				</cftry>
 68				<cfthrow errorcode="202" type="fckeditor">
 69			</cfif>
 70		</cfif>
 71
 72		<cfif isDefined( "REQUEST.Config.HtmlExtensions" ) and not listFindNoCase( REQUEST.Config.HtmlExtensions, CFFILE.ClientFileExt )>
 73			<cfif DetectHtml( sTempFilePath )>
 74				<cftry>
 75				<cffile action="delete" file="#sTempFilePath#">
 76				<cfcatch type="any">
 77				</cfcatch>
 78				</cftry>
 79				<cfthrow errorcode="202" type="fckeditor">
 80			</cfif>
 81		</cfif>
 82
 83		<cfif not IsAllowedExt( CFFILE.ClientFileExt, ARGUMENTS.resourceType )>
 84			<cftry>
 85			<cffile action="delete" file="#sTempFilePath#">
 86			<cfcatch type="any">
 87			</cfcatch>
 88			</cftry>
 89			<cfthrow errorcode="202" type="fckeditor">
 90		</cfif>
 91
 92		<!--- When the original filename already exists, add numbers (0), (1), (2), ... at the end of the filename. --->
 93		<cfscript>
 94			sFileExt = GetExtension( sFileName ) ;
 95			sFilePart = RemoveExtension( sFileName );
 96			while( fileExists( sServerDir & sFileName ) )
 97			{
 98				counter = counter + 1;
 99				sFileName = sFilePart & '(#counter#).' & CFFILE.ClientFileExt;
100				errorNumber = 201;
101			}
102		</cfscript>
103
104 		<cfset destination = sServerDir & sFileName>
105
106		<cflock name="#destination#" timeout="30" type="Exclusive">
107		<cftry>
108			<cffile action="move" source="#sTempFilePath#" destination="#destination#" mode="755">
109			<!--- omit CF 6.1 error during moving uploaded file, just copy that file instead of moving --->
110			<cfcatch type="any">
111				<cffile action="copy" source="#sTempFilePath#" destination="#destination#" mode="755">
112			</cfcatch>
113		</cftry>
114		</cflock>
115
116		<cfset sFileUrl = CombinePaths( GetResourceTypePath( ARGUMENTS.resourceType, sCommand ) , ARGUMENTS.currentFolder ) >
117		<cfset sFileUrl = CombinePaths( sFileUrl , sFileName ) >
118
119		<cfcatch type="fckeditor">
120			<cfset errorNumber = CFCATCH.ErrorCode>
121		</cfcatch>
122
123		<cfcatch type="any">
124			<cfset errorNumber = "1">
125			<cfset customMsg = CFCATCH.Message >
126		</cfcatch>
127
128	</cftry>
129
130	<cfset SendUploadResults( errorNumber, sFileUrl, sFileName, customMsg ) >
131</cffunction>
132
133<cffunction name="GetFolders" returntype="void" output="true">
134	<cfargument name="resourceType" type="String" required="true">
135	<cfargument name="currentFolder" type="String" required="true">
136
137	<cfset var i = 1>
138	<cfset var folders = "">
139	<!--- Map the virtual path to the local server path --->
140	<cfset var sServerDir = ServerMapFolder( ARGUMENTS.resourceType, ARGUMENTS.currentFolder, "GetFolders" ) >
141
142	<!--- Sort directories first, name ascending --->
143	<cfdirectory action="list" directory="#sServerDir#" name="qDir" sort="type,name">
144	<cfscript>
145		while( i lte qDir.recordCount )
146		{
147			if( compareNoCase( qDir.type[i], "FILE" ) and not listFind( ".,..", qDir.name[i] ) )
148			{
149				folders = folders & '<Folder name="#HTMLEditFormat( qDir.name[i] )#" />' ;
150			}
151			i = i + 1;
152		}
153	</cfscript>
154	<cfoutput><Folders>#folders#</Folders></cfoutput>
155</cffunction>
156
157<cffunction name="GetFoldersAndfiles" returntype="void" output="true">
158	<cfargument name="resourceType" type="String" required="true">
159	<cfargument name="currentFolder" type="String" required="true">
160
161	<cfset var i = 1>
162	<cfset var folders = "">
163	<cfset var files = "">
164	<!--- Map the virtual path to the local server path --->
165	<cfset var sServerDir = ServerMapFolder( ARGUMENTS.resourceType, ARGUMENTS.currentFolder, "GetFolders" ) >
166
167	<!--- Sort directories first, name ascending --->
168	<cfdirectory action="list" directory="#sServerDir#" name="qDir" sort="type,name">
169	<cfscript>
170		while( i lte qDir.recordCount )
171		{
172			if( not compareNoCase( qDir.type[i], "DIR" ) and not listFind( ".,..", qDir.name[i] ) )
173			{
174				folders = folders & '<Folder name="#HTMLEditFormat(qDir.name[i])#" />' ;
175			}
176			else if( not compareNoCase( qDir.type[i], "FILE" ) )
177			{
178				fileSizeKB = round(qDir.size[i] / 1024) ;
179				files = files & '<File name="#HTMLEditFormat(qDir.name[i])#" size="#IIf( fileSizeKB GT 0, DE( fileSizeKB ), 1)#" />' ;
180			}
181			i = i + 1 ;
182		}
183	</cfscript>
184	<cfoutput><Folders>#folders#</Folders></cfoutput>
185	<cfoutput><Files>#files#</Files></cfoutput>
186</cffunction>
187
188<cffunction name="CreateFolder" returntype="void" output="true">
189	<cfargument name="resourceType" required="true" type="string">
190	<cfargument name="currentFolder" required="true" type="string">
191
192	<cfset var sNewFolderName = url.newFolderName >
193	<cfset var sServerDir = "" >
194	<cfset var errorNumber = 0>
195	<cfset var sErrorMsg = "">
196	<cfset var currentFolderPath = ServerMapFolder( ARGUMENTS.resourceType, ARGUMENTS.currentFolder, 'CreateFolder' )>
197
198	<cfparam name="url.newFolderName" default="">
199
200	<cfscript>
201		sNewFolderName = SanitizeFolderName( sNewFolderName ) ;
202	</cfscript>
203
204	<cfif not len( sNewFolderName ) or len( sNewFolderName ) gt 255>
205		<cfset errorNumber = 102>
206	<cfelseif directoryExists( currentFolderPath & sNewFolderName )>
207		<cfset errorNumber = 101>
208	<cfelseif find( "..", sNewFolderName )>
209		<cfset errorNumber = 103>
210	<cfelse>
211		<cfset errorNumber = 0>
212
213		<!--- Map the virtual path to the local server path of the current folder. --->
214		<cfset sServerDir = currentFolderPath & sNewFolderName >
215
216		<cftry>
217			<cfdirectory action="create" directory="#currentFolderPath##sNewFolderName#" mode="755">
218			<cfcatch type="any">
219			<!---
220				un-resolvable error numbers in ColdFusion:
221				* 102 : Invalid folder name.
222				* 103 : You have no permissions to create the folder.
223			--->
224			<cfset errorNumber = 110>
225			</cfcatch>
226		</cftry>
227	</cfif>
228
229	<cfoutput><Error number="#errorNumber#" originalDescription="#HTMLEditFormat(sErrorMsg)#" /></cfoutput>
230</cffunction>