2
# FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
# Copyright (C) 2003-2009 Frederico Caldeira Knabben
7
# Licensed under the terms of any of the following licenses at your
10
# - GNU General Public License Version 2 or later (the "GPL")
11
# http://www.gnu.org/licenses/gpl.html
13
# - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
# http://www.gnu.org/licenses/lgpl.html
16
# - Mozilla Public License Version 1.1 or later (the "MPL")
17
# http://www.mozilla.org/MPL/MPL-1.1.html
21
# This is the File Manager Connector for Perl.
27
local($resourceType, $currentFolder) = @_;
29
# Map the virtual path to the local server path.
30
$sServerDir = &ServerMapFolder($resourceType, $currentFolder);
31
print "<Folders>"; # Open the "Folders" node.
33
opendir(DIR,"$sServerDir");
34
@files = grep(!/^\.\.?$/,readdir(DIR));
37
foreach $sFile (@files) {
38
if($sFile != '.' && $sFile != '..' && (-d "$sServerDir$sFile")) {
39
$cnv_filename = &ConvertToXmlAttribute($sFile);
40
print '<Folder name="' . $cnv_filename . '" />';
43
print "</Folders>"; # Close the "Folders" node.
46
sub GetFoldersAndFiles
49
local($resourceType, $currentFolder) = @_;
50
# Map the virtual path to the local server path.
51
$sServerDir = &ServerMapFolder($resourceType,$currentFolder);
53
# Initialize the output buffers for "Folders" and "Files".
54
$sFolders = '<Folders>';
57
opendir(DIR,"$sServerDir");
58
@files = grep(!/^\.\.?$/,readdir(DIR));
61
foreach $sFile (@files) {
62
if($sFile ne '.' && $sFile ne '..') {
63
if(-d "$sServerDir$sFile") {
64
$cnv_filename = &ConvertToXmlAttribute($sFile);
65
$sFolders .= '<Folder name="' . $cnv_filename . '" />' ;
67
($iFileSize,$refdate,$filedate,$fileperm) = (stat("$sServerDir$sFile"))[7,8,9,2];
69
$iFileSize = int($iFileSize / 1024);
74
$cnv_filename = &ConvertToXmlAttribute($sFile);
75
$sFiles .= '<File name="' . $cnv_filename . '" size="' . $iFileSize . '" />' ;
80
print '</Folders>'; # Close the "Folders" node.
82
print '</Files>'; # Close the "Files" node.
88
local($resourceType, $currentFolder) = @_;
92
if($FORM{'NewFolderName'} ne "") {
93
$sNewFolderName = $FORM{'NewFolderName'};
94
$sNewFolderName =~ s/\.|\\|\/|\||\:|\?|\*|\"|<|>|[[:cntrl:]]/_/g;
95
# Map the virtual path to the local server path of the current folder.
96
$sServerDir = &ServerMapFolder($resourceType, $currentFolder);
98
$sServerDir .= $sNewFolderName;
99
$sErrorMsg = &CreateServerFolder($sServerDir);
100
if($sErrorMsg == 0) {
102
} elsif($sErrorMsg eq 'Invalid argument' || $sErrorMsg eq 'No such file or directory') {
103
$sErrorNumber = '102'; #// Path too long.
105
$sErrorNumber = '110';
108
$sErrorNumber = '103';
111
$sErrorNumber = '102' ;
113
# Create the "Error" node.
114
$cnv_errmsg = &ConvertToXmlAttribute($sErrorMsg);
115
print '<Error number="' . $sErrorNumber . '" />';
120
eval("use File::Copy;");
122
local($resourceType, $currentFolder) = @_;
123
$allowedExtensions = $allowedExtensions{$resourceType};
125
$sErrorNumber = '0' ;
128
# Map the virtual path to the local server path.
129
$sServerDir = &ServerMapFolder($resourceType,$currentFolder);
131
# Get the uploaded file name.
132
$sFileName = $new_fname;
133
$sFileName =~ s/\\|\/|\||\:|\?|\*|\"|<|>|[[:cntrl:]]/_/g;
134
$sFileName =~ s/\.(?![^.]*$)/_/g;
137
if($sFileName =~ /([^\\\/]*)\.(.*)$/) {
141
$allowedRegex = qr/^($allowedExtensions)$/i;
142
if (!($ext =~ $allowedRegex)) {
143
SendUploadResults('202', '', '', '');
146
$sOriginalFileName = $sFileName;
150
$sFilePath = $sServerDir . $sFileName;
153
($path,$BaseName,$ext) = &RemoveExtension($sOriginalFileName);
154
$sFileName = $BaseName . '(' . $iCounter . ').' . $ext;
155
$sErrorNumber = '201';
157
copy("$img_dir/$new_fname","$sFilePath");
158
if (defined $CHMOD_ON_UPLOAD) {
159
if ($CHMOD_ON_UPLOAD) {
161
chmod($CHMOD_ON_UPLOAD,$sFilePath);
166
chmod(0777,$sFilePath);
168
unlink("$img_dir/$new_fname");
173
$sErrorNumber = '202' ;
175
$sFileName =~ s/"/\\"/g;
177
SendUploadResults($sErrorNumber, $GLOBALS{'UserFilesPath'}.$resourceType.$currentFolder.$sFileName, $sFileName, '');
180
sub SendUploadResults
183
local($sErrorNumber, $sFileUrl, $sFileName, $customMsg) = @_;
185
# Minified version of the document.domain automatic fix script (#1919).
186
# The original script can be found at _dev/domain_fix_template.js
187
# Note: in Perl replace \ with \\ and $ with \$
189
Content-type: text/html
191
<script type="text/javascript">
192
(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;}}})();
195
print 'window.parent.OnUploadCompleted(' . $sErrorNumber . ',"' . JS_cnv($sFileUrl) . '","' . JS_cnv($sFileName) . '","' . JS_cnv($customMsg) . '") ;';
2
# FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
# Copyright (C) 2003-2010 Frederico Caldeira Knabben
7
# Licensed under the terms of any of the following licenses at your
10
# - GNU General Public License Version 2 or later (the "GPL")
11
# http://www.gnu.org/licenses/gpl.html
13
# - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
# http://www.gnu.org/licenses/lgpl.html
16
# - Mozilla Public License Version 1.1 or later (the "MPL")
17
# http://www.mozilla.org/MPL/MPL-1.1.html
21
# This is the File Manager Connector for Perl.
27
local($resourceType, $currentFolder) = @_;
29
# Map the virtual path to the local server path.
30
$sServerDir = &ServerMapFolder($resourceType, $currentFolder);
31
print "<Folders>"; # Open the "Folders" node.
33
opendir(DIR,"$sServerDir");
34
@files = grep(!/^\.\.?$/,readdir(DIR));
37
foreach $sFile (@files) {
38
if($sFile != '.' && $sFile != '..' && (-d "$sServerDir$sFile")) {
39
$cnv_filename = &ConvertToXmlAttribute($sFile);
40
print '<Folder name="' . $cnv_filename . '" />';
43
print "</Folders>"; # Close the "Folders" node.
46
sub GetFoldersAndFiles
49
local($resourceType, $currentFolder) = @_;
50
# Map the virtual path to the local server path.
51
$sServerDir = &ServerMapFolder($resourceType,$currentFolder);
53
# Initialize the output buffers for "Folders" and "Files".
54
$sFolders = '<Folders>';
57
opendir(DIR,"$sServerDir");
58
@files = grep(!/^\.\.?$/,readdir(DIR));
61
foreach $sFile (@files) {
62
if($sFile ne '.' && $sFile ne '..') {
63
if(-d "$sServerDir$sFile") {
64
$cnv_filename = &ConvertToXmlAttribute($sFile);
65
$sFolders .= '<Folder name="' . $cnv_filename . '" />' ;
67
($iFileSize,$refdate,$filedate,$fileperm) = (stat("$sServerDir$sFile"))[7,8,9,2];
69
$iFileSize = int($iFileSize / 1024);
74
$cnv_filename = &ConvertToXmlAttribute($sFile);
75
$sFiles .= '<File name="' . $cnv_filename . '" size="' . $iFileSize . '" />' ;
80
print '</Folders>'; # Close the "Folders" node.
82
print '</Files>'; # Close the "Files" node.
88
local($resourceType, $currentFolder) = @_;
92
if($FORM{'NewFolderName'} ne "") {
93
$sNewFolderName = $FORM{'NewFolderName'};
94
$sNewFolderName =~ s/\.|\\|\/|\||\:|\?|\*|\"|<|>|[[:cntrl:]]/_/g;
95
# Map the virtual path to the local server path of the current folder.
96
$sServerDir = &ServerMapFolder($resourceType, $currentFolder);
98
$sServerDir .= $sNewFolderName;
99
$sErrorMsg = &CreateServerFolder($sServerDir);
100
if($sErrorMsg == 0) {
102
} elsif($sErrorMsg eq 'Invalid argument' || $sErrorMsg eq 'No such file or directory') {
103
$sErrorNumber = '102'; #// Path too long.
105
$sErrorNumber = '110';
108
$sErrorNumber = '103';
111
$sErrorNumber = '102' ;
113
# Create the "Error" node.
114
$cnv_errmsg = &ConvertToXmlAttribute($sErrorMsg);
115
print '<Error number="' . $sErrorNumber . '" />';
120
eval("use File::Copy;");
122
local($resourceType, $currentFolder) = @_;
123
$allowedExtensions = $allowedExtensions{$resourceType};
125
$sErrorNumber = '0' ;
128
# Map the virtual path to the local server path.
129
$sServerDir = &ServerMapFolder($resourceType,$currentFolder);
131
# Get the uploaded file name.
132
$sFileName = $new_fname;
133
$sFileName =~ s/\\|\/|\||\:|\?|\*|\"|<|>|[[:cntrl:]]/_/g;
134
$sFileName =~ s/\.(?![^.]*$)/_/g;
137
if($sFileName =~ /([^\\\/]*)\.(.*)$/) {
141
$allowedRegex = qr/^($allowedExtensions)$/i;
142
if (!($ext =~ $allowedRegex)) {
143
SendUploadResults('202', '', '', '');
146
$sOriginalFileName = $sFileName;
150
$sFilePath = $sServerDir . $sFileName;
153
($path,$BaseName,$ext) = &RemoveExtension($sOriginalFileName);
154
$sFileName = $BaseName . '(' . $iCounter . ').' . $ext;
155
$sErrorNumber = '201';
157
copy("$img_dir/$new_fname","$sFilePath");
158
if (defined $CHMOD_ON_UPLOAD) {
159
if ($CHMOD_ON_UPLOAD) {
161
chmod($CHMOD_ON_UPLOAD,$sFilePath);
166
chmod(0777,$sFilePath);
168
unlink("$img_dir/$new_fname");
173
$sErrorNumber = '202' ;
175
$sFileName =~ s/"/\\"/g;
177
SendUploadResults($sErrorNumber, $GLOBALS{'UserFilesPath'}.$resourceType.$currentFolder.$sFileName, $sFileName, '');
180
sub SendUploadResults
183
local($sErrorNumber, $sFileUrl, $sFileName, $customMsg) = @_;
185
# Minified version of the document.domain automatic fix script (#1919).
186
# The original script can be found at _dev/domain_fix_template.js
187
# Note: in Perl replace \ with \\ and $ with \$
189
Content-type: text/html
191
<script type="text/javascript">
192
(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;}}})();
195
print 'window.parent.OnUploadCompleted(' . $sErrorNumber . ',"' . JS_cnv($sFileUrl) . '","' . JS_cnv($sFileName) . '","' . JS_cnv($customMsg) . '") ;';