1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
<?php /* * FCKeditor - The text editor for Internet - http://www.fckeditor.net * Copyright (C) 2003-2009 Frederico Caldeira Knabben * * == BEGIN LICENSE == * * Licensed under the terms of any of the following licenses at your * choice: * * - GNU General Public License Version 2 or later (the "GPL") * http://www.gnu.org/licenses/gpl.html * * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") * http://www.gnu.org/licenses/lgpl.html * * - Mozilla Public License Version 1.1 or later (the "MPL") * http://www.mozilla.org/MPL/MPL-1.1.html * * == END LICENSE == * * This is the File Manager Connector for PHP. */ function CombinePaths( $sBasePath, $sFolder ) { return RemoveFromEnd( $sBasePath, '/' ) . '/' . RemoveFromStart( $sFolder, '/' ) ; } function GetResourceTypePath( $resourceType, $sCommand ) { global $Config ;
if ( $sCommand == "QuickUpload") return $Config['QuickUploadPath'][$resourceType] ; else return $Config['FileTypesPath'][$resourceType] ; }
function GetResourceTypeDirectory( $resourceType, $sCommand ) { global $Config ; if ( $sCommand == "QuickUpload") { if ( strlen( $Config['QuickUploadAbsolutePath'][$resourceType] ) > 0 ) return $Config['QuickUploadAbsolutePath'][$resourceType] ;
// Map the "UserFiles" path to a local directory. return Server_MapPath( $Config['QuickUploadPath'][$resourceType] ) ; } else { if ( strlen( $Config['FileTypesAbsolutePath'][$resourceType] ) > 0 ) return $Config['FileTypesAbsolutePath'][$resourceType] ;
// Map the "UserFiles" path to a local directory. return Server_MapPath( $Config['FileTypesPath'][$resourceType] ) ; } }
function GetUrlFromPath( $resourceType, $folderPath, $sCommand ) { return CombinePaths( GetResourceTypePath( $resourceType, $sCommand ), $folderPath ) ; }
function RemoveExtension( $fileName ) { return substr( $fileName, 0, strrpos( $fileName, '.' ) ) ; }
function ServerMapFolder( $resourceType, $folderPath, $sCommand ) { // Get the resource type directory. $sResourceTypePath = GetResourceTypeDirectory( $resourceType, $sCommand ) ;
// Ensure that the directory exists. $sErrorMsg = CreateServerFolder( $sResourceTypePath ) ; if ( $sErrorMsg != '' ) SendError( 1, "Error creating folder \"{$sResourceTypePath}\" ({$sErrorMsg})" ) ;
// Return the resource type directory combined with the required path. return CombinePaths( $sResourceTypePath , $folderPath ) ; }
function GetParentFolder( $folderPath ) { $sPattern = "-[/\\\\][^/\\\\]+[/\\\\]?$-" ; return preg_replace( $sPattern, '', $folderPath ) ; }
function CreateServerFolder( $folderPath, $lastFolder = null ) { global $Config ; $sParent = GetParentFolder( $folderPath ) ;
// Ensure the folder path has no double-slashes, or mkdir may fail on certain platforms while ( strpos($folderPath, '//') !== false ) { $folderPath = str_replace( '//', '/', $folderPath ) ; }
// Check if the parent exists, or create it. if ( !file_exists( $sParent ) ) { //prevents agains infinite loop when we can't create root folder if ( !is_null( $lastFolder ) && $lastFolder === $sParent) { return "Can't create $folderPath directory" ; }
$sErrorMsg = CreateServerFolder( $sParent, $folderPath ) ; if ( $sErrorMsg != '' ) return $sErrorMsg ; }
if ( !file_exists( $folderPath ) ) { // Turn off all error reporting. error_reporting( 0 ) ;
$php_errormsg = '' ; // Enable error tracking to catch the error. ini_set( 'track_errors', '1' ) ;
if ( isset( $Config['ChmodOnFolderCreate'] ) && !$Config['ChmodOnFolderCreate'] ) { mkdir( $folderPath ) ; } else { $permissions = 0777 ; if ( isset( $Config['ChmodOnFolderCreate'] ) ) { $permissions = $Config['ChmodOnFolderCreate'] ; } // To create the folder with 0777 permissions, we need to set umask to zero. $oldumask = umask(0) ; mkdir( $folderPath, $permissions ) ; umask( $oldumask ) ; }
$sErrorMsg = $php_errormsg ;
// Restore the configurations. ini_restore( 'track_errors' ) ; ini_restore( 'error_reporting' ) ;
return $sErrorMsg ; } else return '' ; }
function GetRootPath() { if (!isset($_SERVER)) { global $_SERVER; } $sRealPath = realpath( './' ) ; // #2124 ensure that no slash is at the end $sRealPath = rtrim($sRealPath,"\\/");
$sSelfPath = $_SERVER['PHP_SELF'] ; $sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '/' ) ) ;
$sSelfPath = str_replace( '/', DIRECTORY_SEPARATOR, $sSelfPath ) ;
$position = strpos( $sRealPath, $sSelfPath ) ;
// This can check only that this script isn't run from a virtual dir // But it avoids the problems that arise if it isn't checked if ( $position === false || $position <> strlen( $sRealPath ) - strlen( $sSelfPath ) ) SendError( 1, 'Sorry, can\'t map "UserFilesPath" to a physical path. You must set the "UserFilesAbsolutePath" value in "editor/filemanager/connectors/php/config.php".' ) ;
return substr( $sRealPath, 0, $position ) ; }
// Emulate the asp Server.mapPath function. // given an url path return the physical directory that it corresponds to function Server_MapPath( $path ) { // This function is available only for Apache if ( function_exists( 'apache_lookup_uri' ) ) { $info = apache_lookup_uri( $path ) ; return $info->filename . $info->path_info ; }
// This isn't correct but for the moment there's no other solution // If this script is under a virtual directory or symlink it will detect the problem and stop return GetRootPath() . $path ; }
function IsAllowedExt( $sExtension, $resourceType ) { global $Config ; // Get the allowed and denied extensions arrays. $arAllowed = $Config['AllowedExtensions'][$resourceType] ; $arDenied = $Config['DeniedExtensions'][$resourceType] ;
if ( count($arAllowed) > 0 && !in_array( $sExtension, $arAllowed ) ) return false ;
if ( count($arDenied) > 0 && in_array( $sExtension, $arDenied ) ) return false ;
return true ; }
function IsAllowedType( $resourceType ) { global $Config ; if ( !in_array( $resourceType, $Config['ConfigAllowedTypes'] ) ) return false ;
return true ; }
function IsAllowedCommand( $sCommand ) { global $Config ;
if ( !in_array( $sCommand, $Config['ConfigAllowedCommands'] ) ) return false ;
return true ; }
function GetCurrentFolder() { if (!isset($_GET)) { global $_GET; } $sCurrentFolder = isset( $_GET['CurrentFolder'] ) ? $_GET['CurrentFolder'] : '/' ;
// Check the current folder syntax (must begin and start with a slash). if ( !preg_match( '|/$|', $sCurrentFolder ) ) $sCurrentFolder .= '/' ; if ( strpos( $sCurrentFolder, '/' ) !== 0 ) $sCurrentFolder = '/' . $sCurrentFolder ;
// Ensure the folder path has no double-slashes while ( strpos ($sCurrentFolder, '//') !== false ) { $sCurrentFolder = str_replace ('//', '/', $sCurrentFolder) ; }
// Check for invalid folder paths (..) if ( strpos( $sCurrentFolder, '..' ) || strpos( $sCurrentFolder, "\\" )) SendError( 102, '' ) ;
return $sCurrentFolder ; }
// Do a cleanup of the folder name to avoid possible problems function SanitizeFolderName( $sNewFolderName ) { $sNewFolderName = stripslashes( $sNewFolderName ) ;
// Remove . \ / | : ? * " < > $sNewFolderName = preg_replace( '/\\.|\\\\|\\/|\\||\\:|\\?|\\*|"|<|>|[[:cntrl:]]/', '_', $sNewFolderName ) ;
return $sNewFolderName ; }
// Do a cleanup of the file name to avoid possible problems function SanitizeFileName( $sNewFileName ) { global $Config ;
$sNewFileName = stripslashes( $sNewFileName ) ;
// Replace dots in the name with underscores (only one dot can be there... security issue). if ( $Config['ForceSingleExtension'] ) $sNewFileName = preg_replace( '/\\.(?![^.]*$)/', '_', $sNewFileName ) ;
// Remove \ / | : ? * " < > $sNewFileName = preg_replace( '/\\\\|\\/|\\||\\:|\\?|\\*|"|<|>|[[:cntrl:]]/', '_', $sNewFileName ) ;
return $sNewFileName ; }
// This is the function that sends the results of the uploading process. function SendUploadResults( $errorNumber, $fileUrl = '', $fileName = '', $customMsg = '' ) { // Minified version of the document.domain automatic fix script (#1919). // The original script can be found at _dev/domain_fix_template.js echo <<<EOF <script type="text/javascript"> (function(){var d=document.domain;while (true){try{var A=window.parent.document.domain;break;}catch(e) {};d=d.replace(/.*?(?:\.|$)/,'');if (d.length==0) break;try{document.domain=d;}catch (e){break;}}})(); EOF;
$rpl = array( '\\' => '\\\\', '"' => '\\"' ) ; echo 'window.parent.OnUploadCompleted(' . $errorNumber . ',"' . strtr( $fileUrl, $rpl ) . '","' . strtr( $fileName, $rpl ) . '", "' . strtr( $customMsg, $rpl ) . '") ;' ; echo '</script>' ; exit ; }
?>
|