[pLog-svn] r6128 - plog/branches/lifetype-1.2/class/security

Jon Daley plogworld at jon.limedaley.com
Mon Dec 24 15:46:26 EST 2007


 	There was only one thing funny about working on this.

I think a couple of you have said that the CommentFilter and the 
BayesianFilter used to run at the beginning?  As far as I can see, the 
static method registerFilter() is called prior to the Pipeline 
constructor, and so all of the plugins go first.  I have hard-coded the 
CommentFilter to be at the beginning whenever the pipeline.class.php file 
in included.  It is probably good enough for now, and we can see how to 
fix it better in 2.0 (probably Mark's priority/ordering idea will be the 
best).

I'll check an older version to make sure that it wasn't something that was 
recently changed - but can any of you (I think maybe Mark and Paul, and 
maybe even Oscar said that they thought these two filters ran first?) 
verify that?

On Mon, 24 Dec 2007, jondaley at devel.lifetype.net wrote:

> 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 ;
>         }
>     }
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://limedaley.com/mailman/listinfo/plog-svn
>

-- 
Jon Daley
http://jon.limedaley.com/

If the facts don't fit the theory, change the facts.
-- Albert Einstein


More information about the pLog-svn mailing list