예제 #1
0
 public function get_from_dns()
 {
     global $DB, $error_ar, $DNSSERVER;
     echo "Fetching 'A' records for accounts from our DNS server ...<br>\n";
     $start_time = microtime(1);
     $account_result = $DB->make_select('Accounts', '*', "`Status`!='Deleted'");
     $dns_defaults = array('nameservers' => array($DNSSERVER), 'port' => '53', 'retrans' => 5, 'retry' => 3, 'usevc' => 0, 'stayopen' => 1, 'igntc' => 0, 'recurse' => false, 'debug' => false, 'tcp_timeout' => 5);
     $dns = new Net_DNS_Client($dns_defaults);
     while ($account = $DB->row($account_result)) {
         $domain = $account['domain'];
         $dns_packet = new Net_DNS_Packet();
         $dns_packet->buildQuestion($domain . '.', 'A');
         $dns_packet->header->rd = false;
         $dns_ans = $dns->resolver->send($dns_packet);
         if (empty($dns_ans->answer[0]->address)) {
             $ip = '';
             $error_ar[] = "dns record for account {$domain} not found";
             continue;
             //raw($domain);
         } else {
             $ip = $dns_ans->answer[0]->address;
             //raw("$ip - $domain");
         }
         //if(empty($ip)) { $error_ar[] = "dns record for account $domain not found"; $ip = '0.0.0.0'; }
         $server = $this->ip2server($ip);
         if ($server != $account['ServerID'] && $server != 'none') {
             $error_ar[] = "Server wrong for domain {$domain} , account on server '{$server}', but was at {$account['ServerID']}";
             //$DB->make_update("`Accounts` SET `ServerID`='$server' WHERE `AccountID`=$account[AccountID]");
         } elseif ($server == 'none') {
             $error_ar[] = "IP wrong for domain {$domain} , account on server {$account['ServerID']}, but in DNS at {$ip}";
         }
         //echo "$domain \t $ip \t $server \n";
         /*
         	$account_servers = array();
         	$whmaccount_result = $DB->make_select("SELECT * FROM `whmaccts` WHERE `domain`='$domain'  AND `username`='$account[domain]'");
         	while($whmaccount = $DB->row($whmaccount_result)) $account_servers[] = $whmaccount['server'];
         	if(count($account_servers)==0)  $error_ar[] = "account $domain , no found on servers";
         	elseif(count($account_servers)>1) {
         		foreach($account_servers as $account_server) $error_ar[] = "clone of account $domain on server $account_server";
         		if(!in_array($server,$account_servers)) {
         			$error_ar[] = "ip wrong for domain $domain , account on server $whmaccount[server], but in DNS $server";
         			$server = $whmaccount['server'];
         		}
         	}
         */
         //$DB->make_update("Accounts SET ServerID='$server' WHERE AccountID=$account[AccountID]");
     }
     echo "Finished Step. Time " . intval((microtime(1) - $start_time) * 1000) . "ms.\n\n";
 }
 /**
  * Unknown
  */
 function make_query_packet($packetORname, $type = '', $class = '')
 {
     if (is_object($packetORname) && get_class($packetORname) == 'net_dns_packet') {
         $packet = $packetORname;
     } else {
         $name = $packetORname;
         if ($type == '') {
             $type = 'A';
         }
         if ($class == '') {
             $class = 'IN';
         }
         /*
          * If the name looks like an IP address then do an appropriate
          * PTR query.
          */
         if (preg_match('/^(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$/', $name, $regs)) {
             $name = "{$regs['4']}.{$regs['3']}.{$regs['2']}.{$regs['1']}.in-addr.arpa";
             $type = 'PTR';
         }
         if ($this->debug) {
             echo ";; query({$name}, {$type}, {$class})\n";
         }
         $packet = new Net_DNS_Packet($this->debug);
         $packet->buildQuestion($name, $type, $class);
     }
     $packet->header->rd = $this->recurse;
     return $packet;
 }