Ejemplo n.º 1
0
 public static function lookup_hosts($service, $location, $domain)
 {
     $servers = array();
     $ttl = false;
     $host = "_{$service}._udp.{$location}.{$domain}";
     echo "Service: {$service}, Location: {$location}, Domain: {$domain}\r\nHost: {$host}\r\n";
     $servers = cache::cache_get($host);
     if ($servers === false) {
         echo "Cache Status: MISS\r\n";
         $resolver = new Net_DNS_Resolver();
         $response = $resolver->query($host, 'SRV');
         if ($response) {
             foreach ($response->answer as $rr) {
                 if ($ttl !== false) {
                     $ttl = $rr->ttl;
                 }
                 //$servers[$rr->preference][$rr->weight][] = $rr->target.":".$rr->port;
                 $servers[$rr->preference][$rr->weight][] = $rr->target;
             }
         }
         cache::cache_put($host, $servers, $ttl);
     } else {
         echo "Cache Status: HIT\r\n";
     }
     return $servers;
 }
Ejemplo n.º 2
0
 /**
  * Get host to lookup. Lookup a host if neccessary and get the
  * complete FQDN to lookup.
  *
  * @param string $host      Host OR IP to use for building the lookup.
  * @param string $blacklist Blacklist to use for building the lookup.
  * @param string $isIP      is IP adress?
  *
  * @return string Ready to use host to lookup
  */
 public static function getHostForLookup($hostname, $blacklist, $isIP = true)
 {
     if ($isIP && filter_var($hostname, FILTER_VALIDATE_IP)) {
         return self::buildLookUpIP($hostname, $blacklist);
     }
     if ($isIP && !filter_var($hostname, FILTER_VALIDATE_IP)) {
         $resolver = new \Net_DNS_Resolver();
         $response = @$resolver->query($hostname);
         $ip = isset($response->answer[0]->address) ? $response->answer[0]->address : null;
         if (!$ip || !filter_var($ip, FILTER_VALIDATE_IP)) {
             return null;
         }
         return self::buildLookUpIP($ip, $blacklist);
     }
     return self::buildLookUpHost($hostname, $blacklist);
 }
Ejemplo n.º 3
0
function olc_get_ip_info(&$smarty)
{
    if (SHOW_IP_LOG == TRUE_STRING_S) {
        $customers_ip_text = 'CUSTOMERS_IP';
        $ip = $_SESSION[$customers_ip_text];
        if (!isset($ip)) {
            $ip = $_SERVER['REMOTE_ADDR'];
            if (strlen($ip) > 0) {
                if (function_exists("gethostbyaddr")) {
                    //Get host-name for IP by built-in PHP-function
                    $host = gethostbyaddr($ip);
                }
                if (strlen($host) == 0) {
                    //"gethostbyaddr" does not work always, so try "Net_DNS" first
                    define('FILENAME_NET_DNS', '"Net/DNS.php');
                    if (file_exists(FILENAME_NET_DNS)) {
                        require_once FILENAME_NET_DNS;
                        $res = new Net_DNS_Resolver();
                        $ans = $res->search($ip, "MX");
                        if ($ans) {
                            $host = $ans->answer[0]->ptrdname;
                        }
                    }
                }
                if (strlen($host) > 0) {
                    if ($host != $ip) {
                        $ip .= LPAREN . $host . RPAREN;
                    }
                }
                $ip .= ' -- Datum: ' . date("d.m.Y H:i:s");
                $_SESSION[$customers_ip_text] = $ip;
            }
        }
        if ($smarty) {
            $smarty->assign('IP_LOG', true);
            $smarty->assign($customers_ip_text, $ip);
        }
    }
}
Ejemplo n.º 4
0
	function connect($server_host,$server_port=5222,$connect_timeout=null,$alternate_ip=false) {

		if (is_null($connect_timeout)) $connect_timeout = DEFAULT_CONNECT_TIMEOUT;
		$connector = $this->_connector;

 		if (!$alternate_ip && class_exists('Net_DNS_Resolver')) {
			// Perform SRV record lookups
			$ndr = new Net_DNS_Resolver();
			$answer = $ndr->query("_xmpp-client._tcp.".$server_host,"SRV");
			if ($answer && count($answer->answer) > 0 && !empty($answer->answer[0]->target)) {
				$alternate_ip = $answer->answer[0]->target;
			}
			unset($answer);
			unset($ndr);
 		}

		$this->_connection = &new $connector();
		$this->_server_host = $server_host;
		$this->_server_port = $server_port;
		$this->_server_ip = $alternate_ip ? $alternate_ip : $server_host;
		$this->_connect_timeout = $connect_timeout;

		$this->roster = array();
		$this->services = array();

		$this->_is_win32 = (substr(strtolower(php_uname()),0,3)=="win");
		$this->_sleep_func = $this->_is_win32 ? "win32_sleep" : "posix_sleep";

		return $this->_connect_socket();
	}
