<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.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.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
/********************************************************/
/* NukeSentinel(tm)                                     */
/* By: NukeScripts Network (webmaster@nukescripts.net)  */
/* http://www.nukescripts.net                           */
/* Copyright © 2000-2005 by NukeScripts Network         */
/********************************************************/

if (!defined('ADMIN_ALLOW') && !defined('ADMIN_MAX')) {
	die ("Access Denied");
}

$datetime = time();
if(($xip_lo[0] < 0 OR $xip_lo[0] > 255 OR !is_numeric($xip_lo[0])) OR ($xip_lo[1] < 0 OR $xip_lo[1] > 255 OR !is_numeric($xip_lo[1])) OR ($xip_lo[2] < 0 OR $xip_lo[2] > 255 OR !is_numeric($xip_lo[2])) OR ($xip_lo[3] < 0 OR $xip_lo[3] > 255 OR !is_numeric($xip_lo[3]))) {
  $pagetitle = _AB_NUKESENTINEL.": "._AB_ADDRANGEERROR;
  incoh();
  title($pagetitle);
  Max_OpenTable();
  echo "<br /><center><b>"._AB_LOERROR." </b></center>\n";
  echo "<br /><center><b>"._GOBACK."</b></center><br />\n";
  Max_CloseTable();
  incof();
  die();
}
$xip_lo = implode(".", $xip_lo);
$longip_lo = sprintf("%u", ip2long($xip_lo));
if(($xip_hi[0] < 0 OR $xip_hi[0] > 255 OR !is_numeric($xip_hi[0])) OR ($xip_hi[1] < 0 OR $xip_hi[1] > 255 OR !is_numeric($xip_hi[1])) OR ($xip_hi[2] < 0 OR $xip_hi[2] > 255 OR !is_numeric($xip_hi[2])) OR ($xip_hi[3] < 0 OR $xip_hi[3] > 255 OR !is_numeric($xip_hi[3]))) {
  $pagetitle = _AB_NUKESENTINEL.": "._AB_ADDRANGEERROR;
  incoh();
  title($pagetitle);
  Max_OpenTable();
  echo "<br /><center><b>"._AB_HIERROR." </b></center>\n";
  echo "<br /><center><b>"._GOBACK."</b></center><br />\n";
  Max_CloseTable();
  incof();
  die();
}
$xip_hi = implode(".", $xip_hi);
$longip_hi = sprintf("%u", ip2long($xip_hi));
list($xcountry) = $db->sql_fetchrow($db->sql_query("SELECT `country` FROM `".$prefix."_nsnst_countries` WHERE `c2c`='$xc2c'"));
$test1 = $db->sql_query("SELECT * FROM ".$prefix."_nsnst_ip2country WHERE ip_lo<='$longip_lo' AND ip_hi>='$longip_lo' ORDER BY `ip_lo`");
$test2 = $db->sql_query("SELECT * FROM ".$prefix."_nsnst_ip2country WHERE ip_lo<='$longip_hi' AND ip_hi>='$longip_hi' ORDER BY `ip_lo`");
$test3 = $db->sql_query("SELECT * FROM ".$prefix."_nsnst_ip2country WHERE ip_lo>='$longip_lo' AND ip_hi<='$longip_hi' ORDER BY `ip_lo`");
$test4 = $db->sql_query("SELECT * FROM ".$prefix."_nsnst_ip2country WHERE ip_lo<='$longip_lo' AND ip_hi>='$longip_hi' ORDER BY `ip_lo`");
$testnum1 = $db->sql_numrows($test1);
$testnum2 = $db->sql_numrows($test2);
$testnum3 = $db->sql_numrows($test3);
$testnum4 = $db->sql_numrows($test4);
if($testnum1 > 0 OR $testnum2 >0 OR $testnum3 >0 OR $testnum4 >0) {
  $pagetitle = _AB_NUKESENTINEL.": "._AB_ADDIP2COUNTRYERROR;
  incoh();
  title($pagetitle);
  Max_OpenTable();
  OpenMenu();
  ipbanmenu();
  CarryMenu();
  ip2cmenu();
  CloseMenu();
  Max_CloseTable();
  echo "<br />\n";
  Max_OpenTable();
  echo "<table align='center' border='0' cellpadding='2' cellspacing='2' bgcolor='$bgcolor2' width='100%'>\n";
  echo "<tr bgcolor='$bgcolor1'><td align='center' colspan='6'><b>$xip_lo "._AB_IN.":</b></td></tr>\n";
  if($testnum1 > 0) {
    echo "<tr bgcolor='$bgcolor2'>\n";
    echo "<td width='15%'><b>"._AB_IPLO."</b></td>\n";
    echo "<td width='15%'><b>"._AB_IPHI."</b></td>\n";
    echo "<td align='center' width='10%'><b>"._AB_FLAG."</b></td>\n";
    echo "<td align='center' width='10%'><b>"._AB_CODE."</b></td>\n";
    echo "<td align='center' width='35%'><b>"._AB_COUNTRY."</b></td>\n";
    echo "<td align='center' width='15%'><b>"._AB_FUNCTIONS."</b></td>\n";
    echo "</tr>\n";
    while($testrow1 = $db->sql_fetchrow($test1)) {
      $testrow1['ip_lo_ip'] = long2ip($testrow1['ip_lo']);
      $testrow1['ip_hi_ip'] = long2ip($testrow1['ip_hi']);
      $testrow1['c2c'] = strtoupper($testrow1['c2c']);
      $testrow1['flag_img'] = flag_img($testrow1['c2c']);
      echo "<tr onmouseover=\"this.style.backgroundColor='$bgcolor2'\" onmouseout=\"this.style.backgroundColor='$bgcolor1'\" bgcolor='$bgcolor1'>\n";
      echo "<td><a href=\"".$ab_config['lookup_link'].$testrow1['ip_lo_ip']."\" target=\"_blank\">".$testrow1['ip_lo_ip']."</a></td>\n";
      echo "<td><a href=\"".$ab_config['lookup_link'].$testrow1['ip_hi_ip']."\" target=\"_blank\">".$testrow1['ip_hi_ip']."</a></td>\n";
      echo "<td align='center'>".$testrow1['flag_img']."</td>\n";
      echo "<td align='center'>".$testrow1['c2c']."</td>\n";
      echo "<td align='center'>".$testrow1['country']."</td>\n";
      echo "<td align='center'>&nbsp;<a href='".$admin_file.".php?op=ABIP2CountryEdit&amp;ip_lo=".$testrow1['ip_lo']."&amp;ip_hi=".$testrow1['ip_hi']."&amp;xop=ABMain' target='_blank'><img src='images/nukesentinel/edit.png' border='0' alt='"._AB_EDIT."' title='"._AB_EDIT."' height='16' width='16'></a>&nbsp;<a ";
      echo "href='".$admin_file.".php?op=ABIP2CountryDelete&amp;ip_lo=".$testrow1['ip_lo']."&amp;ip_hi=".$testrow1['ip_hi']."&amp;xop=ABMain' target='_blank'><img src='images/nukesentinel/delete.png' border='0' alt='"._AB_DELETE."' title='"._AB_DELETE."' height='16' width='16'></a>&nbsp;</td>\n";
      echo "</tr>\n";
    }
  } else {
    echo "<tr bgcolor='$bgcolor1'><td align='center' colspan='6'><b>"._AB_NOMATCHES."</b></td></tr>\n";
  }
  echo "</table>\n";
  echo "<br />\n";
  echo "<table align='center' border='0' cellpadding='2' cellspacing='2' bgcolor='$bgcolor2' width='100%'>\n";
  echo "<tr bgcolor='$bgcolor1'><td align='center' colspan='6'><b>$xip_hi "._AB_IN.":</b></td></tr>\n";
  if($testnum2 > 0) {
    echo "<tr bgcolor='$bgcolor2'>\n";
    echo "<td width='15%'><b>"._AB_IPLO."</b></td>\n";
    echo "<td width='15%'><b>"._AB_IPHI."</b></td>\n";
    echo "<td align='center' width='10%'><b>"._AB_FLAG."</b></td>\n";
    echo "<td align='center' width='10%'><b>"._AB_CODE."</b></td>\n";
    echo "<td align='center' width='35%'><b>"._AB_COUNTRY."</b></td>\n";
    echo "<td align='center' width='15%'><b>"._AB_FUNCTIONS."</b></td>\n";
    echo "</tr>\n";
    while($testrow2 = $db->sql_fetchrow($test2)) {
      $testrow2['ip_lo_ip'] = long2ip($testrow2['ip_lo']);
      $testrow2['ip_hi_ip'] = long2ip($testrow2['ip_hi']);
      $testrow2['c2c'] = strtoupper($testrow2['c2c']);
      $testrow2['flag_img'] = flag_img($testrow2['c2c']);
      echo "<tr onmouseover=\"this.style.backgroundColor='$bgcolor2'\" onmouseout=\"this.style.backgroundColor='$bgcolor1'\" bgcolor='$bgcolor1'>\n";
      echo "<td><a href=\"".$ab_config['lookup_link'].$testrow2['ip_lo_ip']."\" target=\"_blank\">".$testrow2['ip_lo_ip']."</a></td>\n";
      echo "<td><a href=\"".$ab_config['lookup_link'].$testrow2['ip_hi_ip']."\" target=\"_blank\">".$testrow2['ip_hi_ip']."</a></td>\n";
      echo "<td align='center'>".$testrow2['flag_img']."</td>\n";
      echo "<td align='center'>".$testrow2['c2c']."</td>\n";
      echo "<td align='center'>".$testrow2['country']."</td>\n";
      echo "<td align='center'>&nbsp;<a href='".$admin_file.".php?op=ABIP2CountryEdit&amp;ip_lo=".$testrow2['ip_lo']."&amp;ip_hi=".$testrow2['ip_hi']."&amp;xop=ABMain' target='_blank'><img src='images/nukesentinel/edit.png' border='0' alt='"._AB_EDIT."' title='"._AB_EDIT."' height='16' width='16'></a>&nbsp;<a ";
      echo "href='".$admin_file.".php?op=ABIP2CountryDelete&amp;ip_lo=".$testrow2['ip_lo']."&amp;ip_hi=".$testrow2['ip_hi']."&amp;xop=ABMain' target='_blank'><img src='images/nukesentinel/delete.png' border='0' alt='"._AB_DELETE."' title='"._AB_DELETE."' height='16' width='16'></a>&nbsp;</td>\n";
      echo "</tr>\n";
    }
  } else {
    echo "<tr bgcolor='$bgcolor1'><td align='center' colspan='6'><b>"._AB_NOMATCHES."</b></td></tr>\n";
  }
  echo "</table>\n";
  echo "<br />\n";
  echo "<table align='center' border='0' cellpadding='2' cellspacing='2' bgcolor='$bgcolor2' width='100%'>\n";
  echo "<tr bgcolor='$bgcolor1'><td align='center' colspan='6'><b>$xip_lo - $xip_hi "._AB_COVERS.":</b></td></tr>\n";
  if($testnum3 > 0) {
    echo "<tr bgcolor='$bgcolor2'>\n";
    echo "<td width='15%'><b>"._AB_IPLO."</b></td>\n";
    echo "<td width='15%'><b>"._AB_IPHI."</b></td>\n";
    echo "<td align='center' width='10%'><b>"._AB_FLAG."</b></td>\n";
    echo "<td align='center' width='10%'><b>"._AB_CODE."</b></td>\n";
    echo "<td align='center' width='35%'><b>"._AB_COUNTRY."</b></td>\n";
    echo "<td align='center' width='15%'><b>"._AB_FUNCTIONS."</b></td>\n";
    echo "</tr>\n";
    while($testrow3 = $db->sql_fetchrow($test3)) {
      $testrow3['ip_lo_ip'] = long2ip($testrow3['ip_lo']);
      $testrow3['ip_hi_ip'] = long2ip($testrow3['ip_hi']);
      $testrow3['c2c'] = strtoupper($testrow3['c2c']);
      $testrow3['flag_img'] = flag_img($testrow3['c2c']);
      echo "<tr onmouseover=\"this.style.backgroundColor='$bgcolor2'\" onmouseout=\"this.style.backgroundColor='$bgcolor1'\" bgcolor='$bgcolor1'>\n";
      echo "<td><a href=\"".$ab_config['lookup_link'].$testrow3['ip_lo_ip']."\" target=\"_blank\">".$testrow3['ip_lo_ip']."</a></td>\n";
      echo "<td><a href=\"".$ab_config['lookup_link'].$testrow3['ip_hi_ip']."\" target=\"_blank\">".$testrow3['ip_hi_ip']."</a></td>\n";
      echo "<td align='center'>".$testrow3['flag_img']."</td>\n";
      echo "<td align='center'>".$testrow3['c2c']."</td>\n";
      echo "<td align='center'>".$testrow3['country']."</td>\n";
      echo "<td align='center'>&nbsp;<a href='".$admin_file.".php?op=ABIP2CountryEdit&amp;ip_lo=".$testrow3['ip_lo']."&amp;ip_hi=".$testrow3['ip_hi']."&amp;xop=ABMain' target='_blank'><img src='images/nukesentinel/edit.png' border='0' alt='"._AB_EDIT."' title='"._AB_EDIT."' height='16' width='16'></a>&nbsp;<a ";
      echo "href='".$admin_file.".php?op=ABIP2CountryDelete&amp;ip_lo=".$testrow3['ip_lo']."&amp;ip_hi=".$testrow3['ip_hi']."&amp;xop=ABMain' target='_blank'><img src='images/nukesentinel/delete.png' border='0' alt='"._AB_DELETE."' title='"._AB_DELETE."' height='16' width='16'></a>&nbsp;</td>\n";
      echo "</tr>\n";
    }
  } else {
    echo "<tr bgcolor='$bgcolor1'><td align='center' colspan='6'><b>"._AB_NOMATCHES."</b></td></tr>\n";
  }
  echo "</table>\n";
  echo "<br />\n";
  echo "<table align='center' border='0' cellpadding='2' cellspacing='2' bgcolor='$bgcolor2' width='100%'>\n";
  echo "<tr bgcolor='$bgcolor1'><td align='center' colspan='6'><b>$xip_lo - $xip_hi "._AB_ISCOVERED.":</b></td></tr>\n";
  if($testnum4 > 0) {
    echo "<tr bgcolor='$bgcolor2'>\n";
    echo "<td width='15%'><b>"._AB_IPLO."</b></td>\n";
    echo "<td width='15%'><b>"._AB_IPHI."</b></td>\n";
    echo "<td align='center' width='10%'><b>"._AB_FLAG."</b></td>\n";
    echo "<td align='center' width='10%'><b>"._AB_CODE."</b></td>\n";
    echo "<td align='center' width='35%'><b>"._AB_COUNTRY."</b></td>\n";
    echo "<td align='center' width='15%'><b>"._AB_FUNCTIONS."</b></td>\n";
    echo "</tr>\n";
    while($testrow4 = $db->sql_fetchrow($test4)) {
      $testrow4['ip_lo_ip'] = long2ip($testrow4['ip_lo']);
      $testrow4['ip_hi_ip'] = long2ip($testrow4['ip_hi']);
      $testrow4['c2c'] = strtoupper($testrow4['c2c']);
      $testrow4['flag_img'] = flag_img($testrow4['c2c']);
      echo "<tr onmouseover=\"this.style.backgroundColor='$bgcolor2'\" onmouseout=\"this.style.backgroundColor='$bgcolor1'\" bgcolor='$bgcolor1'>\n";
      echo "<td><a href=\"".$ab_config['lookup_link'].$testrow4['ip_lo_ip']."\" target=\"_blank\">".$testrow4['ip_lo_ip']."</a></td>\n";
      echo "<td><a href=\"".$ab_config['lookup_link'].$testrow4['ip_hi_ip']."\" target=\"_blank\">".$testrow4['ip_hi_ip']."</a></td>\n";
      echo "<td align='center'>".$testrow4['flag_img']."</td>\n";
      echo "<td align='center'>".$testrow4['c2c']."</td>\n";
      echo "<td align='center'>".$testrow4['country']."</td>\n";
      echo "<td align='center'>&nbsp;<a href='".$admin_file.".php?op=ABIP2CountryEdit&amp;ip_lo=".$testrow4['ip_lo']."&amp;ip_hi=".$testrow4['ip_hi']."&amp;xop=ABMain' target='_blank'><img src='images/nukesentinel/edit.png' border='0' alt='"._AB_EDIT."' title='"._AB_EDIT."' height='16' width='16'></a>&nbsp;<a ";
      echo "href='".$admin_file.".php?op=ABIP2CountryDelete&amp;ip_lo=".$testrow4['ip_lo']."&amp;ip_hi=".$testrow4['ip_hi']."&amp;xop=ABMain' target='_blank'><img src='images/nukesentinel/delete.png' border='0' alt='"._AB_DELETE."' title='"._AB_DELETE."' height='16' width='16'></a>&nbsp;</td>\n";
      echo "</tr>\n";
    }
  } else {
    echo "<tr bgcolor='$bgcolor1'><td align='center' colspan='6'><b>"._AB_NOMATCHES."</b></td></tr>\n";
  }
  echo "</table>\n";
  echo "<br /><center><b>"._GOBACK."</b></center><br />\n";
  Max_CloseTable();
  incof();
} else {
  if (!get_magic_quotes_runtime()) { $xcountry = addslashes($xcountry); }
  $db->sql_query("INSERT INTO `".$prefix."_nsnst_ip2country` VALUES ('$longip_lo', '$longip_hi', '$datetime', '$xc2c', '$xcountry')");
  if($another == 1) {
    Header("Location: ".$admin_file.".php?op=ABIP2CountryAdd");
  }else {
    Header("Location: ".$admin_file.".php?op=ABIP2Country");
  }
}