From 24c91ed78e64cb20b2ba08971d2c35979a2de856 Mon Sep 17 00:00:00 2001 From: alecpl Date: Thu, 20 May 2010 08:04:25 +0000 Subject: - Moved error.inc to /utils - Removed bugs.inc (content copied into main.inc) --- program/include/bugs.inc | 106 ---------------------------------- program/include/iniset.php | 1 - program/include/main.inc | 80 +++++++++++++++++++++++++- program/steps/error.inc | 129 ------------------------------------------ program/steps/utils/error.inc | 129 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 207 insertions(+), 238 deletions(-) delete mode 100644 program/include/bugs.inc delete mode 100644 program/steps/error.inc create mode 100644 program/steps/utils/error.inc diff --git a/program/include/bugs.inc b/program/include/bugs.inc deleted file mode 100644 index cf5855e8e..000000000 --- a/program/include/bugs.inc +++ /dev/null @@ -1,106 +0,0 @@ - | - +-----------------------------------------------------------------------+ - - $Id$ - -*/ - - -/** - * Error handling and logging functions - * - * @package Core - */ - - -/** - * Throw system error and show error page - * - * @param array Named parameters - * - code: Error code (required) - * - type: Error type [php|db|imap|javascript] (required) - * - message: Error message - * - file: File where error occured - * - line: Line where error occured - * @param boolean True to log the error - * @param boolean Terminate script execution - */ -function raise_error($arg=array(), $log=false, $terminate=false) -{ - global $__page_content, $CONFIG, $OUTPUT, $ERROR_CODE, $ERROR_MESSAGE; - - // report bug (if not incompatible browser) - if ($log && $arg['type'] && $arg['message']) - log_bug($arg); - - // display error page and terminate script - if ($terminate) { - $ERROR_CODE = $arg['code']; - $ERROR_MESSAGE = $arg['message']; - include("program/steps/error.inc"); - exit; - } -} - - -/** - * Report error according to configured debug_level - * - * @param array Named parameters - * @see raise_error() - */ -function log_bug($arg_arr) -{ - global $CONFIG; - $program = strtoupper($arg_arr['type']); - - // write error to local log file - if ($CONFIG['debug_level'] & 1) { - $post_query = ($_SERVER['REQUEST_METHOD'] == 'POST' ? '?_task='.urlencode($_POST['_task']).'&_action='.urlencode($_POST['_action']) : ''); - $log_entry = sprintf("%s Error: %s%s (%s %s)", - $program, - $arg_arr['message'], - $arg_arr['file'] ? sprintf(' in %s on line %d', $arg_arr['file'], $arg_arr['line']) : '', - $_SERVER['REQUEST_METHOD'], - $_SERVER['REQUEST_URI'] . $post_query); - - if (!write_log('errors', $log_entry)) { - // send error to PHPs error handler if write_log didn't succeed - trigger_error($arg_arr['message']); - } - } - - // resport the bug to the global bug reporting system - if ($CONFIG['debug_level'] & 2) { - // TODO: Send error via HTTP - } - - // show error if debug_mode is on - if ($CONFIG['debug_level'] & 4) { - print "$program Error"; - - if (!empty($arg_arr['file']) && !empty($arg_arr['line'])) - print " in $arg_arr[file] ($arg_arr[line])"; - - print ': '; - print nl2br($arg_arr['message']); - print '
'; - flush(); - } -} - -?> diff --git a/program/include/iniset.php b/program/include/iniset.php index 29b2cce87..3887fa5f3 100755 --- a/program/include/iniset.php +++ b/program/include/iniset.php @@ -123,6 +123,5 @@ function rcube_pear_error($err) PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'rcube_pear_error'); // include global functions -require_once 'include/bugs.inc'; require_once 'include/main.inc'; require_once 'include/rcube_shared.inc'; diff --git a/program/include/main.inc b/program/include/main.inc index 004212ff8..409d6eed2 100644 --- a/program/include/main.inc +++ b/program/include/main.inc @@ -1618,16 +1618,92 @@ function check_email($email, $dns_check=true) class rcube_base_replacer { private $base_url; - + public function __construct($base) { $this->base_url = $base; } - + public function callback($matches) { return $matches[1] . '="' . make_absolute_url($matches[3], $this->base_url) . '"'; } } +/** + * Throw system error and show error page + * + * @param array Named parameters + * - code: Error code (required) + * - type: Error type [php|db|imap|javascript] (required) + * - message: Error message + * - file: File where error occured + * - line: Line where error occured + * @param boolean True to log the error + * @param boolean Terminate script execution + */ +function raise_error($arg=array(), $log=false, $terminate=false) +{ + global $__page_content, $CONFIG, $OUTPUT, $ERROR_CODE, $ERROR_MESSAGE; + + // report bug (if not incompatible browser) + if ($log && $arg['type'] && $arg['message']) + log_bug($arg); + + // display error page and terminate script + if ($terminate) { + $ERROR_CODE = $arg['code']; + $ERROR_MESSAGE = $arg['message']; + include('program/steps/utils/error.inc'); + exit; + } +} + + +/** + * Report error according to configured debug_level + * + * @param array Named parameters + * @see raise_error() + */ +function log_bug($arg_arr) +{ + global $CONFIG; + $program = strtoupper($arg_arr['type']); + + // write error to local log file + if ($CONFIG['debug_level'] & 1) { + $post_query = ($_SERVER['REQUEST_METHOD'] == 'POST' ? '?_task='.urlencode($_POST['_task']).'&_action='.urlencode($_POST['_action']) : ''); + $log_entry = sprintf("%s Error: %s%s (%s %s)", + $program, + $arg_arr['message'], + $arg_arr['file'] ? sprintf(' in %s on line %d', $arg_arr['file'], $arg_arr['line']) : '', + $_SERVER['REQUEST_METHOD'], + $_SERVER['REQUEST_URI'] . $post_query); + + if (!write_log('errors', $log_entry)) { + // send error to PHPs error handler if write_log didn't succeed + trigger_error($arg_arr['message']); + } + } + + // resport the bug to the global bug reporting system + if ($CONFIG['debug_level'] & 2) { + // TODO: Send error via HTTP + } + + // show error if debug_mode is on + if ($CONFIG['debug_level'] & 4) { + print "$program Error"; + + if (!empty($arg_arr['file']) && !empty($arg_arr['line'])) + print " in $arg_arr[file] ($arg_arr[line])"; + + print ': '; + print nl2br($arg_arr['message']); + print '
'; + flush(); + } +} + ?> diff --git a/program/steps/error.inc b/program/steps/error.inc deleted file mode 100644 index f8bb8461d..000000000 --- a/program/steps/error.inc +++ /dev/null @@ -1,129 +0,0 @@ - | - +-----------------------------------------------------------------------+ - - $Id$ - -*/ - - -// browser is not compatible with this application -if ($ERROR_CODE==409) { - $user_agent = $GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT']; - $__error_title = 'Your browser does not suit the requirements for this application'; - $__error_text = <<Supported browsers:
-»  Netscape 7+
-»  Microsoft Internet Explorer 6+
-»  Mozilla Firefox 1.0+
-»  Opera 8.0+
-»  Safari 1.2+
-
-»  JavaScript enabled
-»  Support for XMLHTTPRequest
- -

