09 Anti Flood Protection By Putyn

Started by Mindless, July 21, 2012, 09:12:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mindless

#1
Was about to convert Retro's Anti-flood protection mod when i discussed it with putyn - After him seeing the mod and some testing he came up with a simple solution.
Credits to putyn.
Xhtml Valid

Create a folder inside include folder named settings and a text file named limitfile.txt - chmod if linux

@File include/config.php add :
Code (php) Select
$TBDEV['flood_time'] = 900; //comment/forum/pm flood limit 900=15mins
$TBDEV['flood_file'] = ROOT_PATH.'/include/settings/limitfile.txt';


Or

@defined directories File include/config.php add :
Code (php) Select
$TBDEV['flood_time'] = 900; //comment/forum/pm flood limit 900=15mins
$TBDEV['flood_file'] = INCL_DIR.'settings'.DIRECTORY_SEPARATOR.'limitfile.txt';



@File lang/en/lang_global.php
Code (php) Select
'gl_sorry' => "Sorry",
'gl_flood_msg' => "Anti-Flood limit in effect - you need to wait - ",



@File bittorrent.php add :
Code (php) Select
function flood_limit($table) {
global $CURUSER,$TBDEV,$lang;
if(!file_exists($TBDEV['flood_file']) || !is_array($max = unserialize(file_get_contents($TBDEV['flood_file']))))
return;
if(!isset($max[$CURUSER['class']]))
return;
$tb = array('posts'=>'posts.userid','comments'=>'comments.user','messages'=>'messages.sender');
$q = mysql_query('SELECT min('.$table.'.added) as first_post, count('.$table.'.id) as how_many FROM '.$table.' WHERE '.$tb[$table].' = '.$CURUSER['id'].' AND '.time().' - '.$table.'.added < '.$TBDEV['flood_time']);
$a = mysql_fetch_assoc($q);
if($a['how_many'] > $max[$CURUSER['class']])
        stderr($lang['gl_sorry'] ,$lang['gl_flood_msg'].''.mkprettytime($TBDEV['flood_time'] - (time() - $a['first_post'])));
}



@File comment.php find
Code (php) Select
$lang = array_merge( load_language('global'), load_language('comment') );


Under it add :
Code (php) Select
flood_limit('comments');


@File sendmessage.php find :
Code (php) Select
$lang = array_merge( load_language('global'), load_language('sendmessage') );


Under it add
Code (php) Select
flood_limit('messages');


@File takemessage.php find :
Code (php) Select
$lang = array_merge( load_language('global'), load_language('takemessage') );


Under it add :
Code (php) Select
flood_limit('messages');


@File messages.php find :
Code (php) Select
$lang = array_merge( load_language('global'), load_language('messages') );


Under it add :
Code (php) Select
flood_limit('messages');


@File forums.php find :
Code (php) Select
$lang = array_merge( load_language('global'), load_language('forums') );


Under it add :
Code (php) Select
flood_limit('posts');


@File staffpanel.php or admin.php tools array add :
Code (php) Select
'floodlimit' => 'floodlimit',


@File staffpanel.php for link :
Code (php) Select
staffpanel.php?tool=floodlimit


Save and upload floodlimit.php to /admin folder - Then set your userclass limits - Note its always one after the totals reached the block will happen :)
Code (php) Select
<?php
//==09 Anti Flood Protection by putyn
if ( ! defined'IN_TBDEV_ADMIN' ) )
{
$HTMLOUT='';
$HTMLOUT .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Error!</title>
</head>
<body>
<div style='font-size:33px;color:white;background-color:red;text-align:center;'>Incorrect access<br />You cannot access this file directly.</div>
</body></html>"
;
echo $HTMLOUT;
exit();
}

require_once(
"include/bittorrent.php");
require_once(
"include/user_functions.php");
require_once(
"include/html_functions.php");



if(
$_SERVER['REQUEST_METHOD'] == 'POST') {

$limits = isset($_POST['limit']) && is_array($_POST['limit']) ? $_POST['limit'] : 0;

foreach($limits as $class=>$limit)
if($limit == 0) unset($limits[$class]);

if(file_put_contents($TBDEV['flood_file'],serialize($limits))) {
//header('Refresh: 2; url=/staffpanel.php?tool=floodlimit');
      
header('Refresh: 2; url=/admin.php?action=floodlimit');
stderr('Success','Limits saved! returning to main page');
} else
stderr('Err','Something went wrong make sure '.$_file.' exists and it is chmoded 0777');

} else {

if(!
file_exists($TBDEV['flood_file']) || !is_array($limit unserialize(file_get_contents($TBDEV['flood_file']))))
$limit = array();

$out begin_main_frame().begin_frame('Edit flood limit');
$out .= '<form method=\'post\' action=\'\' ><table width=\'60%\' align=\'center\'><tr><td class=\'colhead\'>User class</td><td class=\'colhead\'>Limit</td></tr>';
for($i=UC_USER;$i<=UC_SYSOP;$i++)
$out .= '<tr><td align=\'left\'>'.get_user_class_name($i).'</td><td><input name=\'limit['.$i.']\' type=\'text\' size=\'10\' value=\''.(isset($limit[$i]) ? $limit[$i] : 0).'\'/></td></tr>';
$out .= '<tr><td colspan=\'2\'>Note if you want no limit for the user class set the limit to 0</td></tr><tr><td colspan=\'2\' class=\'colhead\'><input type=\'submit\' value=\'Save\' /></td></tr>';
$out .= '</table></form>'.end_frame().end_main_frame();

echo(
stdhead('Flood limit').$out.stdfoot());
}
?>


Max class can be edited on line 32 of flood limit.