From 3080373d4aca5d8794f97eb745b08b854fe77c78 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Mon, 23 Mar 2009 16:49:51 +0100 Subject: [PATCH] Added support for new filtering using REGEXP on supported logstream sources. Currently MYSQL and PostGRESQL are supported due the native support of REGEXP. Other logstreams or database engines are not supported yet. To use REGEXP in searches, prepend the search phrase with the ~ character. --- src/classes/logstream.class.php | 9 +++++++ src/classes/logstreamdb.class.php | 12 +++++++++ src/classes/logstreampdo.class.php | 42 ++++++++++++++++++++++++++++++ src/include/constants_filters.php | 1 + 4 files changed, 64 insertions(+) diff --git a/src/classes/logstream.class.php b/src/classes/logstream.class.php index 9168c58..e0dfaac 100644 --- a/src/classes/logstream.class.php +++ b/src/classes/logstream.class.php @@ -1005,6 +1005,15 @@ abstract class LogStream { $myBits |= FILTER_MODE_SEARCHFULL; } + // If Filter is a REGEX match! + $pos = strpos($szValue, "~"); + if ( $pos !== false && $pos == 0 ) + { + //trunscate - + $szValue = substr( $szValue, 1); + $myBits |= FILTER_MODE_SEARCHREGEX; + } + // return result return $myBits; } diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index a1ef332..3b045a4 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -801,6 +801,18 @@ class LogStreamDB extends LogStream { } // --- } + else if ( $myfilter[FILTER_MODE] & FILTER_MODE_SEARCHREGEX ) + { + // --- Check if user wants to include or exclude! + if ( $myfilter[FILTER_MODE] & FILTER_MODE_INCLUDE) + $addnod = ""; + else + $addnod = " NOT"; + // --- + + $szSearchBegin = " REGEXP '"; + $szSearchEnd = "' "; + } else { // --- Check if user wants to include or exclude! diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index c00d0e0..360e7f0 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -800,6 +800,48 @@ class LogStreamPDO extends LogStream { } // --- } + else if ( $myfilter[FILTER_MODE] & FILTER_MODE_SEARCHREGEX ) + { + //REGEXP Supported by MYSQL + if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + { + // --- Check if user wants to include or exclude! + if ( $myfilter[FILTER_MODE] & FILTER_MODE_INCLUDE) + $addnod = " "; + else + $addnod = " NOT"; + // --- + + $szSearchBegin = "REGEXP '"; + $szSearchEnd = "' "; + } + //REGEXP Supported by POSTGRESQL + else if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + { + // --- Check if user wants to include or exclude! + if ( $myfilter[FILTER_MODE] & FILTER_MODE_INCLUDE) + $addnod = " "; + else + $addnod = " !"; + // --- + + $szSearchBegin = "~* '"; + $szSearchEnd = "' "; + } + else //Fallback use LIKE + { + // --- Check if user wants to include or exclude! + if ( $myfilter[FILTER_MODE] & FILTER_MODE_INCLUDE) + $addnod = " "; + else + $addnod = " NOT"; + // --- + + // Database Layer does not support REGEXP + $szSearchBegin = "LIKE '%"; + $szSearchEnd = "%' "; + } + } else { // --- Check if user wants to include or exclude! diff --git a/src/include/constants_filters.php b/src/include/constants_filters.php index 1e35741..3011f98 100644 --- a/src/include/constants_filters.php +++ b/src/include/constants_filters.php @@ -67,6 +67,7 @@ define('FILTER_MODE', 'filtermode'); define('FILTER_MODE_INCLUDE', 1); define('FILTER_MODE_EXCLUDE', 2); define('FILTER_MODE_SEARCHFULL', 4); +define('FILTER_MODE_SEARCHREGEX', 8); // --- Init Facility LIST $content['filter_facility_list'][] = array( "ID" => SYSLOG_KERN, "DisplayName" => "KERN", "selected" => "" );