4 +-----------------------------------------------------------------------+
5 | program/include/bugs.inc |
7 | This file is part of the BQube Webmail client |
8 | Copyright (C) 2005, BQube Dev - Switzerland |
9 | Licensed under the GNU GPL |
12 | Provide error handling and logging functions |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: bugs.inc 347 2006-09-16 22:58:51Z estadtherr $
23 // throw system error and show error page
24 function raise_error($arg=array(), $log=FALSE, $terminate=FALSE)
26 global $__page_content, $CONFIG, $OUTPUT, $ERROR_CODE, $ERROR_MESSAGE;
30 string type (php, xpath, db, imap, javascript)
36 // report bug (if not incompatible browser)
37 if ($log && $arg['type'] && $arg['message'])
40 // display error page and terminate script
43 $ERROR_CODE = $arg['code'];
44 $ERROR_MESSAGE = $arg['message'];
45 include("program/steps/error.inc");
52 function log_bug($arg_arr)
54 global $CONFIG, $INSTALL_PATH;
55 $program = $arg_arr['type']=='xpath' ? 'XPath' : strtoupper($arg_arr['type']);
57 // write error to local log file
58 if ($CONFIG['debug_level'] & 1)
60 $log_entry = sprintf("[%s] %s Error: %s in %s on line %d\n",
61 date("d-M-Y H:i:s O", mktime()),
67 if (empty($CONFIG['log_dir']))
68 $CONFIG['log_dir'] = $INSTALL_PATH.'logs';
70 // try to open specific log file for writing
71 if ($fp = @fopen($CONFIG['log_dir'].'/errors', 'a'))
74 fwrite($fp, $log_entry);
79 // send error to PHPs error handler
80 trigger_error($arg_arr['message']);
85 // resport the bug to the global bug reporting system
86 if ($CONFIG['debug_level'] & 2)
89 http_request(sprintf('http://roundcube.net/log/bug.php?_type=%s&_domain=%s&_server_ip=%s&_client_ip=%s&_useragent=%s&_url=%s%%3A//%s&_errors=%s%s%s%s%s',
91 $GLOBALS['HTTP_HOST'],
92 $GLOBALS['SERVER_ADDR'],
93 $GLOBALS['REMOTE_ADDR'],
94 rawurlencode($GLOBALS['HTTP_USER_AGENT']),
95 $GLOBALS['SERVER_PORT']==43 ? 'https' : 'http',
96 $GLOBALS['HTTP_HOST'].$GLOBALS['REQUEST_URI'],
97 $arg_arr['file'], $delm,
98 $arg_arr['line'], $delm,
99 rawurlencode($arg_arr['message'])));
103 // show error if debug_mode is on
104 if ($CONFIG['debug_level'] & 4)
106 print "<b>$program Error";
108 if (!empty($arg_arr['file']) && !empty($arg_arr['line']))
109 print " in $arg_arr[file] ($arg_arr[line])";
112 print nl2br($arg_arr['message']);