1<%
2 ' FCKeditor - The text editor for Internet - http://www.fckeditor.net
3 ' Copyright (C) 2003-2007 Frederico Caldeira Knabben
4 '
5 ' == BEGIN LICENSE ==
6 '
7 ' Licensed under the terms of any of the following licenses at your
8 ' choice:
9 '
10 '  - GNU General Public License Version 2 or later (the "GPL")
11 '    http://www.gnu.org/licenses/gpl.html
12 '
13 '  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14 '    http://www.gnu.org/licenses/lgpl.html
15 '
16 '  - Mozilla Public License Version 1.1 or later (the "MPL")
17 '    http://www.mozilla.org/MPL/MPL-1.1.html
18 '
19 ' == END LICENSE ==
20 '
21 ' This file include IO specific functions used by the ASP Connector.
22%>
23<%
24function CombinePaths( sBasePath, sFolder)
25	CombinePaths =  RemoveFromEnd( sBasePath, "/" ) & "/" & RemoveFromStart( sFolder, "/" )
26end function
27
28Function GetResourceTypePath( resourceType, sCommand )
29	if ( sCommand = "QuickUpload") then
30		GetResourceTypePath = ConfigQuickUploadPath.Item( resourceType )
31	else
32		GetResourceTypePath = ConfigFileTypesPath.Item( resourceType )
33	end if
34end Function
35
36Function GetResourceTypeDirectory( resourceType, sCommand )
37	if ( sCommand = "QuickUpload") then
38
39		if ( ConfigQuickUploadAbsolutePath.Item( resourceType ) <> "" ) then
40			GetResourceTypeDirectory = ConfigQuickUploadAbsolutePath.Item( resourceType )
41		else
42			' Map the "UserFiles" path to a local directory.
43			GetResourceTypeDirectory = Server.MapPath( ConfigQuickUploadPath.Item( resourceType ) )
44		end if
45	else
46		if ( ConfigFileTypesAbsolutePath.Item( resourceType ) <> "" ) then
47			GetResourceTypeDirectory = ConfigFileTypesAbsolutePath.Item( resourceType )
48		else
49			' Map the "UserFiles" path to a local directory.
50			GetResourceTypeDirectory = Server.MapPath( ConfigFileTypesPath.Item( resourceType ) )
51		end if
52	end if
53end Function
54
55Function GetUrlFromPath( resourceType, folderPath, sCommand )
56	GetUrlFromPath = CombinePaths( GetResourceTypePath( resourceType, sCommand ), folderPath )
57End Function
58
59Function RemoveExtension( fileName )
60	RemoveExtension = Left( fileName, InStrRev( fileName, "." ) - 1 )
61End Function
62
63Function ServerMapFolder( resourceType, folderPath, sCommand )
64	Dim sResourceTypePath
65	' Get the resource type directory.
66	sResourceTypePath = GetResourceTypeDirectory( resourceType, sCommand )
67
68	' Ensure that the directory exists.
69	CreateServerFolder sResourceTypePath
70
71	' Return the resource type directory combined with the required path.
72	ServerMapFolder = CombinePaths( sResourceTypePath, folderPath )
73End Function
74
75Sub CreateServerFolder( folderPath )
76	Dim oFSO
77	Set oFSO = Server.CreateObject( "Scripting.FileSystemObject" )
78
79	Dim sParent
80	sParent = oFSO.GetParentFolderName( folderPath )
81
82	' Check if the parent exists, or create it.
83	If ( NOT oFSO.FolderExists( sParent ) ) Then CreateServerFolder( sParent )
84
85	If ( oFSO.FolderExists( folderPath ) = False ) Then
86		On Error resume next
87		oFSO.CreateFolder( folderPath )
88
89		if err.number<>0 then
90		dim sErrorNumber
91		Dim iErrNumber, sErrDescription
92		iErrNumber		= err.number
93		sErrDescription	= err.Description
94
95		On Error Goto 0
96
97		Select Case iErrNumber
98			Case 52
99				sErrorNumber = "102"	' Invalid Folder Name.
100			Case 70
101				sErrorNumber = "103"	' Security Error.
102			Case 76
103				sErrorNumber = "102"	' Path too long.
104			Case Else
105				sErrorNumber = "110"
106			End Select
107
108			SendError sErrorNumber, "CreateServerFolder(" & folderPath & ") : " & sErrDescription
109		end if
110
111	End If
112
113	Set oFSO = Nothing
114End Sub
115
116Function IsAllowedExt( extension, resourceType )
117	Dim oRE
118	Set oRE	= New RegExp
119	oRE.IgnoreCase	= True
120	oRE.Global		= True
121
122	Dim sAllowed, sDenied
123	sAllowed	= ConfigAllowedExtensions.Item( resourceType )
124	sDenied		= ConfigDeniedExtensions.Item( resourceType )
125
126	IsAllowedExt = True
127
128	If sDenied <> "" Then
129		oRE.Pattern	= sDenied
130		IsAllowedExt	= Not oRE.Test( extension )
131	End If
132
133	If IsAllowedExt And sAllowed <> "" Then
134		oRE.Pattern		= sAllowed
135		IsAllowedExt	= oRE.Test( extension )
136	End If
137
138	Set oRE	= Nothing
139End Function
140
141Function IsAllowedType( resourceType )
142	Dim oRE
143	Set oRE	= New RegExp
144	oRE.IgnoreCase	= True
145	oRE.Global		= True
146	oRE.Pattern		= "^(" & ConfigAllowedTypes & ")$"
147
148	IsAllowedType = oRE.Test( resourceType )
149
150	Set oRE	= Nothing
151End Function
152
153Function IsAllowedCommand( sCommand )
154	Dim oRE
155	Set oRE	= New RegExp
156	oRE.IgnoreCase	= True
157	oRE.Global		= True
158	oRE.Pattern		= "^(" & ConfigAllowedCommands & ")$"
159
160	IsAllowedCommand = oRE.Test( sCommand )
161
162	Set oRE	= Nothing
163End Function
164
165function GetCurrentFolder()
166	dim sCurrentFolder
167	sCurrentFolder = Request.QueryString("CurrentFolder")
168	If ( sCurrentFolder = "" ) Then sCurrentFolder = "/"
169
170	' Check the current folder syntax (must begin and start with a slash).
171	If ( Right( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = sCurrentFolder & "/"
172	If ( Left( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = "/" & sCurrentFolder
173
174	' Check for invalid folder paths (..)
175	If ( InStr( 1, sCurrentFolder, ".." ) <> 0 ) Then
176		SendError 102, ""
177	End If
178
179	GetCurrentFolder = sCurrentFolder
180end function
181
182' Do a cleanup of the folder name to avoid possible problems
183function SanitizeFolderName( sNewFolderName )
184	Dim oRegex
185	Set oRegex = New RegExp
186	oRegex.Global		= True
187
188' remove . \ / | : ? *  " < >
189	oRegex.Pattern = "(\.|\\|\/|\||:|\?|\*|""|\<|\>)"
190	SanitizeFolderName = oRegex.Replace( sNewFolderName, "_" )
191
192	Set oRegex = Nothing
193end function
194
195' Do a cleanup of the file name to avoid possible problems
196function SanitizeFileName( sNewFileName )
197	Dim oRegex
198	Set oRegex = New RegExp
199	oRegex.Global		= True
200
201	if ( ConfigForceSingleExtension = True ) then
202		oRegex.Pattern = "\.(?![^.]*$)"
203		sNewFileName = oRegex.Replace( sNewFileName, "_" )
204	end if
205
206' remove \ / | : ? *  " < >
207	oRegex.Pattern = "(\\|\/|\||:|\?|\*|""|\<|\>)"
208	SanitizeFileName = oRegex.Replace( sNewFileName, "_" )
209
210	Set oRegex = Nothing
211end function
212
213' This is the function that sends the results of the uploading process.
214Sub SendUploadResults( errorNumber, fileUrl, fileName, customMsg )
215	Response.Clear
216	Response.Write "<script type=""text/javascript"">"
217	Response.Write "window.parent.OnUploadCompleted(" & errorNumber & ",""" & Replace( fileUrl, """", "\""" ) & """,""" & Replace( fileName, """", "\""" ) & """,""" & Replace( customMsg , """", "\""" ) & """) ;"
218	Response.Write "</script>"
219	Response.End
220End Sub
221
222%>
223