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 if (function_exists("get_template_path")){
106 $error_collector.= "<img alt=\"\" align=\"middle\" src='".get_template_path('images/warning.png')."'> ";
107 }
108 $error_collector.= "
109 <font style='font-size:14px;font-weight:bold'>".
110 _("Generating this page caused the PHP interpreter to raise some errors!")."
111 </font>
112 </td>
113 <td align=right>
114 <a href=\"mailto:gosa-bugs@oss.gonicus.de?subject=GOsa%20bugreport&body=%BUGBODY%\">
115 <img border='0' src='images/mailto.png' title='"._("Send bug report to the GOsa Team")."' class='center' alt=''> "._("Send bugreport")."
116 </a>
117 </td>
118 <td align=right>
119 <button onClick='toggle(\"errorbox\")'>".
120 _("Toggle information")."
121 </button>
122 </td>
123 </tr>
124 </table>
125 <div id='errorbox' style='position:absolute; z-index:150; visibility: hidden'>";
126 }
127 }
129 /* Create error header */
130 $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>";
132 $error_collector_mailto .= prepare4mailbody("=== Error === \n");
133 $error_collector_mailto .= prepare4mailbody("PHP error: $errstr ($errfile, line $errline)\n");
134 $error_collector_mailto .= prepare4mailbody("=== /Error === \n\n");
136 /* Extract traceback data - if available */
137 if (function_exists('debug_backtrace')){
138 $trace= debug_backtrace();
140 $error_collector_mailto .= prepare4mailbody("=== Trace ===");
142 /* Generate trace history */
143 for ($index= 0; $index<count($trace); $index++){
146 $ct= $trace[$index];
147 $loc= "";
148 if (isset($ct['class'])){
149 $loc.= _("class")." ".$ct['class'];
150 if (isset($ct['function'])){
151 $loc.= " / ";
152 }
153 }
154 if (isset($ct['function'])){
155 $loc.= _("function")." ".$ct['function'];
156 }
157 if (isset($ct['type'])){
158 switch ($ct['type']){
159 case "::":
160 $type= _("static");
161 break;
163 case "->":
164 $type= _("method");
165 break;
166 }
167 } else {
168 $type= "-";
169 }
170 $args= "";
171 if (isset($ct['args'])){
172 foreach ($ct['args'] as $arg){
174 /* Avoid convertig object to string errors */
175 if(is_object($arg)){
176 $arg = "CLASS: ".get_class($arg);
177 }
179 $args.= htmlentities("\"$arg\", ");
180 }
181 }
182 $args= preg_replace("/, $/", "", $args);
183 if ($args == ""){
184 $args= "-";
185 }
186 if(isset($ct['file'])) {
187 $file= $ct['file'];
188 }else{
189 $file="";
190 }
191 if(isset($ct['line'])) {
192 $line= $ct['line'];
193 }else{
194 $line="";
195 }
196 $color= ($index&1)?'#404040':'606060';
197 $error_collector.= "<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">"._("Trace")."[$index]: $loc</td>";
198 $error_collector.= "<td>"._("File").": $file ("._('Line')." $line)</td><td width=\"10%\">"._("Type").": $type</td></tr>";
199 $error_collector.= "<tr style='background-color:$color'><td colspan=3 style='padding-left:20px;'>"._("Arguments").": $args</td></tr>";
201 /* Add trace part to mailto body */
202 $error_collector_mailto .= prepare4mailbody(
203 "\nTrace[".$index."]:".$loc.
204 "\nFile : ".$file.
205 "\nLine : ".$line.
206 "\nType : ".$type.
207 "\n ".$args.
208 "\n");
209 }
210 }
211 $error_collector_mailto .= prepare4mailbody("=== /Trace === \n");
213 /* Close error table */
214 $error_collector.= "</table>";
216 /* Flush in case of fatal errors */
217 if (preg_match('/^fatal/i', $errstr)){
218 echo $error_collector."</div>";
219 flush();
220 exit;
221 }
222 }
225 function prepare4mailbody($string)
226 {
227 $string = html_entity_decode($string);
229 $from = array(
230 "/%/",
231 "/ /",
232 "/\n/",
233 "/\r/",
234 "/!/",
235 "/#/",
236 "/\*/",
237 "/\//",
238 "/</",
239 "/>/",
240 "/\?/",
241 "/\&/",
242 "/\(/",
243 "/\)/",
244 "/\"/");
246 $to = array(
247 "%25",
248 "%20",
249 "%0A",
250 "%0D",
251 "%21",
252 "%23",
253 "%2A",
254 "%2F",
255 "%3C",
256 "%3E",
257 "%3F",
258 "%38",
259 "%28",
260 "%29",
261 "%22");
263 $string = preg_replace($from,$to,$string);
265 return($string);
266 }
269 function dummy_error_handler()
270 {
271 }
274 /* Get base dir for reference */
275 $BASE_DIR= dirname(dirname(__FILE__));
276 $ROOT_DIR= $BASE_DIR."/html";
277 error_reporting (E_ALL);
279 /* Register error handler */
280 $error_collector= "";
281 $error_collector_mailto= "";
282 set_error_handler('gosaRaiseError');
284 $variables_order= "ES";
285 ini_set("register_globals",0);
286 ini_set("track_vars",1);
287 ini_set("display_errors",1);
288 ini_set("report_memleaks",1);
289 ini_set("include_path",".:$BASE_DIR/include");
291 /* Do smarty setup */
292 require("smarty/Smarty.class.php");
293 $smarty = new Smarty;
294 $smarty->template_dir = $BASE_DIR.'/ihtml/';
295 $smarty->caching= false;
296 $smarty->php_handling= SMARTY_PHP_REMOVE;
298 /* Set timezone */
299 if (function_exists("date_default_timezone_set")){
300 date_default_timezone_set("GMT");
301 }
303 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
304 ?>