1 | #!/usr/bin/env perl
|
---|
2 |
|
---|
3 | #####
|
---|
4 | # FCKeditor - The text editor for Internet - http://www.fckeditor.net
|
---|
5 | # Copyright (C) 2003-2009 Frederico Caldeira Knabben
|
---|
6 | #
|
---|
7 | # == BEGIN LICENSE ==
|
---|
8 | #
|
---|
9 | # Licensed under the terms of any of the following licenses at your
|
---|
10 | # choice:
|
---|
11 | #
|
---|
12 | # - GNU General Public License Version 2 or later (the "GPL")
|
---|
13 | # http://www.gnu.org/licenses/gpl.html
|
---|
14 | #
|
---|
15 | # - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
|
---|
16 | # http://www.gnu.org/licenses/lgpl.html
|
---|
17 | #
|
---|
18 | # - Mozilla Public License Version 1.1 or later (the "MPL")
|
---|
19 | # http://www.mozilla.org/MPL/MPL-1.1.html
|
---|
20 | #
|
---|
21 | # == END LICENSE ==
|
---|
22 | #
|
---|
23 | # This is the File Manager Connector for Perl.
|
---|
24 | #####
|
---|
25 |
|
---|
26 | ##
|
---|
27 | # ATTENTION: To enable this connector, look for the "SECURITY" comment in config.pl.
|
---|
28 | ##
|
---|
29 |
|
---|
30 | ## START: Hack for Windows (Not important to understand the editor code... Perl specific).
|
---|
31 | if(Windows_check()) {
|
---|
32 | chdir(GetScriptPath($0));
|
---|
33 | }
|
---|
34 |
|
---|
35 | sub Windows_check
|
---|
36 | {
|
---|
37 | # IIS,PWS(NT/95)
|
---|
38 | $www_server_os = $^O;
|
---|
39 | # Win98 & NT(SP4)
|
---|
40 | if($www_server_os eq "") { $www_server_os= $ENV{'OS'}; }
|
---|
41 | # AnHTTPd/Omni/IIS
|
---|
42 | if($ENV{'SERVER_SOFTWARE'} =~ /AnWeb|Omni|IIS\//i) { $www_server_os= 'win'; }
|
---|
43 | # Win Apache
|
---|
44 | if($ENV{'WINDIR'} ne "") { $www_server_os= 'win'; }
|
---|
45 | if($www_server_os=~ /win/i) { return(1); }
|
---|
46 | return(0);
|
---|
47 | }
|
---|
48 |
|
---|
49 | sub GetScriptPath {
|
---|
50 | local($path) = @_;
|
---|
51 | if($path =~ /[\:\/\\]/) { $path =~ s/(.*?)[\/\\][^\/\\]+$/$1/; } else { $path = '.'; }
|
---|
52 | $path;
|
---|
53 | }
|
---|
54 | ## END: Hack for IIS
|
---|
55 |
|
---|
56 | require 'util.pl';
|
---|
57 | require 'io.pl';
|
---|
58 | require 'basexml.pl';
|
---|
59 | require 'commands.pl';
|
---|
60 | require 'upload_fck.pl';
|
---|
61 | require 'config.pl';
|
---|
62 |
|
---|
63 | &read_input();
|
---|
64 | &DoResponse();
|
---|
65 |
|
---|
66 | sub DoResponse
|
---|
67 | {
|
---|
68 |
|
---|
69 | if($FORM{'Command'} eq "" || $FORM{'Type'} eq "" || $FORM{'CurrentFolder'} eq "") {
|
---|
70 | return ;
|
---|
71 | }
|
---|
72 | # Get the main request informaiton.
|
---|
73 | $sCommand = &specialchar_cnv($FORM{'Command'});
|
---|
74 | $sResourceType = &specialchar_cnv($FORM{'Type'});
|
---|
75 | $sCurrentFolder = $FORM{'CurrentFolder'};
|
---|
76 |
|
---|
77 | if ( !($sCommand =~ /^(FileUpload|GetFolders|GetFoldersAndFiles|CreateFolder)$/) ) {
|
---|
78 | SendError( 1, "Command not allowed" ) ;
|
---|
79 | }
|
---|
80 |
|
---|
81 | if ( !($sResourceType =~ /^(File|Image|Flash|Media)$/) ) {
|
---|
82 | SendError( 1, "Invalid type specified" ) ;
|
---|
83 | }
|
---|
84 |
|
---|
85 | # Check the current folder syntax (must begin and start with a slash).
|
---|
86 | if(!($sCurrentFolder =~ /\/$/)) {
|
---|
87 | $sCurrentFolder .= '/';
|
---|
88 | }
|
---|
89 | if(!($sCurrentFolder =~ /^\//)) {
|
---|
90 | $sCurrentFolder = '/' . $sCurrentFolder;
|
---|
91 | }
|
---|
92 |
|
---|
93 | # Check for invalid folder paths (..)
|
---|
94 | if ( $sCurrentFolder =~ /(?:\.\.|\\)/ ) {
|
---|
95 | SendError( 102, "" ) ;
|
---|
96 | }
|
---|
97 | if ( $sCurrentFolder =~ /(\/\.)|[[:cntrl:]]|(\/\/)|(\\\\)|([\:\*\?\"\<\>\|])/ ) {
|
---|
98 | SendError( 102, "" ) ;
|
---|
99 | }
|
---|
100 |
|
---|
101 | # File Upload doesn't have to Return XML, so it must be intercepted before anything.
|
---|
102 | if($sCommand eq 'FileUpload') {
|
---|
103 | FileUpload($sResourceType,$sCurrentFolder);
|
---|
104 | return ;
|
---|
105 | }
|
---|
106 |
|
---|
107 | print << "_HTML_HEAD_";
|
---|
108 | Content-Type:text/xml; charset=utf-8
|
---|
109 | Pragma: no-cache
|
---|
110 | Cache-Control: no-cache
|
---|
111 | Expires: Thu, 01 Dec 1994 16:00:00 GMT
|
---|
112 |
|
---|
113 | _HTML_HEAD_
|
---|
114 |
|
---|
115 | &CreateXmlHeader($sCommand,$sResourceType,$sCurrentFolder);
|
---|
116 |
|
---|
117 | # Execute the required command.
|
---|
118 | if($sCommand eq 'GetFolders') {
|
---|
119 | &GetFolders($sResourceType,$sCurrentFolder);
|
---|
120 | } elsif($sCommand eq 'GetFoldersAndFiles') {
|
---|
121 | &GetFoldersAndFiles($sResourceType,$sCurrentFolder);
|
---|
122 | } elsif($sCommand eq 'CreateFolder') {
|
---|
123 | &CreateFolder($sResourceType,$sCurrentFolder);
|
---|
124 | }
|
---|
125 |
|
---|
126 | &CreateXmlFooter();
|
---|
127 |
|
---|
128 | exit ;
|
---|
129 | }
|
---|