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 }
70 /* Create header as needed */
71 if ($error_collector == ""){
73 /* Mailto body header */
74 if(function_exists("prepare4mailbody")){
75 $error_collector_mailto .=prepare4mailbody(
76 "Oups. Seems like you've catched some kind of bug inside GOsa/PHP. You may want to help ".
77 "us to improve the software stability. If so, please provide some more information below.".
78 "\n\n".
79 "*** GOsa bug report ***".
80 "\nGOsa Version: ".get_gosa_version().
81 "\nDate: ".date("d.m.Y").
82 "\nTime: ".date("H:i:s").
83 "\nUser-Agent: ".$_SERVER['HTTP_USER_AGENT']." ".
84 "(Javascript is ".( (isset($_SESSION['js']) && $_SESSION['js']==FALSE) ? "inactive" : "active" ).")".
85 "\n\n".
86 "Please describe what you did to produce this error as detailed as possible. Can you ".
87 "reproduce this bug using the demo on http://www.gosa-project.org ?".
88 "\n\n".
89 "*** PHP runtime information ***".
90 "\nPHP Version: ".phpversion().
91 "\nRunning on: ".php_uname().
92 "\nLoaded Extensions: ".print_array(get_loaded_extensions()).
93 "\nLDAP Module Version: ".get_module_setting('ldap','RCS Version').
94 "\n\n".
95 "*** PHP error information ***\n\n");
96 }
98 if (isset($_SESSION['js']) && $_SESSION['js']==FALSE){
99 $error_collector= "<div>";
100 } else {
101 $error_collector= "
102 <table summary=\"\" width=\"100%\" style='background-color:#E0E0E0;border-bottom:1px solid black;z-index:150;'>
103 <tr>
104 <td>
105 <img alt=\"\" align=\"middle\" src='".get_template_path('images/warning.png')."'>
106 <font style='font-size:14px;font-weight:bold'>".
107 _("Generating this page caused the PHP interpreter to raise some errors!")."
108 </font>
109 </td>
110 <td align=right>
111 <a href=\"mailto:gosa-bugs@oss.gonicus.de?subject=GOsa%20bugreport&body=%BUGBODY%\">
112 <img border='0' src='images/mailto.png' title='"._("Send bug report to the GOsa Team")."' class='center' alt=''> "._("Send bugreport")."
113 </a>
114 </td>
115 <td align=right>
116 <button onClick='toggle(\"errorbox\")'>".
117 _("Toggle information")."
118 </button>
119 </td>
120 </tr>
121 </table>
122 <div id='errorbox' style='position:absolute; z-index:150; visibility: hidden'>";
123 }
124 }
126 /* Create error header */
127 $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>";
129 $error_collector_mailto .= prepare4mailbody("=== Error === \n");
130 $error_collector_mailto .= prepare4mailbody("PHP error: $errstr ($errfile, line $errline)\n");
131 $error_collector_mailto .= prepare4mailbody("=== /Error === \n\n");
133 /* Extract traceback data - if available */
134 if (function_exists('debug_backtrace')){
135 $trace= debug_backtrace();
137 $error_collector_mailto .= prepare4mailbody("=== Trace ===");
139 /* Generate trace history */
140 for ($index= 0; $index<count($trace); $index++){
143 $ct= $trace[$index];
144 $loc= "";
145 if (isset($ct['class'])){
146 $loc.= _("class")." ".$ct['class'];
147 if (isset($ct['function'])){
148 $loc.= " / ";
149 }
150 }
151 if (isset($ct['function'])){
152 $loc.= _("function")." ".$ct['function'];
153 }
154 if (isset($ct['type'])){
155 switch ($ct['type']){
156 case "::":
157 $type= _("static");
158 break;
160 case "->":
161 $type= _("method");
162 break;
163 }
164 } else {
165 $type= "-";
166 }
167 $args= "";
168 if (isset($ct['args'])){
169 foreach ($ct['args'] as $arg){
171 /* Avoid convertig object to string errors */
172 if(is_object($arg)){
173 $arg = "CLASS: ".get_class($arg);
174 }
176 $args.= htmlentities("\"$arg\", ");
177 }
178 }
179 $args= preg_replace("/, $/", "", $args);
180 if ($args == ""){
181 $args= "-";
182 }
183 if(isset($ct['file'])) {
184 $file= $ct['file'];
185 }else{
186 $file="";
187 }
188 if(isset($ct['line'])) {
189 $line= $ct['line'];
190 }else{
191 $line="";
192 }
193 $color= ($index&1)?'#404040':'606060';
194 $error_collector.= "<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">"._("Trace")."[$index]: $loc</td>";
195 $error_collector.= "<td>"._("File").": $file ("._('Line')." $line)</td><td width=\"10%\">"._("Type").": $type</td></tr>";
196 $error_collector.= "<tr style='background-color:$color'><td colspan=3 style='padding-left:20px;'>"._("Arguments").": $args</td></tr>";
198 /* Add trace part to mailto body */
199 $error_collector_mailto .= prepare4mailbody(
200 "\nTrace[".$index."]:".$loc.
201 "\nFile : ".$file.
202 "\nLine : ".$line.
203 "\nType : ".$type.
204 "\n ".$args.
205 "\n");
206 }
207 }
208 $error_collector_mailto .= prepare4mailbody("=== /Trace === \n");
210 /* Close error table */
211 $error_collector.= "</table>";
213 /* Flush in case of fatal errors */
214 if (preg_match('/^fatal/i', $errstr)){
215 echo $error_collector."</div>";
216 flush();
217 exit;
218 }
219 }
222 function dummy_error_handler()
223 {
224 }
227 /* Get base dir for reference */
228 $BASE_DIR= dirname(dirname(__FILE__));
229 $ROOT_DIR= $BASE_DIR."/html";
230 error_reporting (E_ALL);
232 /* Register error handler */
233 $error_collector= "";
234 $error_collector_mailto= "";
235 set_error_handler('gosaRaiseError');
237 $variables_order= "ES";
238 ini_set("register_globals",0);
239 ini_set("track_vars",1);
240 ini_set("display_errors",1);
241 ini_set("report_memleaks",1);
242 ini_set("include_path",".:$BASE_DIR/include");
244 /* Do smarty setup */
245 require("smarty/Smarty.class.php");
246 $smarty = new Smarty;
247 $smarty->template_dir = $BASE_DIR.'/ihtml/';
248 $smarty->caching= false;
249 $smarty->php_handling= SMARTY_PHP_REMOVE;
251 /* Set timezone */
252 if (function_exists("date_default_timezone_set")){
253 date_default_timezone_set("GMT");
254 }
256 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
257 ?>