[ 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/data/validator/rules/ -> emaildnsrule.class.php (source)

   1  <?php
   2  
   3      lt_include(PLOG_CLASS_PATH."class/data/validator/rules/rule.class.php");
   4      lt_include(PLOG_CLASS_PATH."class/net/dns.class.php");
   5      lt_include(PLOG_CLASS_PATH."class/net/http/httpvars.class.php");
   6      lt_include(PLOG_CLASS_PATH."class/config/config.class.php");
   7      lt_include(PLOG_CLASS_PATH."class/data/textfilter.class.php");
   8  
   9      define( "ERROR_RULE_EMAIL_DNS_SERVER_UNREACHABLE", "error_rule_email_dns_server_unreachable");
  10      define( "ERROR_RULE_EMAIL_DNS_SERVER_TEMP_FAIL", "error_rule_email_dns_server_temp_fail");
  11      define( "ERROR_RULE_EMAIL_DNS_NOT_PERMITTED", "error_rule_email_dns_not_permitted");
  12      define( "ERROR_RULE_EMAIL_DNS_BAD_DOMAIN", "error_rule_email_dns_bad_domain");
  13  
  14      /**
  15       * \ingroup Validator_Rules
  16       *
  17       * Given an email address it will connect to the MX server listed for the given domain
  18       * and check whether the given user name has a valid mailbox in the server. This operation
  19       * is a bit costly concerning time, since it takes a while to carry out these operations.
  20       *
  21       * This class will set one of these errors:
  22       *
  23       * - ERROR_RULE_EMAIL_DNS_NOT_PERMITTED
  24       * - ERROR_RULE_EMAIL_DNS_SERVER_UNREACHABLE
  25       */
  26      class EmailDnsRule extends Rule
  27      {
  28          /**
  29           * The constructor does nothing.
  30           */
  31          function EmailDnsRule()
  32          {
  33              $this->Rule();
  34          }
  35  
  36          /**
  37           * Checks the given email address
  38           */
  39          function validate($value)
  40          {
  41              if (empty($value))
  42              {
  43                  $this->_setError(false);
  44                  return true;
  45              }
  46  
  47              list($userName, $domain) = explode("@", $value);
  48  
  49                  // check input
  50              $clean_domain = Textfilter::domainize($domain);
  51              if($clean_domain != $domain){
  52                  $this->_setError(ERROR_RULE_EMAIL_DNS_BAD_DOMAIN);
  53                  return false;
  54              }
  55  
  56              $connectAddress          = $domain;
  57  
  58              if (!Dns::checkdnsrr($domain, "A"))
  59              {
  60                  $this->_setError(ERROR_RULE_EMAIL_DNS_SERVER_UNREACHABLE);
  61                  return false;
  62              }
  63  
  64              if (Dns::checkdnsrr($domain, "MX") && Dns::getmxrr($domain, $mxHosts))
  65              {
  66                  $connectAddress = $mxHosts[0];
  67              }
  68  
  69              if ($connect = fsockopen($connectAddress, 25))
  70              {
  71                  $greeting = fgets($connect, 1024);
  72  
  73                  if (ereg("^220", $greeting))
  74                  {
  75                      $server = &HttpVars::getServer();
  76                      fputs($connect, "HELO " . $server["HTTP_HOST"] . "\r\n");
  77                      $helo = fgets($connect, 1024);
  78  
  79                      $config =& Config::getConfig();
  80                      $lt_from = $config->getValue("post_notification_source_address");
  81                      if($lt_from == "")
  82                          $lt_from = $value;
  83                      
  84                      fputs($connect, "MAIL FROM: <" . $lt_from . ">\r\n");
  85                      $from = fgets($connect, 1024);
  86  
  87                      fputs($connect, "RCPT TO: <" . $value .">\r\n");
  88                      $to = fgets($connect, 1024);
  89  
  90                      fputs($connect, "QUIT\r\n");
  91                      fclose($connect);
  92  
  93                      if (!ereg("^250", $from) || !ereg ("^250", $to))
  94                      {
  95                          if(ereg("^4[0-9][0-9]", $helo) || ereg("^4[0-9][0-9]", $from) || ereg ("^4[0-9][0-9]", $to)){
  96                              $this->_setError(ERROR_RULE_EMAIL_DNS_SERVER_TEMP_FAIL);
  97                                  // Note: see http://bugs.lifetype.net/view.php?id=718 to fix this
  98                              return true;
  99                          }
 100                          else{
 101                              $this->_setError(ERROR_RULE_EMAIL_DNS_NOT_PERMITTED);
 102                              return false;
 103                          }
 104                      }
 105                  }
 106                  else if(ereg("^4[0-9][0-9]", $greeting)){
 107                      $this->_setError(ERROR_RULE_EMAIL_DNS_SERVER_TEMP_FAIL);
 108                      return false;
 109                  }
 110              }
 111              else
 112              {
 113                  $this->_setError(ERROR_RULE_EMAIL_DNS_SERVER_UNREACHABLE);
 114                  return false;
 115              }
 116  
 117              return true;
 118          }
 119      }
 120  ?>


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