예제 #1
0
/**
 * Handle errors.
 *
 * This function will handle all PHP errors thrown at it, without exposing
 * paths, and hopefully, providing much more information to Root Users than
 * the default white error page.
 *
 * This function will call out to CUSTOM_handleError if it exists, but, be
 * advised, only override this function with a very, very stable function. I'd
 * suggest one that outputs some static, basic HTML.
 *
 * The PHP feature that allows us to do so is documented here:
 * http://uk2.php.net/manual/en/function.set-error-handler.php
 *
 * @param  int     $errno      Error Number.
 * @param  string  $errstr     Error Message.
 * @param  string  $errfile    The file the error was raised in.
 * @param  int     $errline    The line of the file that the error was raised at.
 * @param  array   $errcontext An array that points to the active symbol table at the point the error occurred.
 */
function COM_handleError($errno, $errstr, $errfile = '', $errline = 0, $errcontext = '')
{
    global $_CONF, $_USER, $LANG01;
    // Handle @ operator
    if (error_reporting() == 0) {
        return;
    }
    // Table of error code and error type
    $errorTypes = array(1 => 'E_ERROR', 2 => 'E_WARNING', 4 => 'E_PARSE', 8 => 'E_NOTICE', 16 => 'E_CORE_ERROR', 32 => 'E_CORE_WARNING', 64 => 'E_COMPILE_ERROR', 128 => 'E_COMPILE_WARNING', 256 => 'E_USER_ERROR', 512 => 'E_USER_WARNING', 1024 => 'E_USER_NOTICE', 2048 => 'E_STRICT', 4096 => 'E_RECOVERABLE_ERROR', 8192 => 'E_DEPRECATED', 16384 => 'E_USER_DEPRECATED');
    /*
     * If we have a root user, then output detailed error message:
     */
    if (is_array($_USER) && function_exists('SEC_inGroup') || isset($_CONF['rootdebug']) && $_CONF['rootdebug']) {
        if ($_CONF['rootdebug'] || SEC_inGroup('Root')) {
            header('HTTP/1.1 500 Internal Server Error');
            header('Status: 500 Internal Server Error');
            header('Content-Type: text/html; charset=' . COM_getCharset());
            $title = 'An Error Occurred';
            if (!empty($_CONF['site_name'])) {
                $title = $_CONF['site_name'] . ' - ' . $title;
            }
            echo "<html><head><title>{$title}</title></head>\n<body>\n";
            echo '<h1>An error has occurred:</h1>';
            if ($_CONF['rootdebug']) {
                echo '<h2 style="color: red">This is being displayed as "Root Debugging" is enabled
                        in your Geeklog configuration.</h2><p>If this is a production
                        website you <strong><em>must disable</em></strong> this
                        option once you have resolved any issues you are
                        investigating.</p>';
            } else {
                echo '<p>(This text is only displayed to users in the group \'Root\')</p>';
            }
            echo "<p>{$errorTypes[$errno]}({$errno}) - {$errstr} @ {$errfile} line {$errline}</p>";
            if (!function_exists('SEC_inGroup') || !SEC_inGroup('Root')) {
                if ('force' != '' . $_CONF['rootdebug']) {
                    $errcontext = COM_rootDebugClean($errcontext);
                } else {
                    echo '<h2 style="color: red">Root Debug is set to "force", this
                    means that passwords and session cookies are exposed in this
                    message!!!</h2>';
                }
            }
            if (@ini_get('xdebug.default_enable') == 1) {
                ob_start();
                var_dump($errcontext);
                $errcontext = ob_get_contents();
                ob_end_clean();
                echo "{$errcontext}</body></html>";
            } else {
                $btr = debug_backtrace();
                if (count($btr) > 0) {
                    if ($btr[0]['function'] == 'COM_handleError') {
                        array_shift($btr);
                    }
                }
                if (count($btr) > 0) {
                    echo "<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>\n";
                    echo "<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>\n";
                    echo "<tr><th align='right' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>File</th><th align='right' bgcolor='#eeeeec'>Line</th></tr>\n";
                    $i = 1;
                    foreach ($btr as $b) {
                        $f = '';
                        if (!empty($b['file'])) {
                            $f = $b['file'];
                        }
                        $l = '';
                        if (!empty($b['line'])) {
                            $l = $b['line'];
                        }
                        echo "<tr><td bgcolor='#eeeeec' align='right'>{$i}</td><td bgcolor='#eeeeec'>{$b['function']}</td><td bgcolor='#eeeeec'>{$f}</td><td bgcolor='#eeeeec' align='right'>{$l}</td></tr>\n";
                        $i++;
                        if ($i > 100) {
                            echo "<tr><td bgcolor='#eeeeec' align='left' colspan='4'>Possible recursion - aborting.</td></tr>\n";
                            break;
                        }
                    }
                    echo "</table></font>\n";
                }
                echo '<pre>';
                ob_start();
                var_dump($errcontext);
                $errcontext = htmlspecialchars(ob_get_contents());
                ob_end_clean();
                echo "{$errcontext}</pre></body></html>";
            }
            exit;
        }
    }
    /* If there is a custom error handler, fail over to that, but only
     * if the error wasn't in lib-custom.php
     */
    if (is_array($_CONF) && !strstr($errfile, 'lib-custom.php')) {
        if (array_key_exists('path_system', $_CONF)) {
            if (file_exists($_CONF['path_system'] . 'lib-custom.php')) {
                require_once $_CONF['path_system'] . 'lib-custom.php';
            }
            if (function_exists('CUSTOM_handleError')) {
                CUSTOM_handleError($errno, $errstr, $errfile, $errline, $errcontext);
                exit;
            }
        }
    }
    // if we do not throw the error back to an admin, still log it in the error.log
    COM_errorLog("{$errorTypes[$errno]}({$errno}) - {$errstr} @ {$errfile} line {$errline}", 1);
    header('HTTP/1.1 500 Internal Server Error');
    header('Status: 500 Internal Server Error');
    header('Content-Type: text/html; charset=' . COM_getCharset());
    // Does the theme implement an error message html file?
    if (!empty($_CONF['path_layout']) && file_exists($_CONF['path_layout'] . 'errormessage.html')) {
        // NOTE: NOT A TEMPLATE! JUST HTML!
        include $_CONF['path_layout'] . 'errormessage.html';
    } elseif (!empty($_CONF['path_layout_default']) && file_exists($_CONF['path_layout_default'] . 'errormessage.html')) {
        // NOTE: NOT A TEMPLATE! JUST HTML!
        include $_CONF['path_layout_default'] . 'errormessage.html';
    } else {
        // Otherwise, display simple error message
        $title = $LANG01[141];
        if (!empty($_CONF['site_name'])) {
            $title = $_CONF['site_name'] . ' - ' . $title;
        }
        echo "\n        <html>\n            <head>\n                <title>{$title}</title>\n            </head>\n            <body>\n            <div style=\"width: 100%; text-align: center;\">\n            {$LANG01[142]}\n            </div>\n            </body>\n        </html>\n        ";
    }
    exit;
}
예제 #2
0
/**
 * Handle errors.
 *
 * This function will handle all PHP errors thrown at it, without exposing
 * paths, and hopefully, providing much more information to Root Users than
 * the default white error page.
 *
 * This function will call out to CUSTOM_handleError if it exists, but, be
 * advised, only override this function with a very, very stable function. I'd
 * suggest one that outputs some static, basic HTML.
 *
 * The PHP feature that allows us to do so is documented here:
 * http://uk2.php.net/manual/en/function.set-error-handler.php
 *
 * @param  int     $errno      Error Number.
 * @param  string  $errstr     Error Message.
 * @param  string  $errfile    The file the error was raised in.
 * @param  int     $errline    The line of the file that the error was raised at.
 * @param  array   $errcontext An array that points to the active symbol table at the point the error occurred.
 */
