3
* FCKeditor - The text editor for internet
4
* Copyright (C) 2003-2005 Frederico Caldeira Knabben
6
* Licensed under the terms of the GNU Lesser General Public License:
7
* http://www.opensource.org/licenses/lgpl-license.php
9
* For further information visit:
10
* http://www.fckeditor.net/
12
* "Support Open Source software. What about a donation today?"
14
* File Name: connector.php
15
* Main connector file, implements the State Pattern to
16
* redirect requests to the appropriate class based on
17
* the command name passed.
20
* Grant French (grant@mcpuk.net)
22
//Errors in the config.php could still cause problems.
23
global $fckphp_config;
24
require_once "config.php";
26
error_reporting(E_ALL);
27
function errorHandler ($errno, $errstr, $errfile, $errline, $errcontext) {
29
if (strpos($errstr,"var: Deprecated.")===false) {
30
global $fckphp_config;
31
if ($fckphp_config['Debug']===true && $fckphp_config['Debug_Errors']===true) {
32
$oldData=implode("",file($fckphp_config['DebugOutput']));
33
if ($fh=fopen($fckphp_config['DebugOutput'],"w")) {
34
fwrite($fh,"\n".date("d/m/Y H:i:s")."\n");
35
fwrite($fh,"PHP ERROR:::
37
Error Message: $errstr
39
Error Line: $errline\n");
40
if ($fckphp_config['Debug_Trace']) fwrite($fh," Error Context: ".print_r($errcontext,true)."\n");
41
if ($fckphp_config['Debug_GET']) fwrite($fh,"\n\$_GET::\n".print_r($_GET,true)."\n");
42
if ($fckphp_config['Debug_POST']) fwrite($fh,"\n\$_POST::\n".print_r($_POST,true)."\n");
43
if ($fckphp_config['Debug_SERVER']) fwrite($fh,"\n\$_SERVER::\n".print_r($_SERVER,true)."\n");
44
if ($fckphp_config['Debug_SESSIONS']) fwrite($fh,"\n\$_SESSIONS::\n".print_r($_SESSION,true)."\n");
45
fwrite($fh,"\n-------------------------------------------------------\n\n\n");
46
fwrite($fh,$oldData); $oldData="";
53
//display error instead.
54
echo("PHP ERROR::: <br />
55
Error Number: $errno <br />
56
Error Message: $errstr <br />
57
Error File: $errfile <br />
58
Error Line: $errline <br />");
60
if ($fckphp_config['Debug_Trace']) echo "Error Context: ".print_r($errcontext,true)."\n";
61
if ($fckphp_config['Debug_GET']) echo "\$_GET::\n".print_r($_GET,true)."<br />\n";
62
if ($fckphp_config['Debug_POST']) echo "\$_POST::\n".print_r($_POST,true)."<br />\n";
63
if ($fckphp_config['Debug_SERVER']) echo "\$_SERVER::\n".print_r($_SERVER,true)."<br />\n";
64
if ($fckphp_config['Debug_SESSIONS']) echo "\$_SESSIONS::\n".print_r($_SESSION,true)."<br />\n";
65
echo "<br />\n<br />\n";
69
set_error_handler('errorHandler');
71
if (!isset($_SERVER['DOCUMENT_ROOT'])) $_SERVER["DOCUMENT_ROOT"] = $fckphp_config['basedir'];
73
if ($fckphp_config['Debug']===true && $fckphp_config['Debug_Output']) ob_start();
76
//These are the commands we may expect
77
$valid_commands=$fckphp_config['Commands'];
78
$valid_resource_types=$fckphp_config['ResourceTypes'];
82
((isset($_GET['Command']))&&($_GET['Command']!=""))?
88
((isset($_GET['Type']))&&($_GET['Type']!=""))?
93
$cwd=str_replace("..","",
95
((isset($_GET['CurrentFolder']))&&($_GET['CurrentFolder']!=""))?
96
$_GET['CurrentFolder']:
101
$cwd=str_replace("..","",$cwd);
104
((isset($_GET['ExtraParams']))&&($_GET['ExtraParams']!=""))?
105
$_GET['ExtraParams']:
109
if (in_array($command,$valid_commands)) {
111
if ($fckphp_config['auth']['Req']) {
112
require_once "./Auth/".$fckphp_config['auth']['HandlerClass'].".php";
115
$fckphp_config=$auth->authenticate($extra,$fckphp_config);
116
if ($fckphp_config['authSuccess']!==true) {
117
header ("content-type: text/xml");
118
echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
120
<Connector command="authentication_failed" resourceType="authentication_failed">
121
<CurrentFolder path="authentication_failed" url="authentication_failed" />
122
<Error number="-1" />
124
if ($fckphp_config['Debug']===true && $fckphp_config['Debug_Output']) recordOutput();
130
if (!in_array($type,$valid_resource_types)) {
131
echo "Invalid resource type.";
132
if ($fckphp_config['Debug']===true && $fckphp_config['Debug_Output']) recordOutput();
136
require_once "Commands/$command.php";
138
$action=new $command($fckphp_config,$type,$cwd);
141
if ($fckphp_config['Debug']===true && $fckphp_config['Debug_Output']) recordOutput();
144
//No reason for me to be here.
145
echo "Invalid command.";
146
echo str_replace("\n","<br />",print_r($_GET,true));
147
if ($fckphp_config['Debug']===true && $fckphp_config['Debug_Output']) recordOutput();
152
function recordOutput() {
153
global $fckphp_config;
155
if ($fckphp_config['Debug']===true && $fckphp_config['Debug_Output']) {
156
$contents=ob_get_contents();
157
if (strlen($contents)>0) {
158
$oldData=implode("",file($fckphp_config['DebugOutput']));
159
if ($fh=fopen($fckphp_config['DebugOutput'],"w")) {
160
fwrite($fh,"\n".date("d/m/Y H:i:s")."\n");
161
if ($fckphp_config['Debug_GET']) fwrite($fh,"\n\$_GET::\n".print_r($_GET,true)."\n");
162
if ($fckphp_config['Debug_POST']) fwrite($fh,"\n\$_POST::\n".print_r($_POST,true)."\n");
163
if ($fckphp_config['Debug_SERVER']) fwrite($fh,"\n\$_SERVER::\n".print_r($_SERVER,true)."\n");
164
if ($fckphp_config['Debug_SESSIONS']) fwrite($fh,"\n\$_SESSIONS::\n".print_r($_SESSION,true)."\n");
165
fwrite($fh,$contents);
166
fwrite($fh,"\n-------------------------------------------------------\n\n\n");
167
fwrite($fh,$oldData); $oldData="";
175
function outputHeaders() {
177
//Anti browser caching headers
178
//Borrowed from fatboy's implementation (fatFCK@code247.com)
180
// ensure file is never cached
182
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
185
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
188
header("Cache-Control: no-store, no-cache, must-revalidate");
189
header("Cache-Control: post-check=0, pre-check=0", false);
192
header("Pragma: no-cache");