/** * Give the user an option to see a stack trace by adding in a link, but only if they have permission */ function suggest_fatalistic() { if (may_see_stack_dumps() && get_param_integer('keep_fatalistic', 0) == 0 && running_script('index')) { if (count($_POST) == 0) { $stack_trace_url = build_url(array('page' => '_SELF', 'keep_fatalistic' => 1), '_SELF', NULL, true); $st = do_lang_tempcode('WARN_TO_STACK_TRACE', escape_html($stack_trace_url->evaluate())); } elseif (count($_FILES) == 0) { $stack_trace_url = build_url(array('page' => '_SELF', 'keep_fatalistic' => 1), '_SELF', NULL, true); $p = build_keep_post_fields(); $st = do_lang_tempcode('WARN_TO_STACK_TRACE_2', escape_html($stack_trace_url->evaluate()), $p->evaluate()); } else { $stack_trace_url = build_url(array('page' => '', 'keep_fatalistic' => 1), ''); $st = do_lang_tempcode('WARN_TO_STACK_TRACE_3', escape_html($stack_trace_url->evaluate())); } require_code('site'); attach_message($st, 'inform'); } }
/** * 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('“', '”'), 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; } }