Ejemplo n.º 5
0
 /**
  * Query DNS server for MX entries
  * @return
  */
 public function queryMX($domain)
 {
     $hosts = array();
     $mxweights = array();
     if (function_exists('getmxrr')) {
         getmxrr($domain, $hosts, $mxweights);
     } else {
         // windows, we need Net_DNS: http://pear.php.net/package/Net_DNS
         require_once 'Net/DNS.php';
         $resolver = new Net_DNS_Resolver();
         $resolver->debug = $this->debug;
         // nameservers to query
         $resolver->nameservers = $this->nameservers;
         $resp = $resolver->query($domain, 'MX');
         if ($resp) {
             foreach ($resp->answer as $answer) {
                 $hosts[] = $answer->exchange;
                 $mxweights[] = $answer->preference;
             }
         }
     }
     $mxs = array_combine($hosts, $mxweights);
     asort($mxs, SORT_NUMERIC);
     return $mxs;
 }
Ejemplo n.º 6
0
 /** 
  * Get host to lookup. Lookup a host if neccessary and get the
  * complete FQDN to lookup.
  *
  * @param  string Host OR IP to use for building the lookup.
  * @param  string Blacklist to use for building the lookup.
  * @access protected
  * @return string Ready to use host to lookup
  */
 function getHostForLookup($host, $blacklist)
 {
     // Currently only works for v4 addresses.
     if (!Net_CheckIP::check_ip($host)) {
         $resolver = new Net_DNS_Resolver();
         $response = $resolver->query($host);
         $ip = $response->answer[0]->address;
     } else {
         $ip = $host;
     }
     return $this->buildLookUpHost($ip, $blacklist);
 }
Ejemplo n.º 7
0
function validate_email($email, $checkserver = 'n')
{
    $valid_syntax = eregi("^[_a-z0-9\\+\\.\\-]+@[_a-z0-9\\.\\-]+\\.[a-z]{2,4}\$", $email);
    if (!$valid_syntax) {
        return false;
    } elseif ($checkserver == 'y') {
        include_once 'Net/DNS.php';
        $resolver = new Net_DNS_Resolver();
        $domain = substr(strstr($email, '@'), 1);
        $answer = $resolver->query($domain, 'MX');
        if (!$answer) {
            return false;
        } else {
            foreach ($answer->answer as $server) {
                $mxserver[$server->preference] = $server->exchange;
            }
            krsort($mxserver);
            foreach ($mxserver as $server) {
                $test = fsockopen($server, 25, $errno, $errstr, 15);
                if ($test) {
                    fclose($test);
                    return true;
                }
                fclose($test);
            }
            return false;
        }
    } else {
        return true;
    }
}
 /**
  * Query DNS server for MX entriesg
  * @return 
  */
 function queryMX($domain)
 {
     $hosts = array();
     $mxweights = array();
     if (function_exists('getmxrr')) {
         getmxrr($domain, $hosts, $mxweights);
     } else {
         // windows, we need Net_DNS
         require_once 'Net/DNS.php';
         $resolver = new Net_DNS_Resolver();
         $resolver->debug = $this->debug;
         // nameservers to query
         $resolver->nameservers = $this->nameservers;
         $resp = $resolver->query($domain, 'MX');
         if ($resp) {
             foreach ($resp->answer as $answer) {
                 $hosts[] = $answer->exchange;
                 $mxweights[] = $answer->preference;
             }
         }
     }
     return array($hosts, $mxweights);
 }
Ejemplo n.º 9
0
 /**
  * @brief Resolve a LSID using the DNS
  *
  * 
  */
 function Resolve($lsid_to_resolve)
 {
     $result = true;
     $this->lsid = new LSID($lsid_to_resolve);
     $ndr = new Net_DNS_Resolver();
     $answer = $ndr->search("_lsid._tcp." . $this->lsid->getAuthority(), "SRV");
     if ($answer == false) {
         $result = false;
     } else {
         if ($this->debug) {
             echo "<pre>";
             print_r($answer->answer);
             echo "</pre>";
         }
     }
     $this->server = $answer->answer[0]->target;
     $this->port = $answer->answer[0]->port;
     if ($this->report) {
         echo "<p>";
         echo "Authority for <strong>{$lsid_to_resolve}</strong> ";
         if ($result) {
             echo "is located at: ", $this->server, ":", $this->port;
         } else {
             echo "not found";
         }
         echo "</p>";
     }
     return $result;
 }
