<?php
#-------------------------------------------------------------------------
# Module: Newsletter Made Simple
#        (c) to 2008 by Paul Lempkepf
#        (c) 2008 and on by Robert Campbell (calguy1000@cmsmadesimple.org)
#
#  An addon module for CMS Made Simple to provide a flexible
#  mailing list solution.
#
#-------------------------------------------------------------------------
# CMSMS - CMS Made Simple is (c) 2005 by Ted Kulp (wishy@cmsmadesimple.org)
# Visit the CMSMS Homepage at: http://www.cmsmadesimple.org
#
#-------------------------------------------------------------------------
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# However, as a special exception to the GPL, this software is distributed
# as an addon module to CMS Made Simple.  You may not use this software
# in any Non GPL version of CMS Made simple, or in any version of CMS
# Made simple that does not indicate clearly and obviously in its admin
# section that the site was built with CMS Made simple.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Or read it online: http://www.gnu.org/licenses/licenses.html#GPL
#
#-------------------------------------------------------------------------
#END_LICENSE

/******************************************************

These functions can be used on WindowsNT to replace
their built-in counterparts that do not work as
expected.

checkdnsrr_winNT() works just the same, returning true
or false

getmxrr_winNT() returns true or false and provides a
list of MX hosts in order of preference.
testing - jbogard

*******************************************************/
function checkdnsrr_winNT( $host, $type = '' )
{

   if( !empty( $host ) )
   {

       # Set Default Type:
       if( $type == '' ) $type = "MX";

       @exec( "nslookup -type=$type $host", $output );

       if( !is_array( $output ) )
       {
          return false;
       }
       while( list( $k, $line ) = each( $output ) )
       {

           # Valid records begin with host name:
           if( eregi( "^$host", $line ) )
           {
               # record found:
               return true;
           }

       }

       return false;

   }

}

function getmxrr_winNT( $hostname, &$mxhosts )
{

   if( !is_array( $mxhosts ) ) $mxhosts = array();

   if( !empty( $hostname ) )
   {

       @exec( "nslookup -type=MX $hostname", $output, $ret );

       while( list( $k, $line ) = each( $output ) )
       {

           # Valid records begin with hostname:
           if( ereg( "^$hostname\tMX preference = ([0-9]+), mail exchanger = (.*)$", $line, $parts ) )
           {

               $mxhosts[ $parts[1] ] = $parts[2];

           }

       }

       if( count( $mxhosts ) )
       {

           reset( $mxhosts );

           ksort( $mxhosts );

           $i = 0;

           while( list( $pref, $host ) = each( $mxhosts ) )
           {
               $mxhosts2[$i] = $host;
               $i++;
           }

           $mxhosts = $mxhosts2;

           return true;

       }
       else
       {

           return false;

       }

   }

}

?>
