Exemple #1
0
 public function update_observer($type, $message, $errfile, $errline, $errcontext, $backtrace)
 {
     $mail = Variable::get('error_mail');
     if ($mail) {
         $backtrace = htmlspecialchars_decode(str_replace(array('<br />', '&nbsp;'), array("\n", ' '), $backtrace));
         $x = "who=" . Base_AclCommon::get_user() . "\ntype=" . $type . "\nmessage=" . $message . "\nerror file=" . $errfile . "\nerror line=" . $errline . "\n" . $backtrace;
         $d = ModuleManager::get_data_dir(Base_Error::module_name()) . md5($x) . '.txt';
         file_put_contents(EPESI_LOCAL_DIR . '/' . $d, $x);
         $url = get_epesi_url();
         $file_url = rtrim($url, '/') . '/' . $d;
         Base_MailCommon::send($mail, 'Epesi Error - ' . $url, substr($x, 0, strpos($x, "error backtrace")) . "\n" . $file_url, null, null, false, true);
     }
     return true;
 }
Exemple #2
0
 /**
  * 自定义错误处理
  *
  * @param int $errno 错误类型
  * @param string $errstr 错误信息
  * @param string $errfile 错误文件
  * @param int $errline 错误行数
  * @return void
  */
 public static function _errorHandle($errno, $errstr, $errfile, $errline)
 {
     if (($errno & error_reporting()) == $errno) {
         restore_error_handler();
         restore_exception_handler();
         $trace = debug_backtrace();
         unset($trace[0]["function"], $trace[0]["args"]);
         log_message('error', 'Severity: ' . Base_Error::get_name($errno) . '  --> ' . $errstr . ' ' . $errfile . ' ' . $errline, TRUE);
         if (IS_CLI) {
             printf(Base_Error::get_name($errno) . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline);
         } else {
             Core::debug()->error(Base_Error::get_name($errno) . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline);
             if (!IS_AJAX) {
                 // Ajax请求不显示错误页面
                 Base_Error::halt(Base_Error::get_name($errno) . ':' . $errstr, $errfile, $errline, $trace);
             }
         }
     }
 }
Exemple #3
0
 /**
  * Mostramos la página de error según el tipo de error del que se trate.
  *
  * Por defecto se disponen de tan solo 2 errores. 404 y 500.
  * Estás páginas aplican el modelo de sobreescritura de las vistas y se
  * ubican en internal/error/$number.php
  * Donde $number es el numero del error.
  * Además enviamos una variable $debug para informar si es desarrollo o
  * producción.
  *
  * Los errores internos del PHP y las excepciones se mapean automáticamente
  * a la correspondiente vista.
  *
  * @param mixed $description Descripcion del error.
  * @param int $number Numero del error, por defecto 500.
  * @param array $extended Información adicional sobre el error.
  */
 public static function show_error($description, $number = 500, $extended = NULL)
 {
     // Estamos mostrando un error.
     self::$has_error = TRUE;
     // Cargamos la vista.
     $view = View::factory('internal/error/' . $number);
     // Seteamos entorno
     $view->assign('debug', self::$debug);
     // Seteamos las variables base
     $view->assign('descripcion', NULL);
     $view->assign('backtrace', NULL);
     $view->assign('source', NULL);
     // Comprobamos el marco de trabajo.
     if (self::$debug) {
         // Mostramos una pantalla de error para depurar.
         // Agregamos la descripción.
         $view->assign('descripcion', $description);
         // Obtenemos la información util que encontremos en $extended.
         if (is_array($extended)) {
             // Buscamos bracktrace.
             if (isset($extended['backtrace'])) {
                 $view->assign('backtrace', $extended['backtrace']);
             }
             // Buscamos información para mostra el código fuente.
             if (isset($extended['file']) && isset($extended['line'])) {
                 $view->assign('source', self::show_source_error(7, $extended['line'], $extended['file'], self::arr_get($extended, 'reflection', NULL)));
             }
         }
     } else {
         // Mostramos una pantalla de error para el usuario en modo produccion.
         // Es producción
         $view->assign('debug', FALSE);
         // Agregamos la descripción del error.
         $view->assign('descripcion', $description);
     }
     // Cargo template.
     $template = View::factory('internal/template');
     // Asigno datos.
     try {
         $template->assign('contenido', $view->parse());
     } catch (Exception $e) {
         die('ERROR ' . $e->getCode() . ': ' . $e->getMessage());
     }
     $template->assign('number', $number);
     // Mostramos la pantalla de error.
     try {
         $template->show();
     } catch (Exception $e) {
         die('ERROR ' . $e->getCode() . ': ' . $e->getMessage());
     }
     // Terminamos la ejecución
     exit;
 }
Exemple #4
0
function set_status_header($code = 200, $text = '')
{
    $stati = array(200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported');
    if ($code == '' or !is_numeric($code)) {
        Base_Error::show_error('Status codes must be numeric', 500);
    }
    if (isset($stati[$code]) and $text == '') {
        $text = $stati[$code];
    }
    if ($text == '') {
        Base_Error::show_error('No status text available.  Please check your status code number or supply your own message text.', 500);
    }
    $server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : FALSE;
    if (IS_CGI) {
        header("Status: {$code} {$text}", TRUE);
    } elseif ($server_protocol == 'HTTP/1.1' or $server_protocol == 'HTTP/1.0') {
        header($server_protocol . " {$code} {$text}", TRUE, $code);
    } else {
        header("HTTP/1.1 {$code} {$text}", TRUE, $code);
    }
}