[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/net/ -> dns.class.php (source)

   1  <?php
   2  
   3      
   4      lt_include( PLOG_CLASS_PATH."class/misc/osdetect.class.php" );
   5  
   6      /**
   7       * \ingroup Net
   8       *
   9       * Implementation of an alternative version of the checkdnsrr and getmxrr functions which
  10       * are not available in the windows version of the php. The class detects wether we're
  11       * running windows or linux and then depending on the result, we will use the faster and native
  12       * version or the alternative one.
  13       */
  14      class Dns  
  15      {
  16  
  17          /**
  18           * Static function that acts as a wrapper for the native checkdnsrr function. It first detects
  19           * wether we're running in Windows or not and then uses the native version or the alternative one.
  20           *
  21           * For more information:          http://hk2.php.net/checkdnsrr
  22           *
  23           * @param host The we would like to check.
  24           * @param type It defaults to MX, but could be one of A, MX, NS, SOA, PTR, CNAME, AAAA, or ANY.
  25           * @return Returns TRUE if any records are found; returns FALSE if no records were found or if an error occurred.
  26           * @static
  27           */
  28      	function checkdnsrr( $host, $type = "MX" )
  29          {
  30              if( OsDetect::isWindows()) {
  31                  // call the alternative version
  32                  return Dns::checkdnsrr_windows( $host, $type );
  33              }
  34              else {
  35                  // call the native version
  36                  return checkdnsrr( $host, $type );
  37              }
  38          }
  39  
  40          /**
  41           * Function shamelessly copied from a comment made by an anonymous poster, that implements
  42           * an alternative version of checkdnsrr for windows platforms (at least, it works for
  43           * windows nt, 2000 and xp) I will never work in windows 98 because a) I think it's stupid
  44           * to run this in a windows 98 machine and b) because windows 98 is outdated anyway.
  45           *
  46           * Original function: http://hk2.php.net/checkdnsrr
  47           *
  48           * This function should behave in exactly the same way as the native checkdnsrr.
  49           *
  50           * @param host The we would like to check.
  51           * @param type It defaults to MX, but could be one of A, MX, NS, SOA, PTR, CNAME, AAAA, or ANY.
  52           * @return Returns TRUE if any records are found; returns FALSE if no records were found or if an error occurred.
  53           * @static
  54           * @private
  55           */
  56          function checkdnsrr_windows( $host, $type = "MX" )
  57          {
  58              if( !empty( $host ) ) {
  59                  @exec( "nslookup -type=$type $host", $output );
  60  
  61                  while( list( $k, $line ) = each( $output ) ) {
  62                      // Valid records begin with host name:
  63                      if( eregi( "^$host", $line ) ) {
  64                          // record found:
  65                          return true;
  66                      }
  67                  }
  68  
  69                  return false;
  70              }
  71          }
  72  
  73          /**
  74           * Static function that detects wether we're running windows or not and then either uses the native version of
  75           * getmxrr or the alternative one. See getmxrr_windows below for more information.
  76           *
  77           * @param hostname The host for which we want to get the mx records.
  78           * @param mxhosts The array we are going to fill with the mx records.
  79           * @return Returns either true or false.
  80           * @static
  81           */
  82          function getmxrr( $hostname, &$mxhosts )
  83          {
  84              if( OsDetect::isWindows()) {
  85                  // call the alternative version
  86                  return Dns::getmxrr_windows( $hostname, $mxhosts );
  87              }
  88              else {
  89                  // use the native version
  90                  return getmxrr( $hostname, $mxhosts );
  91              }
  92          }
  93  
  94          /**
  95           * Another function shamelessly copied from the same place which implements an alternative version
  96           * of getmxrr.
  97           *
  98           * See http://hk2.php.net/manual/en/function.getmxrr.php for more details.
  99           *
 100           * @param hostname The host for which we want to get the mx records.
 101           * @param mxhosts The array we are going to fill with the mx records.
 102           * @return Returns either true or false.
 103           * @static
 104           * @private
 105           */
 106          function getmxrr_windows( $hostname, &$mxhosts )
 107          {
 108              if( !is_array( $mxhosts )) $mxhosts = array();
 109  
 110              if( !empty( $hostname ) ) {
 111                  @exec( "nslookup -type=MX $hostname", $output, $ret );
 112  
 113                  while( list( $k, $line ) = each( $output ) ) {
 114                      // Valid records begin with hostname:
 115                      if( ereg( "^$hostname\tMX preference = ([0-9]+), mail exchanger = (.*)$", $line, $parts )) {
 116                          $mxhosts[ $parts[1] ] = $parts[2];
 117                      }
 118                  }
 119  
 120                  if( count( $mxhosts ) ) {
 121                      reset( $mxhosts );
 122                      ksort( $mxhosts );
 123  
 124                      $i = 0;
 125  
 126                      while( list( $pref, $host ) = each( $mxhosts ) ) {
 127                          $mxhosts2[$i] = $host;
 128                          $i++;
 129                      }
 130  
 131                      $mxhosts = $mxhosts2;
 132  
 133                      return true;
 134                  }
 135                  else {
 136                      return false;
 137                  }
 138              }
 139          }
 140      }
 141  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics