Files
ipban199/add_ip_save.php
2026-03-16 02:27:59 -04:00

120 lines
2.4 KiB
PHP

<?php
session_start();
date_default_timezone_set("America/Montreal");
$_SESSION['rezult_msg']="";
$_SESSION['ret_link']="";
include('conn.php');
include('functions.php');
$now=date('YmdHis');
//DATA
//ip $ip
//adddate $adddate
//adddate_time $adddate_time
//years $years
//months $months
//days $days
//reason $reason
//type $type
if(!empty($_POST['ip'])&&isset($_POST['ip'])){
$ip=$_POST['ip'];
//verify if ip has /value
if(strpos($ip,"/")==false){
$ip=$ip."/32";
}
}
else{
$ip="";
}
if(!empty($_POST['tbl'])&&isset($_POST['tbl'])){
$table_name=$_POST['tbl'];
}
else{
$table_name="";
}
if($table_name=='blacklist'){
$list=0;
$tbl='b';
}
elseif($table_name=='whitelist'){
$list=1;
$tbl='w';
}
else{
$list="";
$tbl='';
}
$insert_adddate=$now;
if(!empty($_POST['years'])&&isset($_POST['years'])){
$years=$_POST['years'];
}
else{
$years=0;
}
if(!empty($_POST['months'])&&isset($_POST['months'])){
$months=$_POST['months'];
}
else{
$months=0;
}
if(!empty($_POST['days'])&&isset($_POST['days'])){
$days=$_POST['days'];
}
else{
$days=0;
}
$enddate=$insert_adddate;
$enddate=add_days($enddate,$days);
$enddate=add_months($enddate,$months);
$enddate=add_years($enddate,$years);
if(!empty($_POST['perm'])&&isset($_POST['perm'])){
if($_POST['perm']=='on'){
$enddate='99999999999999';
}
}
if(!empty($_POST['reason'])&&isset($_POST['reason'])){
$reason=trim(addslashes($_POST['reason']));
}
else{
$reason="";
}
if(!empty($_POST['type'])&&isset($_POST['type'])||($_POST['type']==0)){
$type=$_POST['type'];
}
else{
$type="";
}
$sql_ins="INSERT INTO $table_name (ip,type,adddate,enddate,reason) VALUES ('$ip','$type','$insert_adddate','$enddate','$reason')";
$sql_last_upd="UPDATE info SET last=$now WHERE list='$list'";
//echo $sql_ins;
//exit;
if(mysqli_query($con,$sql_ins)){
$rez_last_upd=mysqli_query($con,$sql_last_upd);
$_SESSION['rezult_msg']="IP successfully added to the database.";
$link="add_ip_frm.php";
echo $_SESSION['rezult_msg'];
header("location:$link?var=1&tbl=$tbl");
return false;
}
else{
$_SESSION['rezult_msg']="The value was not added to the database. Please try again.<br>".mysqli_error($con);
$_SESSION['ret_link']="add_ip_frm.php";
header("location:error.php?var=2&tbl=$tbl");
return false;
}
?>