Exemplo n.º 1
0
/**
 * Do a fatal exit, echo the header (if possible) and an error message, followed by a debugging back-trace.
 * It also adds an entry to the error log, for reference.
 *
 * @param  mixed				The error message (string or tempcode)
 * @param  boolean			Whether to return
 */
function _fatal_exit($text, $return = false)
{
    @ob_end_clean();
    // Incase in minimodule
    if (!headers_sent()) {
        require_code('firephp');
        if (function_exists('fb')) {
            fb('Error: ' . (is_object($text) ? $text->evaluate() : $text));
        }
    }
    if (running_script('occle')) {
        header('Content-Type: text/xml');
        header('HTTP/1.0 200 Ok');
        header('Content-type: text/xml');
        $output = '<' . '?xml version="1.0" encoding="utf-8" ?' . '>
<response>
	<result>
		<command>' . post_param('command', '') . '</command>
		<stdcommand></stdcommand>
		<stdhtml><div xmlns="http://www.w3.org/1999/xhtml">' . (get_param_integer('keep_fatalistic', 0) == 1 ? static_evaluate_tempcode(get_html_trace()) : '') . '</div></stdhtml>
		<stdout>' . xmlentities(is_object($text) ? str_replace(array('&ldquo;', '&rdquo;'), array('"', '"'), html_entity_decode(strip_tags($text->evaluate()), ENT_QUOTES, get_charset())) : $text) . '</stdout>
		<stderr>' . xmlentities(do_lang('EVAL_ERROR')) . '</stderr>
		<stdnotifications><div xmlns="http://www.w3.org/1999/xhtml"></div></stdnotifications>
	</result>
</response>';
        if ($GLOBALS['XSS_DETECT']) {
            ocp_mark_as_escaped($output);
        }
        exit($output);
    }
    $GLOBALS['HTTP_STATUS_CODE'] = '500';
    if (!headers_sent()) {
        if (function_exists('browser_matches')) {
            if (!browser_matches('ie') && strpos(ocp_srv('SERVER_SOFTWARE'), 'IIS') === false) {
                header('HTTP/1.0 500 Internal server error');
            }
        }
        header('Content-type: text/html; charset=' . get_charset());
        header('Content-Disposition: inline');
    }
    //$x=@ob_get_contents(); @ob_end_clean(); //if (is_string($x)) @print($x);	Disabled as causes weird crashes
    if (array_key_exists('MSN_DB', $GLOBALS) && !is_null($GLOBALS['MSN_DB'])) {
        $GLOBALS['FORUM_DB'] = $GLOBALS['MSN_DB'];
        $GLOBALS['MSN_DB'] = NULL;
    }
    // Supplement error message with some useful info
    if (function_exists('ocp_version_full') && function_exists('ocp_srv')) {
        $sup = ' (version: ' . ocp_version_full() . ', PHP version: ' . phpversion() . ', URL: ' . ocp_srv('REQUEST_URI') . ')';
    } else {
        $sup = '';
    }
    if (is_object($text)) {
        if ($text->pure_lang) {
            $sup = escape_html($sup);
        }
        $text->attach($sup);
    } else {
        $text .= $sup;
    }
    // To break any looping of errors
    //@var_dump(debug_backtrace());@exit($text); // Useful if things go a bit nuts and error won't come out
    global $EXITING;
    if (!function_exists('do_header') || !function_exists('die_html_trace')) {
        $EXITING++;
    }
    //exit(escape_html($text));
    $EXITING++;
    if ($EXITING > 1 || running_script('upgrader') || !class_exists('ocp_tempcode')) {
        if ($EXITING < 3 && function_exists('may_see_stack_dumps') && may_see_stack_dumps() && $GLOBALS['HAS_SET_ERROR_HANDLER']) {
            die_html_trace(is_object($text) ? $text->evaluate() : escape_html($text));
        } else {
            critical_error('EMERGENCY', is_object($text) ? $text->evaluate() : escape_html($text));
        }
    }
    if (may_see_stack_dumps()) {
        $trace = get_html_trace();
    } else {
        $trace = paragraph(do_lang_tempcode('STACK_TRACE_DENIED_ERROR_NOTIFICATION'), 'yrthrty4ttewdf');
    }
    $title = get_page_title('ERROR_OCCURRED');
    if (get_param_integer('keep_fatalistic', 0) == 0) {
        @error_log('ocPortal:  ' . (is_object($text) ? $text->evaluate() : $text) . ' @ ' . get_self_url_easy(), 0);
    }
    $error_tpl = do_template('FATAL_SCREEN', array('_GUID' => '9fdc6d093bdb685a0eda6bb56988a8c5', 'TITLE' => $title, 'WEBSERVICE_RESULT' => get_webservice_result($text), 'MESSAGE' => $text, 'TRACE' => $trace));
    $echo = globalise($error_tpl, NULL, '', true);
    $echo->evaluate_echo();
    if (get_param_integer('keep_fatalistic', 0) == 0) {
        $trace = get_html_trace();
        $error_tpl = do_template('FATAL_SCREEN', array('_GUID' => '9fdc6d093bdb685a0eda6bb56988a8c5', 'TITLE' => $title, 'WEBSERVICE_RESULT' => get_webservice_result($text), 'MESSAGE' => $text, 'TRACE' => $trace));
        relay_error_notification((is_object($text) ? $text->evaluate() : $text) . '[html]' . $error_tpl->evaluate() . '[/html]');
    }
    if (!$return) {
        exit;
    }
}
Exemplo n.º 2
0
/**
 * This is a less-revealing alternative to fatal_exit, that is used for user-errors/common-corruption-scenarios
 *
 * @param  mixed			The error message
 */
function warn_exit($text)
{
    // To break any looping of errors
    global $EXITING;
    if (!is_null($EXITING) || !class_exists('ocp_tempcode')) {
        if (get_domain() == 'localhost' || function_exists('get_member') && has_specific_permission(get_member(), 'see_stack_dump')) {
            die_html_trace($text);
        } else {
            critical_error('RELAY', is_object($text) ? $text->evaluate() : escape_html($text));
        }
    }
    $EXITING = 1;
    $title = get_page_title('ERROR_OCCURRED');
    $echo = new ocp_tempcode();
    $echo->attach(do_template('WARN_SCREEN', array('TITLE' => $title, 'TEXT' => $text, 'PROVIDE_BACK' => false)));
    $css_url = 'install.php?type=css';
    $css_url_2 = 'install.php?type=css_2';
    $logo_url = 'install.php?type=logo';
    $version = strval(ocp_version());
    $version .= (is_numeric(ocp_version_minor()) ? '.' : ' ') . ocp_version_minor();
    if (!array_key_exists('step', $_GET)) {
        $_GET['step'] = 1;
    }
    require_code('tempcode_compiler');
    $css_nocache = _do_template('default', '/css/', 'no_cache', 'no_cache', 'EN', '.css');
    $out_final = do_template('INSTALLER_WRAP', array('CSS_NOCACHE' => $css_nocache, 'DEFAULT_FORUM' => '', 'PASSWORD_PROMPT' => '', 'CSS_URL' => $css_url, 'CSS_URL_2' => $css_url_2, 'LOGO_URL' => $logo_url, 'STEP' => integer_format(intval($_GET['step'])), 'CONTENT' => $echo, 'VERSION' => $version));
    $out_final->evaluate_echo();
    exit;
}