function COM_handleError($errno, $errstr, $errfile = '', $errline = 0, $errcontext = '')
{
    global $_CONF, $_USER;
    // Handle @ operator
    if (error_reporting() == 0) {
        return;
    }
    /*
     * If we have a root user, then output detailed error message:
     */
    if (is_array($_USER) && function_exists('SEC_inGroup') || isset($_CONF['rootdebug']) && $_CONF['rootdebug']) {
        if ($_CONF['rootdebug'] || SEC_inGroup('Root')) {
            header('HTTP/1.1 500 Internal Server Error');
            header('Status: 500 Internal Server Error');
            $title = 'An Error Occurred';
            if (!empty($_CONF['site_name'])) {
                $title = $_CONF['site_name'] . ' - ' . $title;
            }
            echo "<html><head><title>{$title}</title></head>\n<body>\n";
            echo '<h1>An error has occurred:</h1>';
            if ($_CONF['rootdebug']) {
                echo '<h2 style="color: red">This is being displayed as "Root Debugging" is enabled
                        in your Geeklog configuration.</h2><p>If this is a production
                        website you <strong><em>must disable</em></strong> this
                        option once you have resolved any issues you are
                        investigating.</p>';
            } else {
                echo '<p>(This text is only displayed to users in the group \'Root\')</p>';
            }
            echo "<p>{$errno} - {$errstr} @ {$errfile} line {$errline}</p>";
            if (!function_exists('SEC_inGroup') || !SEC_inGroup('Root')) {
                if ('force' != '' . $_CONF['rootdebug']) {
                    $errcontext = COM_rootDebugClean($errcontext);
                } else {
                    echo '<h2 style="color: red">Root Debug is set to "force", this
                    means that passwords and session cookies are exposed in this
                    message!!!</h2>';
                }
            }
            if (@ini_get('xdebug.default_enable') == 1) {
                ob_start();
                var_dump($errcontext);
                $errcontext = ob_get_contents();
                ob_end_clean();
                echo "{$errcontext}</body></html>";
            } else {
                echo '<pre>';
                ob_start();
                var_dump($errcontext);
                $errcontext = htmlspecialchars(ob_get_contents());
                ob_end_clean();
                echo "{$errcontext}</pre></body></html>";
            }
            exit;
        }
    }
    /* If there is a custom error handler, fail over to that, but only
     * if the error wasn't in lib-custom.php
     */
    if (is_array($_CONF) && !strstr($errfile, 'lib-custom.php')) {
        if (array_key_exists('path_system', $_CONF)) {
            if (file_exists($_CONF['path_system'] . 'lib-custom.php')) {
                require_once $_CONF['path_system'] . 'lib-custom.php';
            }
            if (function_exists('CUSTOM_handleError')) {
                CUSTOM_handleError($errno, $errstr, $errfile, $errline, $errcontext);
                exit;
            }
        }
    }
    // if we do not throw the error back to an admin, still log it in the error.log
    COM_errorLog("{$errno} - {$errstr} @ {$errfile} line {$errline}", 1);
    header('HTTP/1.1 500 Internal Server Error');
    header('Status: 500 Internal Server Error');
    // Does the theme implement an error message html file?
    if (!empty($_CONF['path_layout']) && file_exists($_CONF['path_layout'] . 'errormessage.html')) {
        // NOTE: NOT A TEMPLATE! JUST HTML!
        include $_CONF['path_layout'] . 'errormessage.html';
    } else {
        // Otherwise, display simple error message
        $title = 'An Error Occurred';
        if (!empty($_CONF['site_name'])) {
            $title = $_CONF['site_name'] . ' - ' . $title;
        }
        echo "\n        <html>\n            <head>\n                <title>{$title}</title>\n            </head>\n            <body>\n            <div style=\"width: 100%; text-align: center;\">\n            Unfortunately, an error has occurred rendering this page. Please try\n            again later.\n            </div>\n            </body>\n        </html>\n        ";
    }
    exit;
}
예제 #3
0
/**
 * Handle errors.
 *
 * This function will handle all PHP errors thrown at it, without exposing
 * paths, and hopefully, providing much more information to Root Users than
 * the default white error page.
 *
 * This function will call out to CUSTOM_handleError if it exists, but, be
 * advised, only override this function with a very, very stable function. I'd
 * suggest one that outputs some static, basic HTML.
 *
 * The PHP feature that allows us to do so is documented here:
 * http://uk2.php.net/manual/en/function.set-error-handler.php
 *
 * @param  int     $errno      Error Number.
 * @param  string  $errstr     Error Message.
 * @param  string  $errfile    The file the error was raised in.
 * @param  int     $errline    The line of the file that the error was raised at.
 * @param  array   $errcontext An array that points to the active symbol table at the point the error occurred.
 */
