From 88ff746e49e19bc6dad03442415827b5af4aa056 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Tue, 27 Jan 2009 11:52:20 +0100 Subject: [PATCH] Hardened db logstream classes against invalid parameters. Debug Messages are now printed well formated below the site content Fixed pager in detail page --- src/classes/logstreamdb.class.php | 3 +- src/classes/logstreamdisk.class.php | 7 +- src/classes/logstreampdo.class.php | 2 +- src/details.php | 83 ++++++++++++++++++----- src/include/functions_frontendhelpers.php | 69 +++++++++++++++++-- src/lang/en/main.php | 3 + src/templates/details.html | 8 +-- src/templates/include_footer.html | 16 +++++ src/templates/index.html | 4 +- 9 files changed, 165 insertions(+), 30 deletions(-) diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index 6f72064..25eddc0 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -121,6 +121,7 @@ class LogStreamDB extends LogStream { { if ($this->_dbhandle) mysql_close($this->_dbhandle); + $this->_dbhandle = null; return SUCCESS; } @@ -242,7 +243,7 @@ class LogStreamDB extends LogStream { } } - if ( $ret == SUCCESS ) + if ( $ret == SUCCESS && $this->_arrProperties != null ) { // Init and set variables foreach ( $this->_arrProperties as $property ) diff --git a/src/classes/logstreamdisk.class.php b/src/classes/logstreamdisk.class.php index 1791256..3d7ae46 100644 --- a/src/classes/logstreamdisk.class.php +++ b/src/classes/logstreamdisk.class.php @@ -288,8 +288,11 @@ class LogStreamDisk extends LogStream { // Init variables dynamically $line = ''; - foreach ( $this->_arrProperties as $property ) - $arrProperitesOut[$property] = ''; + if ( $this->_arrProperties != null ) + { + foreach ( $this->_arrProperties as $property ) + $arrProperitesOut[$property] = ''; + } do { $pos = -1; diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index c57d8df..dc12f46 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -271,7 +271,7 @@ class LogStreamPDO extends LogStream { } } - if ( $ret == SUCCESS ) + if ( $ret == SUCCESS && $this->_arrProperties != null ) { // Init and set variables foreach ( $this->_arrProperties as $property ) diff --git a/src/details.php b/src/details.php index 7266fe3..41fd3a5 100644 --- a/src/details.php +++ b/src/details.php @@ -64,6 +64,8 @@ else $content['uid_fromgetrequest'] = $content['uid_current']; // Init Pager variables +$content['uid_previous'] = UID_UNKNOWN; +$content['uid_next'] = UID_UNKNOWN; $content['uid_first'] = UID_UNKNOWN; $content['uid_last'] = UID_UNKNOWN; $content['main_pagerenabled'] = false; @@ -71,11 +73,13 @@ $content['main_pager_first_found'] = false; $content['main_pager_previous_found'] = false; $content['main_pager_next_found'] = false; $content['main_pager_last_found'] = false; +// --- -// Set Default reading direction +// --- If set read direction property! + +// Set direction default $content['read_direction'] = EnumReadDirection::Backward; -// If set read direction property! if ( isset($_GET['direction']) ) { if ( $_GET['direction'] == "next" ) @@ -88,7 +92,12 @@ if ( isset($_GET['direction']) ) $content['skiprecords'] = 1; $content['read_direction'] = EnumReadDirection::Forward; } + else if ( $_GET['direction'] == "desc" ) + { + $content['read_direction'] = EnumReadDirection::Forward; + } } +// --- // Init Sorting variables $content['sorting'] = ""; @@ -122,7 +131,7 @@ if ( isset($content['Sources'][$currentSourceID]) ) // && $content['uid_current' $res = $stream->Open( $content['AllColumns'], true ); if ( $res == SUCCESS ) { - // TODO Implement ORDER + // Set Read direction $stream->SetReadDirection($content['read_direction']); // Set current ID and init Counter @@ -279,9 +288,9 @@ if ( isset($content['Sources'][$currentSourceID]) ) // && $content['uid_current' { // Enable Pager in any case here! $content['main_pagerenabled'] = true; -/* + // --- Handle uid_first page button - if ( $content['uid_fromgetrequest'] == $content['uid_first'] ) + if ( $content['uid_fromgetrequest'] == $content['uid_first'] && $content['read_direction'] != EnumReadDirection::Forward ) $content['main_pager_first_found'] = false; else { @@ -293,32 +302,71 @@ if ( isset($content['Sources'][$currentSourceID]) ) // && $content['uid_current' $content['main_pager_first_found'] = false; } // --- -*/ + // --- Handle uid_last page button // Option the last UID from the stream! $content['uid_last'] = $stream->GetLastPageUID(); $content['uid_first'] = $stream->GetFirstPageUID(); - // --- Handle uid_first page button - if ( $content['uid_current'] == $content['uid_first'] ) + // --- Handle uid_first and uid_previousbutton + if ( $content['uid_current'] == $content['uid_first'] || !$content['main_pager_first_found'] ) + { $content['main_pager_first_found'] = false; + $content['main_pager_previous_found'] = false; + } else + { $content['main_pager_first_found'] = true; + $content['main_pager_previous_found'] = true; + } // --- - - // if we found a last uid, and if it is not the current one (which means we already are on the last page ;)! - if ( $content['uid_last'] != -1 && $content['uid_last'] != $content['uid_current']) - $content['main_pager_last_found'] = true; - else + // --- Handle uid_next and uid_last button + if ( $content['uid_current'] == $content['uid_last'] ) + { + $content['main_pager_next_found'] = false; $content['main_pager_last_found'] = false; + } + else + { + $content['main_pager_next_found'] = true; + $content['main_pager_last_found'] = true; + } + // --- + +/* + // if we found a last uid, and if it is not the current one (which means we already are on the last page ;)! + if ( $content['read_direction'] == EnumReadDirection::Forward ) + { + if ( $content['uid_last'] != UID_UNKNOWN ) + $content['main_pager_last_found'] = true; + else + $content['main_pager_last_found'] = false; + } + else + { + if ( $content['uid_last'] != $content['uid_current']) + $content['main_pager_last_found'] = true; + else + $content['main_pager_last_found'] = false; + } // --- // --- Handle uid_next page button - if ( $content['uid_current'] != $content['uid_last'] ) - $content['main_pager_next_found'] = true; + if ( $content['read_direction'] == EnumReadDirection::Forward ) + { + if ( $content['uid_current'] != UID_UNKNOWN ) + $content['main_pager_next_found'] = true; + else + $content['main_pager_next_found'] = false; + } else - $content['main_pager_next_found'] = false; + { + if ( $content['uid_current'] != $content['uid_last'] ) + $content['main_pager_next_found'] = true; + else + $content['main_pager_next_found'] = false; + } // --- // --- Handle uid_previous page button @@ -327,6 +375,9 @@ if ( isset($content['Sources'][$currentSourceID]) ) // && $content['uid_current' else $content['main_pager_previous_found'] = false; // --- + +*/ + } else // Disable pager in this case! $content['main_pagerenabled'] = false; diff --git a/src/include/functions_frontendhelpers.php b/src/include/functions_frontendhelpers.php index f288124..10c7961 100644 --- a/src/include/functions_frontendhelpers.php +++ b/src/include/functions_frontendhelpers.php @@ -234,13 +234,17 @@ function GetFormatedDate($evttimearray) function OutputDebugMessage($szDbg, $szDbgLevel = DEBUG_INFO) { + global $content; + // Check if we should print the Error! if ( GetConfigSetting("MiscShowDebugMsg", 0, CFGLEVEL_USER) == 1 ) { - print(""); - print(""); - print(""); - print("
Debugmessage: " . $szDbg . "

"); + $content['DEBUGMSG'][] = array( + "DBGLEVEL" => $szDbgLevel, + "DBGLEVELTXT" => GetDebugModeString($szDbgLevel), + "DBGLEVELBG" => GetDebugBgColor($szDbgLevel), + "DBGMSG" => "$szDbg" + ); } // Check if the user wants to syslog the error! @@ -250,6 +254,63 @@ function OutputDebugMessage($szDbg, $szDbgLevel = DEBUG_INFO) } } +function GetDebugBgColor( $szDebugMode ) +{ + global $severity_colors; + + switch ( $szDebugMode ) + { + case DEBUG_ULTRADEBUG: + $szReturn = $severity_colors[SYSLOG_DEBUG]; + break; + case DEBUG_DEBUG: + $szReturn = $severity_colors[SYSLOG_INFO]; + break; + case DEBUG_INFO: + $szReturn = $severity_colors[SYSLOG_NOTICE]; + break; + case DEBUG_WARN: + $szReturn = $severity_colors[SYSLOG_WARNING]; + break; + case DEBUG_ERROR: + $szReturn = $severity_colors[SYSLOG_ERR]; + break; + default: + $szReturn = $severity_colors[SYSLOG_NOTICE]; + } + + // Return string result + return $szReturn; +} + +function GetDebugModeString( $szDebugMode ) +{ + switch ( $szDebugMode ) + { + case DEBUG_ULTRADEBUG: + $szReturn = STR_DEBUG_ULTRADEBUG; + break; + case DEBUG_DEBUG: + $szReturn = STR_DEBUG_DEBUG; + break; + case DEBUG_INFO: + $szReturn = STR_DEBUG_INFO; + break; + case DEBUG_WARN: + $szReturn = STR_DEBUG_WARN; + break; + case DEBUG_ERROR: + $szReturn = STR_DEBUG_ERROR; + break; + default: + $szReturn = STR_DEBUG_INFO; + } + + // Return string result + return $szReturn; +} + + function GetPriorityFromDebugLevel( $DebugLevel ) { switch ( $DebugLevel ) diff --git a/src/lang/en/main.php b/src/lang/en/main.php index f0590d4..56e6b42 100644 --- a/src/lang/en/main.php +++ b/src/lang/en/main.php @@ -100,6 +100,9 @@ $content['LN_ERROR_DB_DBFIELDNOTFOUND'] = "Database Field mapping for at least o $content['LN_WARNING_DBUPGRADE'] = "Database Upgrade required"; $content['LN_WARNING_DBUPGRADE_TEXT'] = "The current installed database version is '%1'.
An update to version '%2' is available."; $content['LN_ERROR_REDIRECTABORTED'] = 'Automatic redirect to the page was aborted, as an internal error occured. Please see the error details above and contact our support forums if you need assistance.'; + $content['LN_DEBUGLEVEL'] = "Debug Level"; + $content['LN_DEBUGMESSAGE'] = "Debug Message"; + // Topmenu Entries $content['LN_MENU_SEARCH'] = "Search"; diff --git a/src/templates/details.html b/src/templates/details.html index 43ce3b3..c1baeea 100644 --- a/src/templates/details.html +++ b/src/templates/details.html @@ -22,7 +22,7 @@ Pager:   - {LN_GEN_FIRSTPAGE} + {LN_GEN_FIRSTPAGE} @@ -31,7 +31,7 @@ - {LN_GEN_PREVIOUSPAGE} + {LN_GEN_PREVIOUSPAGE} @@ -44,7 +44,7 @@ - {LN_GEN_NEXTPAGE} + {LN_GEN_NEXTPAGE} @@ -53,7 +53,7 @@ - {LN_GEN_LASTPAGE} + {LN_GEN_LASTPAGE} diff --git a/src/templates/include_footer.html b/src/templates/include_footer.html index 73bfa0e..16c2db0 100644 --- a/src/templates/include_footer.html +++ b/src/templates/include_footer.html @@ -35,6 +35,22 @@ + + + + + + + + + + + +
{LN_DEBUGLEVEL}{LN_DEBUGMESSAGE}
{DBGLEVELTXT} +
{DBGMSG}
+
+ + {EXTRA_FOOTER} \ No newline at end of file diff --git a/src/templates/index.html b/src/templates/index.html index 3139970..8321e34 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -160,12 +160,12 @@ - {LN_GEN_RECORDCOUNT}: + {LN_GEN_RECORDCOUNT}: {main_recordcount} - {LN_GEN_PAGERSIZE}: + {LN_GEN_PAGERSIZE}: