[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/bundled-libs/Net/ -> DNSBL.php (source)

   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
   3  // +----------------------------------------------------------------------+
   4  // | PEAR::Net_DNSBL                                                      |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 2004 Sebastian Nohn <sebastian@nohn.net>               |
   7  // +----------------------------------------------------------------------+
   8  // | This source file is subject to version 3.0 of the PHP license,       |
   9  // | that is bundled with this package in the file LICENSE, and is        |
  10  // | available through the world-wide-web at the following url:           |
  11  // | http://www.php.net/license/3_0.txt.                                  |
  12  // | If you did not receive a copy of the PHP license and are unable to   |
  13  // | obtain it through the world-wide-web, please send a note to          |
  14  // | license@php.net so we can mail you a copy immediately.               |
  15  // +----------------------------------------------------------------------+
  16  // | Authors: Sebastian Nohn <sebastian@nohn.net>                         |
  17  // +----------------------------------------------------------------------+
  18  //
  19  // $Id: DNSBL.php,v 1.4 2004/12/02 14:23:51 nohn Exp $
  20  
  21  /**
  22   * PEAR::Net_DNSBL
  23   *
  24   * This class acts as interface to generic Realtime Blocking Lists
  25   * (RBL)
  26   *
  27   * Net_RBL looks up an supplied host if it's listed in 1-n supplied
  28   * Blacklists
  29   *
  30   * @author  Sebastian Nohn <sebastian@nohn.net>
  31   * @package Net_DNSBL
  32   * @license http://www.php.net/license/3_0.txt
  33   * @version 0.5.3
  34   */
  35  require_once dirname(__FILE__) . '/CheckIP.php';
  36  
  37  class Net_DNSBL {
  38  
  39      /**     
  40       * Array of blacklists.
  41       *
  42       * Must have one or more elements.
  43       *
  44       * @var    array
  45       * @access protected
  46       */
  47      var $blacklists = array('sbl-xbl.spamhaus.net',
  48                              'bl.spamcop.net');
  49  
  50      /**
  51       * Set the blacklist to a desired blacklist.
  52       *
  53       * @param  array Array of blacklists to use. May contain only one element.
  54       * @access public
  55       * @return bool true if the operation was successful
  56       */
  57      function setBlacklists($blacklists)
  58      {
  59          if (is_array($blacklists)) {
  60              $this->blacklists = $blacklists;
  61              return true;
  62          } else {
  63              return false;
  64          } // if
  65      } // function
  66  
  67      /**
  68       * Get the blacklists.
  69       *
  70       * @access public
  71       * @return array Currently set blacklists.
  72       */
  73      function getBlacklists()
  74      {
  75          return $this->blacklists;
  76      }
  77  
  78      /** 
  79       * Checks if the supplied Host is listed in one or more of the
  80       * RBLs.
  81       *
  82       * @param  string Host to check for being listed.
  83       * @access public
  84       * @return boolean true if the checked host is listed in a blacklist.
  85       */
  86      function isListed($host)
  87      {
  88          
  89          $isListed = false;
  90          
  91          foreach ($this->blacklists as $blacklist) {
  92              $result = gethostbyname($this->getHostForLookup($host, $blacklist));
  93              if ($result != $this->getHostForLookup($host, $blacklist)) { 
  94                  $isListed = true;
  95                  
  96                  //if the Host was listed we don't need to check other RBLs,
  97                  break;
  98                  
  99              } // if
 100          } // foreach
 101          
 102          return $isListed;
 103      } // function
 104  
 105      /** 
 106       * Get host to lookup. Lookup a host if neccessary and get the
 107       * complete FQDN to lookup.
 108       *
 109       * @param  string Host OR IP to use for building the lookup.
 110       * @param  string Blacklist to use for building the lookup.
 111       * @access protected
 112       * @return string Ready to use host to lookup
 113       */    
 114      function getHostForLookup($host, $blacklist) 
 115      {
 116          // Currently only works for v4 addresses.
 117          if (!Net_CheckIP::check_ip($host)) {
 118              $ip = gethostbyname($host);
 119          } else {
 120              $ip = $host;
 121          }
 122  
 123          return $this->buildLookUpHost($ip, $blacklist);
 124      } // function
 125  
 126      /**
 127       * Build the host to lookup from an IP.
 128       *
 129       * @param  string IP to use for building the lookup.
 130       * @param  string Blacklist to use for building the lookup.
 131       * @access protected
 132       * @return string Ready to use host to lookup
 133       */    
 134      function buildLookUpHost($ip, $blacklist)
 135      {
 136          return $this->reverseIp($ip).'.'.$blacklist;        
 137      } // function
 138  
 139      /**
 140       * Reverse the order of an IP. 127.0.0.1 -> 1.0.0.127. Currently
 141       * only works for v4-adresses
 142       *
 143       * @param  string IP to reverse.
 144       * @access protected
 145       * @return string Reversed IP
 146       */    
 147      function reverseIp($ip) 
 148      {        
 149          return implode('.', array_reverse(explode('.', $ip)));        
 150      } // function
 151  
 152  } // class
 153  ?>


Généré le : Sat Nov 24 09:00:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics