]> git.donarmstrong.com Git - roundcube.git/blob - program/include/bugs.inc
Imported Upstream version 0.1~rc1~dfsg
[roundcube.git] / program / include / bugs.inc
1 <?php
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                           |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Provide error handling and logging functions                        |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id: bugs.inc 347 2006-09-16 22:58:51Z estadtherr $
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']);
66                  
67     if (empty($CONFIG['log_dir']))
68       $CONFIG['log_dir'] = $INSTALL_PATH.'logs';
69       
70     // try to open specific log file for writing
71     if ($fp = @fopen($CONFIG['log_dir'].'/errors', 'a'))
72     
73       {
74       fwrite($fp, $log_entry);
75       fclose($fp);
76       }
77     else
78       {
79       // send error to PHPs error handler
80       trigger_error($arg_arr['message']);
81       }
82     }
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     {
106     print "<b>$program Error";
107
108     if (!empty($arg_arr['file']) && !empty($arg_arr['line']))
109       print " in $arg_arr[file] ($arg_arr[line])";
110
111     print ":</b>&nbsp;";
112     print nl2br($arg_arr['message']);
113     print '<br />';
114     flush();
115     }
116   }
117
118 ?>