<?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[0] < 0 OR $xip[0] > 255 OR (!is_numeric($xip[0]) AND $xip[0] != "*")) OR ($xip[1] < 0 OR $xip[1] > 255 OR (!is_numeric($xip[1]) AND $xip[1] != "*")) OR ($xip[2] < 0 OR $xip[2] > 255 OR (!is_numeric($xip[2]) AND $xip[2] != "*")) OR ($xip[3] < 0 OR $xip[3] > 255 OR (!is_numeric($xip[3]) AND $xip[3] != "*"))) {
  $pagetitle = _AB_NUKESENTINEL.": "._AB_ADDRANGEERROR;
  incoh();
  title($pagetitle);
  Max_OpenTable();
  echo "<br /><center><b>"._AB_IPERROR." </b></center>\n";
  echo "<br /><center><b>"._GOBACK."</b></center><br />\n";
  Max_CloseTable();
  incof();
  die();
}
$xIPs = implode(".", $xip);
$ip = $db->sql_numrows($db->sql_query("SELECT * FROM `".TABLE_NSNST_BLOCKED_IPS."` WHERE `ip_addr`='$xIPs'"));
$bantime = time();
$xnotes = str_replace("<br />","\r\n",$xnotes);
$xnotes = str_replace("<br />","\r\n",$xnotes);
$xnotes = htmlentities($xnotes, ENT_QUOTES);
if (!get_magic_quotes_runtime()) {
  $xnotes = addslashes($xnotes);
  $xusername = addslashes($xusername);
}
if($xexpires>0) { $xexpires = $bantime + ($xexpires * 86400); }
if ($ip < 1) {
  $temp_qs = $xquery_string;
  $temp_qs = base64_encode($temp_qs);
  $db->sql_query("INSERT INTO `".TABLE_NSNST_BLOCKED_IPS."` VALUES ('$xIPs', '$xuser_id', '$xusername', '$xuser_agent', '$bantime', '$xnotes', '$xreason', '$temp_qs', '$temp_qs', '$temp_qs', '$xx_forward_for', '$xclient_ip', '$xremote_addr', '$xremote_port', '$xrequest_method', '$xexpires', '$xc2c')");
  if ($ab_config['htaccess_path'] != "") {
    $i = 1;
    while ($i <= 3) {
      $tip = substr($xIPs, -2);
      if ($tip == ".*") { $xIPs = substr($xIPs, 0, -2); }
      $i++;
    }
    $tempip = "";
    if ($xIPs != "*") { $tempip = "deny from ".$xIPs."\n"; }
    $doit = fopen($ab_config['htaccess_path'], "a");
    fwrite($doit, $tempip);
    fclose($doit);
  }
}
if($another == 1) {
  redirect_url("".$admin_file.".php?op=ABBlockedIPAdd");
}else {
  redirect_url("".$admin_file.".php?op=ABBlockedIP");
}