<?
include_once "../SYSTEM/include/functions.php";
include_once BASEDIR."SYSTEM/include/mysql.php";
include_once BASEDIR."SYSTEM/include/param.php";
//include_once BASEDIR."SYSTEM/include/ban.php";
include_once BASEDIR."SYSTEM/include/sess.php";
include_once BASEDIR."SYSTEM/include/ban_2.php";
include_once BASEDIR."SYSTEM/include/theme.php";
$title='Бан панель';
$mesto='В админке';
head();

if (!isset($user) || $user['level']<2)
{
header("Location: ../index.php?".SID."");
exit;
}
mysql_query("OPTIMIZE TABLE `$mysql[pref]ban`;");

if (isset($_GET['act']) && $_GET['act']=='ban_ok' && isset($_GET['id']))
{
$id_ank=intval($_GET['id']);

$q = mysql_query("SELECT * FROM `$mysql[pref]users` WHERE `id` = '$id_ank';");

if(mysql_num_rows($q) != 0)
{
$ank = mysql_fetch_array($q, 1);
}
else
{
header ("Location: ../index.php?".SID."");
exit;
}

echo "<div class=\"h\">Бан IP $ank[ip]</div><hr />\n";
if ($mail_in_new>0)echo "<div class=\"privat\"><img src=\"../SYSTEM/themes/$them/img/mail0.gif\" alt=\"\" /> <a href=\"../mail.php?act=in\">Приват</a> [$mail_in_new]</div><hr />\n";

$msg=$_POST['msg'];
$ban_ip=$ank['ip'];


$timeban=0;
if ($_POST['vremja']=='min')$timeban=intval($_POST['time'])*60;
if ($_POST['vremja']=='chas')$timeban=intval($_POST['time'])*60*60;
if ($_POST['vremja']=='sut')$timeban=intval($_POST['time'])*60*60*24;
if ($_POST['vremja']=='mes')$timeban=intval($_POST['time'])*60*60*24*30;


ban_ip($ank['ip'],$timeban,$msg);


echo "IP $ban_ip забанен на $timeban сек<br />\n";
echo "Причина: $msg<br />\n";

echo "<a href=\"../index.php\">&lt;&lt; На главную</a>\n";

foot();
}
if (isset($_GET['act']) && $_GET['act']=='ban_del' && isset($_POST['ip']))
{
mysql_query("DELETE FROM `$mysql[pref]ban` WHERE `ip` = '".$_POST['ip']."';");
action("Снят бан IP $_POST[ip]");
header ("Location: ban.php?".SID."&msg=ban_del");
exit;
}

if (isset($_GET['act']) && $_GET['act']=='ban_add' && isset($_POST['ip']) && isset($_POST['vremja']))
{
$timeban=0;
if ($_POST['vremja']=='min')$timeban=intval($_POST['time'])*60;
if ($_POST['vremja']=='chas')$timeban=intval($_POST['time'])*60*60;
if ($_POST['vremja']=='sut')$timeban=intval($_POST['time'])*60*60*24;
if ($_POST['vremja']=='mes')$timeban=intval($_POST['time'])*60*60*24*30;
$msg=$_POST['msg'];
$ban_ip=$_POST['ip'];
ban_ip($ban_ip,$time+$timeban,$msg);
action("IP $_POST[ip] забанен");
header ("Location: ban.php?".SID."&msg=ban_add");
exit;
}

