[pLog-svn] r6128 - plog/branches/lifetype-1.2/class/security
jondaley at devel.lifetype.net
jondaley at devel.lifetype.net
Mon Dec 24 15:35:35 EST 2007
Author: jondaley
Date: 2007-12-24 15:35:35 -0500 (Mon, 24 Dec 2007)
New Revision: 6128
Modified:
plog/branches/lifetype-1.2/class/security/pipeline.class.php
Log:
The 'comment filter' that checks size, etc. now runs first. The bayesian filter runs last. The pipeline only runs once, where once a filter marks it as spam, the following plugins can act accordingly (most likely not do anything). The only thing to note is that because the pipeline only runs once, earlier plugins do not get a chance to reset any data, but we currently don't have any plugins that would benefit from that feature anyway
Modified: plog/branches/lifetype-1.2/class/security/pipeline.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/security/pipeline.class.php 2007-12-24 20:33:03 UTC (rev 6127)
+++ plog/branches/lifetype-1.2/class/security/pipeline.class.php 2007-12-24 20:35:35 UTC (rev 6128)
@@ -11,6 +11,7 @@
lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/security/commentfilter.class.php" );
/**
* global array used to hold the list of filters that we're going to use in the pipeline.
@@ -18,7 +19,9 @@
* level...
*/
$_pLogPipelineRegisteredFilters = array();
+ Pipeline::registerFilter("CommentFilter");
+
/**
* \ingroup Security
*
@@ -50,7 +53,7 @@
* that is currently processing the incoming request
*/
var $_blogInfo;
-
+
/**
* variable to hold the final result of executing the pipeline
*/
@@ -65,29 +68,27 @@
*/
function Pipeline( $httpRequest, $blogInfo = null )
{
-
-
$this->_httpRequest = $httpRequest;
$this->_blogInfo = $blogInfo;
-
- $this->_registerDefaultFilters();;
+ $this->_registerPostDefaultFilters();
}
/**
- * Method that takes care of registering the default filters used in the pipeline.
+ * Method that takes care of registering the default filters
+ * that should be run at the end of the pipeline.
*
- * More can be added anytime by using the registerFilter() method.
+ * In 2.0, this will probably change to have a priority value
+ * or something to order the filters
+ *
+ * This should be called after all other filters have been
+ * registered
* @static
* @return Always true
*/
- function _registerDefaultFilters()
+ function _registerPostDefaultFilters()
{
- lt_include( PLOG_CLASS_PATH."class/security/commentfilter.class.php" );
lt_include( PLOG_CLASS_PATH."class/security/bayesianfilter.class.php" );
-
- $this->registerFilter( "CommentFilter" );
$this->registerFilter( "BayesianFilter" );
-
return true;
}
@@ -117,7 +118,8 @@
lt_include( PLOG_CLASS_PATH . 'class/security/pipelinerequest.class.php' );
lt_include( PLOG_CLASS_PATH . 'class/security/pipelineresult.class.php' );
global $_pLogPipelineRegisteredFilters;
-
+ static $defaultsRegistered = false;
+
// check if the pipeline is enabled
$config =& Config::getConfig();
if( $config->getValue( "security_pipeline_enabled" ) == false ) {
@@ -125,48 +127,36 @@
return new PipelineResult( true );
}
+ // any filters that should be at the end of the
+ // pipeline (like the bayesian filter)
+ if(!$defaultFiltersRegistered){
+ $defaultFiltersRegistered = true;
+ $this->_registerPostDefaultFilters();
+ }
+
// Assume that this will be successful
$this->_result = new PipelineResult( true );
+ $rejected = false;
+
// if enabled, then check all the filters
foreach( $_pLogPipelineRegisteredFilters as $filterClass ) {
- // create an instance of the filter
- $pipelineRequest = new PipelineRequest( $this->_httpRequest, $this->_blogInfo );
+ // create an instance of the filter
+ $pipelineRequest = new PipelineRequest( $this->_httpRequest,
+ $this->_blogInfo,
+ $rejected );
$filter = new $filterClass( $pipelineRequest );
- // and execute it...
+ // and execute it...
$result = $filter->filter();
- // if there was an error, we better say so now
- // and quite, making sure that we're keeping the
- // error code
-
- // Save off the result
- $this->_result = $result;
-
+
+ // if there was an error, save it, and notify
+ // the following filters in the chain
if( !$result->isValid()) {
- // break out of this loop
- break;
+ $rejected = true;
+ $this->_result = $result;
}
}
- // If one of the filters returns that this was not a valid result
- if ( !$this->_result->isValid() ) {
- // Now rerun through all of the filters so they can clean up
- // if they have saved anything persistantly
- // This also gives filters a chance to do anything else they
- // want to do (i.e. report ip address to dns blacklist)
-
- foreach( $_pLogPipelineRegisteredFilters as $filterClass ) {
- // create an instance of the filter
- $pipelineRequest = new PipelineRequest( $this->_httpRequest,
- $this->_blogInfo,
- true );
- $filter = new $filterClass( $pipelineRequest );
- // and execute it...
- $result = $filter->filter();
- // if there was an error, we want to keep going
- }
- }
-
return $this->_result ;
}
}
More information about the pLog-svn
mailing list