From 40ad2c5fa27d46ef2d1e4bf8eab27397d608d9f8 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Tue, 5 Aug 2008 14:26:08 +0200 Subject: [PATCH] Added support for FULL and PARTIAL String search by prepending a = into the search. Also improved the search functionallety within the logstream sources. Include and Exclude does now correctly work for string filters in the diskfile source. PDO and MYSQL Logstream work faster now on string filtering when Full String filter is used, for example when you filter by host. --- src/classes/logstream.class.php | 23 ++++++++++++++----- src/classes/logstreamdb.class.php | 27 +++++++++++++++++----- src/classes/logstreamdisk.class.php | 35 +++++++++++++++++++++++++---- src/classes/logstreampdo.class.php | 25 ++++++++++++++++----- src/include/constants_filters.php | 5 +++-- src/index.php | 8 +++---- 6 files changed, 97 insertions(+), 26 deletions(-) diff --git a/src/classes/logstream.class.php b/src/classes/logstream.class.php index 2513ce9..42e6304 100644 --- a/src/classes/logstream.class.php +++ b/src/classes/logstream.class.php @@ -493,25 +493,38 @@ abstract class LogStream { */ private function SetFilterIncludeMode(&$szValue) { - // Set Filtermode + // Init BIT! + $myBits = FILTER_MODE_INCLUDE; + + // If Filter is Included $pos = strpos($szValue, "+"); if ( $pos !== false && $pos == 0 ) { //trunscate + $szValue = substr( $szValue, 1); - return FILTER_MODE_INCLUDE; + $myBits = FILTER_MODE_INCLUDE; } + // If Filter is Excluded $pos = strpos($szValue, "-"); if ( $pos !== false && $pos == 0 ) { //trunscate - $szValue = substr( $szValue, 1); - return FILTER_MODE_EXCLUDE; + $myBits = FILTER_MODE_EXCLUDE; } - // Default is include which means + - return FILTER_MODE_INCLUDE; + // If Filter is a FULL text match! + $pos = strpos($szValue, "="); + if ( $pos !== false && $pos == 0 ) + { + //trunscate - + $szValue = substr( $szValue, 1); + $myBits |= FILTER_MODE_SEARCHFULL; + } + + // return result + return $myBits; } /* diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index 3122609..2aaf1be 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -522,25 +522,40 @@ class LogStreamDB extends LogStream { switch( $myfilter[FILTER_TYPE] ) { case FILTER_TYPE_STRING: - // Check if user wants to include or exclude! - if ( $myfilter[FILTER_MODE] == FILTER_MODE_INCLUDE) + // --- Check if user wants to include or exclude! + if ( $myfilter[FILTER_MODE] & FILTER_MODE_INCLUDE) $addnod = ""; else $addnod = " NOT"; + // --- - // If Syslog message, we have AND handling, otherwise OR! + // --- Either make a LIKE or a equal query! + if ( $myfilter[FILTER_MODE] & FILTER_MODE_SEARCHFULL ) + { + $szSearchBegin = " = '"; + $szSearchEnd = "' "; + } + else + { + $szSearchBegin = " LIKE '%"; + $szSearchEnd = "%' "; + } + // --- + + // --- If Syslog message, we have AND handling, otherwise OR! if ( $propertyname == SYSLOG_MESSAGE ) $addor = " AND "; else $addor = " OR "; + // --- - // Not create LIKE Filters + // Now Create LIKE Filters if ( isset($tmpfilters[$propertyname]) ) - $tmpfilters[$propertyname][FILTER_VALUE] .= $addor . $dbmapping[$szTableType][$propertyname] . $addnod . " LIKE '%" . $myfilter[FILTER_VALUE] . "%'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $addor . $dbmapping[$szTableType][$propertyname] . $addnod . $szSearchBegin . $myfilter[FILTER_VALUE] . $szSearchEnd; else { $tmpfilters[$propertyname][FILTER_TYPE] = FILTER_TYPE_STRING; - $tmpfilters[$propertyname][FILTER_VALUE] = $dbmapping[$szTableType][$propertyname] . $addnod . " LIKE '%" . $myfilter[FILTER_VALUE] . "%'"; + $tmpfilters[$propertyname][FILTER_VALUE] = $dbmapping[$szTableType][$propertyname] . $addnod . $szSearchBegin . $myfilter[FILTER_VALUE] . $szSearchEnd; } break; case FILTER_TYPE_NUMBER: diff --git a/src/classes/logstreamdisk.class.php b/src/classes/logstreamdisk.class.php index f5ba74a..dbfed7e 100644 --- a/src/classes/logstreamdisk.class.php +++ b/src/classes/logstreamdisk.class.php @@ -633,13 +633,13 @@ class LogStreamDisk extends LogStream { if ( $propertyname == SYSLOG_MESSAGE ) { // Include Filter - if ( $myfilter[FILTER_MODE] == FILTER_MODE_INCLUDE ) + if ( $myfilter[FILTER_MODE] & FILTER_MODE_INCLUDE ) { if ( stripos($propertyvalue, $myfilter[FILTER_VALUE]) === false ) $bEval = false; } // Exclude Filter - else if ( $myfilter[FILTER_MODE] == FILTER_MODE_EXCLUDE ) + else if ( $myfilter[FILTER_MODE] & FILTER_MODE_EXCLUDE ) { if ( stripos($propertyvalue, $myfilter[FILTER_VALUE]) !== false ) $bEval = false; @@ -649,8 +649,35 @@ class LogStreamDisk extends LogStream { else { $bIsOrFilter = true; // Set isOrFilter to true - if ( stripos($propertyvalue, $myfilter[FILTER_VALUE]) !== false ) - $bOrFilter = true; + + // Include Filter + if ( $myfilter[FILTER_MODE] & FILTER_MODE_INCLUDE ) + { + if ( $myfilter[FILTER_MODE] & FILTER_MODE_SEARCHFULL ) + { + if ( strtolower($propertyvalue) == strtolower($myfilter[FILTER_VALUE]) ) + $bOrFilter = true; + } + else + { + if ( stripos($propertyvalue, $myfilter[FILTER_VALUE]) !== false ) + $bOrFilter = true; + } + } + // Exclude Filter + else if ( $myfilter[FILTER_MODE] & FILTER_MODE_EXCLUDE ) + { + if ( $myfilter[FILTER_MODE] & FILTER_MODE_SEARCHFULL ) + { + if ( strtolower($propertyvalue) != strtolower($myfilter[FILTER_VALUE]) ) + $bOrFilter = true; + } + else + { + if ( stripos($propertyvalue, $myfilter[FILTER_VALUE]) === false ) + $bOrFilter = true; + } + } break; } break; diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index 4ed509c..5bd8f3a 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -530,25 +530,40 @@ class LogStreamPDO extends LogStream { switch( $myfilter[FILTER_TYPE] ) { case FILTER_TYPE_STRING: - // Check if user wants to include or exclude! - if ( $myfilter[FILTER_MODE] == FILTER_MODE_INCLUDE) + // --- Check if user wants to include or exclude! + if ( $myfilter[FILTER_MODE] & FILTER_MODE_INCLUDE) $addnod = ""; else $addnod = " NOT"; + // --- - // If Syslog message, we have AND handling, otherwise OR! + // --- Either make a LIKE or a equal query! + if ( $myfilter[FILTER_MODE] & FILTER_MODE_SEARCHFULL ) + { + $szSearchBegin = " = '"; + $szSearchEnd = "' "; + } + else + { + $szSearchBegin = " LIKE '%"; + $szSearchEnd = "%' "; + } + // --- + + // --- If Syslog message, we have AND handling, otherwise OR! if ( $propertyname == SYSLOG_MESSAGE ) $addor = " AND "; else $addor = " OR "; + // --- // Not create LIKE Filters if ( isset($tmpfilters[$propertyname]) ) - $tmpfilters[$propertyname][FILTER_VALUE] .= $addor . $dbmapping[$szTableType][$propertyname] . $addnod . " LIKE '%" . $myfilter[FILTER_VALUE] . "%'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $addor . $dbmapping[$szTableType][$propertyname] . $addnod . $szSearchBegin . $myfilter[FILTER_VALUE] . $szSearchEnd; else { $tmpfilters[$propertyname][FILTER_TYPE] = FILTER_TYPE_STRING; - $tmpfilters[$propertyname][FILTER_VALUE] = $dbmapping[$szTableType][$propertyname] . $addnod . " LIKE '%" . $myfilter[FILTER_VALUE] . "%'"; + $tmpfilters[$propertyname][FILTER_VALUE] = $dbmapping[$szTableType][$propertyname] . $addnod . $szSearchBegin . $myfilter[FILTER_VALUE] . $szSearchEnd; } break; case FILTER_TYPE_NUMBER: diff --git a/src/include/constants_filters.php b/src/include/constants_filters.php index c2348a1..441bf6a 100644 --- a/src/include/constants_filters.php +++ b/src/include/constants_filters.php @@ -63,8 +63,9 @@ define('FILTER_TYPE', 'filtertype'); define('FILTER_DATEMODENAME', 'datemodename'); define('FILTER_VALUE', 'value'); define('FILTER_MODE', 'filtermode'); -define('FILTER_MODE_INCLUDE', 0); -define('FILTER_MODE_EXCLUDE', 1); +define('FILTER_MODE_INCLUDE', 1); +define('FILTER_MODE_EXCLUDE', 2); +define('FILTER_MODE_SEARCHFULL', 4); // --- Init Facility LIST $content['filter_facility_list'][] = array( "ID" => SYSLOG_KERN, "DisplayName" => "KERN", "selected" => "" ); diff --git a/src/index.php b/src/index.php index c0f1dbd..4594f65 100644 --- a/src/index.php +++ b/src/index.php @@ -545,7 +545,7 @@ if ( isset($content['Sources'][$currentSourceID]) ) // Set OnClick Menu for SYSLOG_SYSLOGTAG $content['syslogmessages'][$counter]['values'][$mycolkey]['hasbuttons'] = true; $content['syslogmessages'][$counter]['values'][$mycolkey]['buttons'][] = array( - 'ButtonUrl' => '?filter=syslogtag%3A' . $logArray[$mycolkey] . '&search=Search' . $content['additional_url_sourceonly'], + 'ButtonUrl' => '?filter=syslogtag%3A%3D' . urlencode($logArray[$mycolkey]) . '&search=Search' . $content['additional_url_sourceonly'], 'DisplayName' => $content['LN_VIEW_FILTERFOR'] . "'" . $logArray[$mycolkey] . "'", 'IconSource' => $content['MENU_BULLET_BLUE'] ); @@ -560,7 +560,7 @@ if ( isset($content['Sources'][$currentSourceID]) ) // Set OnClick Menu for SYSLOG_HOST $content['syslogmessages'][$counter]['values'][$mycolkey]['hasbuttons'] = true; $content['syslogmessages'][$counter]['values'][$mycolkey]['buttons'][] = array( - 'ButtonUrl' => '?filter=source%3A' . $logArray[$mycolkey] . '&search=Search' . $content['additional_url_sourceonly'], + 'ButtonUrl' => '?filter=source%3A%3D' . urlencode($logArray[$mycolkey]) . '&search=Search' . $content['additional_url_sourceonly'], 'DisplayName' => $content['LN_VIEW_FILTERFOR'] . "'" . $logArray[$mycolkey] . "'", 'IconSource' => $content['MENU_BULLET_BLUE'] ); @@ -571,7 +571,7 @@ if ( isset($content['Sources'][$currentSourceID]) ) // Set OnClick Menu for SYSLOG_EVENT_LOGTYPE $content['syslogmessages'][$counter]['values'][$mycolkey]['hasbuttons'] = true; $content['syslogmessages'][$counter]['values'][$mycolkey]['buttons'][] = array( - 'ButtonUrl' => '?filter=eventlogtype%3A' . $logArray[$mycolkey] . '&search=Search' . $content['additional_url_sourceonly'], + 'ButtonUrl' => '?filter=eventlogtype%3A%3D' . urlencode($logArray[$mycolkey]) . '&search=Search' . $content['additional_url_sourceonly'], 'DisplayName' => $content['LN_VIEW_FILTERFOR'] . "'" . $logArray[$mycolkey] . "'", 'IconSource' => $content['MENU_BULLET_BLUE'] ); @@ -586,7 +586,7 @@ if ( isset($content['Sources'][$currentSourceID]) ) // Set OnClick Menu for SYSLOG_EVENT_SOURCE $content['syslogmessages'][$counter]['values'][$mycolkey]['hasbuttons'] = true; $content['syslogmessages'][$counter]['values'][$mycolkey]['buttons'][] = array( - 'ButtonUrl' => '?filter=eventlogsource%3A' . $logArray[$mycolkey] . '&search=Search' . $content['additional_url_sourceonly'], + 'ButtonUrl' => '?filter=eventlogsource%3A%3D' . urlencode($logArray[$mycolkey]) . '&search=Search' . $content['additional_url_sourceonly'], 'DisplayName' => $content['LN_VIEW_FILTERFOR'] . "'" . $logArray[$mycolkey] . "'", 'IconSource' => $content['MENU_BULLET_BLUE'] );