[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 /** 4 * \defgroup Security 5 * 6 * The Security module provides a basic implementation of a generic Pipeline to which we can 7 * register "filters", which wil carry out specific actions. Any of the filters can interrupt the 8 * processing, depending on the logic of the filter. Please see the Pipeline class for more information. 9 */ 10 11 12 13 lt_include( PLOG_CLASS_PATH."class/config/config.class.php" ); 14 15 /** 16 * global array used to hold the list of filters that we're going to use in the pipeline. 17 * Now again, more than ever, wish that PHP4 had support for static attributes at the class 18 * level... 19 */ 20 $_pLogPipelineRegisteredFilters = array(); 21 22 /** 23 * \ingroup Security 24 * 25 * Implementation of a basic security framework based on a 26 * pipeline. Every element of the pipeline implements a simple 27 * security mechanism. When one of the filters in the pipeline 28 * find a condition that is matched by the incoming request, the 29 * request will be blocked and the processing of the pipeline will be stopped. 30 * 31 * As of pLog 1.0, plugins can also register new filters dynamically via the PluginBase::registerFilter(), which 32 * eventually uses the static method Pipeline::registerFilter() Since it is static, this method is not restricted 33 * to plugins and can be used by any other class at run time to add new filters. 34 * 35 * The out of the box implementation of the Pipeline comes with a null filter (a filter that does nothing -- go figure :)) 36 * and a filter that implements a Bayesian filter for advanced spam protection. See the BayesianFilter class for more information. 37 */ 38 class Pipeline 39 { 40 41 /** 42 * HTTP request that will be used if the filter is doing 43 * some content filtering 44 */ 45 var $_httpRequest; 46 47 /** 48 * the BlogInfo object that has information about the blog 49 * that is currently processing the incoming request 50 */ 51 var $_blogInfo; 52 53 /** 54 * variable to hold the final result of executing the pipeline 55 */ 56 var $_result; 57 58 /** 59 * Constructor 60 * 61 * @param httpRequest The HTTP request 62 * @param blogInfo The BlogInfo object with information about the blog 63 * that is currently executing this pipeline 64 */ 65 function Pipeline( $httpRequest, $blogInfo = null ) 66 { 67 68 69 $this->_httpRequest = $httpRequest; 70 $this->_blogInfo = $blogInfo; 71 72 $this->_registerDefaultFilters();; 73 } 74 75 /** 76 * Method that takes care of registering the default filters used in the pipeline. 77 * 78 * More can be added anytime by using the registerFilter() method. 79 * @static 80 * @return Always true 81 */ 82 function _registerDefaultFilters() 83 { 84 lt_include( PLOG_CLASS_PATH."class/security/nullpipelinefilter.class.php" ); 85 lt_include( PLOG_CLASS_PATH."class/security/commentfilter.class.php" ); 86 lt_include( PLOG_CLASS_PATH."class/security/bayesianfilter.class.php" ); 87 88 $this->registerFilter( "NullPipelineFilter" ); 89 $this->registerFilter( "CommentFilter" ); 90 $this->registerFilter( "BayesianFilter" ); 91 92 return true; 93 } 94 95 /** 96 * Static method that registers a filter externally 97 * 98 * @param filterClass A class that implements the PipelineFilter interface 99 * @static 100 * @return Always returns true. 101 */ 102 function registerFilter( $filterClass ) 103 { 104 global $_pLogPipelineRegisteredFilters; 105 106 if( !is_array($_pLogPipelineRegisteredFilters)) // make sure that we have an array... 107 $_pLogPipelineRegisteredFilters = Array(); 108 109 $_pLogPipelineRegisteredFilters["$filterClass"] = $filterClass; 110 } 111 112 /** 113 * Processes the pipeline, using the request and blogInfo 114 * objects as given in the constructor. 115 */ 116 function process() 117 { 118 lt_include( PLOG_CLASS_PATH . 'class/security/pipelinerequest.class.php' ); 119 lt_include( PLOG_CLASS_PATH . 'class/security/pipelineresult.class.php' ); 120 global $_pLogPipelineRegisteredFilters; 121 122 // check if the pipeline is enabled 123 $config =& Config::getConfig(); 124 if( $config->getValue( "security_pipeline_enabled" ) == false ) { 125 // pipeline is disabled, so everything's fine 126 return new PipelineResult( true ); 127 } 128 129 // Assume that this will be successful 130 $this->_result = new PipelineResult( true ); 131 132 // if enabled, then check all the filters 133 foreach( $_pLogPipelineRegisteredFilters as $filterClass ) { 134 // create an instance of the filter 135 $pipelineRequest = new PipelineRequest( $this->_httpRequest, $this->_blogInfo ); 136 $filter = new $filterClass( $pipelineRequest ); 137 // and execute it... 138 $result = $filter->filter(); 139 // if there was an error, we better say so now 140 // and quite, making sure that we're keeping the 141 // error code 142 143 // Save off the result 144 $this->_result = $result; 145 146 if( !$result->isValid()) { 147 // break out of this loop 148 break; 149 } 150 } 151 152 // If one of the filters returns that this was not a valid result 153 if ( !$this->_result->isValid() ) { 154 // Now rerun through all of the filters so they can clean up 155 // if they have saved anything persistantly 156 // This also gives filters a chance to do anything else they 157 // want to do (i.e. report ip address to dns blacklist) 158 159 foreach( $_pLogPipelineRegisteredFilters as $filterClass ) { 160 // create an instance of the filter 161 $pipelineRequest = new PipelineRequest( $this->_httpRequest, 162 $this->_blogInfo, 163 true ); 164 $filter = new $filterClass( $pipelineRequest ); 165 // and execute it... 166 $result = $filter->filter(); 167 // if there was an error, we want to keep going 168 } 169 } 170 171 return $this->_result ; 172 } 173 } 174 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |