<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2005 by Philippe Brunier   */
/*                                                                      */
/* IPBAN                                                                */
/*                                                                      */
/* 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.       */
/************************************************************************/
/***********************************/
/* 05.01.2001 - martvin@box43.pl   */
/***********************************/
/* 12.09.2002 - Achel_Jay          */
/***********************************/
/* 30.01.2003 and 10.05.2004 Snipe */
/***********************************/
function ipbani($ip){
   if (file_exists("meta/meta.php"))
      include ("meta/meta.php");
   echo "<title>NPDS</title></head><body bgcolor=\"white\"><br /><p align=\"center\"><span style=\"font-size: 14px; font-family: Arial; font-weight: bold; color: red;\">";
   echo "IP / DNS : $ip<br /><br />";
   echo "Access Denied / Acc&egrave;s Refus&eacute;";
   if (cur_charset=="utf-8") echo" / &#x901A;&#x5165;&#x88AB;&#x5426;&#x8BA4;";
   echo "</span>";
   echo "<br /><br /><span style=\"font-size: 12px; font-family: Arial; font-weight: bold; color: black;\">NPDS - Portal System";
   echo "</span></p></body></html>";
   die();
}

if (file_exists("modules/ipban/data_ban.php")) {
   include ("modules/ipban/data_ban.php");
   $ip  = getip();
   $ip_net = explode("|",$ip_ban);
   foreach ($ip_net as $ban_ip) {
      if (strstr($ban_ip,'*')) {
         $ban_ip_p=explode ( ".", $ban_ip);
         $a=count($ban_ip_p);
         array_splice($ban_ip_p, $a-1);
            $ip_p=explode ( ".", $ip, $a);
         array_splice($ip_p, $a-1);

          if ($ban_ip_p == $ip_p) {
             ipbani($ip);
          }
      }
      else if ($ip == $ban_ip) {
        ipbani($ip);
      }
   }
}

if ($dns_verif) {
   if (file_exists("modules/ipban/dns_ban.php")) {
      include ("modules/ipban/dns_ban.php");
      if ($host=@gethostbyaddr($ip)!=''){
         $dns_net = explode("|",$dns_ban);
         foreach ($dns_net as $ban_dns) {
            $maskDNS = explode("*", $ban_dns);
            $nb=count($maskDNS)-1;
            $nbdeb = strlen ($maskDNS[0]);
            $nbfin = 0 - strlen ($maskDNS[$nb]);
            $fin = substr ($host, $nbfin);
            $deb = substr ($host, 0, $nbdeb);
            if ($deb==$maskDNS[0] and $fin==$maskDNS[$nb]) {
               ipbani($host);
            }
         }
      }
   }
}
?>
