PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/fckeditor/editor/filemanager/browser/mcpuk/connectors/php/connector.php

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