1 | #####
|
---|
2 | # FCKeditor - The text editor for Internet - http://www.fckeditor.net
|
---|
3 | # Copyright (C) 2003-2009 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 is the File Manager Connector for Perl.
|
---|
22 | #####
|
---|
23 |
|
---|
24 | sub GetFolders
|
---|
25 | {
|
---|
26 |
|
---|
27 | local($resourceType, $currentFolder) = @_;
|
---|
28 |
|
---|
29 | # Map the virtual path to the local server path.
|
---|
30 | $sServerDir = &ServerMapFolder($resourceType, $currentFolder);
|
---|
31 | print "<Folders>"; # Open the "Folders" node.
|
---|
32 |
|
---|
33 | opendir(DIR,"$sServerDir");
|
---|
34 | @files = grep(!/^\.\.?$/,readdir(DIR));
|
---|
35 | closedir(DIR);
|
---|
36 |
|
---|
37 | foreach $sFile (@files) {
|
---|
38 | if($sFile != '.' && $sFile != '..' && (-d "$sServerDir$sFile")) {
|
---|
39 | $cnv_filename = &ConvertToXmlAttribute($sFile);
|
---|
40 | print '<Folder name="' . $cnv_filename . '" />';
|
---|
41 | }
|
---|
42 | }
|
---|
43 | print "</Folders>"; # Close the "Folders" node.
|
---|
44 | }
|
---|
45 |
|
---|
46 | sub GetFoldersAndFiles
|
---|
47 | {
|
---|
48 |
|
---|
49 | local($resourceType, $currentFolder) = @_;
|
---|
50 | # Map the virtual path to the local server path.
|
---|
51 | $sServerDir = &ServerMapFolder($resourceType,$currentFolder);
|
---|
52 |
|
---|
53 | # Initialize the output buffers for "Folders" and "Files".
|
---|
54 | $sFolders = '<Folders>';
|
---|
55 | $sFiles = '<Files>';
|
---|
56 |
|
---|
57 | opendir(DIR,"$sServerDir");
|
---|
58 | @files = grep(!/^\.\.?$/,readdir(DIR));
|
---|
59 | closedir(DIR);
|
---|
60 |
|
---|
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 . '" />' ;
|
---|
66 | } else {
|
---|
67 | ($iFileSize,$refdate,$filedate,$fileperm) = (stat("$sServerDir$sFile"))[7,8,9,2];
|
---|
68 | if($iFileSize > 0) {
|
---|
69 | $iFileSize = int($iFileSize / 1024);
|
---|
70 | if($iFileSize < 1) {
|
---|
71 | $iFileSize = 1;
|
---|
72 | }
|
---|
73 | }
|
---|
74 | $cnv_filename = &ConvertToXmlAttribute($sFile);
|
---|
75 | $sFiles .= '<File name="' . $cnv_filename . '" size="' . $iFileSize . '" />' ;
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|
79 | print $sFolders ;
|
---|
80 | print '</Folders>'; # Close the "Folders" node.
|
---|
81 | print $sFiles ;
|
---|
82 | print '</Files>'; # Close the "Files" node.
|
---|
83 | }
|
---|
84 |
|
---|
85 | sub CreateFolder
|
---|
86 | {
|
---|
87 |
|
---|
88 | local($resourceType, $currentFolder) = @_;
|
---|
89 | $sErrorNumber = '0' ;
|
---|
90 | $sErrorMsg = '' ;
|
---|
91 |
|
---|
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);
|
---|
97 | if(-w $sServerDir) {
|
---|
98 | $sServerDir .= $sNewFolderName;
|
---|
99 | $sErrorMsg = &CreateServerFolder($sServerDir);
|
---|
100 | if($sErrorMsg == 0) {
|
---|
101 | $sErrorNumber = '0';
|
---|
102 | } elsif($sErrorMsg eq 'Invalid argument' || $sErrorMsg eq 'No such file or directory') {
|
---|
103 | $sErrorNumber = '102'; #// Path too long.
|
---|
104 | } else {
|
---|
105 | $sErrorNumber = '110';
|
---|
106 | }
|
---|
107 | } else {
|
---|
108 | $sErrorNumber = '103';
|
---|
109 | }
|
---|
110 | } else {
|
---|
111 | $sErrorNumber = '102' ;
|
---|
112 | }
|
---|
113 | # Create the "Error" node.
|
---|
114 | $cnv_errmsg = &ConvertToXmlAttribute($sErrorMsg);
|
---|
115 | print '<Error number="' . $sErrorNumber . '" />';
|
---|
116 | }
|
---|
117 |
|
---|
118 | sub FileUpload
|
---|
119 | {
|
---|
120 | eval("use File::Copy;");
|
---|
121 |
|
---|
122 | local($resourceType, $currentFolder) = @_;
|
---|
123 | $allowedExtensions = $allowedExtensions{$resourceType};
|
---|
124 |
|
---|
125 | $sErrorNumber = '0' ;
|
---|
126 | $sFileName = '' ;
|
---|
127 | if($new_fname) {
|
---|
128 | # Map the virtual path to the local server path.
|
---|
129 | $sServerDir = &ServerMapFolder($resourceType,$currentFolder);
|
---|
130 |
|
---|
131 | # Get the uploaded file name.
|
---|
132 | $sFileName = $new_fname;
|
---|
133 | $sFileName =~ s/\\|\/|\||\:|\?|\*|\"|<|>|[[:cntrl:]]/_/g;
|
---|
134 | $sFileName =~ s/\.(?![^.]*$)/_/g;
|
---|
135 |
|
---|
136 | $ext = '';
|
---|
137 | if($sFileName =~ /([^\\\/]*)\.(.*)$/) {
|
---|
138 | $ext = $2;
|
---|
139 | }
|
---|
140 |
|
---|
141 | $allowedRegex = qr/^($allowedExtensions)$/i;
|
---|
142 | if (!($ext =~ $allowedRegex)) {
|
---|
143 | SendUploadResults('202', '', '', '');
|
---|
144 | }
|
---|
145 |
|
---|
146 | $sOriginalFileName = $sFileName;
|
---|
147 |
|
---|
148 | $iCounter = 0;
|
---|
149 | while(1) {
|
---|
150 | $sFilePath = $sServerDir . $sFileName;
|
---|
151 | if(-e $sFilePath) {
|
---|
152 | $iCounter++ ;
|
---|
153 | ($path,$BaseName,$ext) = &RemoveExtension($sOriginalFileName);
|
---|
154 | $sFileName = $BaseName . '(' . $iCounter . ').' . $ext;
|
---|
155 | $sErrorNumber = '201';
|
---|
156 | } else {
|
---|
157 | copy("$img_dir/$new_fname","$sFilePath");
|
---|
158 | if (defined $CHMOD_ON_UPLOAD) {
|
---|
159 | if ($CHMOD_ON_UPLOAD) {
|
---|
160 | umask(000);
|
---|
161 | chmod($CHMOD_ON_UPLOAD,$sFilePath);
|
---|
162 | }
|
---|
163 | }
|
---|
164 | else {
|
---|
165 | umask(000);
|
---|
166 | chmod(0777,$sFilePath);
|
---|
167 | }
|
---|
168 | unlink("$img_dir/$new_fname");
|
---|
169 | last;
|
---|
170 | }
|
---|
171 | }
|
---|
172 | } else {
|
---|
173 | $sErrorNumber = '202' ;
|
---|
174 | }
|
---|
175 | $sFileName =~ s/"/\\"/g;
|
---|
176 |
|
---|
177 | SendUploadResults($sErrorNumber, $GLOBALS{'UserFilesPath'}.$resourceType.$currentFolder.$sFileName, $sFileName, '');
|
---|
178 | }
|
---|
179 |
|
---|
180 | sub SendUploadResults
|
---|
181 | {
|
---|
182 |
|
---|
183 | local($sErrorNumber, $sFileUrl, $sFileName, $customMsg) = @_;
|
---|
184 |
|
---|
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 \$
|
---|
188 | print <<EOF;
|
---|
189 | Content-type: text/html
|
---|
190 |
|
---|
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;}}})();
|
---|
193 |
|
---|
194 | EOF
|
---|
195 | print 'window.parent.OnUploadCompleted(' . $sErrorNumber . ',"' . JS_cnv($sFileUrl) . '","' . JS_cnv($sFileName) . '","' . JS_cnv($customMsg) . '") ;';
|
---|
196 | print '</script>';
|
---|
197 | exit ;
|
---|
198 | }
|
---|
199 |
|
---|
200 | 1;
|
---|