Example #1
0
/**
* Wrapper function for the default phpBB msg_handler method.
* This function will overwrite the $phpbb_root_path variable
* if $errno == E_USER_ERROR. This way the "return to index"
* link on the error page will point towards the STK index
* instead of the phpBB index
*/
function stk_msg_handler($errno, $msg_text, $errfile, $errline)
{
    // Sometimes phpBB call this after finishing a certain task, this breaks the ERK!
    // A little bit of fallback here, call the critical repair kit error handler
    if (defined('IN_ERK')) {
        global $critical_repair;
        $critical_repair->trigger_error($msg_text, false, array($errno, $errfile, $errline));
    }
    // If the STK triggers a fatal error before IN_STK is defined we'll show a page
    // informing the user that the ERK *might* resolve this issue.
    if (!defined('IN_STK') && in_array($errno, array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE))) {
        // Trigger error through the critical repair class
        if (!class_exists('critical_repair')) {
            include STK_ROOT_PATH . 'includes/critical_repair.' . PHP_EXT;
        }
        $cr = new critical_repair();
        if ($errno == E_USER_ERROR) {
            $lines = array('The Support Toolkit encountered a fatal error.', 'The Support Toolkit includes an Emergency Repair Kit (ERK), a tool designed to resolve certain errors that prevent phpBB from functioning. It is advised that you run the ERK now so it can attempt to repair the error it has detected.<br />
To run the ERK, click <a href="' . STK_ROOT_PATH . 'erk.php">here</a>.');
            $redirect_stk = false;
        } else {
            $lines = array($msg_text);
            $redirect_stk = true;
        }
        // Trigger
        $cr->trigger_error($lines, $redirect_stk);
    }
    // This is nasty :(
    if ($errno == E_USER_ERROR) {
        global $phpbb_root_path;
        $phpbb_root_path = STK_ROOT_PATH;
    }
    // Call the phpBB error message handler
    msg_handler($errno, $msg_text, $errfile, $errline);
}
Example #2
0
        if ($unit == 'g') {
            $mem_limit *= 1024;
        } else {
            if (is_numeric($unit)) {
                $mem_limit = floor((int) ($mem_limit . $unit) / 1048576);
            }
        }
    }
    $mem_limit = max(128, $mem_limit) . 'M';
} else {
    $mem_limit = '128M';
}
@ini_set('memory_limit', $mem_limit);
// Init critical repair and run the tools that *must* be ran before initing anything else
include STK_ROOT_PATH . 'includes/critical_repair.' . PHP_EXT;
$critical_repair = new critical_repair();
$critical_repair->initialise();
$critical_repair->run_tool('bom_sniffer');
$critical_repair->run_tool('config_repair');
require STK_ROOT_PATH . 'common.' . PHP_EXT;
// We'll run the rest of the critical repair tools automatically now
$critical_repair->autorun_tools();
// At this point things should be runnable
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('acp/common', $config['default_style']);
stk_add_lang('common');
// Purge teh caches
$umil = new umil(true);
$umil->cache_purge(array('data'));
Example #3
0
/**
 * Support Toolkit Error handler
 *
 * A wrapper for the phpBB `msg_handler` function, which is mainly used
 * to update variables before calling the actual msg_handler and is able
 * to handle various special cases.
 *
 * @global type $stk_no_error
 * @global string $phpbb_root_path
 * @param type $errno
 * @param string $msg_text
 * @param type $errfile
 * @param type $errline
 * @return boolean
 */
