RAccServer.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace fcgisrv;
  3. require_once(BASE_ROOT_PATH . '/helper/area_helper.php');
  4. require_once(BASE_CORE_PATH . '/framework/function/http.php');
  5. require_once(BASE_ROOT_PATH . '/helper/session_helper.php');
  6. require_once(BASE_ROOT_PATH . '/helper/sensitive_word/dfa.php');
  7. require_once(BASE_ROOT_PATH . '/helper/exceptionex.php');
  8. require_once(BASE_ROOT_PATH . '/helper/session_helper.php');
  9. require_once(BASE_HELPER_PATH . '/fcgisrv/BaseServer.php');
  10. require_once(BASE_HELPER_PATH . '/refill/util.php');
  11. require_once(BASE_HELPER_PATH . '/session.php');
  12. use Log;
  13. use Base;
  14. use UnSignException;
  15. use Exception;
  16. use errcode;
  17. class RAccServer extends BaseServer
  18. {
  19. public function __construct()
  20. {
  21. parent::__construct();
  22. $exfiles = [];
  23. $this->setExFiles($exfiles);
  24. }
  25. static private $stInstance = NULL;
  26. static public function instance()
  27. {
  28. if(self::$stInstance == NULL) {
  29. self::$stInstance = new RAccServer();
  30. }
  31. return self::$stInstance;
  32. }
  33. protected function is_exclude($file)
  34. {
  35. $exister = function ($file, $subex)
  36. {
  37. $path = BASE_PATH . $subex;
  38. $dir = dirname($file);
  39. return ($path == $dir);
  40. };
  41. $ret = parent::is_exclude($file);
  42. if ($ret) {
  43. return true;
  44. }
  45. global $config;
  46. $exclude_dirs = $config['access_include_dirs'];
  47. foreach ($exclude_dirs as $dir)
  48. {
  49. if($exister($file,$dir)) {
  50. return true;
  51. }
  52. }
  53. return false;
  54. }
  55. function handle_request($file)
  56. {
  57. try
  58. {
  59. fcgi_header("Content-Type: text/html; charset=UTF-8");
  60. if(file_exists($file))
  61. {
  62. if ($this->isIndex($file)) {
  63. Base::mobile_control();
  64. } elseif ($this->is_exclude($file)) {
  65. include $file;
  66. } else {
  67. echo "You cannot access this file.";
  68. }
  69. }
  70. else
  71. {
  72. echo "no such file.";
  73. }
  74. }
  75. catch (UnSignException $ex) {
  76. joutput_error(errcode::ErrSignParamter,errcode::msg(errcode::ErrSignParamter));
  77. }
  78. catch (Exception $ex) {
  79. joutput_error($ex->getCode(),'异常错误');
  80. Log::record("run_looper exception catch code={$ex->getCode()} msg={$ex->getMessage()} trace={$ex->getTraceAsString()}", Log::ERR);
  81. }
  82. }
  83. }