public function action_login()
 {
     $debug_hash = $_POST['debug_hash'];
     if (in_array($debug_hash, $this->password)) {
         \Core::cookie()->set('_debug_open', \Bootstrap::get_debug_hash($debug_hash), null, '/');
     }
     $this->redirect('/opendebugger');
 }
Esempio n. 2
0
 public static function setup()
 {
     static $run = null;
     if (!$run) {
         /**
          * 是否管理模式
          *
          * @var boolean
          */
         \define('IS_ADMIN_MODE', false);
         $is_online_debug = function () {
             if (!isset($_COOKIE['_debug_open'])) {
                 return false;
             }
             if (!isset(\Bootstrap::$config['core']['debug_open_password'])) {
                 return false;
             }
             if (!\is_array(\Bootstrap::$config['core']['debug_open_password'])) {
                 \Bootstrap::$config['core']['debug_open_password'] = array((string) \Bootstrap::$config['core']['debug_open_password']);
             }
             foreach (\Bootstrap::$config['core']['debug_open_password'] as $item) {
                 if ($_COOKIE['_debug_open'] == \Bootstrap::get_debug_hash($item)) {
                     return true;
                 }
             }
             return false;
         };
         if ($is_online_debug()) {
             $local_debug = true;
         } elseif (isset(\Bootstrap::$config['core']['local_debug_cfg']) && \Bootstrap::$config['core']['local_debug_cfg']) {
             if (\function_exists('\\get_cfg_var')) {
                 $local_debug = \get_cfg_var(\Bootstrap::$config['core']['local_debug_cfg']) ? true : false;
             } else {
                 $local_debug = false;
             }
         } else {
             $local_debug = false;
         }
         /**
          * 是否AJAX请求
          *
          * @var boolean
          */
         \define('IS_DEBUG', $local_debug);
         if (\IS_DEBUG && isset(\Bootstrap::$config['core']['libraries']['debug']) && \is_array(\Bootstrap::$config['core']['libraries']['debug']) && \Bootstrap::$config['core']['libraries']['debug']) {
             foreach (\Bootstrap::$config['core']['libraries']['debug'] as $lib) {
                 static::import_library($lib);
             }
         }
         static::$project =& \Bootstrap::$project;
         static::$include_puth =& \Bootstrap::$include_path;
         static::$charset = \Bootstrap::$config['core']['charset'];
         # 检查\Bootstrap版本
         if (\version_compare(\Bootstrap::VERSION, '2.0', '<')) {
             static::show_500('系统\\Bootstrap版本太低,请先升级\\Bootstrap。');
             exit;
         }
         if ((\IS_CLI || \IS_DEBUG) && \class_exists('\\DevException', true)) {
             # 注册脚本
             \register_shutdown_function(array('\\DevException', 'shutdown_handler'));
             # 捕获错误
             \set_exception_handler(array('\\DevException', 'exception_handler'));
             \set_error_handler(array('\\DevException', 'error_handler'), \error_reporting());
         } else {
             # 注册脚本
             \register_shutdown_function(array('\\Core', 'shutdown_handler'));
             # 捕获错误
             \set_exception_handler(array('\\Core', 'exception_handler'));
             \set_error_handler(array('\\Core', 'error_handler'), \error_reporting());
         }
         if (!\IS_CLI) {
             \header('X-Powered-By: PHP/' . \PHP_VERSION . ', MyQEE/' . static::VERSION);
             \HttpIO::setup();
         }
         if (\IS_SYSTEM_MODE && false === static::check_system_request_allow()) {
             # 内部请求验证不通过
             static::show_500('system request hash error');
         }
     }
     if (\IS_DEBUG && isset($_REQUEST['debug']) && \class_exists('\\Debug_Profiler', true)) {
         \Debug_Profiler::setup();
     }
     if (!\IS_CLI) {
         \register_shutdown_function(function () {
             \HttpIO::send_headers();
             # 输出内容
             echo \HttpIO::$body;
             if ($_GET['test']) {
                 //TODO///////TEST
                 echo '<br><pre>';
                 echo \microtime(1) - \START_TIME;
                 echo "\n";
                 echo (\memory_get_usage() - \START_MEMORY) / 1024 . 'kb';
                 echo "\n";
                 echo \memory_get_usage() / 1024 . 'kb';
                 echo "\n";
                 echo '<br><hr>include path<br>';
                 \print_r(\Bootstrap::$include_path);
                 \print_r(\get_included_files());
                 echo '</pre>';
             }
         });
     }
 }