Ejemplo n.º 10
0
 /** 
  * Get host to lookup. Lookup a host if neccessary and get the
  * complete FQDN to lookup.
  *
  * @param string $host      Host OR IP to use for building the lookup.
  * @param string $blacklist Blacklist to use for building the lookup.
  *
  * @access protected
  * @return string Ready to use host to lookup
  */
 protected function getHostForLookup($host, $blacklist)
 {
     // Currently only works for v4 addresses.
     if (filter_var($host, FILTER_VALIDATE_IP)) {
         $ip = $host;
     } else {
         $resolver = new Net_DNS_Resolver();
         $response = $resolver->query($host);
         $ip = isset($response->answer[0]->address) ? $response->answer[0]->address : null;
     }
     if (!$ip || !filter_var($ip, FILTER_VALIDATE_IP)) {
         return;
     }
     return $this->buildLookUpHost($ip, $blacklist);
 }
Ejemplo n.º 11
0
function validateEmail($email, $domainCheck = false, $verify = false, $probe_address='', $helo_address='', $return_errors=false) {
	global $debug;
	$server_timeout = 180; # timeout in seconds. Some servers deliberately wait a while (tarpitting)
	if($debug) {echo "<pre>";}
	# Check email syntax with regex
	if (preg_match('/^([a-zA-Z0-9\._\+-]+)\@((\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,7}|[0-9]{1,3})(\]?))$/', $email, $matches)) {
		$user = $matches[1];
		$domain = $matches[2];
		# Check availability of  MX/A records
		if ($domainCheck) {
			if(function_exists('checkdnsrr')) {
				# Construct array of available mailservers
				if(getmxrr($domain, $mxhosts, $mxweight)) {
					for($i=0;$i<count($mxhosts);$i++){
						$mxs[$mxhosts[$i]] = $mxweight[$i];
					}
					asort($mxs);
					$mailers = array_keys($mxs);
				} elseif(checkdnsrr($domain, 'A')) {
					$mailers[0] = gethostbyname($domain);
				} else {
					$mailers=array();
				}
			} else {
			# DNS functions do not exist - we are probably on Win32.
			# This means we have to resort to other means, like the Net_DNS PEAR class.
			# For more info see http://pear.php.net
			# For this you also need to enable the mhash module (lib_mhash.dll).
			# Another way of doing this is by using a wrapper for Win32 dns functions like
			# the one descrieb at http://px.sklar.com/code.html/id=1304
				require_once 'Net/DNS.php';
				$resolver = new Net_DNS_Resolver();
				# Workaround for bug in Net_DNS, you have to explicitly tell the name servers
				#
				# ***********  CHANGE THIS TO YOUR OWN NAME SERVERS **************
				$resolver->nameservers = array ('217.149.196.6', '217.149.192.6');
				
				$mx_response = $resolver->query($domain, 'MX');
				$a_response  = $resolver->query($domain, 'A');
				if ($mx_response) {
					foreach ($mx_response->answer as $rr) {
							$mxs[$rr->exchange] = $rr->preference;
					}
					asort($mxs);
					$mailers = array_keys($mxs);
				} elseif($a_response) {
					$mailers[0] = gethostbyname($domain);
				} else {
					$mailers = array();
				}
				
			}
			
			$total = count($mailers);
			# Query each mailserver
			if($total > 0 && $verify) {
				# Check if mailers accept mail
				for($n=0; $n < $total; $n++) {
					# Check if socket can be opened
					if($debug) { echo "Checking server $mailers[$n]...\n";}
					$connect_timeout = $server_timeout;
					$errno = 0;
					$errstr = 0;
					# Try to open up socket
					if($sock = @fsockopen($mailers[$n], 25, $errno , $errstr, $connect_timeout)) {
						$response = fgets($sock);
						if($debug) {echo "Opening up socket to $mailers[$n]... Succes!\n";}
						stream_set_timeout($sock, 30);
						$meta = stream_get_meta_data($sock);
						if($debug) { echo "$mailers[$n] replied: $response\n";}
						$cmds = array(
							"HELO $helo_address",
							"MAIL FROM: <$probe_address>",
							"RCPT TO: <$email>",
							"QUIT",
						);
						# Hard error on connect -> break out
						# Error means 'any reply that does not start with 2xx '
						if(!$meta['timed_out'] && !preg_match('/^2\d\d[ -]/', $response)) {
							$error = "Error: $mailers[$n] said: $response\n";
							break;
						}
						foreach($cmds as $cmd) {
							$before = microtime(true);
							fputs($sock, "$cmd\r\n");
							$response = fgets($sock, 4096);
							$t = 1000*(microtime(true)-$before);
							if($debug) {echo htmlentities("$cmd\n$response") . "(" . sprintf('%.2f', $t) . " ms)\n";}
							if(!$meta['timed_out'] && preg_match('/^5\d\d[ -]/', $response)) {
								$error = "Unverified address: $mailers[$n] said: $response";
								break 2;
							}
						}
						fclose($sock);
						if($debug) { echo "Succesful communication with $mailers[$n], no hard errors, assuming OK";}
						break;
					} elseif($n == $total-1) {
						$error = "None of the mailservers listed for $domain could be contacted";
					}
				}
			} elseif($total <= 0) {
				$error = "No usable DNS records found for domain '$domain'";
			}
		}
	} else {
		$error = 'Address syntax not correct';
	}
	if($debug) { echo "</pre>";}
	
	if($return_errors) {
		# Give back details about the error(s).
		# Return FALSE if there are no errors.
		if(isset($error)) return htmlentities($error); else return false;
	} else {
		# 'Old' behaviour, simple to understand
		if(isset($error)) return false; else return true;
	}
}
Ejemplo n.º 12
0
 function dns_get_ns($hostname, &$ns_array)
 {
     // 答えを返すところをクリアしておく
     if (!empty($ns_array)) {
         while (array_pop($ns_array)) {
         }
     }
     // まだキャッシュがなければ以前に得た結果のキャッシュファイルを読み込む
     if (empty($this->dns_get_ns_cache)) {
         $fp = fopen(DATA_HOME . SPAM_FILTER_DNSGETNS_CACHE_FILE, "a+") or die_message('Cannot read dns_get_ns cache file: ' . SPAM_FILTER_DNSGETNS_CACHE_FILE . "\n");
         flock($fp, LOCK_SH);
         while ($csv = fgetcsv($fp, 1000, ",")) {
             $host = array_shift($csv);
             $time = $csv[0];
             if ($time + SPAM_FILTER_DNSGETNS_CACHE_DAY * 24 * 60 * 60 < time()) {
                 continue;
             }
             // 古すぎる情報は捨てる
             $this->dns_get_ns_cache["{$host}"] = $csv;
         }
         flock($fp, LOCK_UN);
         fclose($fp);
     }
     // キャッシュの結果に入ってるならそこから結果を引いて返す
     $cache = $this->dns_get_ns_cache["{$hostname}"];
     if (!empty($cache)) {
         $time = array_shift($cache);
         foreach ($cache as $ns) {
             $ns_array[] = $ns;
         }
         return TRUE;
     }
     // ホスト名を上から一つづつ減らしてNSが得られるまで試す
     // 例: www.subdomain.example.com→subdomain.example.com→example.com
     $domain_array = explode(".", $hostname);
     $ns_found = FALSE;
     do {
         $domain = implode(".", $domain_array);
         // 環境で使える手段に合わせてドメインのNSを得る
         if (function_exists('dns_get_record')) {
             // 内部関数 dns_get_record 使える場合
             $lookup = dns_get_record($domain, DNS_NS);
             if (!empty($lookup)) {
                 foreach ($lookup as $record) {
                     $ns_array[] = $record['target'];
                 }
                 $ns_found = TRUE;
             }
         } else {
             if (include_once 'Net/DNS.php') {
                 // PEARのDNSクラスが使える場合
                 $resolver = new Net_DNS_Resolver();
                 if (SPAM_FILTER_IS_WINDOWS) {
                     $resolver->nameservers[0] = $this->getDNSServer();
                 }
                 $response = $resolver->query($domain, 'NS');
                 if ($response) {
                     foreach ($response->answer as $rr) {
                         if ($rr->type == "NS") {
                             $ns_array[] = $rr->nsdname;
                         } else {
                             if ($rr->type == "CNAME") {
                                 // CNAMEされてるときは、そっちを再帰で引く
                                 $this->dns_get_ns($rr->rdatastr(), $ns_array);
                             }
                         }
                     }
                     $ns_found = TRUE;
                 }
             } else {
                 // PEARも使えない場合、外部コマンドnslookupによりNSを取得
                 is_executable(SPAM_FILTER_NSLOOKUP_PATH) or die_message("Cannot execute nslookup. see NSLOOKUP_PATH setting.\n");
                 @exec(SPAM_FILTER_NSLOOKUP_PATH . " -type=ns " . $domain, $lookup);
                 foreach ($lookup as $line) {
                     if (preg_match('/\\s*nameserver\\s*=\\s*(\\S+)$/', $line, $ns) || preg_match('/\\s*origin\\s*=\\s*(\\S+)$/', $line, $ns) || preg_match('/\\s*primary name server\\s*=\\s*(\\S+)$/', $line, $ns)) {
                         $ns_array[] = $ns[1];
                         $ns_found = TRUE;
                     }
                 }
             }
         }
     } while (!$ns_found && array_shift($domain_array) != NULL);
     // NSが引けていたら、結果をキャッシュに入れて保存
     if ($ns_found) {
         // 結果をキャッシュに登録
         $cache = $ns_array;
         array_unshift($cache, time());
         // 引いた時間も保持
         $this->dns_get_ns_cache["{$hostname}"] = $cache;
         // キャッシュをファイルに保存
         $fp = fopen(DATA_HOME . SPAM_FILTER_DNSGETNS_CACHE_FILE, "w") or die_message("Cannot write dns_get_ns cache file: " . SPAM_FILTER_DNSGETNS_CACHE_FILE . "\n");
         flock($fp, LOCK_EX);
         foreach ($this->dns_get_ns_cache as $host => $cachedata) {
             $csv = $host;
             foreach ($cachedata as $data) {
                 $csv .= "," . $data;
             }
             $csv .= "\n";
             fputs($fp, $csv);
         }
         flock($fp, LOCK_UN);
         fclose($fp);
     }
     return $ns_found;
 }
