Экстремальный программинг. Защита от ботов.
Разрешил гостям писать всего в три раздела.
И сам пошел читать про яваскрипт защиту.
Надо было делать наоборот)))
Не более чем через 5 минут поперли, демоны.
Всего, правда, 2 сообщения.
В условиях тяжелого артобстрела писал защиту с использованием капчи Гаррета.
Ключевые моменты.
./sources/action_public/topics.php
$antibot="";
if (!intval($this->ipsclass->member['id']) and !$this->ipsclass->is_bot)
{
$bid = md5( uniqid(microtime()) );
// Set a new 6 character numerical string
mt_srand ((double) microtime() * 1000000);
$b_code = mt_rand(10,99)."+".mt_rand(10,99)."=";
$this->ipsclass->DB->do_insert( 'reg_antispam', array ( 'regid' => $bid,
'regcode' => $b_code,
'ip_address' => $this->ipsclass->input['IP_ADDRESS'],
'ctime' => time(),
) );
$this->ipsclass->load_language('lang_register');
$antibot = $this->ipsclass->compiled_templates['skin_topic']->post_bot_defence($bid);
}./sources/classes/post/class_post.php
if (!intval($this->ipsclass->member['id']) and !$this->ipsclass->is_bot)
{
$bid = md5( uniqid(microtime()) );
// Set a new 6 character numerical string
mt_srand ((double) microtime() * 1000000);
$b_code = mt_rand(10,99)."+".mt_rand(10,99)."=";
$this->ipsclass->DB->do_insert( 'reg_antispam', array ( 'regid' => $bid,
'regcode' => $b_code,
'ip_address' => $this->ipsclass->input['IP_ADDRESS'],
'ctime' => time(),
) );
$this->ipsclass->load_language('lang_register');
$form .= $this->ipsclass->compiled_templates['skin_post']->post_bot_defence($bid);
}./sources/action_public/post.php
$answering=false;
if($this->han_post->obj['action_codes'][ $this->ipsclass->input['CODE'] ][0] )
{
$answering=true;
}
if (!intval($this->ipsclass->member['id']) and $answering)
{
if ( $this->ipsclass->input['bid'] == "" )
{
$this->ipsclass->Error( array( LEVEL => 1, MSG => 'missing_code') );
}
$this->ipsclass->DB->simple_construct( array( 'select' => '*',
'from' => 'reg_antispam',
'where' => "regid='".trim(addslashes($this->ipsclass->input['bid']))."'"
) );
$this->ipsclass->DB->simple_exec();
if ( ! $row = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->Error( array( LEVEL => 1, MSG => 'missing_code') );
}
$code = $row['regcode'];
$code_array = array();
$code_array = explode("+", $code);
$sum_result = intval($code_array[0]) + intval(substr($code_array[1], 0, strlen($code_array[1])-1));
if ( trim( $this->ipsclass->input['reg_code'] ) != $sum_result )
{
$this->ipsclass->Error( array( LEVEL => 1, MSG => 'error_code') );
}
$this->ipsclass->DB->simple_exec_query( array( 'delete' => 'reg_antispam', 'where' => "regid='".trim(addslashes($this->ipsclass->input['bid']))."'" ) );
}html
<table class='ipbtable' cellspacing="0">
<tr>
<td width="1%">
{ipb.lang['las_input']}<div class="desc">{ipb.lang['las_input_text']}</div>
<input type="text" size="25" maxlength="32" name="reg_code" />
<input type="hidden" name="bid" value="{$bid}" />
</td>
<td align="center"><img src="{ipb.script_url}act=Reg&CODE=image&rc={$bid}" alt="{ipb.lang['alt_loadingimg']}" /></td>
</tr>
</table>Естественно это самые большие куски и ничего у вас не получится, тем более я не сказал, куда.
Есть еще пара мелочей.
Проверим на деле.
Пока ок.

4 комментария
Рекомендуемые комментарии