2603.0 - First effort...
This commit is contained in:
140
add_ip_bulk_save.php
Normal file
140
add_ip_bulk_save.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?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
|
||||
//enddate $enddate
|
||||
//reason $reason
|
||||
//type $type
|
||||
|
||||
$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="";
|
||||
}
|
||||
|
||||
if(!empty($_POST['bulk'])&&isset($_POST['bulk'])){
|
||||
$bulk=trim($_POST['bulk']);
|
||||
}
|
||||
else{
|
||||
$bulk="";
|
||||
}
|
||||
|
||||
if(!empty($_POST['listtype'])&&isset($_POST['listtype'])){
|
||||
$tbl=$_POST['listtype'];
|
||||
|
||||
if($tbl=='b'){
|
||||
$table_name="blacklist";
|
||||
$list=0;
|
||||
}
|
||||
elseif($tbl=='w'){
|
||||
$table_name="whitelist";
|
||||
$list=1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$tbl="";
|
||||
$table_name="";
|
||||
}
|
||||
|
||||
if($tbl<>"" && $bulk<>""){
|
||||
$bulk_array=explode("\r\n",$bulk);
|
||||
$bulk_array=array_filter($bulk_array, 'trim');
|
||||
$no_of_rows=count($bulk_array);
|
||||
|
||||
$dupes = 0;
|
||||
$nodupes = 0;
|
||||
for($i=0;$i<$no_of_rows;$i++){
|
||||
$columns=explode(",",$bulk_array[$i]);
|
||||
//print_r($columns);
|
||||
$ip=$columns[0];
|
||||
|
||||
//verify if ip has /value
|
||||
if(strpos($ip,"/")==false){
|
||||
$ip=$ip."/32";
|
||||
}
|
||||
|
||||
$sql_ins="INSERT INTO $table_name (ip,type,adddate,enddate,reason) VALUES ('$ip','$type','$now','$enddate','$reason')";
|
||||
//echo $sql_ins;
|
||||
//echo "<br>";
|
||||
if(!mysqli_query($con,$sql_ins)){
|
||||
// Ignore the error if it is a duplicate entry, just continue.
|
||||
if(substr_compare(mysqli_error($con),"Duplicate",0,9,FALSE) !== 0) {
|
||||
$_SESSION['rezult_msg']="There was an error while recording the row ".$i." in the database. Please try again.<br>".mysqli_error($con);
|
||||
$_SESSION['ret_link']="add_ip_bulk_frm.php";
|
||||
header("location:error.php?var=2");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
$dupes++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$nodupes++;
|
||||
}
|
||||
|
||||
if($i==($no_of_rows-1)){
|
||||
$sql_last_upd="UPDATE info SET last=$now WHERE list='$list'";
|
||||
$rez_last_upd=mysqli_query($con,$sql_last_upd);
|
||||
$_SESSION['rezult_msg']=" OK! ( " . $nodupes . " ) records were successfully added to the " . $table_name . " database. Ignored ( " . $dupes . " ) duplicates in ( " . $no_of_rows . " ) lines.";
|
||||
$link="add_ip_bulk_frm.php";
|
||||
header("location:$link?var=1");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$_SESSION['rezult_msg']="There is insuficient information to be able to add records to the database. Please try again.<br>".mysqli_error($con);
|
||||
$_SESSION['ret_link']="add_ip_bulk_frm.php";
|
||||
header("location:error.php?var=2");
|
||||
return false;
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user