Exemplo n.º 1
0
 /**
  * 系统错误,可直接将Exception对象传给$msg
  * @param string/Exception $msg
  */
 public static function show_500($msg = null)
 {
     Core::close_buffers(false);
     # 避免输出的CSS头试抛出页面无法显示
     @header('Content-Type: text/html;charset=' . Core::config('charset'), true);
     HttpIO::$status = 500;
     HttpIO::send_headers();
     if (null === $msg) {
         $msg = __('Internal Server Error');
     }
     if (IS_DEBUG && class_exists('DevException', false)) {
         if ($msg instanceof Exception) {
             $e = $msg;
         } else {
             $e = new Exception($msg);
         }
         echo DevException::exception_handler($e, true);
         exit;
     }
     if (IS_CLI) {
         echo "", $msg, CRLF, "", CRLF;
         exit;
     }
     try {
         if ($msg instanceof Exception) {
             $error = $msg->getMessage();
             $trace_obj = $msg;
         } else {
             $error = $msg;
             $trace_obj = new Exception($msg);
         }
         $error_config = Core::config('error500');
         $view = new View('error/500');
         if ($error_config && isset($error_config['close']) && $error_config['close'] == true) {
             # 不记录
             $view->error_saved = false;
             $error_no = '';
         } else {
             $trace_array = array('project' => Core::$project, 'admin_mode' => IS_ADMIN_MODE, 'uri' => HttpIO::$uri, 'url' => HttpIO::PROTOCOL . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"], 'post' => HttpIO::POST(null, HttpIO::PARAM_TYPE_OLDDATA), 'get' => $_SERVER['QUERY_STRING'], 'cookie' => HttpIO::COOKIE(null, HttpIO::PARAM_TYPE_OLDDATA), 'client_ip' => HttpIO::IP, 'user_agent' => HttpIO::USER_AGENT, 'referrer' => HttpIO::REFERRER, 'server_ip' => $_SERVER["SERVER_ADDR"]);
             $date = @date('Y-m-d');
             $no = strtoupper(substr(md5(serialize($trace_array)), 10, 10));
             $error_no = $date . '-' . $no;
             # 其它数据
             $trace_array['server_name'] = function_exists('php_uname') ? php_uname('a') : 'unknown';
             $trace_array['time'] = TIME;
             $trace_array['use_time'] = microtime(1) - START_TIME;
             $trace_array['trace'] = (string) $trace_obj;
             $trace_string = Core::json_encode($trace_array);
             $view->error_saved = true;
             # 记录错误日志
             try {
                 if (isset($error_config['save_type']) && $error_config['save_type']) {
                     $save_type = $error_config['save_type'];
                 } else {
                     $save_type = 'file';
                 }
                 if ($save_type === 'file') {
                     # 文件模式
                     $write_mode = Core::config('file_write_mode');
                     if (preg_match('#^(db|cache|fluent)://(([a-z0-9\\.\\-_]+)(?:\\:|/)([a-z0-9_]+))$#i', $write_mode, $m)) {
                         $save_type = $m[1];
                         $error_config['server'] = $m[2];
                         $error_config['type_config'] = $m[3];
                     }
                 }
                 switch ($save_type) {
                     case 'database':
                         $obj = $error_config['type_config'] ? new Database($error_config['type_config']) : new Database();
                         $data = array('time' => strtotime($date . ' 00:00:00'), 'no' => $no, 'log' => $obj->is_support_object_value() ? $trace_array : $trace_string, 'expire_time' => TIME + 7 * 86400);
                         $obj->insert('error500_log', $data);
                         break;
                     case 'cache':
                         $obj = $error_config['type_config'] ? new Cache($error_config['type_config']) : new Cache();
                         if (!$obj->get($error_no)) {
                             $obj->set($error_no, $trace_string, 7 * 86400);
                         }
                         break;
                     case 'fluent':
                         if (strpos($error_config['server'], ':') !== false) {
                             $fd_server = 'tcp://' . $error_config['server'];
                         } else {
                             $fd_server = 'udp://' . $error_config['server'];
                         }
                         $obj = Fluent::instance($fd_server);
                         $obj->push('system.error500', $trace_array);
                         break;
                     default:
                         $file = DIR_LOG . 'error500' . DS . str_replace('-', DS, $date) . DS . $no . '.log';
                         if (!is_file($file)) {
                             File::create_file($file, date('Y-m-d\\TH:i:s') . ' - ' . $trace_string, null, null, $error_config['type_config'] ? $error_config['type_config'] : 'default');
                         }
                         break;
                 }
             } catch (Exception $e) {
             }
         }
         $view->error_no = $error_no;
         $view->error = $error;
         $view->render(true);
     } catch (Exception $e) {
         list($REQUEST_URI) = explode('?', $_SERVER['REQUEST_URI'], 2);
         $REQUEST_URI = htmlspecialchars(rawurldecode($REQUEST_URI));
         echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . CRLF . '<html>' . CRLF . '<head>' . CRLF . '<title>Internal Server Error</title>' . CRLF . '</head>' . CRLF . '<body>' . CRLF . '<h1>Internal Server Error</h1>' . CRLF . '<p>The requested URL ' . $REQUEST_URI . ' was error on this server.</p>' . CRLF . '<hr />' . CRLF . $_SERVER['SERVER_SIGNATURE'] . '<br/><br/><br/>' . CRLF . 'Powered by MyQEE V' . Core::VERSION . CRLF . '</body>' . CRLF . '</html>';
     }
     exit;
 }
Exemplo n.º 2
0
 /**
  * 设置HTTP的状态
  *
  * @param int $status
  */
 public static function status($status = null)
 {
     if (HttpIO::$status) {
         HttpIO::$status = $status;
     }
     return HttpIO::$status;
 }
Exemplo n.º 3
0
 /**
  * Inline exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses    self::exception_text
  * @param   Exception $e object exception object
  * @return  bool
  */
 public static function exception_handler(Exception $e, $return = false)
 {
     try {
         if (IS_CLI) {
             $str = self::exception_text($e) . "\n" . $e->__toString() . "\n";
             if ($return) {
                 return $str;
             } else {
                 echo $str;
             }
             return true;
         }
         $trace = $e->getTrace();
         if ($e instanceof ErrorException) {
             if (version_compare(PHP_VERSION, '5.3', '<')) {
                 // Workaround for a bug in ErrorException::getTrace() that exists in
                 // all PHP 5.2 versions. @see http://bugs.php.net/bug.php?id=45895
                 for ($i = count($trace) - 1; $i > 0; --$i) {
                     if (isset($trace[$i - 1]['args'])) {
                         // Re-position the args
                         $trace[$i]['args'] = $trace[$i - 1]['args'];
                         // Remove the args
                         unset($trace[$i - 1]['args']);
                     }
                 }
             }
         }
         if (true !== $return) {
             Core::close_buffers(false);
             if ($e->getCode() === E_PAGE_NOT_FOUND) {
                 HttpIO::$status = 404;
             } elseif ($e->getCode() >= 400 && $e->getCode() <= 410) {
                 HttpIO::$status = 404;
             } elseif ($e->getCode() >= 500 && $e->getCode() <= 510) {
                 HttpIO::$status = 404;
             } else {
                 HttpIO::$status = 500;
             }
             @header('Content-Type:text/html;charset=utf-8');
             HttpIO::send_headers();
         }
         ob_start();
         include Core::find_file('views', self::$template);
         $string = ob_get_clean();
         if ($return) {
             return $string;
         } else {
             echo $string;
         }
         return true;
     } catch (Exception $e) {
         ob_get_level() and ob_clean();
         echo self::exception_text($e), "\n";
         exit(1);
     }
 }
Exemplo n.º 4
0
 /**
  * 系统错误,可直接将Exception对象传给$msg
  *
  * @param string/Exception $msg
  */
 public static function show_500($msg = null, $error_code = 500)
 {
     # 将输出全部清除
     static::close_buffers(false);
     \HttpIO::status($error_code);
     \HttpIO::send_headers();
     if (null === $msg) {
         $msg = \__('Internal Server Error');
     }
     if (\IS_DEBUG && \class_exists('\\DevException', false)) {
         if ($msg instanceof \Exception) {
             throw $msg;
         } else {
             throw new \Exception($msg, 0);
         }
     }
     if (\IS_CLI) {
         echo $msg . \CRLF;
         exit;
     }
     try {
         $view = new \View('error/500');
         $error = '';
         if ($msg instanceof \Exception) {
             $error .= 'Msg :' . $msg->getMessage() . \CRLF . "Line:" . $msg->getLine() . \CRLF . "File:" . static::debug_path($msg->getFile());
         } else {
             $error .= $msg;
         }
         $view->error = $error;
         $view->render(true);
     } catch (\Exception $e) {
         list($REQUEST_URI) = \explode('?', $_SERVER['REQUEST_URI'], 2);
         $REQUEST_URI = \htmlspecialchars(\rawurldecode($REQUEST_URI));
         echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . \CRLF . '<html>' . \CRLF . '<head>' . \CRLF . '<title>' . \__('Internal Server Error') . '</title>' . \CRLF . '</head>' . \CRLF . '<body>' . \CRLF . '<h1>' . \__('Internal Server Error') . '</h1>' . \CRLF . '<p>The requested URL ' . $REQUEST_URI . ' was error on this server.</p>' . \CRLF . '<hr>' . \CRLF . $_SERVER['SERVER_SIGNATURE'] . \CRLF . '<!-- ' . \htmlspecialchars($msg) . ' -->' . \CRLF . '</body>' . \CRLF . '</html>';
     }
     exit;
 }
Exemplo n.º 5
0
 /**
  * Inline exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses	Kohana::exception_text
  * @param   object   exception object
  * @return  boolean
  */
 public static function exception_handler(Exception $e, $return = false)
 {
     try {
         // Get the exception information
         $type = get_class($e);
         $code = $e->getCode();
         $message = $e->getMessage();
         $file = $e->getFile();
         $line = $e->getLine();
         if (isset(self::$php_errors[$code])) {
             $code = self::$php_errors[$code];
         }
         // Create a text version of the exception
         $error = self::exception_text($e);
         if (IS_CLI) {
             // Just display the text of the exception
             echo "\n{$error}\n";
             return TRUE;
         }
         // Get the exception backtrace
         $trace = $e->getTrace();
         if ($e instanceof ErrorException) {
             if (version_compare(PHP_VERSION, '5.3', '<')) {
                 // Workaround for a bug in ErrorException::getTrace() that exists in
                 // all PHP 5.2 versions. @see http://bugs.php.net/bug.php?id=45895
                 for ($i = count($trace) - 1; $i > 0; --$i) {
                     if (isset($trace[$i - 1]['args'])) {
                         // Re-position the args
                         $trace[$i]['args'] = $trace[$i - 1]['args'];
                         // Remove the args
                         unset($trace[$i - 1]['args']);
                     }
                 }
             }
         }
         if ($return !== true) {
             Core::close_buffers(FALSE);
         }
         if ($e->getCode() == 43) {
             HttpIO::$status = 404;
         } else {
             HttpIO::$status = 500;
         }
         HttpIO::send_headers();
         // Start an output buffer
         ob_start();
         // Include the exception HTML
         include Core::find_file('views', self::$template);
         // Display the contents of the output buffer
         $string = ob_get_clean();
         if ($return) {
             return $string;
         } else {
             echo $string;
         }
         return TRUE;
     } catch (Exception $e) {
         // Clean the output buffer if one exists
         ob_get_level() and ob_clean();
         // Display the exception text
         echo self::exception_text($e), "\n";
         exit(1);
     }
 }
Exemplo n.º 6
0
 /**
  * 系统错误,可直接将Exception对象传给$msg
  * @param string/Exception $msg
  */
 public static function show_500($msg = null)
 {
     Core::close_buffers(false);
     HttpIO::$status = 500;
     HttpIO::send_headers();
     if (null === $msg) {
         $msg = __('Internal Server Error');
     }
     if (IS_DEBUG && class_exists('ErrException', false)) {
         if ($msg instanceof Exception) {
             throw $msg;
         } else {
             throw new Exception($msg, 0);
         }
     }
     if (IS_CLI) {
         echo $msg . CRLF;
         exit;
     }
     try {
         $view = new View('error/500');
         $error = '';
         if ($msg instanceof Exception) {
             $error .= 'Msg :' . $msg->getMessage() . CRLF . "Line:" . $msg->getLine() . CRLF . "File:" . Core::debug_path($msg->getFile());
         } else {
             $error .= $msg;
         }
         $view->error = $error;
         $view->render(true);
     } catch (Exception $e) {
         list($REQUEST_URI) = explode('?', $_SERVER['REQUEST_URI'], 2);
         $REQUEST_URI = htmlspecialchars(rawurldecode($REQUEST_URI));
         echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . CRLF . '<html>' . CRLF . '<head>' . CRLF . '<title>Internal Server Error</title>' . CRLF . '</head>' . CRLF . '<body>' . CRLF . '<h1>' . __('Internal Server Error') . '</h1>' . CRLF . '<p>The requested URL ' . $REQUEST_URI . ' was error on this server.</p>' . CRLF . '<hr>' . CRLF . $_SERVER['SERVER_SIGNATURE'] . CRLF . '</body>' . CRLF . '</html>';
     }
     # 执行注册的shutdown方法,并忽略输出的内容
     ob_start();
     Core::run_shutdown_function();
     ob_end_clean();
     exit;
 }
Exemplo n.º 7
0
 /**
  * 系统错误,可直接将Exception对象传给$msg
  * @param string/Exception $msg
  */
 public static function show_500($msg = null)
 {
     Core::close_buffers(false);
     # 避免输出的CSS头试抛出页面无法显示
     @header('Content-Type: text/html;charset=' . Core::config('core.charset'), true);
     HttpIO::$status = 500;
     HttpIO::send_headers();
     if (null === $msg) {
         $msg = __('Internal Server Error');
     }
     if (IS_DEBUG && class_exists('ErrException', false)) {
         if ($msg instanceof Exception) {
             throw $msg;
         } else {
             throw new Exception($msg, 0);
         }
     }
     if (IS_CLI) {
         echo "";
         if ($msg instanceof Exception) {
             echo $msg->getMessage() . CRLF;
         } else {
             echo $msg . CRLF;
         }
         echo "";
         echo CRLF;
         exit;
     }
     try {
         if ($msg instanceof Exception) {
             $error = $msg->getMessage();
             $trace_obj = $msg;
         } else {
             $error = $msg;
             $trace_obj = new Exception($msg);
         }
         $error_config = Core::config('core.error500');
         $view = new View('error/500');
         if ($error_config && isset($error_config['close']) && $error_config['close'] == true) {
             # 不记录
             $view->error_saved = false;
         } else {
             $trace_array = array('project' => Core::$project, 'uri' => HttpIO::$uri, 'url' => HttpIO::PROTOCOL . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"], 'post' => HttpIO::POST(null, HttpIO::PARAM_TYPE_OLDDATA), 'get' => $_SERVER['QUERY_STRING'], 'cookie' => HttpIO::COOKIE(null, HttpIO::PARAM_TYPE_OLDDATA), 'client_ip' => HttpIO::IP, 'user_agent' => HttpIO::USER_AGENT, 'referrer' => HttpIO::REFERRER, 'server_ip' => $_SERVER["SERVER_ADDR"], 'trace' => $trace_obj->__toString());
             $date = @date('Y-m-d');
             $no = strtoupper(substr(md5(serialize($trace_array)), 10, 10));
             $error_no = $date . '-' . $no;
             # 其它数据
             $trace_array['server_name'] = function_exists('php_uname') ? php_uname('a') : 'unknown';
             $trace_array['time'] = TIME;
             $trace_array['use_time'] = microtime(1) - START_TIME;
             $trace_array['trace'] = $trace_obj;
             $trace_data = base64_encode(gzcompress(serialize($trace_array), 9));
             unset($trace_array);
             $view->error_saved = true;
             # 记录错误日志
             try {
                 if (isset($error_config['save_type']) && $error_config['save_type']) {
                     $save_type = $error_config['save_type'];
                 } else {
                     $save_type = 'file';
                 }
                 if ($save_type == 'file') {
                     # 文件模式
                     $write_mode = Core::config('core.file_write_mode');
                     if (preg_match('#^(db|cache)://([a-z0-9_]+)/([a-z0-9_]+)$#i', $write_mode, $m)) {
                         $save_type = $m[1];
                         $error_config['type_config'] = $m[2];
                     }
                 }
                 switch ($save_type) {
                     case 'database':
                         $obj = $error_config['type_config'] ? new Database($error_config['type_config']) : new Database();
                         $data = array('time' => strtotime($date . ' 00:00:00'), 'no' => $no, 'log' => $trace_data, 'expire_time' => TIME + 7 * 86400);
                         $obj->insert('error500_log', $data);
                         break;
                     case 'cache':
                         $obj = $error_config['type_config'] ? new Cache($error_config['type_config']) : new Cache();
                         if (!$obj->get($error_no)) {
                             $obj->set($error_no, $trace_data, 7 * 86400);
                         }
                         break;
                     default:
                         $file = DIR_LOG . 'error500' . DS . str_replace('-', DS, $date) . DS . $no . '.log';
                         if (!is_file($file)) {
                             File::create_file($file, $trace_data, null, null, $error_config['type_config'] ? $error_config['type_config'] : 'default');
                         }
                         break;
                 }
             } catch (Exception $e) {
             }
         }
         $view->error_no = $error_no;
         $view->error = $error;
         $view->render(true);
     } catch (Exception $e) {
         list($REQUEST_URI) = explode('?', $_SERVER['REQUEST_URI'], 2);
         $REQUEST_URI = htmlspecialchars(rawurldecode($REQUEST_URI));
         echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . CRLF . '<html>' . CRLF . '<head>' . CRLF . '<title>Internal Server Error</title>' . CRLF . '</head>' . CRLF . '<body>' . CRLF . '<h1>' . __('Internal Server Error') . '</h1>' . CRLF . '<p>The requested URL ' . $REQUEST_URI . ' was error on this server.</p>' . CRLF . '<hr />' . CRLF . $_SERVER['SERVER_SIGNATURE'] . CRLF . '</body>' . CRLF . '</html>';
     }
     exit;
 }
Exemplo n.º 8
0
 /**
  * Inline exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses	Kohana::exception_text
  * @param   object   exception object
  * @return  boolean
  */
 public static function exception_handler(\Exception $e, $return = false)
 {
     try {
         // Get the exception information
         $type = get_class($e);
         $code = $e->getCode();
         $message = $e->getMessage();
         $file = $e->getFile();
         $line = $e->getLine();
         if (isset(static::$php_errors[$code])) {
             $code = static::$php_errors[$code];
         }
         // Create a text version of the exception
         $error = static::exception_text($e);
         if (\IS_CLI) {
             echo "\n{$error}\n";
             return true;
         }
         // Get the exception backtrace
         $trace = $e->getTrace();
         if ($return !== true) {
             \Core::close_buffers(false);
         }
         if ($e->getCode() == 43 || $e->getCode() == 404) {
             \HttpIO::status(404);
         } else {
             \HttpIO::status(500);
         }
         \HttpIO::send_headers();
         \ob_start();
         include \Core::find_view(static::$template);
         $string = ob_get_clean();
         if ($return) {
             return $string;
         } else {
             echo $string;
         }
         return true;
     } catch (\Exception $e) {
         // Clean the output buffer if one exists
         \ob_get_level() && \ob_clean();
         // Display the exception text
         echo static::exception_text($e), "\n";
         exit(1);
     }
 }
Exemplo n.º 9
0
 /**
  * 页面跳转
  *
  * @param   string   redirect location
  * @param   integer  status code: 301, 302, etc
  * @return  void
  * @uses    Core_url::site
  * @uses    HttpIO::send_headers
  */
 public static function redirect($url, $code = 302)
 {
     if (strpos($url, '://') === true) {
         // Make the URI into a URL
         $url = Core::url($url);
     }
     // Set the response status
     HttpIO::$status = $code;
     // Set the location header
     HttpIO::$headers['Location'] = $url;
     // Send headers
     HttpIO::send_headers();
     // Stop execution
     exit;
 }