Ejemplo n.º 13
0
function validateEmail($email, $domainCheck = false, $verify = false, $probe_address = '', $helo_address = '', $return_errors = false)
{
    global $debug;
    $debug = false;
    /*
        Time-outs.
        Be sure to have set PHP's "max_execution_time" to some value greater than the total time of the
        communication. This means of course also (a fair amount) larger than any of the next two values.
        Of course, large timeouts will cause the verification to take alot of time. There are servers
        that have configured such large delays that they are unsuitable for verifcation with a web page.
    
        TCP connect timeout (seconds). Some servers deliberately wait a while before responding (tarpitting). */
    $tcp_connect_timeout = 18000;
    /*
    Some server (exim) can be configured to wait before acknowledging. If you issues the next command
    too soon, it will drop the SMTP conversation with stuff like: "554 SMTP synchronization error".
    */
    $smtp_timeout = 6000;
    if ($debug) {
        echo "<pre>";
    }
    # Check email syntax with regex
    if (preg_match('/^([a-zA-Z0-9\'\\._\\+-]+)\\@((\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,7}|[0-9]{1,3})(\\]?))$/', $email, $matches)) {
        $user = $matches[1];
        $domain = $matches[2];
        // if only a@b.com or test@xyz.com then fail
        if (strlen($user) <= 1 || strpos($user, 'test') !== false) {
            return false;
        }
        return true;
        /*
            Some MTAs do not like people ringing their door bell too much.
            If this is the case, sender    verification will get your IP address
            blacklisted. This is a problem when your web server is also a
            mail server. If you MTA is Postfix, you can whitelist addresses
            so that they are not verified any more:
            in Postfix, see    http://www.postfix.org/ADDRESS_VERIFICATION_README.html#sender_always
            This list should be taken into account by this script, otherwise 
            your IP address will get blacklisted anyway.
            The code below ONLY works when the access list is of type 'pcre', see
            http://www.postfix.org/pcre_table.5.html for how to construct this.
        */
        $whitelist = dirname(__FILE__) . '/whitelist.txt';
        if ($exluded = explode("\n", @file_get_contents($whitelist))) {
            if ($debug) {
                echo "in file {$whitelist}\n";
            }
            $regexes = array();
            foreach ($exluded as $line) {
                if ($debug) {
                    echo "whitelist line {$line}\n";
                }
                preg_match('/^(\\/.*?\\/)\\s+OK/', $line, $matches);
                if (@$matches[1]) {
                    if ($debug) {
                        echo "found whitelist {$matches['1']}\n";
                    }
                    array_push($regexes, $matches[1]);
                }
            }
            foreach ($regexes as $regex) {
                if ($debug) {
                    echo "compare domain {$regex} in {$email}\n";
                }
                preg_match($regex, "{$user}@{$domain}", $m);
                if (@$m[0]) {
                    if ($debug) {
                        echo "{$whitelist} contains matching whitelist regex '" . $regex . "'\n";
                    }
                    if ($return_errors) {
                        # Give back details about the error(s).
                        # Return FALSE if there are no errors.
                        if (isset($error)) {
                            return htmlentities($error);
                        } else {
                            return false;
                        }
                    } else {
                        # 'Old' behaviour, simple to understand
                        if (isset($error)) {
                            return false;
                        } else {
                            return true;
                        }
                    }
                }
            }
        }
        # Check availability of  MX/A records
        if ($domainCheck) {
            if (function_exists('checkdnsrr')) {
                # Construct array of available mailservers
                getmxrr($domain, $mxhosts, $mxweight);
                if (count($mxhosts) > 0) {
                    for ($i = 0; $i < count($mxhosts); $i++) {
                        $mxs[$mxhosts[$i]] = $mxweight[$i];
                    }
                    asort($mxs);
                    $mailers = array_keys($mxs);
                    # No MX found, use A
                } elseif (checkdnsrr($domain, 'A')) {
                    $mailers[0] = gethostbyname($domain);
                } else {
                    $mailers = array();
                }
            } else {
                # DNS functions do not exist - we are probably on Win32.
                # This means we have to resort to other means, like the Net_DNS PEAR class.
                # For more info see http://pear.php.net
                # For this you also need to enable the mhash module (lib_mhash.dll).
                # Another way of doing this is by using a wrapper for Win32 dns functions like
                # the one descrieb at http://px.sklar.com/code.html/id=1304
                require_once 'Net/DNS.php';
                $resolver = new Net_DNS_Resolver();
                # Workaround for bug in Net_DNS, you have to explicitly tell the name servers
                #
                # ***********  CHANGE THIS TO YOUR OWN NAME SERVERS **************
                $resolver->nameservers = array('217.149.196.6', '217.149.192.6');
                $mx_response = $resolver->query($domain, 'MX');
                $a_response = $resolver->query($domain, 'A');
                if ($mx_response) {
                    foreach ($mx_response->answer as $rr) {
                        $mxs[$rr->exchange] = $rr->preference;
                    }
                    asort($mxs);
                    $mailers = array_keys($mxs);
                } elseif ($a_response) {
                    $mailers[0] = gethostbyname($domain);
                } else {
                    $mailers = array();
                }
            }
            $total = count($mailers);
            # Query each mailserver
            if ($total > 0 && $verify) {
                # Check if mailers accept mail
                for ($n = 0; $n < $total; $n++) {
                    # Check if socket can be opened
                    if ($debug) {
                        echo "Checking server {$mailers[$n]}...\n";
                    }
                    $errno = 0;
                    $errstr = 0;
                    # Try to open up TCP socket
                    if ($sock = @fsockopen($mailers[$n], 25, $errno, $errstr, $tcp_connect_timeout)) {
                        $response = fread($sock, 8192);
                        if ($debug) {
                            echo "Opening up socket to {$mailers[$n]}... Success!\n";
                        }
                        stream_set_timeout($sock, $smtp_timeout);
                        $meta = stream_get_meta_data($sock);
                        if ($debug) {
                            echo "{$mailers[$n]} replied: {$response}\n";
                        }
                        $cmds = array("HELO {$helo_address}", "MAIL FROM: <{$probe_address}>", "RCPT TO:<{$email}>", "QUIT");
                        # Hard error on connect -> break out
                        # Error means 'any reply that does not start with 2xx '
                        if (!$meta['timed_out'] && !preg_match('/^2\\d\\d[ -]/', $response)) {
                            $error = "Error: {$mailers[$n]} said: {$response}\n";
                            break;
                        }
                        foreach ($cmds as $cmd) {
                            $before = microtime(true);
                            fputs($sock, "{$cmd}\r\n");
                            $response = fread($sock, 4096);
                            $t = 1000 * (microtime(true) - $before);
                            if ($debug) {
                                echo htmlentities("{$cmd}\n{$response}") . "(" . sprintf('%.2f', $t) . " ms)\n";
                            }
                            if (!$meta['timed_out'] && preg_match('/^5\\d\\d[ -]/', $response)) {
                                $error = "Unverified address: {$mailers[$n]} said: {$response}";
                                break 2;
                            }
                        }
                        fclose($sock);
                        if ($debug) {
                            echo "Succesful communication with {$mailers[$n]}, no hard errors, assuming OK";
                        }
                        break;
                    } elseif ($n == $total - 1) {
                        $error = "None of the mailservers listed for {$domain} could be contacted";
                    }
                }
            } elseif ($total <= 0) {
                $error = "No usable DNS records found for domain '{$domain}'";
            }
        }
    } else {
        $error = 'Address syntax not correct';
    }
    if ($debug) {
        echo "</pre>";
    }
    if ($return_errors) {
        # Give back details about the error(s).
        # Return FALSE if there are no errors.
        if (isset($error)) {
            return nl2br(htmlentities($error));
        } else {
            return false;
        }
    } else {
        # 'Old' behaviour, simple to understand
        if (isset($error)) {
            return false;
        } else {
            return true;
        }
    }
}
Ejemplo n.º 14
0
function getdnsattributes_VMWO($l, $ip)
{
    $r = new Net_DNS_Resolver();
    $r->nameservers = array("ws1.maxmind.com");
    $p = $r->search($l . "." . $ip . ".s.maxmind.com", "TXT", "IN");
    $str = is_object($p->answer[0]) ? $p->answer[0]->string() : '';
    //ereg("\"(.*)\"",$str,$regs); // mike challis PHP5.3 fix
    preg_match("/\"(.*)\"/", $str, $regs);
    $str = isset($regs[1]) ? $regs[1] : '';
    return $str;
}
Ejemplo n.º 15
0
 function ZoneAXFR($domain, $server)
 {
     require_once "Net/DNS.php";
     $res = new Net_DNS_Resolver();
     //$res->debug = 1;
     $res->persistent_tcp = 1;
     $res->nameservers = array($server);
     $answer = $res->axfr($domain);
     /*
     echo "<pre>"; 
     var_dump($answer); 
     //var_dump($res); 
     //var_dump($answer[0]->header->rcode); 
     echo "</pre>";
     exit;
     */
     // check for errors
     /*
     if ($res->errorstring != "NOERROR") {
         $this->err=70;
         $this->errstr .= sprintf(my_("Zone transfer for domain %s failed with message %s"), $this->domain, $res->errorstring)."\n";
         return "";
     }
     */
     if ($answer) {
         $this->hname = array();
         $i = 1;
         // kill form information
         foreach ($answer as $rr) {
             if ($rr->type == "SOA") {
                 //var_dump($rr);
                 $this->ttl = $rr->ttl;
                 $this->refresh = $rr->refresh;
                 $this->retry = $rr->retry;
                 $this->expire = $rr->expire;
                 $this->minimum = $rr->minimum;
                 $this->responsiblemail = $rr->rname;
             }
             if ($rr->type == "NS" and $rr->name == $this->domain) {
                 $this->hname[$i++] = $this->strip_domain($rr->nsdname, $this->domain);
             }
         }
         $this->err = 0;
         return $answer;
     } else {
         $this->errstr .= sprintf(my_("Zone transfer for domain %s failed - using defaults: %s"), $this->domain, $res->errorstring) . "\n";
         // could not do transfer, so use defaults from now on!
         $this->err = -1;
         return "";
     }
 }
