1 | #!/usr/bin/env perl
|
---|
2 |
|
---|
3 | #####
|
---|
4 | # FCKeditor - The text editor for internet
|
---|
5 | # Copyright (C) 2003-2006 Frederico Caldeira Knabben
|
---|
6 | #
|
---|
7 | # Licensed under the terms of the GNU Lesser General Public License:
|
---|
8 | # http://www.opensource.org/licenses/lgpl-license.php
|
---|
9 | #
|
---|
10 | # For further information visit:
|
---|
11 | # http://www.fckeditor.net/
|
---|
12 | #
|
---|
13 | # "Support Open Source software. What about a donation today?"
|
---|
14 | #
|
---|
15 | # File Name: connector.cgi
|
---|
16 | # This is the File Manager Connector for Perl.
|
---|
17 | #
|
---|
18 | # File Authors:
|
---|
19 | # Takashi Yamaguchi (jack@omakase.net)
|
---|
20 | # Frederico Caldeira Knabben (fredck@fckeditor.net)
|
---|
21 | #####
|
---|
22 |
|
---|
23 | ##
|
---|
24 | # ATTENTION: To enable this connector, look for the "SECURITY" comment in this file.
|
---|
25 | ##
|
---|
26 |
|
---|
27 | ## START: Hack for Windows (Not important to understand the editor code... Perl specific).
|
---|
28 | if(Windows_check()) {
|
---|
29 | chdir(GetScriptPath($0));
|
---|
30 | }
|
---|
31 |
|
---|
32 | sub Windows_check
|
---|
33 | {
|
---|
34 | # IIS,PWS(NT/95)
|
---|
35 | $www_server_os = $^O;
|
---|
36 | # Win98 & NT(SP4)
|
---|
37 | if($www_server_os eq "") { $www_server_os= $ENV{'OS'}; }
|
---|
38 | # AnHTTPd/Omni/IIS
|
---|
39 | if($ENV{'SERVER_SOFTWARE'} =~ /AnWeb|Omni|IIS\//i) { $www_server_os= 'win'; }
|
---|
40 | # Win Apache
|
---|
41 | if($ENV{'WINDIR'} ne "") { $www_server_os= 'win'; }
|
---|
42 | if($www_server_os=~ /win/i) { return(1); }
|
---|
43 | return(0);
|
---|
44 | }
|
---|
45 |
|
---|
46 | sub GetScriptPath {
|
---|
47 | local($path) = @_;
|
---|
48 | if($path =~ /[\:\/\\]/) { $path =~ s/(.*?)[\/\\][^\/\\]+$/$1/; } else { $path = '.'; }
|
---|
49 | $path;
|
---|
50 | }
|
---|
51 | ## END: Hack for IIS
|
---|
52 |
|
---|
53 | require 'util.pl';
|
---|
54 | require 'io.pl';
|
---|
55 | require 'basexml.pl';
|
---|
56 | require 'commands.pl';
|
---|
57 | require 'upload_fck.pl';
|
---|
58 |
|
---|
59 | ##
|
---|
60 | # SECURITY: REMOVE/COMMENT THE FOLLOWING LINE TO ENABLE THIS CONNECTOR.
|
---|
61 | ##
|
---|
62 | &SendError( 1, 'This connector is disabled. Please check the "editor/filemanager/browser/default/connectors/perl/connector.cgi" file' ) ;
|
---|
63 |
|
---|
64 | &read_input();
|
---|
65 |
|
---|
66 | if($FORM{'ServerPath'} ne "") {
|
---|
67 | $GLOBALS{'UserFilesPath'} = $FORM{'ServerPath'};
|
---|
68 | if(!($GLOBALS{'UserFilesPath'} =~ /\/$/)) {
|
---|
69 | $GLOBALS{'UserFilesPath'} .= '/' ;
|
---|
70 | }
|
---|
71 | } else {
|
---|
72 | $GLOBALS{'UserFilesPath'} = '/UserFiles/';
|
---|
73 | }
|
---|
74 |
|
---|
75 | # Map the "UserFiles" path to a local directory.
|
---|
76 | $rootpath = &GetRootPath();
|
---|
77 | $GLOBALS{'UserFilesDirectory'} = $rootpath . $GLOBALS{'UserFilesPath'};
|
---|
78 |
|
---|
79 | &DoResponse();
|
---|
80 |
|
---|
81 | sub DoResponse
|
---|
82 | {
|
---|
83 |
|
---|
84 | if($FORM{'Command'} eq "" || $FORM{'Type'} eq "" || $FORM{'CurrentFolder'} eq "") {
|
---|
85 | return ;
|
---|
86 | }
|
---|
87 | # Get the main request informaiton.
|
---|
88 | $sCommand = $FORM{'Command'};
|
---|
89 | $sResourceType = $FORM{'Type'};
|
---|
90 | $sCurrentFolder = $FORM{'CurrentFolder'};
|
---|
91 |
|
---|
92 | # Check the current folder syntax (must begin and start with a slash).
|
---|
93 | if(!($sCurrentFolder =~ /\/$/)) {
|
---|
94 | $sCurrentFolder .= '/';
|
---|
95 | }
|
---|
96 | if(!($sCurrentFolder =~ /^\//)) {
|
---|
97 | $sCurrentFolder = '/' . $sCurrentFolder;
|
---|
98 | }
|
---|
99 |
|
---|
100 | # Check for invalid folder paths (..)
|
---|
101 | if ( $sCurrentFolder =~ /\.\./ ) {
|
---|
102 | SendError( 102, "" ) ;
|
---|
103 | }
|
---|
104 |
|
---|
105 | # File Upload doesn't have to Return XML, so it must be intercepted before anything.
|
---|
106 | if($sCommand eq 'FileUpload') {
|
---|
107 | FileUpload($sResourceType,$sCurrentFolder);
|
---|
108 | return ;
|
---|
109 | }
|
---|
110 |
|
---|
111 | print << "_HTML_HEAD_";
|
---|
112 | Content-Type:text/xml; charset=utf-8
|
---|
113 | Pragma: no-cache
|
---|
114 | Cache-Control: no-cache
|
---|
115 | Expires: Thu, 01 Dec 1994 16:00:00 GMT
|
---|
116 |
|
---|
117 | _HTML_HEAD_
|
---|
118 |
|
---|
119 | &CreateXmlHeader($sCommand,$sResourceType,$sCurrentFolder);
|
---|
120 |
|
---|
121 | # Execute the required command.
|
---|
122 | if($sCommand eq 'GetFolders') {
|
---|
123 | &GetFolders($sResourceType,$sCurrentFolder);
|
---|
124 | } elsif($sCommand eq 'GetFoldersAndFiles') {
|
---|
125 | &GetFoldersAndFiles($sResourceType,$sCurrentFolder);
|
---|
126 | } elsif($sCommand eq 'CreateFolder') {
|
---|
127 | &CreateFolder($sResourceType,$sCurrentFolder);
|
---|
128 | }
|
---|
129 |
|
---|
130 | &CreateXmlFooter();
|
---|
131 |
|
---|
132 | exit ;
|
---|
133 | }
|
---|
134 |
|
---|