PHP Code:
//from google.com and edited by Demantor
function validateIpAddress($ip)
{
if(preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$ip))
{
$parts=explode(".",$ip);
foreach($parts as $ip_parts)
{
if(intval($ip_parts)>255 || intval($ip_parts)<0)
return false;
}
return $ip;
}
else
return false;
}
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP']))
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function clean_news($value)
{
$check = $value;
$search = array('chr(', 'chr=', 'chr%20', '%20chr', 'wget%20', '%20wget', 'wget(',
'cmd=', '%20cmd', 'cmd%20', 'rush=', '%20rush', 'rush%20',
'union%20', '%20union', 'union(', 'union=', 'echr(', '%20echr', 'echr%20', 'echr=',
'esystem(', 'esystem%20', 'cp%20', '%20cp', 'cp(', 'mdir%20', '%20mdir', 'mdir(',
'mcd%20', 'mrd%20', 'rm%20', '%20mcd', '%20mrd', '%20rm',
'mcd(', 'mrd(', 'rm(', 'mcd=', 'mrd=', 'mv%20', 'rmdir%20', 'mv(', 'rmdir(',
'chmod(', 'chmod%20', '%20chmod', 'chmod(', 'chmod=', 'chown%20', 'chgrp%20', 'chown(', 'chgrp(',
'locate%20', 'grep%20', 'locate(', 'grep(', 'diff%20', 'kill%20', 'kill(', 'killall',
'passwd%20', '%20passwd', 'passwd(', 'telnet%20', 'vi(', 'vi%20',
'insert%20into', 'select%20', 'fopen', 'fwrite', '%20like', 'like%20',
'$_request', '$_get', '$request', '$get', '.system', 'HTTP_PHP', '&aim', '%20getenv', 'getenv%20',
'new_password', '&icq','/etc/password','/etc/shadow', '/etc/groups', '/etc/gshadow',
'HTTP_USER_AGENT', 'HTTP_HOST', '/bin/ps', 'wget%20', 'uname\x20-a', '/usr/bin/id',
'/bin/echo', '/bin/kill', '/bin/', '/chgrp', '/chown', '/usr/bin', 'g\+\+', 'bin/python',
'bin/tclsh', 'bin/nasm', 'perl%20', 'traceroute%20', 'ping%20', '.pl', 'lsof%20',
'/bin/mail', '.conf', 'motd%20', 'HTTP/1.', '.inc.php', 'config.php', 'cgi-', '.eml',
'file\://', 'window.open', '<script>', 'javascript\://','img src', 'img%20src','.jsp','ftp.exe',
'xp_enumdsn', 'xp_availablemedia', 'xp_filelist', 'xp_cmdshell', 'nc.exe', '.htpasswd',
'servlet', '/etc/passwd', 'wwwacl', '~root', '~ftp', '.js', '.jsp', 'admin_', '.history',
'bash_history', '.bash_history', '~nobody', 'server-info', 'server-status', 'reboot%20', 'halt%20',
'powerdown%20', '/home/ftp', '/home/www', 'secure_site, ok', 'chunked', 'org.apache', '/servlet/con',
'<script', 'UPDATE', 'SELECT', 'DROP', '/robot.txt' ,'/perl' ,'mod_gzip_status', 'db_mysql.inc', '.inc', 'select%20from',
'select from', 'drop%20', 'getenv', 'http_', '_php', 'php_', 'phpinfo()', '<?php', '?>', 'sql=');
$value = str_replace($search, '', $value);
$value = preg_replace(sql_regcase("/(update|select|declare|cast|exec|0x|union|insert|delete|drop table|show tables|'|#|\*|--|\\\\)/"),"",$value);
$value = trim($value);
$value = strip_tags($value);
$value = addslashes($value);
$value = str_replace("'", "''", $value);
if( $check != $value )
{
//ipbansystem();
setmessage("Illegal Characters detected!", array("Please, check your entered data.", "You Entered: $check", "Allowed is: $value", "Please, Correct your data."));
$date = date("d-m-y - H:i:s");
$logfile = fopen("logs/log.php","a+");
$logtext = "[$date] IP: [{$_SERVER['REMOTE_ADDR']}] - ::: Data['$check'] - Staff['{$_SESSION[UserID]}'] - AID['{$_SESSION[AID]}']\r\n";
fputs($logfile, $logtext);
fclose($logfile);
header("Location: index.php");
die();
}
return( $value );
}
function CheckIP()
{
$ip = getRealIpAddr();
$query = mssql_query("SELECT * FROM IPBans WHERE IP = '$ip' AND Opened = 1");
if( mssql_num_rows($query) != 0 )
{
SetMessage("Your IP: $ip is Banned!", array("The access to CTGunz Servers is forbidden!", "If you see that this Ban is a mistake/incorrect; Please contact an Administrator or post your request on the Forums."));
header("Location: index.php");
die();
}
}
PHP Code:
<?
//This Function was made by: Demantor.
if($_SESSION[UserID] == "")
{
SetMessage("Message from System", array("Please login first to IPBAN a player Globally!"));
SetURL("index.php?do=BanIP");
header("Location: index.php?do=login");
die();
}
$AID = Clean($_SESSION[AID]);
$uGradex = mssql_query_logged("SELECT UGradeID FROM Account WHERE AID = '$AID'");
$uGrade = mssql_fetch_assoc($uGradex);
if($uGrade[UGradeID] != 255 && $uGrade[UGradeID] != 254){
SetMessage("Error!", array("You are not a staff member; You can't use this function!"));
header("Location: index.php?do=index");
die();
}
SetTitle("CTGunz - IPBAN");
if(isset($_POST[submit]))
{
$userx = clean($_POST[userid]);
$BannedIP = clean($_POST[IP]);
$ipcheck = validateIpAddress($BannedIP);
$myip = getRealIpAddr();
$Reasonx = clean_news($_POST[Reason]);
$staff = clean($_SESSION[UserID]);
if($userx == ""){
SetMessage("IP Ban", array("You must Enter the Account Name of the IP to Ban!"));
header("Location: index.php?do=BanIP");
die();
}
elseif($BannedIP == ""){
SetMessage("IP Ban", array("You must Enter the IP to Ban!"));
header("Location: index.php?do=BanIP");
die();
}
elseif($BannedIP != $ipcheck){
setmessage("ERROR!", array("Incorrect Entered IP: $BannedIP", "This IP doesn't Exist in the Network!", "Please Check your entered IP"));
header("Location: index.php?do=BanIP");
die();
}
elseif(mssql_num_rows(mssql_query_logged("SELECT * FROM IPBans(nolock) WHERE iP = '$BannedIP' AND Opened = '1'")) <> 0){
SetMessage("IP Ban", array("IP: $BannedIP is Already Banned :)"));
header("Location: index.php?do=BanIP");
die();
}
elseif($BannedIP == $myip){
SetMessage("IP Ban", array("IP: $BannedIP is your own IP, you can't Ban yourself ROFL :)"));
header("Location: index.php?do=BanIP");
die();
}
elseif(((mssql_num_rows(mssql_query_logged("SELECT * FROM Login(nolock) WHERE LastIP = '$BannedIP'"))) == 0) & (mssql_num_rows(mssql_query_logged("SELECT * FROM Account(nolock) WHERE RegisterIP = '$BannedIP'"))) == 0){
SetMessage("IP Ban", array("The Entered IP: '$BannedIP' doesn't Exist in the Database Information!", "You can only ban IPs which belong to an Account(s) in CTGunZ"));
header("Location: index.php?do=BanIP");
die();
}
elseif(mssql_num_rows(mssql_query_logged("SELECT * FROM Login(nolock) INNER JOIN Account(nolock) on Login.AID = Account.AID WHERE Login.LastIP = '$BannedIP' and ((Account.UGradeID = 255) or (Account.UGradeID = 254) or (Account.UGradeID = 252))")) <> 0){
SetMessage("IP Ban", array("nah nah, Bad Boy. You can't ban a staff's IP = )", "Don't try."));
header("Location: index.php?do=BanIP");
die();
}
else{
if(mssql_num_rows(mssql_query("SELECT * FROM IPBans(nolock) WHERE iP = '$BannedIP' AND Opened = '0'")) == 1){
Mssql_query ("Update IPBans SET Opened = 1, AccountBan = '$userx', banDate = GETDATE(), Reason = '$Reasonx', StaffMemeber = '$staff', StaffIP = '$_SERVER[REMOTE_ADDR]' WHERE ip = '$BannedIP'");
}else{
Mssql_query_logged ("INSERT INTO IPBans(AccountBan, IP, banDate, Opened, Reason, StaffMemeber,
StaffIP) VALUES ('$userx', '$BannedIP', GETDATE(), 1, '$Reasonx', '$staff',
'$_SERVER[REMOTE_ADDR]')");
}
SetMessage("IP Ban", array("IP: $BannedIP successfully Banned :) ", "Log Written with: $staff" , "For Reason: $Reasonx"));
header("Location: index.php?do=BanIP");
die();
}
}else{
?>
<html>
<head>
</head>
<body onload="FP_preloadImgs(/*url*/'../images/btn_register_on.jpg')">
<table style="border-collapse: collapse;" border="0"
width="100%">
<tbody>
<tr>
<td valign="top" width="183">
<div align="center"></div>
</td>
<td valign="top">
<div align="center">
<table style="border-collapse: collapse;" border="1"
bordercolor="#000000" width="100%">
<tbody>
<tr>
<td
style="background-image: url(images/content_bar.jpg); background-repeat: no-repeat; background-position: center top;"
background="http://forum.ragezone.com/images/content_bar.jpg" height="24">
<div align="center"><font face="Tahoma"
size="2"><b>CTGunZ Global IP Banning!</b></font></div>
</td>
</tr>
<tr>
<td bgcolor="#2c2a2a">
<div align="center">
<form method="post" action="index.php?do=BanIP"
name="BanIP">
<table style="border-collapse: collapse; float: left;"
border="0" height="100%" width="408">
<tbody>
<tr>
<td width="9">
<img src="http://forum.ragezone.com/images/mis_arrow.jpg" id="img13"
border="0" height="9" width="5"></td>
<td align="left" width="183">
<div align="left">Banned Player's
Account</div>
</td>
<td align="left" width="183">
<input name="userid" size="19"
class="textLogin" type="text"></td>
<td width="16"> </td>
</tr>
<tr>
<td colspan="4" width="402">
<table
style="border-collapse: collapse; float: left; width: 408px; height: 26px;"
border="0">
<tbody>
<tr>
<td width="9"><img
src="http://forum.ragezone.com/images/mis_arrow.jpg" id="img13" border="0"
height="9" width="5"></td>
<td align="left" width="183">
<div align="left">IP to Ban</div>
</td>
<td align="left" width="183"><input
name="IP" size="19" class="textLogin" type="text"></td>
<td width="16"> </td>
</tr>
<tr>
<td><img src="http://forum.ragezone.com/images/mis_arrow.jpg"
id="img13" border="0" height="9" width="5"></td>
<td>Reason</td>
<td><input name="Reason"
size="19" class="textLogin" type="text"></td>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
</tr>
<tr>
<td width="9"> </td>
<td colspan="2" width="366">
<p align="center"><input
src="http://forum.ragezone.com/images/btn_register_off.jpg" name="img123"
onmouseout="FP_swapImgRestore()"
onmouseover="FP_swapImg(1,1,/*id*/'img123',/*url*/'images/btn_register_on.jpg')"
border="0" height="22" type="image" width="136"></p>
</td>
<td width="16"> </td>
</tr>
<tr>
<td width="9"> </td>
<td width="183"> </td>
<td width="183"> </td>
<td width="16"> </td>
</tr>
</tbody>
</table>
<input name="submit" value="1"
type="hidden"></form>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<td valign="top" width="171">
<div align="center"></div>
</td>
</tr>
</tbody>
</table>
</body>
</html>
<? } ?>