Ejemplo n.º 16
0
 /**
  * Gets or sets the nameservers to be queried.
  *
  * Returns the current nameservers if an array of new nameservers is not
  * given as the argument OR sets the nameservers to the given nameservers.
  *
  * Nameservers not specified by ip address must be able to be resolved by
  * the default settings of a new Net_DNS_Resolver.
  *
  * @access public
  */
 function nameservers($nsa = array())
 {
     $defres = new Net_DNS_Resolver();
     if (is_array($nsa)) {
         $a = array();
         foreach ($nsa as $ns) {
             if (preg_match('/^(\\d+(:?\\.\\d+){0,3})$/', $ns)) {
                 $a[] = $ns == 0 ? '0.0.0.0' : $ns;
             } else {
                 $names = array();
                 if (!preg_match('/\\./', $ns)) {
                     if (!empty($defres->searchlist)) {
                         foreach ($defres->searchlist as $suffix) {
                             $names[] = $ns . '.' . $suffix;
                         }
                     } elseif (!empty($defres->domain)) {
                         $names[] = $ns . '.' . $defres->domain;
                     }
                 } else {
                     $names[] = $ns;
                 }
                 $packet = $defres->search($ns);
                 if (is_object($packet)) {
                     $addresses = $this->cname_addr($names, $packet);
                     foreach ($addresses as $b) {
                         $a[] = $b;
                     }
                     $a = array_unique($a);
                 }
             }
         }
         if (count($a)) {
             $this->nameservers = $a;
         }
     }
     return $this->nameservers;
 }
