Backtrace:
\n\n";
foreach( $backtrace as $trace => $frame )
{
// 2 is the file that actually died. We don't need to list the error handlers in the trace.
if( $trace < 2 ) {
continue;
}
$args = array();
if( $trace > 2 ) { // The call in the error handler is irrelevent anyway, so don't bother with the arg list
if ( isset( $frame['args'] ) )
{
foreach( $frame['args'] as $arg )
{
if ( is_array( $arg ) && array_key_exists( 0, $arg ) && is_string( $arg[0] ) ) {
$argument = htmlspecialchars( $arg[0] );
} elseif( is_string( $arg ) ) {
$argument = htmlspecialchars( $arg );
} else {
$argument = NULL;
}
$args[] = "'{$argument}'";
}
}
}
$frame['class'] = (isset($frame['class'])) ? $frame['class'] : '';
$frame['type'] = (isset($frame['type'])) ? $frame['type'] : '';
$frame['file'] = (isset($frame['file'])) ? $frame['file'] : '';
$frame['line'] = (isset($frame['line'])) ? $frame['line'] : '';
$func = "";
$arg_list = implode(", ", $args);
if( $trace == 2 ) {
$func = "See above for details.";
} else {
$func = htmlspecialchars($frame['class'] . $frame['type'] . $frame['function']) . '(' . $arg_list . ')';
}
$out .= 'File: ' . $frame['file'] . "
\n";
$out .= 'Line: ' . $frame['line'] . "
\n";
$out .= 'Call: ' . $func . "
\n\n";
}
return $out;
}
function error_fatal($type, $message, $file, $line = 0)
{
global $set;
switch($type)
{
case E_USER_ERROR:
$type_str = 'Error';
break;
case E_WARNING:
case E_USER_WARNING:
$type_str = 'Warning';
break;
case E_NOTICE:
case E_USER_NOTICE:
$type_str = 'Notice';
break;
case PDNSADMIN_QUERY_ERROR:
$type_str = 'Query Error';
break;
default:
$type_str = 'Unknown Error';
}
if (strstr($file, 'eval()')) {
$split = preg_split('/[\(\)]/', $file);
$file = $split[0];
$line = $split[1];
$message .= ' (in evaluated code)';
}
$details = null;
$backtrace = null;
if (strpos($message, 'Template not found') === false) {
$backtrace = get_backtrace();
}
if ($type != PDNSADMIN_QUERY_ERROR) {
if (strpos($message, 'mysql_fetch_array(): supplied argument') === false) {
$lines = null;
$details2 = null;
if (strpos($message, 'Template not found') !== false) {
$backtrace = '';
$trace = debug_backtrace();
$file = $trace[2]['file'];
$line = $trace[2]['line'];
}
if (file_exists($file)) {
$lines = file($file);
}
if ($lines) {
$details2 = "
Code:
\n
" . error_getlines($lines, $line) . '';
}
} else {
$details2 = "
MySQL Said:
" . mysql_error() . '
\n';
}
$details .= "
$type_str [$type]:
\n
The error was reported on line $line of $file
\n\n$details2";
} else {
$details .= "
$type_str [$line]:
\n
This type of error is reported by MySQL.
Query:
$file
\n";
}
$checkbug = error_report($type, $message, $file, $line);
// IIS does not use $_SERVER['QUERY_STRING'] in the same way as Apache and might not set it
if (isset($_SERVER['QUERY_STRING'])) {
$temp_querystring = str_replace("&","&", $_SERVER['QUERY_STRING']);
} else {
$temp_querystring = '';
}
// DO NOT allow this information into the error reports!!!
$details = str_replace( $set['db_name'], "****", $details );
$details = str_replace( $set['db_pass'], "****", $details );
$details = str_replace( $set['db_user'], "****", $details );
$details = str_replace( $set['db_host'], "****", $details );
$backtrace = str_replace( $set['db_name'], "****", $backtrace );
$backtrace = str_replace( $set['db_pass'], "****", $backtrace );
$backtrace = str_replace( $set['db_user'], "****", $backtrace );
$backtrace = str_replace( $set['db_host'], "****", $backtrace );
// Don't send it if this isn't available. Spamming mail servers is a bad bad thing.
// This will also email the user agent string, in case errors are being generated by evil bots.
if( isset($set['admin_email']) ) {
$mailer = new mailer($set['admin_email'], $set['admin_email'], 'PDNS-Admin Error Module', false);
$mailer->setSubject('PDNS-Admin Error Report');
$agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'N/A';
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
$error_report = "PDNS-Admin has exited with an error!\n";
$error_report .= "The error details are as follows:\n\nURL: http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] . "\n";
$error_report .= "Querying user agent: " . $agent . "\n";
$error_report .= "Querying IP: " . $ip . "\n\n";
$error_report .= strip_tags($message) . "\n\n" . strip_tags($details) . "\n\n" . strip_tags($backtrace);
$error_report = str_replace( ' ', ' ', html_entity_decode($error_report) );
$mailer->setMessage($error_report);
$mailer->setRecipient($set['admin_email']);
$mailer->doSend();
}
return "