/**
* Error and message handler, call with trigger_error if read
*/
function msg_handler($errno, $msg_text, $errfile, $errline)
{
    global $cache, $db, $auth, $template, $config, $user, $request;
    global $phpEx, $phpbb_root_path, $msg_title, $msg_long_text;
    // 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;
    }
    // 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 = phpbb_filter_root_path($errfile);
                $msg_text = phpbb_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') || isset($auth) && $auth->acl_get('a_')) {
                $msg_text = $log_text;
                // If this is defined there already was some output
                // So let's not break it
                if (defined('IN_DB_UPDATE')) {
                    echo '<div class="errorbox">' . $msg_text . '</div>';
                    $db->sql_return_on_error(true);
                    phpbb_end_update($cache, $config);
                }
            }
            if ((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
            send_status_line(503, 'Service Unavailable');
            garbage_collection();
            // Try to not call the adm page data...
            echo '<!DOCTYPE html>';
            echo '<html dir="ltr">';
            echo '<head>';
            echo '<meta charset="utf-8">';
            echo '<meta http-equiv="X-UA-Compatible" content="IE=edge">';
            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="https://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Limited';
            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') {
                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);
                }
            }
            $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));
            if ($request->is_ajax()) {
                global $refresh_data;
                $json_response = new \phpbb\json_response();
                $json_response->send(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, 'REFRESH_DATA' => !empty($refresh_data) ? $refresh_data : null));
            }
            // 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 #2
0
//  than the max execution time)
@set_time_limit(0);
while (!$migrator->finished()) {
    try {
        $migrator->update();
    } catch (\phpbb\db\migration\exception $e) {
        echo $e->getLocalisedMessage($user);
        phpbb_end_update($cache, $config);
    }
    $state = array_merge(array('migration_schema_done' => false, 'migration_data_done' => false), $migrator->last_run_migration['state']);
    // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
    if (time() - $update_start_time >= $safe_time_limit) {
        echo '<br />' . $user->lang['DATABASE_UPDATE_NOT_COMPLETED'] . '<br /><br />';
        echo '<a href="' . append_sid($phpbb_root_path . 'install/database_update.' . $phpEx, 'type=' . $request->variable('type', 0) . '&amp;language=' . $request->variable('language', 'en')) . '" class="button1">' . $user->lang['DATABASE_UPDATE_CONTINUE'] . '</a>';
        phpbb_end_update($cache, $config);
    }
}
if ($orig_version != $config['version']) {
    $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_UPDATE_DATABASE', false, array($orig_version, $config['version']));
}
echo $user->lang['DATABASE_UPDATE_COMPLETE'] . '<br />';
if ($request->variable('type', 0)) {
    echo $user->lang['INLINE_UPDATE_SUCCESSFUL'] . '<br /><br />';
    echo '<a href="' . append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=update&amp;sub=update_db&amp;language=' . $request->variable('language', 'en')) . '" class="button1">' . $user->lang['CONTINUE_UPDATE_NOW'] . '</a>';
} else {
    echo '<div class="errorbox">' . $user->lang['UPDATE_FILES_NOTICE'] . '</div>';
    echo $user->lang['COMPLETE_LOGIN_TO_BOARD'];
}
$config->delete('version_update_from');
phpbb_end_update($cache, $config);