diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index c00d0e0..6e64808 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -139,6 +139,8 @@ class LogStreamPDO extends LogStream { * @return integer Error state */ public function Verify() { + global $content, $dbmapping; + // Create DSN String $myDBDriver = $this->_logStreamConfigObj->GetPDODatabaseType(); $myDsn = $this->_logStreamConfigObj->CreateConnectDSN(); @@ -150,7 +152,7 @@ class LogStreamPDO extends LogStream { { global $extraErrorDescription; $extraErrorDescription = "PDO Database Driver not loaded: " . $myDBDriver . "
Please check your php configuration extensions"; - // $this->PrintDebugError($extraErrorDescription); +// OutputDebugMessage("LogStreamPDO|Verify: $extraErrorDescription", DEBUG_ERROR); // return error code return ERROR_DB_INVALIDDBDRIVER; @@ -165,17 +167,33 @@ class LogStreamPDO extends LogStream { catch (PDOException $e) { global $extraErrorDescription; - $extraErrorDescription = "PDO Database Connection failed: " . $e->getMessage() . "
DSN: " . $myDsn; - // $this->PrintDebugError($extraErrorDescription); + $extraErrorDescription = "PDO Database Connection failed: " . $e->getMessage(); + + // Append extra data if admin user + if ( isset($content['SESSION_ISADMIN']) && $content['SESSION_ISADMIN'] ) + $extraErrorDescription .= "
AdminDebug - DSN: " . $myDsn; + + // Debug Output +// OutputDebugMessage("LogStreamPDO|Verify: $extraErrorDescription", DEBUG_ERROR); // return error code return ERROR_DB_CONNECTFAILED; } + // Check if Table Mapping exists + if ( !isset($dbmapping[$this->_logStreamConfigObj->DBTableType]) ) + { + // Return error + return ERROR_DB_INVALIDDBMAPPING; + } + + // Check if table exists try { // This is one way to check if the table exists! But I don't really like it tbh -.- - $tmpStmnt = $this->_dbhandle->prepare("SELECT ID FROM " . $this->_logStreamConfigObj->DBTableName . " WHERE ID=1"); + $szIdField = $dbmapping[$this->_logStreamConfigObj->DBTableType][SYSLOG_UID]; + $szTestQuery = "SELECT MAX(" . $szIdField . ") FROM " . $this->_logStreamConfigObj->DBTableName; + $tmpStmnt = $this->_dbhandle->prepare( $szTestQuery ); $tmpStmnt->execute(); $colcount = $tmpStmnt->columnCount(); if ( $colcount <= 0 ) @@ -185,6 +203,7 @@ class LogStreamPDO extends LogStream { { global $extraErrorDescription; $extraErrorDescription = "Could not find table: " . $e->getMessage(); +// OutputDebugMessage("LogStreamPDO|Verify: $extraErrorDescription", DEBUG_ERROR); // return error code return ERROR_DB_TABLENOTFOUND; diff --git a/src/include/functions_common.php b/src/include/functions_common.php index 2a82d78..e9a412f 100644 --- a/src/include/functions_common.php +++ b/src/include/functions_common.php @@ -1146,6 +1146,14 @@ function GetEventTime($szTimStr) $eventtime[EVTIME_TIMEZONE] = date_default_timezone_get(); // > WTF TODO! > $out[7] $eventtime[EVTIME_MICROSECONDS] = 0; } + // Sample: 2008-02-19 + else if ( preg_match("/([0-9]{4,4})-([0-9]{1,2})-([0-9]{1,2})/", $szTimStr, $out ) ) + { + // RFC 3164 typical timestamp + $eventtime[EVTIME_TIMESTAMP] = mktime(0, 0, 0, $out[2], $out[3], $out[1]); + $eventtime[EVTIME_TIMEZONE] = date_default_timezone_get(); // WTF TODO! + $eventtime[EVTIME_MICROSECONDS] = 0; + } else { $eventtime[EVTIME_TIMESTAMP] = 0; @@ -1160,6 +1168,31 @@ function GetEventTime($szTimStr) return $eventtime; } +/* +* Helper function to output debug messages +*/ +function OutputDebugMessage($szDbg, $szDbgLevel = DEBUG_INFO) +{ + global $content; + + // Check if we should print the Error! + if ( GetConfigSetting("MiscShowDebugMsg", 0, CFGLEVEL_USER) == 1 ) + { + $content['DEBUGMSG'][] = array( + "DBGLEVEL" => $szDbgLevel, + "DBGLEVELTXT" => GetDebugModeString($szDbgLevel), + "DBGLEVELBG" => GetDebugBgColor($szDbgLevel), + "DBGMSG" => "$szDbg" + ); + } + + // Check if the user wants to syslog the error! + if ( GetConfigSetting("MiscDebugToSyslog", 0, CFGLEVEL_GLOBAL) == 1 ) + { + syslog(GetPriorityFromDebugLevel($szDbgLevel), $szDbg); + } +} + /* * GetMonthFromString * diff --git a/src/include/functions_frontendhelpers.php b/src/include/functions_frontendhelpers.php index 10c7961..310baf4 100644 --- a/src/include/functions_frontendhelpers.php +++ b/src/include/functions_frontendhelpers.php @@ -232,28 +232,6 @@ function GetFormatedDate($evttimearray) return $szDateFormatted = date("Y-m-d H:i:s", $evttimearray[EVTIME_TIMESTAMP] ); } -function OutputDebugMessage($szDbg, $szDbgLevel = DEBUG_INFO) -{ - global $content; - - // Check if we should print the Error! - if ( GetConfigSetting("MiscShowDebugMsg", 0, CFGLEVEL_USER) == 1 ) - { - $content['DEBUGMSG'][] = array( - "DBGLEVEL" => $szDbgLevel, - "DBGLEVELTXT" => GetDebugModeString($szDbgLevel), - "DBGLEVELBG" => GetDebugBgColor($szDbgLevel), - "DBGMSG" => "$szDbg" - ); - } - - // Check if the user wants to syslog the error! - if ( GetConfigSetting("MiscDebugToSyslog", 0, CFGLEVEL_GLOBAL) == 1 ) - { - syslog(GetPriorityFromDebugLevel($szDbgLevel), $szDbg); - } -} - function GetDebugBgColor( $szDebugMode ) { global $severity_colors;