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

@set_time_limit( 600 );
$pagetitle = _AB_NUKESENTINEL.": "._AB_ADMINISTRATION.": "._AB_IMPORTRANGE;
incoh();
title($pagetitle);
Max_OpenTable();
OpenMenu();
ipbanmenu();
CarryMenu();
importmenu();
CloseMenu();
Max_CloseTable();
br('1');
Max_OpenTable();
ABLoadDataMenu($importer, "ABImportBlockedRange");
if(isset($importer) AND $importer > "") {
  $message = "Everything seems to have completed succeesfully :)\n";
  echo "<hr>\n";
  // Read and import Country Data
  $import_data = @file("import/".$importer.".data");
  $import_data = implode($import_data);
  if(!$import_data OR $import_data == "") {
    echo "<center><b>"._AB_UNAVAILABLE."</b></center>\n";
  } else {
    $import_data - str_replace("\r", "", $import_data);
    $import_data = explode("\n", $import_data);
    $import_count = count($import_data);
    for($i=0; $i<$import_count; $i++) {
      $import_data[$i] = trim($import_data[$i]);
      if ($import_data[$i] > "") {
        $grabline = explode("||", $import_data[$i]);
        $grabline[4] = stripslashes($grabline[4]);
        $grabline[4] = addslashes($grabline[4]);
        $grabline[ip_lo] = long2ip($grabline[0]);
        $grabline[ip_hi] = long2ip($grabline[1]);
        $test = $db->sql_numrows($db->sql_query("SELECT * FROM `".TABLE_NSNST_BLOCKED_RANGES."` WHERE (`ip_lo` = '$grabline[0]' AND `ip_hi` = '$grabline[1]') OR (`ip_lo` <= '$grabline[0]' AND `ip_hi` >= '$grabline[0]') OR (`ip_lo` <= '$grabline[1]' AND `ip_hi` >= '$grabline[1]')"));
        if (!$test) {
          $datainserted = False;
          $importby = _AB_IMPORTBY." "._AB_NUKESENTINEL;
          $datetime = time();
          $datainserted = $db->sql_query("INSERT INTO `".TABLE_NSNST_BLOCKED_RANGES."` VALUES('$grabline[0]', '$grabline[1]', '$datetime', '$importby', 0, 0, '$grabline[3]')");
          if (!$datainserted) {
            echo "<b>$grabline[ip_lo] - $grabline[ip_hi] "._AB_NOTINSERTED." ".TABLE_NSNST_BLOCKED_RANGES."</b><br />\n";
            $importmess = "";
          }
        } else {
          echo "<i>$grabline[ip_lo] - $grabline[ip_hi] "._AB_OVERLAPS." ".TABLE_NSNST_BLOCKED_RANGES."</i><br />\n";
          $importmess = "";
        }
      }
    }
  }
}
Max_CloseTable();
incof();