Your configuration:
-$user_agent

-EOF; -} - -// authorization error -else if ($ERROR_CODE==401) { - $__error_title = "AUTHORIZATION FAILED"; - $__error_text = "Could not verify that you are authorized to access this service!
\n". - "Please contact your server-administrator."; -} - -// failed request (wrong step in URL) -else if ($ERROR_CODE==404) { - $__error_title = "REQUEST FAILED/FILE NOT FOUND"; - $request_url = htmlentities($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); - $__error_text = << -Please contact your server-administrator. - -

Failed request:
-http://$request_url

-EOF; -} - -// database connection error -else if ($ERROR_CODE==601) -{ - $__error_title = "CONFIGURATION ERROR"; - $__error_text = nl2br($ERROR_MESSAGE) . "
Please read the INSTALL instructions!"; -} - -// database connection error -else if ($ERROR_CODE==603) { - $__error_title = "DATABASE ERROR: CONNECTION FAILED!"; - $__error_text = "Unable to connect to the database!
Please contact your server-administrator."; -} - -// system error -else { - $__error_title = "SERVICE CURRENTLY NOT AVAILABLE!"; - $__error_text = "Please contact your server-administrator."; - - if (($CONFIG['debug_level'] & 4) && $ERROR_MESSAGE) - $__error_text = $ERROR_MESSAGE; - else - $__error_text = sprintf('Error No. [%s]', $ERROR_CODE); -} - - -// Ajax request -if ($OUTPUT && ($OUTPUT instanceof rcube_json_output)) { - header("HTTP/1.0 $ERROR_CODE $__error_title"); - die; -} - -// compose page content -$__page_content = << -

