<?php
@mysql_connect('[color=red]insert host here (usually localhost)[/color]',
'[color=red]insert database username here[/color]',
'[color=red]insert database password here[/color]')
or die('Cannot connect to MySQL server');
@mysql_select_db('[color=red]insert database name here[/color]');
@mysql_query('set names utf8');
$ips=isset($_POST['newips'])?$_POST['newips']:'';
$rmips=isset($_POST['rmips'])?$_POST['rmips']:'';
if(!empty($_POST['submit_clear'])){
$sql="TRUNCATE TABLE `ips` ";
mysql_query($sql);
}
if(!empty($_POST['submit_addips'])){
$ips=str_replace("\n",',',$ips);
$ips=str_replace("\r",'',$ips);
$iparray=explode(',',$ips);
$message='';
$count=0;
foreach($iparray as $k=>$ip){
$long = ip2long($ip);
if ($long == -1 || $long === FALSE || $long==0 ) {
$iparray[$k] .= '----- NOT A IP ADDRESS';
}else{
$long=sprintf('%u',$long);
$sql="insert into ips(id, ip, addtime) values(null, '$long', now() ) ";
$result=mysql_query($sql);
if($result===false){
$iparray[$k] .= '---- Already Exists'; //mysql_error();
}else{
$count++;
unset($iparray[$k]);
}
}
}
$ips=implode("\r\n",$iparray);
}
if(!empty($_POST['submit_rmips'])){
$rmips=str_replace("\n",',',$rmips);
$rmips=str_replace("\r",'',$rmips);
$iparray=explode(',',$rmips);
$message='';
$rcount=0;
foreach($iparray as $k=>$ip){
$long = ip2long($ip);
if ($long == -1 || $long === FALSE || $long==0 ) {
$iparray[$k] .= '----- NOT A IP ADDRESS';
}else{
$long=sprintf('%u',$long);
$sql="delete from ips where ip='$long' ";
// echo $sql;
$result=mysql_query($sql);
if($result===false){
$iparray[$k] .= '---- Not Exists'; //mysql_error();
}else{
$rcount++;
////$message .= " Added IP: {$iparray[$k]} \n";
unset($iparray[$k]);
}
}
}
$rmips=implode("\r\n",$iparray);
}
$sql="select ip from ips order by ip ";
$query=mysql_query($sql);
$allcount=mysql_num_rows($query);
$allips='';
while($row=mysql_fetch_row($query)){
$allips .= long2ip($row[0])."\r\n";
}
?>
<html>
<head>
<title>Sort Banned IP List</title>
<script type="text/javascript">
function CopyToClipboard() {
var t=document.getElementById('allips');
t.focus();
t.select();
CopiedTxt = document.selection.createRange();
CopiedTxt.execCommand("Copy");
}
</script>
<style>
body {
font-family: Verdana, Tahoma, Arial, sans-serif;
font-size: 12px;
}
table tr td {
font-family: Verdana, Tahoma, Arial, sans-serif;
font-size: 12px;
}
</style>
</head>
<body>
<h1>Sort Banned IP# List</h1>
<div style="color:blue;"><?=nl2br($message) ?>
<?
if($count>0) echo 'Total:'.$count.' ips added';
?>
</div>
<form name="form1" method="POST">
<table width="100%">
<tr>
<td>ADD NEW IP Number(s) to BAN Here<br/>
<textarea name="newips" cols="45" rows="10" ><?=$ips?></textarea>
<input type="submit" name="submit_addips" value="Add" /><br/><br/>
<a href="index.php" >Refresh</a>
</td>
<td width="50%" rowspan="2">
<button name="copy" onclick="CopyToClipboard();" >Select</button> All banned IP #'s from this list: Total <?=$allcount ?> <input type="submit" name="submit_clear" value="Clear List" /><br/>
Note: Clearing list will delete all IP numbers from database.<br/>
<textarea name="allips" cols="25" rows="30" ><?=$allips?></textarea>
</td></tr>
<tr>
<td>DELETE a BANNED IP Number here:<br/>
<textarea name="rmips" cols="45" rows="10" ><?=$rmips?></textarea>
<input type="submit" name="submit_rmips" value="Remove" /><br/><br/>
</td></tr>
</table>
</form>
</body>
</html>