if (isset($_GET['act']) && $_GET['act']=='ban' && isset($_GET['id']))
{
$id_ank=intval($_GET['id']);

$q = mysql_query("SELECT * FROM `$mysql[pref]users` WHERE `id` = '$id_ank';");

if(mysql_num_rows($q) != 0)
{
$ank = mysql_fetch_array($q, 1);
}
else
{
header ("Location: ../index.php?".SID."");
exit;
}








echo "<div class=\"h\">Бан IP $ank[ip]</div><hr />\n";

if ($mail_in_new>0)echo "<div class=\"privat\"><img src=\"../SYSTEM/themes/$them/img/mail0.gif\" alt=\"\" /> <a href=\"../mail.php?act=in\">Приват</a> [$mail_in_new]</div><hr />\n";

echo "<form method=\"post\" action=\"ban.php?act=ban_ok&amp;id=$id_ank\">\n";

echo "Время:<br />\n<input name=\"time\" class=\"form\" value=\"1\" type=\"text\" /><br />\n";

echo "Единица:<br />\n";
echo "<select class=\"form\" name=\"vremja\">\n";
echo "<option value=\"min\">Минуты</option>\n";
echo "<option value=\"chas\">Часы</option>\n";
echo "<option value=\"sut\">Сутки</option>\n";
echo "<option value=\"mes\">Месяцы</option>\n";
echo "</select><br />\n";

echo "Причина:<br />\n<textarea name=\"msg\" class=\"form\" rows=\"3\"></textarea><br />\n";
echo "<br /><input value=\"Забанить\" class=\"form\" type=\"submit\" />\n";

echo "</form>\n";

echo "<hr /><a href=\"../index.php\">&lt;&lt; На главную</a>\n";

foot();
}

echo "<div class=\"h\">Бан IP</div><hr />\n";
if ($mail_in_new>0)echo "<div class=\"privat\"><img src=\"../SYSTEM/themes/$them/img/mail0.gif\" alt=\"\" /> <a href=\"../mail.php?act=in\">Приват</a> [$mail_in_new]</div><hr />\n";

if (isset($_GET['msg']))
{
$msg=$_GET['msg'];
echo "<span style=\"color:$color[msg]\"><b>";
if ($msg=='ban_del'){echo "Бан снят";}
if ($msg=='ban_add'){echo "IP добавлен в базу бана";}

echo "</b></span>\n<br />\n<br />\n";
}

$q = mysql_query("SELECT COUNT(DISTINCT ip, prich) FROM `$mysql[pref]ban`;");
if (mysql_result($q, 0)>0)
{
echo "<form method=\"post\" action=\"ban.php?act=ban_del\">\n";
echo "Сбисок забаненых IP:<br /><br />\n";
echo "<select class=\"form\" name=\"ip\">\n";

mysql_query("DELETE FROM `$mysql[pref]ban` WHERE `time` < '$time' ;");
$q = mysql_query("SELECT DISTINCT ip, prich FROM `$mysql[pref]ban`;");
while ($ank = mysql_fetch_array($q)){
echo "<option value=\"$ank[ip]\">$ank[ip] ($ank[prich])</option>\n";}
echo "</select><br />\n";

echo "<br /><input value=\"Снять бан\" class=\"form\" type=\"submit\" />\n";

echo "</form>\n";
}


echo "<form method=\"post\" action=\"ban.php?act=ban_add\">\n";

echo "<b>Забанить:</b><br />\n";
$ip_b='0.0.0.0';
if (isset($_GET['ip']))
{
$ip_b=$_GET['ip'];
}
echo "IP:<br />\n<input name=\"ip\" class=\"form\" value=\"$ip_b\" type=\"text\" /><br />\n";
echo "Время:<br />\n<input name=\"time\" class=\"form\" value=\"1\" type=\"text\" /><br />\n";

echo "Единица:<br />\n";
echo "<select class=\"form\" name=\"vremja\">\n";
echo "<option value=\"min\">Минуты</option>\n";
echo "<option value=\"chas\">Часы</option>\n";
echo "<option value=\"sut\">Сутки</option>\n";
echo "<option value=\"mes\">Месяцы</option>\n";
echo "</select><br />\n";

echo "Причина:<br />\n<textarea name=\"msg\" class=\"form\" rows=\"3\"></textarea><br />\n";
echo "<br />\n<input value=\"Забанить\" class=\"form\" type=\"submit\" />\n";

echo "</form>\n";




echo "<hr /><a href=\"index.php\">&lt;&lt; Админка</a>\n";
echo "<br /><a href=\"../index.php\">&lt;&lt; На главную</a>\n";

foot();
?>
