ultimix
security_validator.php
Go to the documentation of this file.
1 <?php
2 
3  /*
4  * This source code is a part of the Ultimix Project.
5  * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6  * it's own license wich could be found from the corresponding files or sources.
7  * This source code is provided "as is" without any warranties or garanties.
8  *
9  * Have a nice day!
10  *
11  * @url http://ultimix.sorceforge.net
12  *
13  * @author Alexey "gdever" Dodonov
14  */
15 
27 
38  var $Pred = false;
39  var $Settings = false;
40  var $String = false;
41  var $SupportedDataTypes = false;
42 
53  function __construct()
54  {
55  try
56  {
57  $this->Pred = get_package( 'security::security_validator::predicates' , 'last' , __FILE__ );
58  $this->SecurityParser = get_package( 'security::security_parser' , 'last' , __FILE__ );
59  $this->String = get_package( 'string' , 'last' , __FILE__ );
60  $this->SupportedDataTypes = get_package( 'security::supported_data_types' , 'last' , __FILE__ );
61  }
62  catch( Exception $e )
63  {
64  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
65  }
66  }
67 
102  private function validate_default( $Data , $Name , $Predicates , $j )
103  {
104  try
105  {
106  $o = $this->Pred;
107  if( strpos( $Predicates[ $j ] , 'value_' ) === 0 )
108  {
109  return( $o->exec_value( $Data , $Name , $Predicates , $j ) );
110  }
111  if( strpos( $Predicates[ $j ] , 'min_' ) === 0 )
112  {
113  return( $o->exec_min( $Data , $Name , $Predicates , $j ) );
114  }
115  if( strpos( $Predicates[ $j ] , 'max_' ) === 0 )
116  {
117  return( $o->exec_max( $Data , $Name , $Predicates , $j ) );
118  }
119  if( strpos( $Predicates[ $j ] , 'same_as_' ) === 0 )
120  {
121  return( $o->exec_same_as( $Data , $Name , $Predicates , $j ) );
122  }
123  return( $o->exec_simple( $Data , $Name , $Predicates , $j ) );
124  }
125  catch( Exception $e )
126  {
127  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
128  }
129  }
130 
165  private function handle_data_predicates( $Data , $Name , $Predicates , $j )
166  {
167  try
168  {
169  switch( $Predicates[ $j ] )
170  {
171  case( 'email' ): return( $this->Pred->validate_email( $Data , $Name , $Predicates ) );
172  case( 'float' ): return( $this->Pred->validate_float( $Data , $Name , $Predicates ) );
173  case( 'integer' ): return( $this->Pred->validate_integer( $Data , $Name , $Predicates ) );
174  case( 'raw' ): return( $this->Pred->validate_string( $Data , $Name , $Predicates ) );
175  case( 'string' ): return( $this->Pred->validate_string( $Data , $Name , $Predicates ) );
176  case( 'command' ): return( $this->Pred->validate_command( $Data , $Name , $Predicates ) );
177  }
178  return( 0 );
179  }
180  catch( Exception $e )
181  {
182  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
183  }
184  }
185 
220  private function handle_extra_predicates( $Data , $Name , $Predicates , $j )
221  {
222  try
223  {
224  $p = $Predicates[ $j ];
225 
226  if( $p == 'set' )
227  {
228  return( $this->Pred->validate_set( $Data , $Name , $Predicates ) );
229  }
230  elseif( $p == 'not_set' )
231  {
232  return( $this->Pred->validate_not_set( $Data , $Name , $Predicates ) );
233  }
234  elseif( $p == 'not_filled' )
235  {
236  return( $this->Pred->validate_not_filled( $Data , $Name , $Predicates ) );
237  }
238  elseif( $p == 'allow_not_set')
239  {
240  return( true );
241  }
242 
243  return( 0 );
244  }
245  catch( Exception $e )
246  {
247  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
248  }
249  }
250 
281  private function handle_predicates( $Data , $Name , $Predicates )
282  {
283  try
284  {
285  $c = count( $Predicates );
286 
287  for( $j = 0 ; $j < $c ; $j++ )
288  {
289  if( ( $Result = $this->handle_data_predicates( $Data , $Name , $Predicates , $j ) ) !== 0 )
290  {
291  }
292  elseif( ( $Result = $this->handle_extra_predicates( $Data , $Name , $Predicates , $j ) ) !== 0 )
293  {
294  }
295  elseif( $this->validate_default( $Data , $Name , $Predicates , $j ) === false )
296  {
297  return( false );
298  }
299  if( $Result === false )
300  {
301  return( false );
302  }
303  }
304 
305  return( true );
306  }
307  catch( Exception $e )
308  {
309  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
310  }
311  }
312 
339  function validate_custom_fields( $Data , $ParsingScript )
340  {
341  try
342  {
343  $this->Pred->ErrorMessage = false;
344  $ParsingScript = str_replace( '#' , ';' , $ParsingScript );
345  $Script = explode( ';' , $ParsingScript );
346 
347  foreach( $Script as $s )
348  {
349  $s = explode( ':' , $s );
350  $Name = $s[ 0 ];
351  $Predicates = explode( ',' , $s[ 1 ] );
352  if( $this->handle_predicates( $Data , $Name , $Predicates ) === false )
353  {
354  return( false );
355  }
356  }
357 
358  return( true );
359  }
360  catch( Exception $e )
361  {
362  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
363  }
364  }
365 
388  function validate_fields( $ParsingScript )
389  {
390  try
391  {
392  return( $this->validate_custom_fields( array_merge( $_GET , $_POST ) , $ParsingScript ) );
393  }
394  catch( Exception $e )
395  {
396  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
397  }
398  }
399 
418  function get_error_message()
419  {
420  try
421  {
422  return( $this->Pred->ErrorMessage );
423  }
424  catch( Exception $e )
425  {
426  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
427  }
428  }
429  }
430 
431 ?>