Allow automatically blocking a range of IPs when spam is detected

This commit is contained in:
Kijin Sung 2016-12-13 22:32:38 +09:00
parent 5cab16418e
commit aef7f01ed9
4 changed files with 93 additions and 30 deletions

View file

@ -22,11 +22,16 @@ $lang->msg_alert_limited_message_by_config = '%s 초 이내에 쪽지 발송은
$lang->msg_alert_denied_word = '"%s"는 사용 금지된 단어입니다.';
$lang->msg_alert_registered_denied_ip = '금지 IP에 등록되어 정상적인 활동에 제한을 받게 됐습니다. 사이트 관리자에게 문의 바랍니다.';
$lang->msg_alert_trackback_denied = '한 글에는 하나의 트랙백만 허용됩니다.';
$lang->cmd_interval = '10초 동안 3회 이상 글을 작성하면 스패머로 간주하시겠습니까? 글, 댓글 작성과 엮인글 발송, 쪽지 발송을 차단합니다.';
$lang->cmd_check_trackback = '하나의 글에 2회 이상 엮인글을 등록하면 스패머로 간주하시겠습니까? 엮인글을 차단합니다.';
$lang->cmd_interval = '글, 댓글 스팸 차단';
$lang->cmd_interval_help = '10초 동안 3회 이상 글이나 댓글을 작성하면 스패머로 간주하고 글, 댓글 작성과 엮인글 발송, 쪽지 발송을 차단합니다.';
$lang->cmd_check_trackback = '트랙백 스팸 차단';
$lang->cmd_check_trackback_help = '하나의 글에 2회 이상 엮인글을 등록하면 스패머로 간주하고 엮인글을 차단합니다.<br>트랙백 모듈이 설치되어 있는 경우에만 적용됩니다.';
$lang->cmd_ipv4_block_range = 'IPv4 차단 범위';
$lang->cmd_ipv6_block_range = 'IPv6 차단 범위';
$lang->cmd_block_range_self = '해당 IP만 차단';
$lang->cmd_block_range_help = '스패머 발견시 비슷한 대역의 IP를 한꺼번에 차단할 수 있습니다.<br>지나치게 광범위하게 차단하면 정상적인 사용자에게 피해가 발생할 수 있으니 주의하시기 바랍니다.';
$lang->cmd_block_range = '마지막 %s자리가 같은 IP를 모두 차단';
$lang->add = '추가';
$lang->yes = '예';
$lang->no = '아니오';
$lang->msg_duplicate = '이미 존재합니다.';
$lang->msg_invalid_ip = 'IP 주소 형식이 올바르지 않습니다.';
$lang->msg_invalid_word = '스팸 키워드는 2~40자 사이여야 합니다.';

View file

@ -17,16 +17,32 @@ class spamfilterAdminController extends spamfilter
function procSpamfilterAdminInsertConfig()
{
// Get the default information
$argsConfig = Context::gets('limits','check_trackback');
$flag = Context::get('flag');
//interval, limit_count
if($argsConfig->check_trackback!='Y') $argsConfig->check_trackback = 'N';
if($argsConfig->limits!='Y') $argsConfig->limits = 'N';
$args = Context::gets('limits', 'check_trackback', 'ipv4_block_range', 'ipv6_block_range');
// Set default values
if ($args->limits != 'Y')
{
$args->limits = 'N';
}
if ($args->check_trackback != 'Y')
{
$args->check_trackback = 'N';
}
if (!preg_match('#^/(\d+)$#', $args->ipv4_block_range, $matches) || $matches[1] > 32 || $matches[1] < 16)
{
$args->ipv4_block_range = '';
}
if (!preg_match('#^/(\d+)$#', $args->ipv6_block_range, $matches) || $matches[1] > 128 || $matches[1] < 64)
{
$args->ipv6_block_range = '';
}
// Create and insert the module Controller object
$oModuleController = getController('module');
$moduleConfigOutput = $oModuleController->insertModuleConfig('spamfilter',$argsConfig);
$moduleConfigOutput = $oModuleController->insertModuleConfig('spamfilter', $args);
if(!$moduleConfigOutput->toBool()) return $moduleConfigOutput;
$this->setMessage('success_updated');
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispSpamfilterAdminConfigBlock');
$this->setRedirectUrl($returnUrl);
}

View file

