Source for file connector.php

Documentation is available at connector.php

  1. <?php /*
  2.  * FCKeditor - The text editor for internet
  3.  * Copyright (C) 2003-2005 Frederico Caldeira Knabben
  4.  * 
  5.  * Licensed under the terms of the GNU Lesser General Public License:
  6.  *         http://www.opensource.org/licenses/lgpl-license.php
  7.  * 
  8.  * For further information visit:
  9.  *         http://www.fckeditor.net/
  10.  * 
  11.  * File Name: connector.php
  12.  *     Main connector file, implements the State Pattern to 
  13.  *     redirect requests to the appropriate class based on 
  14.  *     the command name passed.
  15.  * 
  16.  * File Authors:
  17.  *         Grant French (grant@mcpuk.net)
  18.  */
  19. //Errors in the config.php could still cause problems.
  20. global $fckphp_config;
  21. require_once "config.php";
  22.  
  23. function errorHandler ($errno$errstr$errfile$errline$errcontext{
  24.     $reported=false;
  25.     if (strpos($errstr,"var: Deprecated.")===false{
  26.         global $fckphp_config;
  27.         if ($fckphp_config['Debug']===true && $fckphp_config['Debug_Errors']===true{
  28.             $oldData=implode("",file($fckphp_config['DebugOutput']));
  29.             if ($fh=fopen($fckphp_config['DebugOutput'],"w")) {
  30.                 fwrite($fh,"\n".date("d/m/Y H:i:s")."\n");
  31.                 fwrite($fh,"PHP ERROR::: 
  32.                         Error Number: $errno
  33.                         Error Message: $errstr
  34.                         Error File: $errfile
  35.                         Error Line: $errline\n");
  36.                 if ($fckphp_config['Debug_Trace']fwrite($fh,"        Error Context: ".print_r($errcontext,true)."\n");
  37.                 if ($fckphp_config['Debug_GET']fwrite($fh,"\n\$_GET::\n".print_r($_GET,true)."\n");
  38.                 if ($fckphp_config['Debug_POST']fwrite($fh,"\n\$_POST::\n".print_r($_POST,true)."\n");
  39.                 if ($fckphp_config['Debug_SERVER']fwrite($fh,"\n\$_SERVER::\n".print_r($_SERVER,true)."\n");
  40.                 if ($fckphp_config['Debug_SESSIONS']fwrite($fh,"\n\$_SESSIONS::\n".print_r($_SESSION,true)."\n");
  41.                 fwrite($fh,"\n-------------------------------------------------------\n\n\n");
  42.                 fwrite($oldData)$oldData="";
  43.                 fclose($fh);
  44.                 $reported=true;
  45.             
  46.         }
  47.         
  48.         if (!$reported{
  49.             //display error instead.
  50.             echo("PHP ERROR::: <br />
  51.                     Error Number: $errno <br />
  52.                     Error Message: $errstr <br />
  53.                     Error File: $errfile <br />
  54.                     Error Line: $errline <br />");
  55.                 
  56.             if ($fckphp_config['Debug_Trace']echo "Error Context: ".print_r($errcontext,true)."\n";    
  57.             if ($fckphp_config['Debug_GET']echo "\$_GET::\n".print_r($_GET,true)."<br />\n";
  58.             if ($fckphp_config['Debug_POST']echo "\$_POST::\n".print_r($_POST,true)."<br />\n";
  59.             if ($fckphp_config['Debug_SERVER']echo "\$_SERVER::\n".print_r($_SERVER,true)."<br />\n";
  60.             if ($fckphp_config['Debug_SESSIONS']echo "\$_SESSIONS::\n".print_r($_SESSION,true)."<br />\n";
  61.             echo "<br />\n<br />\n";
  62.         }
  63.     }
  64. }
  65. set_error_handler('errorHandler');
  66.  
  67. if (!isset($_SERVER['DOCUMENT_ROOT'])) $_SERVER["DOCUMENT_ROOT"$fckphp_config['basedir'];
  68.  
  69. if ($fckphp_config['Debug']===true && $fckphp_config['Debug_Output']ob_start();
  70.  
  71. //These are the commands we may expect
  72. $valid_commands=$fckphp_config['Commands'];
  73. $valid_resource_types=$fckphp_config['ResourceTypes'];
  74.  
  75. //Get the passed data
  76. $command=(
  77.         ((isset($_GET['Command']))&&($_GET['Command']!=""))?
  78.             $_GET['Command']:
  79.             ""
  80.         );
  81.         
  82. $type=(
  83.         ((isset($_GET['Type']))&&($_GET['Type']!=""))?
  84.             $_GET['Type']:
  85.             "File"
  86.         );
  87.         
  88. $cwd=str_replace("..","",
  89.         (
  90.         ((isset($_GET['CurrentFolder']))&&($_GET['CurrentFolder']!=""))?
  91.             $_GET['CurrentFolder']:
  92.             "/"
  93.         )
  94.         );
  95.         
  96. $cwd=str_replace("..","",$cwd);
  97.  
  98. $extra=(
  99.         ((isset($_GET['ExtraParams']))&&($_GET['ExtraParams']!=""))?
  100.             $_GET['ExtraParams']:
  101.             ""
  102.         );
  103.  
  104. if (in_array($command,$valid_commands)) {
  105.  
  106.     if ($fckphp_config['auth']['Req']{
  107.         require_once "./Auth/".$fckphp_config['auth']['HandlerClass'].".php";
  108.         
  109.         $auth=new Auth();
  110.         $fckphp_config=$auth->authenticate($extra,$fckphp_config);
  111.         if ($fckphp_config['authSuccess']!==true{
  112.             header ("content-type: text/xml");
  113.             echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
  114.             ?>
  115. <Connector command="authentication_failed" resourceType="authentication_failed">
  116.     <CurrentFolder path="authentication_failed" url="authentication_failed" />
  117.     <Error number="-1" />
  118. </Connector><?php
  119.             if ($fckphp_config['Debug']===true  && $fckphp_config['Debug_Output']recordOutput();
  120.             exit(0);
  121.         }
  122.     }
  123.  
  124.     //bit of validation
  125.     if (!in_array($type,$valid_resource_types)) {
  126.         echo "Invalid resource type.";
  127.         if ($fckphp_config['Debug']===true  && $fckphp_config['Debug_Output']recordOutput();
  128.         exit(0);
  129.     }
  130.     
  131.     require_once "Commands/$command.php";
  132.  
  133.     $action=new $command($fckphp_config,$type,$cwd);
  134.  
  135.     $action->run();
  136.     if ($fckphp_config['Debug']===true && $fckphp_config['Debug_Output']recordOutput();
  137.     
  138. else {
  139.     //No reason for me to be here.
  140.     echo "Invalid command.";
  141.     echo str_replace("\n","<br />",print_r($_GET,true));
  142.     if ($fckphp_config['Debug']===true  && $fckphp_config['Debug_Output']recordOutput();
  143.     exit(0);
  144. }
  145.  
  146.  
  147. function recordOutput({
  148.     global $fckphp_config;
  149.  
  150.     if ($fckphp_config['Debug']===true  && $fckphp_config['Debug_Output']{
  151.         $contents=ob_get_contents();
  152.         if (strlen($contents)>0{
  153.             $oldData=implode("",file($fckphp_config['DebugOutput']));
  154.             if ($fh=fopen($fckphp_config['DebugOutput'],"w")) {
  155.                 fwrite($fh,"\n".date("d/m/Y H:i:s")."\n");
  156.                 if ($fckphp_config['Debug_GET']fwrite($fh,"\n\$_GET::\n".print_r($_GET,true)."\n");
  157.                 if ($fckphp_config['Debug_POST']fwrite($fh,"\n\$_POST::\n".print_r($_POST,true)."\n");
  158.                 if ($fckphp_config['Debug_SERVER']fwrite($fh,"\n\$_SERVER::\n".print_r($_SERVER,true)."\n");
  159.                 if ($fckphp_config['Debug_SESSIONS']fwrite($fh,"\n\$_SESSIONS::\n".print_r($_SESSION,true)."\n");
  160.                 fwrite($fh,$contents);
  161.                 fwrite($fh,"\n-------------------------------------------------------\n\n\n");
  162.                 fwrite($fh,$oldData)$oldData="";
  163.                 fclose($fh);
  164.             }
  165.         }
  166.         ob_flush();
  167.     }
  168. }
  169.  
  170. function outputHeaders({
  171.  
  172.     //Anti browser caching headers
  173.     //Borrowed from fatboy's implementation  (fatFCK@code247.com)
  174.     
  175.     // ensure file is never cached
  176.     // Date in the past
  177.     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  178.     
  179.     // always modified
  180.     header("Last-Modified: " gmdate("D, d M Y H:i:s"" GMT");
  181.     
  182.     // HTTP/1.1
  183.     header("Cache-Control: no-store, no-cache, must-revalidate");
  184.     header("Cache-Control: post-check=0, pre-check=0"false);
  185.     
  186.     // HTTP/1.0
  187.     header("Pragma: no-cache");
  188. }
  189. ?>

Documentation generated on Mon, 05 May 2008 16:18:08 +0400 by phpDocumentor 1.4.0