Esempio n. 3
0
 /**
  * 系统初始化
  *
  * @param boolean $auto_execute 是否自动运行
  */
 public static function setup($auto_execute = true)
 {
     static $run = null;
     if (!$run) {
         $run = true;
         # 注册自动加载类
         spl_autoload_register(array('Bootstrap', 'auto_load'));
         # 读取配置
         if (!is_file(DIR_SYSTEM . 'config' . EXT)) {
             self::show_error('Please rename the file config.new.php to config.php');
         }
         $include_config_file = function (&$config, $file) {
             include $file;
         };
         self::$config = array('core' => array());
         # 读取主配置
         $include_config_file(self::$config['core'], DIR_SYSTEM . 'config' . EXT);
         # 读Debug配置
         if (isset(self::$config['core']['debug_config']) && self::$config['core']['debug_config'] && is_file(DIR_SYSTEM . 'debug.config' . EXT)) {
             $include_config_file(self::$config['core'], DIR_SYSTEM . 'debug.config' . EXT);
         }
         # DEBUG配置
         if (isset(self::$config['core']['local_debug_cfg']) && self::$config['core']['local_debug_cfg']) {
             if (function_exists('get_cfg_var')) {
                 $open_debug = get_cfg_var(self::$config['core']['local_debug_cfg']) ? 1 : 0;
             } else {
                 $open_debug = 0;
             }
         } else {
             $open_debug = 0;
         }
         /**
          * 判断是否开启了在线调试
          *
          * @return boolean
          */
         $is_online_debug = function () {
             if (IS_SYSTEM_MODE) {
                 if (isset($_SERVER['HTTP_X_MYQEE_SYSTEM_DEBUG']) && $_SERVER['HTTP_X_MYQEE_SYSTEM_DEBUG'] == '1') {
                     return true;
                 } else {
                     return false;
                 }
             }
             if (!isset($_COOKIE['_debug_open'])) {
                 return false;
             }
             if (!isset(Bootstrap::$config['core']['debug_open_password'])) {
                 return false;
             }
             if (!is_array(Bootstrap::$config['core']['debug_open_password'])) {
                 return false;
             }
             foreach (Bootstrap::$config['core']['debug_open_password'] as $user => $pass) {
                 if ($_COOKIE['_debug_open'] == Bootstrap::get_debug_hash($user, $pass)) {
                     return true;
                 }
             }
             return false;
         };
         if ($is_online_debug()) {
             $open_debug == 1 << 1 | $open_debug;
         }
         unset($is_online_debug);
         /**
          * 是否开启DEBUG模式
          *
          *     if (IS_DEBUG>>1)
          *     {
          *         //开启了在线调试
          *     }
          *
          *     if (IS_DEBUG & 1)
          *     {
          *         //本地调试打开
          *     }
          *
          *     if (IS_DEBUG)
          *     {
          *         // 开启了调试
          *     }
          *
          * @var int
          */
         define('IS_DEBUG', $open_debug);
         # 请求模式
         $request_mode = '';
         if (IS_CLI) {
             if (!isset($_SERVER["argv"])) {
                 exit('Err Argv');
             }
             $argv = $_SERVER["argv"];
             //$argv[0]为文件名
             if (isset($argv[1]) && $argv[1] && isset(self::$config['core']['projects'][$argv[1]])) {
                 self::$project = $argv[1];
             }
             array_shift($argv);
             //将文件名移除
             array_shift($argv);
             //将项目名移除
             self::$path_info = trim(implode('/', $argv));
             unset($argv);
         } else {
             self::setup_by_url($request_mode);
             if (isset(self::$config['core']['charset'])) {
                 # 输出文件头
                 header('Content-Type: text/html;charset=' . self::$config['core']['charset']);
             }
         }
         # 设置页面错误等级
         if (isset(self::$config['core']['error_reporting'])) {
             error_reporting(self::$config['core']['error_reporting']);
         }
         # 设置时区
         if (isset(self::$config['core']['timezone']) && self::$config['core']['timezone']) {
             date_default_timezone_set(self::$config['core']['timezone']);
         }
         /**
          * 加载类库
          * @var array $arr
          */
         $load_library = function ($arr) {
             # 逆向排序
             rsort($arr);
             foreach ($arr as $library_name) {
                 if (!$library_name) {
                     continue;
                 }
                 try {
                     Bootstrap::import_library($library_name);
                 } catch (Exception $e) {
                     Bootstrap::show_error($e->getMessage());
                 }
             }
         };
         /**
          * 是否后台模式
          *
          * @var boolean
          */
         define('IS_ADMIN_MODE', !IS_CLI && $request_mode == 'admin' ? true : false);
         if (IS_SYSTEM_MODE) {
             # 设置控制器在[system]目录下
             self::$dir_setting['controller'][0] .= DS . '[system]';
         }
         # 如果有autoload目录,则设置加载目录
         if (isset(self::$config['core']['libraries']['autoload']) && is_array(self::$config['core']['libraries']['autoload']) && self::$config['core']['libraries']['autoload']) {
             $load_library(self::$config['core']['libraries']['autoload']);
         }
         if (IS_CLI) {
             # cli模式
             if (isset(self::$config['core']['libraries']['cli']) && is_array(self::$config['core']['libraries']['cli']) && self::$config['core']['libraries']['cli']) {
                 $load_library(self::$config['core']['libraries']['cli']);
             }
             if (!IS_SYSTEM_MODE) {
                 # 控制器在[shell]目录下
                 self::$dir_setting['controller'][0] .= DS . '[shell]';
             }
         } elseif (IS_ADMIN_MODE) {
             # 后台模式
             if (isset(self::$config['core']['libraries']['admin']) && is_array(self::$config['core']['libraries']['admin']) && self::$config['core']['libraries']['admin']) {
                 $load_library(self::$config['core']['libraries']['admin']);
             }
             if (!IS_SYSTEM_MODE) {
                 # 控制器在[admin]目录下
                 self::$dir_setting['controller'][0] .= DS . '[admin]';
             }
         } elseif ($request_mode == 'app') {
             # APP模式
             if (isset(self::$config['core']['libraries']['app']) && is_array(self::$config['core']['libraries']['app']) && self::$config['core']['libraries']['app']) {
                 $load_library(self::$config['core']['libraries']['app']);
             }
         }
         if (IS_DEBUG) {
             # 加载debug类库
             if (isset(self::$config['core']['libraries']['debug']) && is_array(self::$config['core']['libraries']['debug']) && self::$config['core']['libraries']['debug']) {
                 $load_library(self::$config['core']['libraries']['debug']);
             }
             # 输出一些系统信息
             Core::debug()->group('include path');
             foreach (self::$include_path as $value) {
                 Core::debug()->log(Core::debug_path($value));
             }
             Core::debug()->groupEnd();
             if (self::$project) {
                 Core::debug()->info('project: ' . self::$project);
             } elseif ($request_mode == 'app') {
                 Core::debug()->info('app mode');
             } else {
                 Core::debug()->info('default application');
             }
             if (IS_ADMIN_MODE) {
                 Core::debug()->info('admin mode');
             }
         }
         unset($load_library);
         Core::setup();
     }
     # 直接执行
     if ($auto_execute) {
         if (IS_CLI || IS_SYSTEM_MODE) {
             self::execute(self::$path_info);
         } else {
             ob_start();
             try {
                 self::execute(self::$path_info);
             } catch (Exception $e) {
                 $code = $e->getCode();
                 if (404 === $code || E_PAGE_NOT_FOUND === $code) {
                     Core::show_404($e->getMessage());
                 } elseif (500 === $code) {
                     Core::show_500($e->getMessage());
                 } else {
                     Core::show_500($e->getMessage(), $code);
                 }
             }
             HttpIO::$body = ob_get_clean();
         }
         # 全部全部连接
         Core::close_all_connect();
     }
 }