b2evolution PHP Cross Reference Blogging Systems

Source: /inc/antispam/model/_iprange.class.php - 145 lines - 3936 bytes - Summary - Text - Print

Description: This file implements the IP Range class. This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}. See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**

   3   * This file implements the IP Range class.

   4   *

   5   * This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}.

   6   * See also {@link http://sourceforge.net/projects/evocms/}.

   7   *

   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}.

   9  *

  10   * @license http://b2evolution.net/about/license.html GNU General Public License (GPL)

  11   *

  12   * {@internal Open Source relicensing agreement:

  13   * EVO FACTORY grants Francois PLANQUE the right to license

  14   * EVO FACTORY contributions to this file and the b2evolution project

  15   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  16   * }}

  17   *

  18   * @package evocore

  19   *

  20   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  21   * @author asimo: Evo Factory / Attila Simo

  22   *

  23   * @version $Id: _iprange.class.php 849 2012-02-16 09:09:09Z attila $

  24   */
  25  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  26  
  27  load_class( '_core/model/dataobjects/_dataobject.class.php', 'DataObject' );
  28  
  29  
  30  /**

  31   * Slug Class

  32   *

  33   * @package evocore

  34   */
  35  class IPRange extends DataObject
  36  {
  37      var $IPv4start;
  38  
  39      var $IPv4end;
  40  
  41      var $user_count;
  42  
  43      var $status;
  44  
  45      var $block_count;
  46  
  47      /**

  48       * Constructor

  49       *

  50       * @param object table Database row

  51       */
  52  	function IPRange( $db_row = NULL )
  53      {
  54          // Call parent constructor:

  55          parent::DataObject( 'T_antispam__iprange', 'aipr_', 'aipr_ID' );
  56  
  57          if( $db_row != NULL )
  58          {
  59              $this->ID = $db_row->aipr_ID;
  60              $this->IPv4start = $db_row->aipr_IPv4start;
  61              $this->IPv4end = $db_row->aipr_IPv4end;
  62              $this->user_count = $db_row->aipr_user_count;
  63              $this->status = $db_row->aipr_status;
  64              $this->block_count = $db_row->aipr_block_count;
  65          }
  66      }
  67  
  68  
  69      /**

  70       * Get a member param by its name

  71       *

  72       * @param mixed Name of parameter

  73       * @return mixed Value of parameter

  74       */
  75  	function get( $parname )
  76      {
  77          return parent::get( $parname );
  78      }
  79  
  80  
  81      /**

  82       * Set param value

  83       *

  84       * @param string parameter name

  85       * @param mixed parameter value

  86       * @param boolean true to set to NULL if empty value

  87       * @return boolean true, if a value has been set; false if it has not changed

  88       */
  89  	function set( $parname, $parvalue, $make_null = false )
  90      {
  91          return $this->set_param( $parname, 'string', $parvalue, $make_null );
  92      }
  93  
  94  
  95      /**

  96       * Load data from Request form fields.

  97       *

  98       * @return boolean true if loaded data seems valid.

  99       */
 100  	function load_from_Request()
 101      {
 102          global $Messages;
 103  
 104          $aipr_status = param( 'aipr_status', 'string', true );
 105          $this->set( 'status', $aipr_status, true );
 106  
 107          $aipr_IPv4start = param( 'aipr_IPv4start', 'string', true );
 108          param_check_regexp( 'aipr_IPv4start', '#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#i', T_('Please enter a correct IP range start') );
 109          $aipr_IPv4start = ip2int( $aipr_IPv4start );
 110          $this->set( 'IPv4start', $aipr_IPv4start );
 111  
 112          $aipr_IPv4end = param( 'aipr_IPv4end', 'string', true );
 113          param_check_regexp( 'aipr_IPv4end', '#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#i', T_('Please enter a correct IP range end') );
 114          $aipr_IPv4end = ip2int( $aipr_IPv4end );
 115          $this->set( 'IPv4end', $aipr_IPv4end );
 116  
 117          if( $aipr_IPv4start > $aipr_IPv4end )
 118          {
 119              $Messages->add( T_('IP range start must be less than IP range end'), 'error' );
 120          }
 121  
 122          if( ! param_errors_detected() )
 123          {    // Check IPs for inside in other ranges
 124              if( $ip_range = get_ip_range( $aipr_IPv4start, $aipr_IPv4end, $this->ID ) )
 125              {
 126                  $Messages->add( sprintf( T_('IP range already exists with params: %s'), int2ip( $ip_range->aipr_IPv4start ).' - '.int2ip( $ip_range->aipr_IPv4end ) ), 'error' );
 127              }
 128          }
 129  
 130          return ! param_errors_detected();
 131      }
 132  
 133  
 134      /**

 135       * Get name of IP range

 136       *

 137       * @return string Name of IP range

 138       */
 139  	function get_name()
 140      {
 141          return int2ip( $this->IPv4start ).' - '.int2ip( $this->IPv4end );
 142      }
 143  }
 144  
 145  ?>

title

Description

title

Description

title

Description

title

title

Body