<?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");
}

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') AND (`ip_lo`!='$old_ip_lo' AND `ip_hi`!='$old_ip_hi')");
$test2 = $db->sql_query("SELECT * FROM `".$prefix."_nsnst_ip2country` WHERE (`ip_lo`<='$longip_hi' AND `ip_hi`>='$longip_hi') AND (`ip_lo`!='$old_ip_lo' AND `ip_hi`!='$old_ip_hi')");
$testnum1 = $db->sql_numrows($test1);
$testnum2 = $db->sql_numrows($test2);
if($testnum1 > 0 Or $testnum2 >0) {
  $pagetitle = _AB_NUKESENTINEL.": "._AB_ADDIP2COUNTRYERROR;
  incoh();
  title($pagetitle);
  Max_OpenTable();
  OpenMenu();
  ipbanmenu();
  CarryMenu();
  ip2cmenu();
  CloseMenu();
  Max_CloseTable();
  br('1');
  Max_OpenTable();
  if($testnum1 > 0) {
    $testrow1 = $db->sql_fetchrow($test1);
    echo "<br /><center><b>$xip_lo: "._AB_IN." ".long2ip($testrow1['ip_lo'])." "._AB_TO." ".long2ip($testrow1['ip_hi'])." "._AB_FROM." ".$testrow1['country']."</b></center>\n";
  }
  if($testnum2 > 0) {
    $testrow2 = $db->sql_fetchrow($test2);
    echo "<br /><center><b>$xip_hi: "._AB_IN." ".long2ip($testrow2['ip_lo'])." "._AB_TO." ".long2ip($testrow2['ip_hi'])." "._AB_FROM." ".$testrow2['country']."</b></center>\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("UPDATE `".$prefix."_nsnst_ip2country` SET `ip_lo`='$longip_lo', `ip_hi`='$longip_hi', `c2c`='$xc2c', `country`='$xcountry' WHERE `ip_lo`='$old_ip_lo' AND `ip_hi`='$old_ip_hi'");
  Header("Location: ".$admin_file.".php?op=$xop&min=$min&column=$column&direction=$direction&sip=$sip&showcountry=$showcountry");
}