Ejemplo n.º 17
0
 /**
  * Initializes the default values for the Header object.
  * 
  * Builds a header object from either default values, or from a DNS
  * packet passed into the constructor as $data
  *
  * @param string $data  A DNS packet of which the header will be parsed.
  * @return  object  Net_DNS_Header
  * @access public
  */
 function Net_DNS_Header($data = '')
 {
     if ($data != '') {
         /*
          * The header MUST be at least 12 bytes.
          * Passing the full datagram to this constructor
          * will examine only the header section of the DNS packet
          */
         if (strlen($data) < 12) {
             return false;
         }
         $a = unpack('nid/C2flags/n4counts', $data);
         $this->id = $a['id'];
         $this->qr = $a['flags1'] >> 7 & 0x1;
         $this->opcode = $a['flags1'] >> 3 & 0xf;
         $this->aa = $a['flags1'] >> 2 & 0x1;
         $this->tc = $a['flags1'] >> 1 & 0x1;
         $this->rd = $a['flags1'] & 0x1;
         $this->ra = $a['flags2'] >> 7 & 0x1;
         $this->rcode = $a['flags2'] & 0xf;
         $this->qdcount = $a['counts1'];
         $this->ancount = $a['counts2'];
         $this->nscount = $a['counts3'];
         $this->arcount = $a['counts4'];
     } else {
         $this->id = Net_DNS_Resolver::nextid();
         $this->qr = 0;
         $this->opcode = 0;
         $this->aa = 0;
         $this->tc = 0;
         $this->rd = 1;
         $this->ra = 0;
         $this->rcode = 0;
         $this->qdcount = 1;
         $this->ancount = 0;
         $this->nscount = 0;
         $this->arcount = 0;
     }
     if (Net_DNS::opcodesbyval($this->opcode)) {
         $this->opcode = Net_DNS::opcodesbyval($this->opcode);
     }
     if (Net_DNS::rcodesbyval($this->rcode)) {
         $this->rcode = Net_DNS::rcodesbyval($this->rcode);
     }
 }
