2603.0 - First effort...
This commit is contained in:
263
search_db.php
Normal file
263
search_db.php
Normal file
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
include('header.php');
|
||||
?>
|
||||
<!-- makes table row clickable-->
|
||||
<script>
|
||||
jQuery(document).ready(function($) {
|
||||
$(".clickable-row").click(function() {
|
||||
window.location = $(this).data("href");
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
//delete confirmation
|
||||
<!--
|
||||
function del(ip,tbl){
|
||||
var answer=confirm("Are you sure you want to delete this IP?");
|
||||
var ipf=ip;
|
||||
var tbl=tbl;
|
||||
|
||||
if(answer){
|
||||
window.location.href="delete.php?ip="+ipf+"&tbl="+tbl;
|
||||
}
|
||||
}
|
||||
-->
|
||||
</script>
|
||||
<?php
|
||||
include('topmenu.php');
|
||||
include('functions.php');
|
||||
date_default_timezone_set("America/Montreal");
|
||||
$_SESSION['rezult_msg']="";
|
||||
$_SESSION['ret_link']="";
|
||||
|
||||
|
||||
|
||||
echo "<div class='container' style='padding-left:20px; width:100%'>";
|
||||
include('conn.php');
|
||||
|
||||
if(!empty($_POST['listtype'])&&isset($_POST['listtype'])){
|
||||
$listtype=$_POST['listtype'];
|
||||
switch($listtype){
|
||||
case 'a':
|
||||
$caption="Blacklist and Whitelist";
|
||||
break;
|
||||
case 'b':
|
||||
$caption="Blacklist";
|
||||
break;
|
||||
case 'w':
|
||||
$caption="Whitelist";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$listtype="a";
|
||||
$caption="Blacklist and Whitelist";
|
||||
}
|
||||
|
||||
if(!empty($_POST['IP'])&&isset($_POST['IP'])){
|
||||
$ip=trim($_POST['IP']);
|
||||
$ip_srch=$ip;
|
||||
}
|
||||
else{
|
||||
$ip="";
|
||||
$ip_srch="";
|
||||
}
|
||||
|
||||
if(isset($_POST['type'])&&($_POST['type'])<>'-1'){
|
||||
$type=$_POST['type'];
|
||||
$sql_type="SELECT label FROM type WHERE type=$type";
|
||||
$rez_type=mysqli_query($con,$sql_type);
|
||||
$rd_tp=mysqli_fetch_array($rez_type);
|
||||
$displaytype=$rd_tp['label'];
|
||||
}
|
||||
else{
|
||||
$type="-1";
|
||||
$displaytype="";
|
||||
}
|
||||
|
||||
if(!empty($_POST['date'])&&isset($_POST['date'])){
|
||||
$dateform=$_POST['date'];
|
||||
$date=datetodigits($_POST['date']).'000000';
|
||||
}
|
||||
else{
|
||||
$dateform="0000-00-00";
|
||||
$date="00000000000000";
|
||||
}
|
||||
|
||||
|
||||
if($ip<>"" && $date=="00000000000000" && $type=="-1"){
|
||||
$condition= "WHERE ip LIKE '%$ip%'";
|
||||
}
|
||||
elseif($ip=="" && $date<>"00000000000000" && $type=="-1"){
|
||||
$condition= "WHERE adddate>=$date";
|
||||
}
|
||||
elseif($ip=="" && $date=="00000000000000" && $type<>"-1"){
|
||||
$condition= "WHERE type.type=$type";
|
||||
}
|
||||
elseif($ip<>"" && $date<>"00000000000000" && $type=="-1"){
|
||||
$condition= "WHERE ip LIKE '%$ip%' AND adddate>=$date";
|
||||
}
|
||||
elseif($ip<>"" && $date<>"00000000000000" && $type<>"-1"){
|
||||
$condition= "WHERE ip LIKE '%$ip%' AND adddate>=$date AND type.type=$type";
|
||||
}
|
||||
elseif($ip<>"" && $date=="00000000000000" && $type<>"-1"){
|
||||
$condition= "WHERE ip LIKE '%$ip%' AND type.type=$type";
|
||||
}
|
||||
elseif($ip=="" && $date<>"00000000000000" && $type<>"-1"){
|
||||
$condition= "WHERE adddate>=$date AND type.type=$type";
|
||||
}
|
||||
elseif($ip=="" && $date=="00000000000000" && $type=="-1"){
|
||||
$condition= "";
|
||||
}
|
||||
|
||||
switch($listtype){
|
||||
case 'a':
|
||||
$sql_find_w="SELECT whitelist.*, type.label FROM whitelist
|
||||
LEFT OUTER JOIN type ON whitelist.type=type.type
|
||||
$condition ORDER BY ip ASC";
|
||||
$rez_find_w=mysqli_query($con,$sql_find_w);
|
||||
|
||||
$sql_find_b="SELECT blacklist.*, type.label FROM blacklist
|
||||
LEFT OUTER JOIN type ON blacklist.type=type.type
|
||||
$condition ORDER BY ip ASC";
|
||||
$rez_find_b=mysqli_query($con,$sql_find_b);
|
||||
break;
|
||||
case 'b':
|
||||
$sql_find_w="";
|
||||
$rez_find_w="";
|
||||
|
||||
$sql_find_b="SELECT blacklist.*, type.label FROM blacklist
|
||||
LEFT OUTER JOIN type ON blacklist.type=type.type
|
||||
$condition ORDER BY ip ASC";
|
||||
$rez_find_b=mysqli_query($con,$sql_find_b);
|
||||
break;
|
||||
case 'w':
|
||||
$sql_find_w="SELECT whitelist.*, type.label FROM whitelist
|
||||
LEFT OUTER JOIN type ON whitelist.type=type.type
|
||||
$condition ORDER BY ip ASC";
|
||||
$rez_find_w=mysqli_query($con,$sql_find_w);
|
||||
|
||||
$sql_find_b="";
|
||||
$rez_find_b="";
|
||||
break;
|
||||
}
|
||||
/*echo $ip;
|
||||
echo $sql_find_b;
|
||||
echo "<br>";
|
||||
echo $sql_find_w;
|
||||
exit;*/
|
||||
if($sql_find_b<>""){
|
||||
if(mysqli_num_rows($rez_find_b)==0 && mysqli_num_rows($rez_find_w)==0){
|
||||
$_SESSION['rezult_msg']="<span style='font-style:italic'>There aren't any Blacklist results for IP - <b>$ip_srch</b>, Type - <b>$displaytype</b>, Date - <b>$dateform</b> in the database. Please try again.</span><br>".mysqli_error($con);
|
||||
$link="index.php?var=2";
|
||||
header("location:$link");
|
||||
return false;
|
||||
}
|
||||
elseif(mysqli_num_rows($rez_find_b)==0 && mysqli_num_rows($rez_find_w)<>0){
|
||||
echo "<span style='font-style:italic'>There aren't any Blacklist results for IP - <b>$ip_srch</b>, Type - <b>$displaytype</b>, Date - <b>$dateform</b> in the database. Please try again.</span><br>".mysqli_error($con);
|
||||
goto Whitelist_lbl;
|
||||
}
|
||||
else{
|
||||
//search results
|
||||
$title="Blacklist Results";
|
||||
echo "<h2>$title</h2>";
|
||||
|
||||
$sqltoexport=trim($sql_find_b);
|
||||
|
||||
//echo "<p style='font-style: italic; color: #0084B4'>* click table row to edit</p>";
|
||||
|
||||
echo"<form name='b' action='export.php' method='POST'><button type='submit' class='btn' onclick='window.location.href=\"export.php\";'> Export CSV <i class='fa fa-download'></i> </button>
|
||||
<input type='hidden' name='sql_find_b' value=\"$sqltoexport\">
|
||||
</form><br>";
|
||||
|
||||
echo "<div style='text-align:center'>";
|
||||
echo "<div style='display:inline-block; width:95%'>";
|
||||
echo "<table class='table table-condensed table-striped table-hover' style='text-align:left'>";
|
||||
echo "<tr>
|
||||
<th>IP</th>
|
||||
<th>Add Date</th>
|
||||
<th>End Date</th>
|
||||
<th>Type</th>
|
||||
<th>Reason</th>
|
||||
<th>Edit</th>
|
||||
<th style='text-align:center'>Delete</th>
|
||||
</tr>";
|
||||
while($rd_bl=mysqli_fetch_array($rez_find_b)){
|
||||
echo "<tr>";
|
||||
$adddate=print_datetime($rd_bl['adddate']);
|
||||
$enddate=print_datetime($rd_bl['enddate']);
|
||||
$ip=$rd_bl['ip'];
|
||||
echo "<td>".$rd_bl['ip']."</td>";
|
||||
echo "<td>".$adddate."</td>";
|
||||
echo "<td>".$enddate."</td>";
|
||||
echo "<td>".$rd_bl['type']." - ".$rd_bl['label']."</td>";
|
||||
echo "<td>".$rd_bl['reason']."</td>";
|
||||
echo "<td><button class='btn btn-secondary btn-sm' onclick='window.location.href=\"edit_ip_frm.php?ip=$ip&tbl=b\";'><i class='fa fa-edit'></i></button></td>";
|
||||
echo "<td align='center'><button class='btn btn-danger btn-sm' onclick=\"del('".$ip."','b');\"><i class='fa fa-trash'></i></button></td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
echo "</table>";
|
||||
echo "</div>";
|
||||
echo "</div>";
|
||||
}
|
||||
}
|
||||
|
||||
if($sql_find_w<>""){
|
||||
if(mysqli_num_rows($rez_find_w)==0 && mysqli_num_rows($rez_find_b)==0){
|
||||
$_SESSION['rezult_msg']="<span style='font-style:italic'>There aren't any Whitelist results for IP - <b>$ip_srch</b>, Type - <b>$displaytype</b>, Date - <b>$dateform</b> in the database. Please try again.</span><br>".mysqli_error($con);
|
||||
$link="index.php?var=2";
|
||||
header("location:$link");
|
||||
return false;
|
||||
}
|
||||
elseif(mysqli_num_rows($rez_find_w)==0 && mysqli_num_rows($rez_find_b)<>0){
|
||||
echo "<span style='font-style:italic'>There aren't any Whitelist results for IP - <b>$ip_srch</b>, Type - <b>$displaytype</b>, Date - <b>$dateform</b> in the database. Please try again.</span><br>".mysqli_error($con);
|
||||
}
|
||||
else{
|
||||
Whitelist_lbl:
|
||||
//search results
|
||||
$title="Whitelist Results";
|
||||
echo "<h2>$title</h2>";
|
||||
|
||||
$sqltoexportw=trim($sql_find_w);
|
||||
|
||||
//echo "<p style='font-style: italic; color: #0084B4'>* click table row to edit</p>";
|
||||
|
||||
echo"<form name='w' action='export.php' method='POST'><button type='submit' class='btn' onclick='window.location.href=\"export.php\";'> Export CSV <i class='fa fa-download'></i> </button>
|
||||
<input type='hidden' name='sql_find_w' value=\"$sqltoexportw\">
|
||||
</form><br>";
|
||||
|
||||
echo "<div style='text-align:center'>";
|
||||
echo "<div style='display:inline-block; width:95%'>";
|
||||
echo "<table class='table table-condensed table-striped table-hover' style='text-align:left'>";
|
||||
echo "<tr>
|
||||
<th>IP</th>
|
||||
<th>Add Date</th>
|
||||
<th>End Date</th>
|
||||
<th>Type</th>
|
||||
<th>Reason</th>
|
||||
<th>Edit</th>
|
||||
<th style='text-align:center'>Delete</th>
|
||||
</tr>";
|
||||
while($rd_wl=mysqli_fetch_array($rez_find_w)){
|
||||
$ip=$rd_wl['ip'];
|
||||
echo "<tr>";
|
||||
$adddatew=print_datetime($rd_wl['adddate']);
|
||||
$enddatew=print_datetime($rd_wl['enddate']);
|
||||
echo "<td>".$rd_wl['ip']."</td>";
|
||||
echo "<td>".$adddatew."</td>";
|
||||
echo "<td>".$enddatew."</td>";
|
||||
echo "<td>".$rd_wl['type']." - ".$rd_wl['label']."</td>";
|
||||
echo "<td>".$rd_wl['reason']."</td>";
|
||||
echo "<td><button class='btn btn-secondary btn-sm' onclick='window.location.href=\"edit_ip_frm.php?ip=$ip&tbl=w\";'><i class='fa fa-edit'></i></button></td>";
|
||||
echo "<td align='center'><button class='btn btn-danger btn-sm' onclick=\"del('".$ip."','w');\"><i class='fa fa-trash'></i></button></td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
echo "</table>";
|
||||
echo "</div>";
|
||||
echo "</div>";
|
||||
}
|
||||
}
|
||||
echo "</div>";
|
||||
?>
|
||||
Reference in New Issue
Block a user