$__error_title

-

$__error_text

- -EOF; - -if ($OUTPUT && $OUTPUT->template_exists('error')) { - $OUTPUT->reset(); - $OUTPUT->send('error'); -} - -$__skin = $CONFIG->skin ? $CONFIG->skin : 'default'; - -// print system error page -print << - -RoundCube|Mail : ERROR $ERROR_CODE - - - - -
- -$__page_content - -
- - - -EOF; - -exit; -?> diff --git a/program/steps/utils/error.inc b/program/steps/utils/error.inc new file mode 100644 index 000000000..364c953e7 --- /dev/null +++ b/program/steps/utils/error.inc @@ -0,0 +1,129 @@ + | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + + +// browser is not compatible with this application +if ($ERROR_CODE==409) { + $user_agent = $GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT']; + $__error_title = 'Your browser does not suit the requirements for this application'; + $__error_text = <<Supported browsers:
+»  Netscape 7+
+»  Microsoft Internet Explorer 6+
+»  Mozilla Firefox 1.0+
+»  Opera 8.0+
+»  Safari 1.2+
+
+»  JavaScript enabled
+»  Support for XMLHTTPRequest
+ +

Your configuration:
+$user_agent

+EOF; +} + +// authorization error +else if ($ERROR_CODE==401) { + $__error_title = "AUTHORIZATION FAILED"; + $__error_text = "Could not verify that you are authorized to access this service!
\n". + "Please contact your server-administrator."; +} + +// failed request (wrong step in URL) +else if ($ERROR_CODE==404) { + $__error_title = "REQUEST FAILED/FILE NOT FOUND"; + $request_url = htmlentities($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); + $__error_text = << +Please contact your server-administrator. + +

Failed request:
+http://$request_url

+EOF; +} + +// database connection error +else if ($ERROR_CODE==601) +{ + $__error_title = "CONFIGURATION ERROR"; + $__error_text = nl2br($ERROR_MESSAGE) . "
Please read the INSTALL instructions!"; +} + +// database connection error +else if ($ERROR_CODE==603) { + $__error_title = "DATABASE ERROR: CONNECTION FAILED!"; + $__error_text = "Unable to connect to the database!
Please contact your server-administrator."; +} + +// system error +else { + $__error_title = "SERVICE CURRENTLY NOT AVAILABLE!"; + $__error_text = "Please contact your server-administrator."; + + if (($CONFIG['debug_level'] & 4) && $ERROR_MESSAGE) + $__error_text = $ERROR_MESSAGE; + else + $__error_text = sprintf('Error No. [%s]', $ERROR_CODE); +} + + +// Ajax request +if ($OUTPUT && ($OUTPUT instanceof rcube_json_output)) { + header("HTTP/1.0 $ERROR_CODE $__error_title"); + die; +} + +// compose page content +$__page_content = << +

$__error_title

+

$__error_text

+ +EOF; + +if ($OUTPUT && $OUTPUT->template_exists('error')) { + $OUTPUT->reset(); + $OUTPUT->send('error'); +} + +$__skin = $CONFIG->skin ? $CONFIG->skin : 'default'; + +// print system error page +print << + +RoundCube|Mail : ERROR $ERROR_CODE + + + + +
+ +$__page_content + +
+ + + +EOF; + +exit; +?> -- cgit v1.2.3