Ejemplo n.º 18
0
 public function getdnsattributes($l, $ip)
 {
     $r = new Net_DNS_Resolver();
     $r->nameservers = array("ws1.maxmind.com");
     $p = $r->search($l . "." . $ip . ".s.maxmind.com", "TXT", "IN");
     $str = is_object($p->answer[0]) ? $p->answer[0]->string() : '';
     $str = substr($str, 1, -1);
     return $str;
 }
 /**
  *  validate html form 
  *
  *  @param array $errors    array with error messages
  *  @return bool            TRUE if given values of form are OK, FALSE otherwise
  */
 function validate_form(&$errors)
 {
     global $lang_str, $config, $data;
     if (false === parent::validate_form($errors)) {
         return false;
     }
     /* Check if the domain name is not prohibited */
     if (!empty($_POST['domainname']) and in_array($_POST['domainname'], $this->opt['prohibited_domain_names'])) {
         $errors[] = $lang_str['prohibited_domain_name'];
         return false;
     }
     /* Check if domain name does not already exists */
     $o = array('check_deleted_flag' => false, 'filter' => array('name' => $_POST['domainname']));
     $data->add_method('get_domain');
     if (false === ($domains = $data->get_domain($o))) {
         return false;
     }
     if (count($domains)) {
         $errors[] = $lang_str['err_domain_already_hosted'];
         return false;
     }
     // create DNS resolver object
     $ndr = new Net_DNS_Resolver();
     // query for SRV record
     $dns_lookup = "_sip._udp." . $_POST['domainname'];
     $dns_answer = $ndr->rawQuery($dns_lookup, "SRV");
     if (!$dns_answer) {
         ErrorHandler::log_errors(PEAR::raiseError($lang_str['err_dns_lookup'], null, null, null, $ndr->errorstring));
         return false;
     }
     if (!$dns_answer->answer) {
         $errors[] = str_replace("<hostname>", $dns_lookup, $lang_str['err_no_srv_record']);
         return false;
     }
     $srv_ok = false;
     $srv_false_rec = array();
     foreach ($dns_answer->answer as $v) {
         if ($v->port == $config->srv_sip_proxy_port and $v->target == $config->srv_sip_proxy_hostname) {
             $srv_ok = true;
             break;
         }
         $srv_false_rec[] = array("host" => $v->target, "port" => $v->port);
     }
     if ($srv_ok) {
         return true;
     }
     $err = $lang_str['err_wrong_srv_record'] . "\n";
     foreach ($srv_false_rec as $v) {
         $err .= "host: " . $v['host'] . ", port: " . $v['port'] . "\n";
     }
     $errors[] = $err;
     return false;
 }
