commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/include/bugs.inc | |
|
6 |
| | |
|
7 |
| This file is part of the BQube Webmail client | |
|
8 |
| Copyright (C) 2005, BQube Dev - Switzerland | |
30233b
|
9 |
| Licensed under the GNU GPL | |
4e17e6
|
10 |
| | |
T |
11 |
| PURPOSE: | |
|
12 |
| Provide error handling and logging functions | |
|
13 |
| | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
|
|
18 |
$Id$ |
|
19 |
|
|
20 |
*/ |
|
21 |
|
|
22 |
|
|
23 |
// throw system error and show error page |
|
24 |
function raise_error($arg=array(), $log=FALSE, $terminate=FALSE) |
|
25 |
{ |
|
26 |
global $__page_content, $CONFIG, $OUTPUT, $ERROR_CODE, $ERROR_MESSAGE; |
|
27 |
|
|
28 |
/* $arg keys: |
|
29 |
int code |
|
30 |
string type (php, xpath, db, imap, javascript) |
|
31 |
string message |
|
32 |
sring file |
|
33 |
int line |
|
34 |
*/ |
|
35 |
|
|
36 |
// report bug (if not incompatible browser) |
|
37 |
if ($log && $arg['type'] && $arg['message']) |
|
38 |
log_bug($arg); |
|
39 |
|
|
40 |
// display error page and terminate script |
|
41 |
if ($terminate) |
|
42 |
{ |
|
43 |
$ERROR_CODE = $arg['code']; |
|
44 |
$ERROR_MESSAGE = $arg['message']; |
|
45 |
include("program/steps/error.inc"); |
|
46 |
exit; |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
|
|
51 |
// report error |
|
52 |
function log_bug($arg_arr) |
|
53 |
{ |
|
54 |
global $CONFIG, $INSTALL_PATH; |
|
55 |
$program = $arg_arr['type']=='xpath' ? 'XPath' : strtoupper($arg_arr['type']); |
|
56 |
|
|
57 |
// write error to local log file |
|
58 |
if ($CONFIG['debug_level'] & 1) |
|
59 |
{ |
|
60 |
$log_entry = sprintf("[%s] %s Error: %s in %s on line %d\n", |
|
61 |
date("d-M-Y H:i:s O", mktime()), |
|
62 |
$program, |
|
63 |
$arg_arr['message'], |
|
64 |
$arg_arr['file'], |
|
65 |
$arg_arr['line']); |
fd8c50
|
66 |
|
T |
67 |
if (empty($CONFIG['log_dir'])) |
|
68 |
$CONFIG['log_dir'] = $INSTALL_PATH.'logs'; |
|
69 |
|
9fc381
|
70 |
// try to open specific log file for writing |
T |
71 |
if ($fp = @fopen($CONFIG['log_dir'].'/errors', 'a')) |
fd8c50
|
72 |
|
4e17e6
|
73 |
{ |
T |
74 |
fwrite($fp, $log_entry); |
|
75 |
fclose($fp); |
|
76 |
} |
9fc381
|
77 |
else |
T |
78 |
{ |
|
79 |
// send error to PHPs error handler |
|
80 |
trigger_error($arg_arr['message']); |
|
81 |
} |
4e17e6
|
82 |
} |
T |
83 |
|
|
84 |
/* |
|
85 |
// resport the bug to the global bug reporting system |
|
86 |
if ($CONFIG['debug_level'] & 2) |
|
87 |
{ |
|
88 |
$delm = '%AC'; |
|
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', |
|
90 |
$arg_arr['type'], |
|
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']))); |
|
100 |
} |
|
101 |
*/ |
|
102 |
|
|
103 |
// show error if debug_mode is on |
|
104 |
if ($CONFIG['debug_level'] & 4) |
|
105 |
{ |
31b2ce
|
106 |
print "<b>$program Error"; |
T |
107 |
|
|
108 |
if (!empty($arg_arr['file']) && !empty($arg_arr['line'])) |
|
109 |
print " in $arg_arr[file] ($arg_arr[line])"; |
|
110 |
|
|
111 |
print ":</b> "; |
4e17e6
|
112 |
print nl2br($arg_arr['message']); |
T |
113 |
print '<br />'; |
|
114 |
flush(); |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
|
|
119 |
?> |