26 require_once(
'variables.inc');
27 require_once(
'class_URL.inc');
34 return htmlspecialchars($str, ENT_QUOTES | ENT_HTML5,
'UTF-8');
42 return html_entity_decode($html, ENT_QUOTES | ENT_HTML5,
'UTF-8');
45 function html_trace ($errstr =
"")
49 'userinfo/loginUser' => [1],
50 'change_password' => [1],
51 'cred_decrypt' => [0, 1],
52 'LDAP/__construct' => [1],
54 if (!function_exists(
'debug_backtrace')) {
57 $trace = array_slice(debug_backtrace(), 1);
60 if (isset($trace[0][
'file'])) {
61 $loc =
' - ' . _(
'File') .
': ' . $trace[0][
'file'];
62 if (isset($trace[0][
'line'])) {
63 $loc .=
' (' . _(
'Line') .
' ' . $trace[0][
'line'] .
')';
67 $return_html =
'<table width="100%" style="background-color:#402005;color:white;border:2px solid red;border-spacing:0;border-collapse:collapse;">' .
68 '<tr><td colspan="3">' .
69 '<h1 style="color:white">' .
htmlescape(_(
'PHP error') .
' "' . $errstr .
'"' . $loc) .
'</h1>' .
71 $return_mailto = rawurlencode(
'=== Trace ===');
73 for ($index = 1, $c = count($trace); $index < $c; $index++) {
77 if (isset($ct[
'class'])) {
78 $loc .= _(
'class') .
' ' . $ct[
'class'];
79 $func .= $ct[
'class'];
80 if (isset($ct[
'function'])) {
85 if (isset($ct[
'function'])) {
86 $loc .= _(
'function') .
' ' . $ct[
'function'];
87 $func .= $ct[
'function'];
89 if (isset($ct[
'type'])) {
90 switch ($ct[
'type']) {
107 if (isset($ct[
'args'])) {
108 if (isset($hideArgs[$func])) {
109 $hideArgsIndexes = $hideArgs[$func];
111 $hideArgsIndexes = [];
113 $f =
function ($index, $arg) use (&$f, $hideArgsIndexes) {
115 if (($i == 0) && in_array($index, $hideArgsIndexes)) {
121 if (is_object($arg)) {
122 return 'CLASS: ' . get_class($arg);
123 } elseif (is_array($arg)) {
125 $ret =
'array(' . implode(
',', array_map($f, array_keys($arg), $arg)) .
')';
129 if (strlen(
"$arg") > 512) {
130 $arg = substr(
"$arg", 0, 512) .
"…";
135 $args = implode(
',', array_map($f, array_keys($ct[
'args']), $ct[
'args']));
140 if (isset($ct[
'file'])) {
145 if (isset($ct[
'line'])) {
150 $color = ($index & 1) ?
'#404040' :
'606060';
151 $return_html .=
"<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">" .
htmlescape(_(
"Trace") .
"[$index]: $loc") .
'</td>';
152 $return_html .=
"<td>" .
htmlescape(_(
"File") .
": $file (" . _(
'Line') .
" $line)") .
'</td><td width="10%">' .
htmlescape(_(
"Type") .
": $type") .
'</td></tr>';
153 $return_html .=
"<tr style='background-color:$color'><td colspan=3 style='padding-left:20px;'>" .
htmlescape(_(
"Arguments") .
": $args") .
'</td></tr>';
156 $return_mailto .= rawurlencode(
157 "\nTrace[" . $index .
"]:" . $loc .
158 "\nFile : " . $file .
159 "\nLine : " . $line .
160 "\nType : " . $type .
165 $return_html .=
"</table>";
166 $return_mailto .= rawurlencode(
"=== /Trace ===");
168 return [$return_html, $return_mailto];
184 global $error_collector, $config, $error_collector_mailto;
187 restore_error_handler();
190 if (error_reporting() == 0) {
191 set_error_handler(
'gosaRaiseError', E_WARNING | E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT);
196 if (preg_match(
'/imap_open/', $errstr)) {
197 set_error_handler(
'gosaRaiseError', E_WARNING | E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT);
202 if (preg_match(
'/ldap_error/', $errstr) && preg_match(
'/sizelimit/', $errstr)) {
203 set_error_handler(
'gosaRaiseError', E_WARNING | E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT);
208 if (class_exists(
'logging') && !preg_match(
'/No such object/', $errstr)) {
209 logging::log(
'error',
'php', $errfile, [],
'Type:' . $errno .
', Message:' . $errstr .
', File:' . $errfile .
', Line: ' . $errline);
213 if (isset($config->data) && $config->get_cfg_value(
'displayerrors') !=
'TRUE') {
214 set_error_handler(
'gosaRaiseError', E_WARNING | E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT);
219 if ($error_collector ==
"") {
226 <img src="geticon.php?context=status&icon=dialog-warning&size=16" alt="" class="center"/> 227 <strong style="font-size:14px">' .
228 htmlescape(_(
'Generating this page caused the PHP interpreter to raise some errors!')) .
' 232 <button onClick="$(\'errorbox\').toggle();">' .
239 <div id="errorbox" style="position:absolute; z-index:150; display: none;">';
242 list($html_trace, $mailto_trace) = html_trace($errstr);
243 $error_collector .= $html_trace;
247 trigger_error(
"Source error: " . $errstr .
" in " . $errfile .
" on line " . $errline);
250 $error_collector = str_replace(
'display: none;',
'', $error_collector);
252 echo $error_collector .
"</div>";
257 set_error_handler(
'gosaRaiseError', E_WARNING | E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT);
268 logging::log(
'error',
'fatal',
'', [],
'Uncaught ' . get_class($throwable) .
': ' . $throwable->getMessage());
269 }
catch (Throwable $t) {
275 $throwable->display();
277 $error =
new FatalError(
htmlescape(sprintf(_(
'Uncaught %s: %s'), get_class($throwable), $throwable->getMessage())), 0, $throwable);
280 }
catch (Throwable $t) {
282 echo
'Uncaught ' . get_class($throwable) .
': ' . $throwable->getMessage();
297 echo
"PHP version needs to be " .
PHP_MIN_VERSION .
" or above to run FusionDirectory. Aborted.";
302 date_default_timezone_set(
"GMT");
305 $BASE_DIR = dirname(dirname(__FILE__));
306 $ROOT_DIR = $BASE_DIR .
"/html";
307 error_reporting(E_ALL | E_STRICT);
310 $error_collector =
"";
311 $error_collector_mailto =
"";
313 set_error_handler(
'gosaRaiseError', E_WARNING | E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT);
314 set_exception_handler(
'fusiondirectoryExceptionHandler');
316 $variables_order =
'ES';
317 ini_set(
'track_vars',
'1');
318 ini_set(
'display_errors',
'1');
319 ini_set(
'report_memleaks',
'1');
320 ini_set(
'include_path',
".:$BASE_DIR/include:" .
PHP_DIR .
':' .
PEAR_DIR);
325 $smarty =
new Smarty;
327 $smarty->setTemplateDir($BASE_DIR .
'/ihtml/');
328 $smarty->caching = Smarty::CACHING_OFF;
329 $smarty->assign(
'css_files', []);
330 $smarty->assign(
'js_files', []);
332 $smarty->registerPlugin(
'modifier',
'base64_encode',
'base64_encode');
334 $smarty->php_handling = Smarty::PHP_REMOVE;
const PHP_DIR(isset($_SERVER['CONFIG_FILE']))
php library path
const SMARTY(!defined("CONFIG_FILE"))
Allow setting the config file in the apache configuration e.g. SetEnv CONFIG_FILE fusiondirectory...
fusiondirectoryExceptionHandler(Throwable $throwable)
Catches throwables that no one catched.
htmlescape(string $str)
Escape string for HTML output.
const PEAR_DIR
php pear path
static destroy(string $reason='')
Destroy a session.
gosaRaiseError($errno, $errstr, $errfile, $errline)
Raise an error.
static log(string $action, string $objecttype, string $object, array $changes=[], string $result='')
logging method
const PHP_MIN_VERSION
Minimum PHP version.
Fatal error class. Does not extend FusionDirectoryError.
static getSslUrl()
Returns SSL URL to redirect to.
static sslOn()
Returns TRUE if SSL was used to contact FD, whether directly or through a proxy.
dummy_error_handler()
Dummy error handler.
htmlunescape(string $html)
Unescape string for HTML output, reverse of htmlescape.
const PHP_ERROR_FATAL
Toggle crashing on PHP error, used for test suites.