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