From 9955bed2c14719b71939d4e23022738b280d8d8d Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Thu, 23 Jun 2011 16:18:48 +0200 Subject: [PATCH] Log MySQL - errors to syslog and do not print them in public, fixes #214 Signed-off-by: Florian Aders (EleRas) --- lib/classes/database/class.db.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/classes/database/class.db.php b/lib/classes/database/class.db.php index 92ba3c63..eddf89c7 100644 --- a/lib/classes/database/class.db.php +++ b/lib/classes/database/class.db.php @@ -135,7 +135,7 @@ class db } } /* - * this is not for 0.9.x + * this is not for 0.9.x */ //mysql_query("SET NAMES utf8", $this->link_id); //mysql_query("SET CHARACTER SET utf8", $this->link_id); @@ -340,27 +340,25 @@ class db { global $filename; + $text = 'MySQL - Error: ' . str_replace("\n", "\t", $errormsg); if($mysqlActive) { $this->geterrdescno(); - $errormsg.= "\n"; - $errormsg.= 'mysql error number: ' . $this->errno . "\n"; - $errormsg.= 'mysql error desc: ' . $this->errdesc . "\n"; + $text .= "; ErrNo: " . $this->errno . "; Desc: " . $this->errdesc; } - $errormsg.= 'Time/date: ' . date('d/m/Y h:i A') . "\n"; - if($filename != 'cronscript.php') { - $errormsg.= 'Script: ' . htmlspecialchars(getenv('REQUEST_URI')) . "\n"; - $errormsg.= 'Referer: ' . htmlspecialchars(getenv('HTTP_REFERER')) . "\n"; - die(nl2br($errormsg)); + $text .= "; Script: " . getenv('REQUEST_URI') . "; Ref: " . getenv('HTTP_REFERER'); } else { - $errormsg.= 'Script: -- Cronscript --' . "\n"; - die($errormsg); + $text .= "; Script: cronscript"; } + openlog("Froxlor", LOG_NDELAY, LOG_USER); + syslog(LOG_ERR, $text); + closelog(); + die("A MySQL error occured, This should not happen, a detailed description may be found in Syslog"); } }