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

$expiretime = time();
$clearresult = $db->sql_query("SELECT * FROM `".TABLE_NSNST_BLOCKED_IPS."` WHERE (`expires`<'$expiretime' AND `expires`!='0')");
while($clearblock = $db->sql_fetchrow($clearresult)) {
  $db->sql_query("DELETE FROM `".TABLE_NSNST_BLOCKED_IPS."` WHERE `ip_addr`='".$clearblock['ip_addr']."'");
  $db->sql_query("OPTIMIZE TABLE `".TABLE_NSNST_BLOCKED_IPS."`");
  if($ab_config['htaccess_path'] != "") {
    if($ab_config['htaccess_path'] != "") { $ipfile = file($ab_config['htaccess_path']); }
    $ipfile = implode("", $ipfile);
    $i = 1;
    while ($i <= 3) {
      $tip = substr($clearblock['ip_addr'], -2);
      if ($tip == ".*") { $clearblock['ip_addr'] = substr($clearblock['ip_addr'], 0, -2); }
      $i++;
    }
    $testip = "deny from ".$clearblock['ip_addr']."\n";
    $ipfile = str_replace($testip, "", $ipfile);
    $doit = fopen($ab_config['htaccess_path'], "w");
    fwrite($doit, $ipfile);
    fclose($doit);
  }
}
redirect_url("".$admin_file.".php?op=ABBlockedIP");