function COM_handleError($errno, $errstr, $errfile = '', $errline = 0, $errcontext = '')
{
    global $_CONF, $_USER, $_SYSTEM;
    // Handle @ operator
    if (error_reporting() == 0) {
        return;
    }
    /*
     * If we have a root user, then output detailed error message:
     */
    if (is_array($_USER) && function_exists('SEC_inGroup') || isset($_SYSTEM['rootdebug']) && $_SYSTEM['rootdebug']) {
        if ($_SYSTEM['rootdebug'] || SEC_inGroup('Root')) {
            $title = 'An Error Occurred';
            if (!empty($_CONF['site_name'])) {
                $title = $_CONF['site_name'] . ' - ' . $title;
            }
            echo "<html><head><title>{$title}</title></head>\n<body>\n";
            echo '<h1>An error has occurred:</h1>';
            if ($_SYSTEM['rootdebug']) {
                echo '<h2 style="color: red">This is being displayed as "Root Debugging" is enabled
                        in your glFusion siteconfig.php.</h2><p>If this is a production
                        website you <strong><em>should disable</em></strong> this
                        option once you have resolved any issues you are
                        troubleshooting.</p>';
            } else {
                echo '<p>(This text is only displayed to users in the group \'Root\')</p>';
            }
            echo "<p>{$errno} - {$errstr} @ {$errfile} line {$errline}</p>";
            if (!function_exists('SEC_inGroup') || !SEC_inGroup('Root')) {
                if ('force' != '' . $_SYSTEM['rootdebug']) {
                    $errcontext = COM_rootDebugClean($errcontext);
                } else {
                    echo '<h2 style="color: red">Root Debug is set to "force", this
                    means that passwords and session cookies are exposed in this
                    message!!!</h2>';
                }
            }
            if (@ini_get('xdebug.default_enable') == 1) {
                ob_start();
                var_dump($errcontext);
                $errcontext = ob_get_contents();
                ob_end_clean();
                echo "{$errcontext}</body></html>";
            } else {
                $btr = debug_backtrace();
                if (count($btr) > 0) {
                    if ($btr[0]['function'] == 'COM_handleError') {
                        array_shift($btr);
                    }
                }
                if (count($btr) > 0) {
                    echo "<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>\n";
                    echo "<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>\n";
                    echo "<tr><th align='right' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>File</th><th align='right' bgcolor='#eeeeec'>Line</th></tr>\n";
                    $i = 1;
                    foreach ($btr as $b) {
                        $f = '';
                        if (!empty($b['file'])) {
                            $f = $b['file'];
                        }
                        $l = '';
                        if (!empty($b['line'])) {
                            $l = $b['line'];
                        }
                        echo "<tr><td bgcolor='#eeeeec' align='right'>{$i}</td><td bgcolor='#eeeeec'>{$b['function']}</td><td bgcolor='#eeeeec'>{$f}</td><td bgcolor='#eeeeec' align='right'>{$l}</td></tr>\n";
                        $i++;
                        if ($i > 100) {
                            echo "<tr><td bgcolor='#eeeeec' align='left' colspan='4'>Possible recursion - aborting.</td></tr>\n";
                            break;
                        }
                    }
                    echo "</table></font>\n";
                }
                echo '<pre>';
                ob_start();
                var_dump($errcontext);
                $errcontext = htmlspecialchars(ob_get_contents());
                ob_end_clean();
                echo "{$errcontext}</pre></body></html>";
            }
            exit;
        }
    }
    /* If there is a custom error handler, fail over to that, but only
     * if the error wasn't in lib-custom.php
     */
    if (is_array($_CONF) && !strstr($errfile, 'lib-custom.php')) {
        if (array_key_exists('path_system', $_CONF)) {
            if (file_exists($_CONF['path_system'] . 'lib-custom.php')) {
                require_once $_CONF['path_system'] . 'lib-custom.php';
            }
            if (function_exists('CUSTOM_handleError')) {
                CUSTOM_handleError($errno, $errstr, $errfile, $errline, $errcontext);
                exit;
            }
        }
    }
    // if we do not throw the error back to an admin, still log it in the error.log
    COM_errorLog("{$errno} - {$errstr} @ {$errfile} line {$errline}", 1);
    // Does the theme implement an error message html file?
    if (!empty($_CONF['path_layout']) && file_exists($_CONF['path_layout'] . 'errormessage.html')) {
        // NOTE: NOT A TEMPLATE! JUST HTML!
        include $_CONF['path_layout'] . 'errormessage.html';
    } else {
        // Otherwise, display simple error message
        $title = 'An Error Occurred';
        if (!empty($_CONF['site_name'])) {
            $title = $_CONF['site_name'] . ' - ' . $title;
        }
        echo "\n        <html>\n            <head>\n                <title>{$title}</title>\n            </head>\n            <body>\n            <div style=\"width: 100%; text-align: center;\">\n            There has been an error in building this page. Please try again later.\n            </div>\n            </body>\n        </html>\n        ";
    }
    exit;
}