Ejemplo n.º 20
0
function getdnsattributes($l, $ip)
{
    $r = new Net_DNS_Resolver();
    $r->nameservers = array("ws1.maxmind.com");
    $p = $r->search($l . "." . $ip . ".s.maxmind.com", "TXT", "IN");
    $str = is_object($p->answer[0]) ? $p->answer[0]->string() : '';
    ereg("\"(.*)\"", $str, $regs);
    $str = $regs[1];
    return $str;
}
Ejemplo n.º 21
0
function get_mx($dnsname)
{
    $resolver = new Net_DNS_Resolver();
    $response = $resolver->query($dnsname, 'MX');
    global $res_array;
    if ($response) {
        foreach ($response->answer as $rr) {
            $ipaddr = "";
            $ip_type = "";
            $ipaddr = get_ip_for_a($rr->exchange);
            if (Net_CheckIP::check_ip($ipaddr)) {
                $ip_type = "ipv4";
            }
            if (Net_IPv6::checkIPv6($ipaddr)) {
                $ip_type = "ipv6";
            }
            array_push($res_array, array('prio' => $rr->preference, 'dnsname' => $rr->exchange, 'ipaddr' => $ipaddr, 'iptype' => $ip_type));
        }
        asort($res_array);
        return true;
    } else {
        return false;
    }
}