/** * 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; } }
/** * Attach a message to the page output. * * @param mixed The type of special message * @param ID_TEXT The template to use * @set inform notice warn * @return string Blank string so it can be chained in the Tempcode compiler. You will rarely want to use this return value. It's kind of a failsafe. */ function attach_message($message, $type = 'inform') { if (error_reporting() == 0 && $type == 'warn') { return ''; } // Suppressing errors static $am_looping = false; if ($am_looping) { return ''; } // Was a lang lookup error and got in an infinite loop of attaching errors about missing lang errors (because each iteration causes a reevaluation of past messages) $am_looping = true; global $DONE_HEADER, $ATTACH_MESSAGE_CALLED, $ATTACHED_MESSAGES, $ATTACHED_MESSAGES_RAW; foreach ($ATTACHED_MESSAGES_RAW as $last) { if (array(is_object($last[0]) ? $last[0]->evaluate() : $last[0], $last[1]) == array(is_object($message) ? $message->evaluate() : $message, $type)) { $am_looping = false; return ''; // Already shown } } $ATTACH_MESSAGE_CALLED++; if ($ATTACH_MESSAGE_CALLED > 5) { critical_error('EMERGENCY', is_object($message) ? $message->evaluate() : escape_html($message)); } if ($DONE_HEADER) { // Drastic measures global $FAILED_TO_ATTACH_ALL_ERRORS; if (!$FAILED_TO_ATTACH_ALL_ERRORS) { // Okay, start recording what will be shown on the bottom from this point $ATTACHED_MESSAGES = new ocp_tempcode(); $ATTACHED_MESSAGES_RAW = array(); $FAILED_TO_ATTACH_ALL_ERRORS = true; } } if ($type == 'warn' && strlen(is_object($message) ? $message->evaluate() : $message) < 130) { require_code('failure'); $webservice_result = get_webservice_result($message); if ($webservice_result !== NULL) { if (is_object($message) && $message->pure_lang) { $message = $message->evaluate(); } elseif (is_object($message)) { $message = escape_html($message->evaluate()); } else { $message = escape_html($message); } $message = do_template('CROP_TEXT_MOUSE_OVER', array('TEXT_LARGE' => $webservice_result, 'TEXT_SMALL' => protect_from_escaping($message))); $message = protect_from_escaping($message); } } if (get_param_integer('keep_fatalistic', 0) == 1 && $type == 'warn') { fatal_exit($message); } $ATTACHED_MESSAGES_RAW[] = array($message, $type); $message = do_template('ADDITIONAL', array('_GUID' => 'ec843c8619d21fbeeb512686ea300a17', 'TYPE' => $type, 'MESSAGE' => is_string($message) ? escape_html($message) : $message)); $ATTACHED_MESSAGES->attach($message); $ATTACH_MESSAGE_CALLED--; $am_looping = false; return ''; }
/** * Get the tempcode for a warn page. * * @param tempcode The title of the warn page * @param mixed The text to put on the warn page (either tempcode or string) * @param boolean Whether to provide a back button * @return tempcode The warn page */ function warn_screen($title, $text, $provide_back = true) { require_code('failure'); $text_eval = is_object($text) ? $text->evaluate() : $text; if ($text_eval == do_lang('MISSING_RESOURCE')) { $GLOBALS['HTTP_STATUS_CODE'] = '404'; if (!headers_sent()) { if (!browser_matches('ie') && strpos(ocp_srv('SERVER_SOFTWARE'), 'IIS') === false) { header('HTTP/1.0 404 Not Found'); } } if (ocp_srv('HTTP_REFERER') != '') { relay_error_notification($text_eval . ' ' . do_lang('REFERRER', ocp_srv('HTTP_REFERER'), substr(get_browser_string(), 0, 255)), false, 'error_occurred_missing_resource'); } } if (get_param_integer('keep_fatalistic', 0) == 1) { fatal_exit($text); } return do_template('WARN_SCREEN', array('_GUID' => 'a762a7ac8cd08623a0ed6413d9250d97', 'TITLE' => $title, 'WEBSERVICE_RESULT' => get_webservice_result($text), 'TEXT' => $text, 'PROVIDE_BACK' => $provide_back)); }