function stk_msg_handler($errno, $msg_text, $errfile, $errline)
{
    // First and foremost handle the case where phpBB calls trigger error
    // but the STK really needs to continue.
    global $critical_repair, $stk_no_error, $user;
    if (!isset($user->lang['STK_FATAL_ERROR'])) {
        stk_add_lang('common');
    }
    if ($stk_no_error === true) {
        return true;
    }
    // Do not display notices if we suppress them via @
    if (error_reporting() == 0 && $errno != E_USER_ERROR && $errno != E_USER_WARNING && $errno != E_USER_NOTICE) {
        return;
    }
    if (!defined('E_DEPRECATED')) {
        define('E_DEPRECATED', 8192);
    }
    // Ignore Strict and Deprecated notices
    if (in_array($errno, array(E_STRICT, E_DEPRECATED))) {
        return true;
    }
    // We encounter an error while in the ERK, this need some special treatment
    $error_level = array(E_ERROR => 'Fatal error', E_WARNING => 'Runtime Error', E_PARSE => 'Parse error', E_NOTICE => 'Notice');
    switch ($errno) {
        case E_ERROR:
        case E_PARSE:
        case E_WARNING:
        case E_NOTICE:
        case E_CORE_ERROR:
        case E_COMPILE_ERROR:
        case E_USER_ERROR:
        case E_RECOVERABLE_ERROR:
            $backtrace = get_backtrace();
            $msg_text = '<br /><b>[phpBB Debug] PHP ' . $error_level[$errno] . ':</b> in file ' . phpbb_filter_root_path($errfile) . ' on line <b>' . $errline . ': ' . $msg_text . '</b><br />' . $backtrace . '';
            break;
        default:
            break;
    }
    if (defined('IN_ERK')) {
        $critical_repair->trigger_error($msg_text, $errno == E_USER_ERROR ? false : true);
    } else {
        if (!defined('IN_STK')) {
            // We're encountering an error before the STK is fully loaded
            // Set out own message if needed
            if ($errno == E_USER_ERROR) {
                $msg_text = $user->lang['STK_FATAL_ERROR'];
            }
            if (!isset($critical_repair)) {
                $critical_repair = new critical_repair();
            }
            $critical_repair->trigger_error($msg_text, $errno == E_USER_ERROR ? false : true);
        }
    }
    //-- Normal phpBB msg_handler
    global $cache, $db, $auth, $template, $config, $user;
    global $phpEx, $phpbb_root_path, $msg_title, $msg_long_text;
    // Message handler is stripping text. In case we need it, we are possible to define long text...
    if (isset($msg_long_text) && $msg_long_text && !$msg_text) {
        $msg_text = $msg_long_text;
    }
    if (!defined('E_DEPRECATED')) {
        define('E_DEPRECATED', 8192);
    }
    switch ($errno) {
        case E_NOTICE:
        case E_WARNING:
            // Check the error reporting level and return if the error level does not match
            // If DEBUG is defined the default level is E_ALL
            if (($errno & (defined('DEBUG') ? E_ALL : error_reporting())) == 0) {
                return;
            }
            if (strpos($errfile, 'cache') === false && strpos($errfile, 'template.') === false) {
                $errfile = stk_filter_root_path($errfile);
                $msg_text = stk_filter_root_path($msg_text);
                $error_name = $errno === E_WARNING ? 'PHP Warning' : 'PHP Notice';
                echo '<b>[phpBB Debug] ' . $error_name . '</b>: in file <b>' . $errfile . '</b> on line <b>' . $errline . '</b>: <b>' . $msg_text . '</b><br />' . "\n";
                // we are writing an image - the user won't see the debug, so let's place it in the log
                if (defined('IMAGE_OUTPUT') || defined('IN_CRON')) {
                    add_log('critical', 'LOG_IMAGE_GENERATION_ERROR', $errfile, $errline, $msg_text);
                }
                echo '<br /><br />BACKTRACE<br />' . get_backtrace() . '<br />' . "\n";
            }
            return;
            break;
        case E_USER_ERROR:
            if (!empty($user) && !empty($user->lang)) {
                $msg_text = !empty($user->lang[$msg_text]) ? $user->lang[$msg_text] : $msg_text;
                $msg_title = !isset($msg_title) ? $user->lang['GENERAL_ERROR'] : (!empty($user->lang[$msg_title]) ? $user->lang[$msg_title] : $msg_title);
                $l_return_index = sprintf($user->lang['RETURN_INDEX'], '<a href="' . $phpbb_root_path . '">', '</a>');
                $l_notify = '';
                if (!empty($config['board_contact'])) {
                    $l_notify = '<p>' . sprintf($user->lang['NOTIFY_ADMIN_EMAIL'], $config['board_contact']) . '</p>';
                }
            } else {
                $msg_title = 'General Error';
                $l_return_index = '<a href="' . $phpbb_root_path . '">Return to index page</a>';
                $l_notify = '';
                if (!empty($config['board_contact'])) {
                    $l_notify = '<p>Please notify the board administrator or webmaster: <a href="mailto:' . $config['board_contact'] . '">' . $config['board_contact'] . '</a></p>';
                }
            }
            $log_text = $msg_text;
            $backtrace = get_backtrace();
            if ($backtrace) {
                $log_text .= '<br /><br />BACKTRACE<br />' . $backtrace;
            }
            if (defined('IN_INSTALL') || defined('DEBUG_EXTRA') || isset($auth) && $auth->acl_get('a_')) {
                $msg_text = $log_text;
            }
            if ((defined('DEBUG') || defined('IN_CRON') || defined('IMAGE_OUTPUT')) && isset($db)) {
                // let's avoid loops
                $db->sql_return_on_error(true);
                add_log('critical', 'LOG_GENERAL_ERROR', $msg_title, $log_text);
                $db->sql_return_on_error(false);
            }
            // Do not send 200 OK, but service unavailable on errors
            stk_send_status_line(503, 'Service Unavailable');
            garbage_collection();
            // Try to not call the adm page data...
            echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
            echo '<html xmlns="http://www.w3.org/1999/xhtml" dir="' . $user->lang['DIRECTION'] . '" lang="' . $user->lang['USER_LANG'] . '" xml:lang="' . $user->lang['USER_LANG'] . '">';
            echo '<head>';
            echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
            echo '<title>' . $msg_title . '</title>';
            echo '<style type="text/css">' . "\n" . '/* <![CDATA[ */' . "\n";
            echo '* { margin: 0; padding: 0; } html { font-size: 100%; height: 100%; margin-bottom: 1px; background-color: #E4EDF0; } body { font-family: "Lucida Grande", Verdana, Helvetica, Arial, sans-serif; color: #536482; background: #E4EDF0; font-size: 62.5%; margin: 0; } ';
            echo 'a:link, a:active, a:visited { color: #006699; text-decoration: none; } a:hover { color: #DD6900; text-decoration: underline; } ';
            echo '#wrap { padding: 0 20px 15px 20px; min-width: 615px; } #page-header { text-align: right; height: 40px; } #page-footer { clear: both; font-size: 1em; text-align: center; } ';
            echo '.panel { margin: 4px 0; background-color: #FFFFFF; border: solid 1px  #A9B8C2; } ';
            echo '#errorpage #page-header a { font-weight: bold; line-height: 6em; } #errorpage #content { padding: 10px; } #errorpage #content h1 { line-height: 1.2em; margin-bottom: 0; color: #DF075C; } ';
            echo '#errorpage #content div { margin-top: 20px; margin-bottom: 5px; border-bottom: 1px solid #CCCCCC; padding-bottom: 5px; color: #333333; font: bold 1.2em "Lucida Grande", Arial, Helvetica, sans-serif; text-decoration: none; line-height: 120%; text-align: left; } ';
            echo "\n" . '/* ]]> */' . "\n";
            echo '</style>';
            echo '</head>';
            echo '<body id="errorpage">';
            echo '<div id="wrap">';
            echo '	<div id="page-header">';
            echo '		' . $l_return_index;
            echo '	</div>';
            echo '	<div id="acp">';
            echo '	<div class="panel">';
            echo '		<div id="content">';
            echo '			<h1>' . $msg_title . '</h1>';
            echo '			<div>' . $msg_text . '</div>';
            echo $l_notify;
            echo '		</div>';
            echo '	</div>';
            echo '	</div>';
            echo '	<div id="page-footer">';
            echo '		Powered by <a href="http://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Group';
            echo '	</div>';
            echo '</div>';
            echo '</body>';
            echo '</html>';
            exit_handler();
            // On a fatal error (and E_USER_ERROR *is* fatal) we never want other scripts to continue and force an exit here.
            exit;
            break;
        case E_USER_WARNING:
        case E_USER_NOTICE:
            define('IN_ERROR_HANDLER', true);
            if (empty($user->data)) {
                $user->session_begin();
            }
            // We re-init the auth array to get correct results on login/logout
            $auth->acl($user->data);
            if (empty($user->lang)) {
                $user->setup();
            }
            if ($msg_text == 'ERROR_NO_ATTACHMENT' || $msg_text == 'NO_FORUM' || $msg_text == 'NO_TOPIC' || $msg_text == 'NO_USER') {
                stk_send_status_line(404, 'Not Found');
            }
            $msg_text = !empty($user->lang[$msg_text]) ? $user->lang[$msg_text] : $msg_text;
            $msg_title = !isset($msg_title) ? $user->lang['INFORMATION'] : (!empty($user->lang[$msg_title]) ? $user->lang[$msg_title] : $msg_title);
            if (!defined('HEADER_INC')) {
                if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) {
                    adm_page_header($msg_title);
                } else {
                    page_header($msg_title, false);
                }
            }
            $template->set_filenames(array('body' => 'message_body.html'));
            $template->assign_vars(array('MESSAGE_TITLE' => $msg_title, 'MESSAGE_TEXT' => $msg_text, 'S_USER_WARNING' => $errno == E_USER_WARNING ? true : false, 'S_USER_NOTICE' => $errno == E_USER_NOTICE ? true : false));
            // We do not want the cron script to be called on error messages
            define('IN_CRON', true);
            if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) {
                adm_page_footer();
            } else {
                page_footer();
            }
            exit_handler();
            break;
            // PHP4 compatibility
        // PHP4 compatibility
        case E_DEPRECATED:
            return true;
            break;
    }
    // If we notice an error not handled here we pass this back to PHP by returning false
    // This may not work for all php versions
    return false;
}
Example #4
0
        if ($unit == 'g') {
            $mem_limit *= 1024;
        } else {
            if (is_numeric($unit)) {
                $mem_limit = floor((int) ($mem_limit . $unit) / 1048576);
            }
        }
    }
    $mem_limit = max(128, $mem_limit) . 'M';
} else {
    $mem_limit = '128M';
}
@ini_set('memory_limit', $mem_limit);
// Init critical repair and run the tools that *must* be ran before initing anything else
include STK_ROOT_PATH . 'includes/critical_repair.' . PHP_EXT;
$critical_repair = new critical_repair();
$critical_repair->run_tool('bom_sniffer');
$critical_repair->run_tool('config_repair');
require STK_ROOT_PATH . 'common.' . PHP_EXT;
// We'll run the rest of the critical repair tools automatically now
$critical_repair->autorun_tools();
// At this point things should be runnable
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('acp/common', $config['default_style']);
// Purge teh caches
$umil = new umil(true);
$umil->cache_purge(array('data', 'template', 'theme', 'imageset'));
// Let's tell the user all is okay :)
$critical_repair->trigger_error("The Emergency Repair Kit hasn't found any critical issues within your phpBB installation.", true);