?
Path : /home/admin/domains/happytokorea.com/public_html_bk/happyezystyle/board/Sources/ |
Current File : /home/admin/domains/happytokorea.com/public_html_bk/happyezystyle/board/Sources/Errors.php |
<?php /********************************************************************************** * Errors.php * *********************************************************************************** * SMF: Simple Machines Forum * * Open-Source Project Inspired by Zef Hemel (zef@zefhemel.com) * * =============================================================================== * * Software Version: SMF 2.0 RC1 * * Software by: Simple Machines (http://www.simplemachines.org) * * Copyright 2006-2009 by: Simple Machines LLC (http://www.simplemachines.org) * * 2001-2006 by: Lewis Media (http://www.lewismedia.com) * * Support, News, Updates at: http://www.simplemachines.org * *********************************************************************************** * This program is free software; you may redistribute it and/or modify it under * * the terms of the provided license as published by Simple Machines LLC. * * * * This program is distributed in the hope that it is and will be useful, but * * WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY * * or FITNESS FOR A PARTICULAR PURPOSE. * * * * See the "license.txt" file for details of the Simple Machines license. * * The latest version can always be found at http://www.simplemachines.org. * **********************************************************************************/ if (!defined('SMF')) die('Hacking attempt...'); /* The purpose of this file is... errors. (hard to guess, huh?) It takes care of logging, error messages, error handling, database errors, and error log administration. It does this with: bool db_fatal_error(bool loadavg = false) - loads Subs-Auth.php and calls show_db_error(). - this is used for database connection error handling. - loadavg means this is a load average problem, not a database error. string log_error(string error_message, string error_type = general, string filename = none, int line = none) - logs an error, if error logging is enabled. - depends on the enableErrorLogging setting. - filename and line should be __FILE__ and __LINE__, respectively. - returns the error message. (ie. die(log_error($msg));) void fatal_error(string error_message, mixed (bool or string) log = general) - stops execution and displays an error message. - logs the error message if log is missing or true. void fatal_lang_error(string error_message_key, mixed (bool or string) log = general, array sprintf = array()) - stops execution and displays an error message by key. - uses the string with the error_message_key key. - loads the Errors language file. - applies the sprintf information if specified. - the information is logged if log is true or missing. - logs the error in the forum's default language while displaying the error message in the user's language void error_handler(int error_level, string error_string, string filename, int line) - this is a standard PHP error handler replacement. - dies with fatal_error() if the error_level matches with error_reporting. void setup_fatal_error_context(string error_message) - uses the fatal_error sub template of the Errors template - or the error sub template in the Wireless template. - used by fatal_error() and fatal_lang_error() */ // Just wrap it so we don't take up time and space here in Errors.php. function db_fatal_error($loadavg = false) { global $sourcedir; // Just load the other file and run it. require_once($sourcedir . '/Subs-Auth.php'); show_db_error($loadavg); // Since we use "or db_fatal_error();" this is needed... return false; } // Log an error, if the option is on. function log_error($error_message, $error_type = 'general', $file = null, $line = null) { global $txt, $modSettings, $sc, $user_info, $smcFunc, $scripturl, $last_error; // Check if error logging is actually on. if (empty($modSettings['enableErrorLogging'])) return $error_message; // Basically, htmlspecialchars it minus &. (for entities!) $error_message = strtr($error_message, array('<' => '<', '>' => '>', '"' => '"')); $error_message = strtr($error_message, array('<br />' => '<br />', '<b>' => '<b>', '</b>' => '</b>', "\n" => '<br />')); // Add a file and line to the error message? // Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line if ($file == null) $file = ''; else // Window style slashes don't play well, lets convert them to the unix style. $file = str_replace('\\', '/', $file); if ($line == null) $line = 0; else $line = (int) $line; // Just in case there's no id_member or IP set yet. if (empty($user_info['id'])) $user_info['id'] = 0; if (empty($user_info['ip'])) $user_info['ip'] = ''; // Find the best query string we can... $query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING']; // Don't log the session hash in the url twice, it's a waste. $query_string = htmlspecialchars('?' . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string)); // Just so we know what board error messages are from. if (isset($_POST['board']) && !isset($_GET['board'])) $query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board']; // What types of categories do we have? $known_error_types = array( 'general', 'critical', 'database', 'undefined_vars', 'user', 'template', 'debug', ); // Make sure the category that was specified is a valid one $error_type = in_array($error_type, $known_error_types) && $error_type !== true ? $error_type : 'general'; // Don't log the same error countless times, as we can get in a cycle of depression... $error_info = array($user_info['id'], time(), $user_info['ip'], $query_string, $error_message, (string) $sc, $error_type, $file, $line); if (empty($last_error) || $last_error != $error_info) { // Insert the error into the database. $smcFunc['db_insert']('', '{db_prefix}log_errors', array('id_member' => 'int', 'log_time' => 'int', 'ip' => 'string-16', 'url' => 'string-65534', 'message' => 'string-65534', 'session' => 'string', 'error_type' => 'string', 'file' => 'string-255', 'line' => 'int'), $error_info, array('id_error') ); $last_error = $error_info; } // Return the message to make things simpler. return $error_message; } // An irrecoverable error. function fatal_error($error, $log = 'general') { global $txt, $context, $modSettings; // We don't have $txt yet, but that's okay... if (empty($txt)) die($error); setup_fatal_error_context($log || (!empty($modSettings['enableErrorLogging']) && $modSettings['enableErrorLogging'] == 2) ? log_error($error, $log) : $error); } // A fatal error with a message stored in the language file. function fatal_lang_error($error, $log = 'general', $sprintf = array()) { global $txt, $language, $modSettings, $user_info, $settings; // If we have no theme stuff we can't have the lanuage file... if (empty($settings)) die($error); $reload_lang_file = true; // Log the error in the forum's language, but don't waste the time if we aren't logging if ($log || (!empty($modSettings['enableErrorLogging']) && $modSettings['enableErrorLogging'] == 2)) { loadLanguage('Errors', $language); $reload_lang_file = $language != $user_info['language']; $error_message = empty($sprintf) ? $txt[$error] : vsprintf($txt[$error], $sprintf); log_error($error_message, $log); } // Load the language file, only if it needs to be reloaded if ($reload_lang_file) { loadLanguage('Errors'); $error_message = empty($sprintf) ? $txt[$error] : vsprintf($txt[$error], $sprintf); } setup_fatal_error_context($error_message); } // Handler for standard error messages. function error_handler($error_level, $error_string, $file, $line) { global $settings, $modSettings, $db_show_debug; // Ignore errors if we're ignoring them or they are strict notices from PHP 5 (which cannot be solved without breaking PHP 4.) if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && (empty($modSettings['enableErrorLogging']) || $modSettings['enableErrorLogging'] != 2))) return; if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename'])) { if (function_exists('debug_backtrace')) { $array = debug_backtrace(); for ($i = 0; $i < count($array); $i++) { if ($array[$i]['function'] != 'loadSubTemplate') continue; // This is a bug in PHP, with eval, it seems! if (empty($array[$i]['args'])) $i++; break; } if (isset($array[$i]) && !empty($array[$i]['args'])) $file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; else $file = realpath($settings['current_include_filename']) . ' (eval?)'; } else $file = realpath($settings['current_include_filename']) . ' (eval?)'; } if (isset($db_show_debug) && $db_show_debug === true) { // Commonly, undefined indexes will occur inside attributes; try to show them anyway! if ($error_level % 255 != E_ERROR) { $temporary = ob_get_contents(); if (substr($temporary, -2) == '="') echo '"'; } // Debugging! This should look like a PHP error message. echo '<br /> <b>', $error_level % 255 == E_ERROR ? 'Error' : ($error_level % 255 == E_WARNING ? 'Warning' : 'Notice'), '</b>: ', $error_string, ' in <b>', $file, '</b> on line <b>', $line, '</b><br />'; } $error_type = strpos(strtolower($error_string), 'undefined') !== false ? 'undefined_vars' : 'general'; $message = log_error($error_level . ': ' . $error_string, $error_type, $file, $line); //Let's give integrations a chance to ouput a bit differently if (isset($modSettings['integrate_output_error']) && function_exists($modSettings['integrate_output _error'])) $modSettings['integrate_output_error']($message, $error_type, $error_level, $file, $line); // Dying on these errors only causes MORE problems (blank pages!) if ($file == 'Unknown') return; // If this is an E_ERROR or E_USER_ERROR.... die. Violently so. if ($error_level % 255 == E_ERROR) obExit(false); else return; // If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die. Violently so. if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); // We should NEVER get to this point. Any fatal error MUST quit, or very bad things can happen. if ($error_level % 255 == E_ERROR) die('Hacking attempt...'); } function setup_fatal_error_context($error_message) { global $context, $txt, $ssi_on_error_method; // Don't bother indexing errors mate... $context['robot_no_index'] = true; if (!isset($context['error_title'])) $context['error_title'] = $txt['error_occured']; $context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message; if (empty($context['page_title'])) $context['page_title'] = $context['error_title']; // Whatever it is, it's not good! Make sure bots understand that. header('HTTP/1.1 500 Internal Server Error'); // Display the error message - wireless? if (defined('WIRELESS') && WIRELESS) $context['sub_template'] = WIRELESS_PROTOCOL . '_error'; // Load the template and set the sub template. else { loadTemplate('Errors'); $context['sub_template'] = 'fatal_error'; } // If this is SSI, what do they want us to do? if (SMF == 'SSI') { if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && function_exists($ssi_on_error_method)) $ssi_on_error_method(); elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) loadSubTemplate('fatal_error'); // No layers? if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) exit; } // We want whatever for the header, and a footer. (footer includes sub template!) obExit(null, true); /* DO NOT IGNORE: If you are creating a bridge to SMF or modifying this function, you MUST make ABSOLUTELY SURE that this function quits and DOES NOT RETURN TO NORMAL PROGRAM FLOW. Otherwise, security error messages will not be shown, and your forum will be in a very easily hackable state. */ trigger_error('Hacking attempt...', E_USER_ERROR); } ?>