@ -111,10 +111,20 @@ class spamfilterModel extends spamfilter
// Ban the IP address if the interval is exceeded
if($count>=$limit_count)
{
if (\RX_CLIENT_IP_VERSION == 4)
{
$suffix = $config->ipv4_block_range ?: '';
}
else
{
$suffix = $config->ipv6_block_range ?: '';
}
$oSpamFilterController = getController('spamfilter');
$oSpamFilterController->insertIP(\RX_CLIENT_IP, 'AUTO-DENIED : Over limit');
$oSpamFilterController->insertIP(\RX_CLIENT_IP . $suffix, 'AUTO-DENIED : Over limit');
return new Object(-1, 'msg_alert_registered_denied_ip');
}
// If the number of limited posts is not reached, keep creating.
if($count)
{

View file

@ -5,32 +5,64 @@
<li><a href="{getUrl('','module','admin','act','dispSpamfilterAdminDeniedWordList')}">{$lang->cmd_denied_word}</a></li>
<li class="x_active"><a href="{getUrl('','module','admin','act','dispSpamfilterAdminConfigBlock')}">{$lang->cmd_config_block}</a></li>
</ul>
<form action="./" method="post" id="spamfilterConfig">
<form action="./" method="post" id="spamfilterConfig" class="x_form-horizontal">
<input type="hidden" name="act" value="procSpamfilterAdminInsertConfig" />
<input type="hidden" name="module" value="spamfilter" />
<input type="hidden" name="ruleset" value="insertConfig" />
<input type="hidden" name="xe_validator_id" value="modules/spamfilter/tpl/1" />
<div class="x_control-group">
<p><strong>{$lang->cmd_interval}</strong></p>
<label for="spamCond1_yes" class="x_inline">
<input type="radio" name="limits" id="spamCond1_yes" value="Y" checked="checked"|cond="$config->limits=='Y' || $config->limits ==''" />
{$lang->cmd_yes}
</label>
<label for="spamCond1_no" class="x_inline">
<input type="radio" name="limits" id="spamCond1_no" value="N" checked="checked"|cond="$config->limits!='Y' && $config->limits !=''" />
{$lang->cmd_no}
</label>
<label class="x_control-label">{$lang->cmd_interval}</label>
<div class="x_controls">
<label for="spamCond1_yes" class="x_inline">
<input type="radio" name="limits" id="spamCond1_yes" value="Y" checked="checked"|cond="$config->limits=='Y' || $config->limits ==''" />
{$lang->cmd_yes}
</label>
<label for="spamCond1_no" class="x_inline">
<input type="radio" name="limits" id="spamCond1_no" value="N" checked="checked"|cond="$config->limits!='Y' && $config->limits !=''" />
{$lang->cmd_no}
</label>
<p class="x_help-block">{$lang->cmd_interval_help}</p>
</div>
</div>
<div class="x_control-group">
<p><strong>{$lang->cmd_check_trackback}</strong></p>
<label for="spamCond2_yes" class="x_inline">
<input type="radio" name="check_trackback" id="spamCond2_yes" value="Y" checked="checked"|cond="$config->check_trackback=='Y' || $config->check_trackback==''" />
{$lang->cmd_yes}
</label>
<label for="spamCond2_no" class="x_inline">
<input type="radio" name="check_trackback" id="spamCond2_no" value="N" checked="checked"|cond="$config->check_trackback!='Y' && $config->check_trackback!=''" / >
{$lang->cmd_no}
</label>
<label class="x_control-label">{$lang->cmd_check_trackback}</label>
<div class="x_controls">
<label for="spamCond2_yes" class="x_inline">
<input type="radio" name="check_trackback" id="spamCond2_yes" value="Y" checked="checked"|cond="$config->check_trackback=='Y' || $config->check_trackback==''" />
{$lang->cmd_yes}
</label>
<label for="spamCond2_no" class="x_inline">
<input type="radio" name="check_trackback" id="spamCond2_no" value="N" checked="checked"|cond="$config->check_trackback!='Y' && $config->check_trackback!=''" / >
{$lang->cmd_no}
</label>
<p class="x_help-block">{$lang->cmd_check_trackback_help}</p>
</div>
</div>
<div class="x_control-group">
<label for="ipv4_block_range" class="x_control-label">{$lang->cmd_ipv4_block_range}</label>
<div class="x_controls">
<select name="ipv4_block_range" id="ipv4_block_range">
<option value="/32" selected="selected"|cond="!$config->ipv4_block_range">/32 ({$lang->cmd_block_range_self})</option>
{$suffixes = range(28, 16, -4)}
<option loop="$suffixes => $suffix" value="/{$suffix}" selected="selected"|cond="$config->ipv4_block_range == ('/' . $suffix)">/{$suffix}
<block cond="$suffix % 8 == 0">({sprintf($lang->cmd_block_range, (32 - $suffix) / 8)})</block>
</option>
</select>
<p class="x_help-block">{$lang->cmd_block_range_help}</p>
</div>
</div>
<div class="x_control-group">
<label for="ipv6_block_range" class="x_control-label">{$lang->cmd_ipv6_block_range}</label>
<div class="x_controls">
<select name="ipv6_block_range" id="ipv6_block_range">
<option value="/32" selected="selected"|cond="!$config->ipv6_block_range">/128 ({$lang->cmd_block_range_self})</option>
{$suffixes = range(120, 64, -8)}
<option loop="$suffixes => $suffix" value="/{$suffix}" selected="selected"|cond="$config->ipv6_block_range == ('/' . $suffix)">/{$suffix}
<block cond="$suffix % 16 == 0">({sprintf($lang->cmd_block_range, (128 - $suffix) / 16)})</block>
</option>
</select>
<p class="x_help-block">{$lang->cmd_block_range_help}</p>
</div>
</div>
<div class="x_clearfix btnArea">
<div class="x_pull-right">