1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 function gosaRaiseError($errno, $errstr, $errfile, $errline)
22 {
23 global $error_collector,$error_collector_mailto,$config;
25 if(function_exists("gosa_log")){
26 gosa_log($errno." ".$errstr." ".$errfile." ".$errline);
27 }
29 /* Return if error reporting is set to zero */
30 if (error_reporting() == 0){
31 return;
32 }
34 /* Workaround for buggy imap_open error outputs */
35 if (preg_match('/imap_open/', $errstr)){
36 return;
37 }
39 /* FIXME: Workaround for PHP5 error message flooding. The new OOM
40 code want's us to use public/protected/private instead of flat
41 var declarations. For now I can't workaround this - let's ignore
42 the messages till the next major release which may drop support
43 for PHP4. */
44 if (preg_match('/var: Deprecated./', $errstr)){
45 return;
46 }
48 /* FIXME: Same as above. Compatibility does error flooding.*/
49 if (preg_match('/zend.ze1_compatibility_mode/', $errstr)){
50 return;
51 }
53 /* Hide ldap size limit messages */
54 if (preg_match('/ldap_error/', $errstr)){
55 if (preg_match('/sizelimit/', $errstr)){
56 return;
57 }
58 }
60 if((isset($config->data))){
61 if((isset($config->data['MAIN']['DISPLAYERRORS']))&&(!preg_match("/^true$/i",$config->data['MAIN']['DISPLAYERRORS']))){
63 /* Write to syslog */
64 gosa_log ("PHP error: $errstr ($errfile, line $errline)");
65 return;
66 }
67 }
69 /* Hide timezone warnings, gosa */
70 if(preg_match("/date.timezone/",$errstr)){
72 $tmp= get_default_timezone();
73 echo $tmp['name'];
74 echo $errfile;
75 echo "<br>";
76 return;
77 }
80 /* Create header as needed */
81 if ($error_collector == ""){
83 /* Mailto body header */
84 if(function_exists("prepare4mailbody")){
85 $error_collector_mailto .=prepare4mailbody(
86 "Oups. Seems like you've catched some kind of bug inside GOsa/PHP. You may want to help ".
87 "us to improve the software stability. If so, please provide some more information below.".
88 "\n\n".
89 "*** GOsa bug report ***".
90 "\nGOsa Version: ".get_gosa_version().
91 "\nDate: ".date("d.m.Y").
92 "\nTime: ".date("H:i:s").
93 "\nUser-Agent: ".$_SERVER['HTTP_USER_AGENT']." ".
94 "(Javascript is ".( (isset($_SESSION['js']) && $_SESSION['js']==FALSE) ? "inactive" : "active" ).")".
95 "\n\n".
96 "Please describe what you did to produce this error as detailed as possible. Can you ".
97 "reproduce this bug using the demo on http://www.gosa-project.org ?".
98 "\n\n".
99 "*** PHP runtime information ***".
100 "\nPHP Version: ".phpversion().
101 "\nRunning on: ".php_uname().
102 "\nLoaded Extensions: ".print_array(get_loaded_extensions()).
103 "\nLDAP Module Version: ".get_module_setting('ldap','RCS Version').
104 "\n\n".
105 "*** PHP error information ***\n\n");
106 }
108 if (isset($_SESSION['js']) && $_SESSION['js']==FALSE){
109 $error_collector= "<div>";
110 } else {
111 $error_collector= "
112 <table summary=\"\" width=\"100%\" style='background-color:#E0E0E0;border-bottom:1px solid black;z-index:150;'>
113 <tr>
114 <td>
115 <img alt=\"\" align=\"middle\" src='".get_template_path('images/warning.png')."'>
116 <font style='font-size:14px;font-weight:bold'>".
117 _("Generating this page caused the PHP interpreter to raise some errors!")."
118 </font>
119 </td>
120 <td align=right>
121 <a href=\"mailto:gosa-bugs@oss.gonicus.de?subject=GOsa%20bugreport&body=%BUGBODY%\">
122 <img border='0' src='images/mailto.png' title='"._("Send bug report to the GOsa Team")."' class='center' alt=''> "._("Send bugreport")."
123 </a>
124 </td>
125 <td align=right>
126 <button onClick='toggle(\"errorbox\")'>".
127 _("Toggle information")."
128 </button>
129 </td>
130 </tr>
131 </table>
132 <div id='errorbox' style='position:absolute; z-index:150; visibility: hidden'>";
133 }
134 }
136 /* Create error header */
137 $error_collector.= "<table summary=\"\" width=\"100%\" cellspacing=0 style='background-color:#402005;color:white;border:2px solid red'><tr><td colspan=3><h1 style='color:white'>"._("PHP error")." \"$errstr\"</h1></td></tr>";
139 $error_collector_mailto .= prepare4mailbody("=== Error === \n");
140 $error_collector_mailto .= prepare4mailbody("PHP error: $errstr ($errfile, line $errline)\n");
141 $error_collector_mailto .= prepare4mailbody("=== /Error === \n\n");
143 /* Extract traceback data - if available */
144 if (function_exists('debug_backtrace')){
145 $trace= debug_backtrace();
147 $error_collector_mailto .= prepare4mailbody("=== Trace ===");
149 /* Generate trace history */
150 for ($index= 0; $index<count($trace); $index++){
153 $ct= $trace[$index];
154 $loc= "";
155 if (isset($ct['class'])){
156 $loc.= _("class")." ".$ct['class'];
157 if (isset($ct['function'])){
158 $loc.= " / ";
159 }
160 }
161 if (isset($ct['function'])){
162 $loc.= _("function")." ".$ct['function'];
163 }
164 if (isset($ct['type'])){
165 switch ($ct['type']){
166 case "::":
167 $type= _("static");
168 break;
170 case "->":
171 $type= _("method");
172 break;
173 }
174 } else {
175 $type= "-";
176 }
177 $args= "";
178 if (isset($ct['args'])){
179 foreach ($ct['args'] as $arg){
181 /* Avoid convertig object to string errors */
182 if(is_object($arg)){
183 $arg = "CLASS: ".get_class($arg);
184 }
186 $args.= htmlentities("\"$arg\", ");
187 }
188 }
189 $args= preg_replace("/, $/", "", $args);
190 if ($args == ""){
191 $args= "-";
192 }
193 if(isset($ct['file'])) {
194 $file= $ct['file'];
195 }else{
196 $file="";
197 }
198 if(isset($ct['line'])) {
199 $line= $ct['line'];
200 }else{
201 $line="";
202 }
203 $color= ($index&1)?'#404040':'606060';
204 $error_collector.= "<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">"._("Trace")."[$index]: $loc</td>";
205 $error_collector.= "<td>"._("File").": $file ("._('Line')." $line)</td><td width=\"10%\">"._("Type").": $type</td></tr>";
206 $error_collector.= "<tr style='background-color:$color'><td colspan=3 style='padding-left:20px;'>"._("Arguments").": $args</td></tr>";
208 /* Add trace part to mailto body */
209 $error_collector_mailto .= prepare4mailbody(
210 "\nTrace[".$index."]:".$loc.
211 "\nFile : ".$file.
212 "\nLine : ".$line.
213 "\nType : ".$type.
214 "\n ".$args.
215 "\n");
216 }
217 }
218 $error_collector_mailto .= prepare4mailbody("=== /Trace === \n");
220 /* Close error table */
221 $error_collector.= "</table>";
223 /* Flush in case of fatal errors */
224 if (preg_match('/^fatal/i', $errstr)){
225 echo $error_collector."</div>";
226 flush();
227 exit;
228 }
229 }
232 function dummy_error_handler()
233 {
234 }
237 /* Get base dir for reference */
238 $BASE_DIR= dirname(dirname(__FILE__));
239 $ROOT_DIR= $BASE_DIR."/html";
240 error_reporting (E_ALL);
242 /* Register error handler */
243 $error_collector= "";
244 $error_collector_mailto= "";
245 set_error_handler('gosaRaiseError');
247 $variables_order= "ES";
248 ini_set("register_globals",0);
249 ini_set("track_vars",1);
250 ini_set("display_errors",1);
251 ini_set("report_memleaks",1);
252 ini_set("include_path",".:$BASE_DIR/include");
254 /* Do smarty setup */
255 require("smarty/Smarty.class.php");
256 $smarty = new Smarty;
257 $smarty->template_dir = $BASE_DIR.'/ihtml/';
258 $smarty->caching= false;
259 $smarty->php_handling= SMARTY_PHP_REMOVE;
261 /* Set timezone */
262 if (function_exists("date_default_timezone_set")){
263 # date_default_timezone_set("GMT");
264 }
266 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
267 ?>