Merge pull request #656 from kijin/pr/spamfilter

스팸필터 모듈 기능 개선 및 오류 수정
This commit is contained in:
Kijin Sung 2016-12-13 23:38:46 +09:00 committed by GitHub
commit 6a9185d2b3
12 changed files with 271 additions and 135 deletions

View file

@ -1,7 +1,10 @@
<?php
$lang->cmd_denied_ip = 'IP Address Blacklist';
$lang->cmd_denied_word = 'Word Blacklist';
$lang->spamfilter = 'Spam filter';
$lang->cmd_denied_word = 'Keyword Blacklist';
$lang->cmd_config_block = 'Automatic Blocking';
$lang->add_denied_ip = 'Add IP address or range';
$lang->add_denied_word = 'Add keyword';
$lang->spamfilter = 'Spam Filter';
$lang->denied_ip = 'Blocked IP Address';
$lang->interval = 'Interval for spam filtering';
$lang->limit_count = 'No. of post limited';
@ -10,21 +13,29 @@ $lang->word = 'Keyword';
$lang->hit = 'Hit';
$lang->latest_hit = 'Latest Hits';
$lang->about_interval = 'All articles attempted for posting within the assigned time will be blocked.';
$lang->about_limit_count = 'If exceeded the posting limitation,
that IP will be regarded as a spam, thus will have limitations on posting articles, comments, and trackbacks.';
$lang->about_denied_ip = 'You can add IP address range like 127.0.0.* by using *.';
$lang->about_denied_word = 'When you add a word to Word Blacklist,
articles including it will be blocked.';
$lang->about_check_trackback = 'A single IP per article is allowed for trackbacks.';
$lang->msg_alert_limited_by_config = 'Posting an article within %s seconda is not allowed.\\n If you keep trying, your IP address will be blacklisted.';
$lang->msg_alert_limited_message_by_config = 'sending an message within %s seconda is not allowed.\\n If you keep trying, your IP address will be blacklisted.';
$lang->msg_alert_denied_word = 'The word "%s" is not allowed.';
$lang->msg_alert_registered_denied_ip = 'Your IP address is blacklisted,\\n so you may have limitations on normal using of this site.\\n If you have any questions on that matter, please contact the site administrator.';
$lang->about_denied_ip = 'Please enter one IP address (e.g. 127.0.0.1) or range (e.g. 127.0.0.0/24) per line. Comments may start with //.';
$lang->about_denied_word = 'Please enter one keyword per line. Keywords may contain 2 to 40 characters.';
$lang->msg_alert_limited_by_config = 'Please do not post repeatedly within %d seconds. If you keep trying, your IP address will be blocked.';
$lang->msg_alert_limited_message_by_config = 'Please do not send messages repeatedly within %d seconds. If you keep trying, your IP address will be blocked.';
$lang->msg_alert_denied_word = 'The word "%s" is not allowed on this site.';
$lang->msg_alert_registered_denied_ip = 'Your IP address has been blocked for abuse. Please contact the administrator.';
$lang->msg_alert_trackback_denied = 'Only one trackback per an article is allowed.';
$lang->cmd_interval = 'Do you want to blacklist the users who attempt to post articles more than 3 times for 10 seconds? The blacklisted users cannot write articles or comments and send trackbacks.';
$lang->cmd_check_trackback = 'Do you want to blacklist the users who attempt to post more than 2 trackbacks to one article? The blacklisted users cannot post trackbacks.';
$lang->cmd_interval = 'Block Post/Comment Spam';
$lang->cmd_interval_help = 'Block IP addresses that post or comment too much in a short time. Blocked IP addresses will not be able to post, comment, or send messages.';
$lang->cmd_check_trackback = 'Block Trackback Spam';
$lang->cmd_check_trackback_help = 'Block IP addresses that send multiple trackbacks to the same document.<br>This only works if the trackback module is installed.';
$lang->cmd_limits_interval = 'Block Interval';
$lang->cmd_limits_interval_help = 'Block IP addresses that post or comment too much within this number of seconds.';
$lang->cmd_limits_count = 'Post/Comment Count';
$lang->cmd_limits_count_help = 'Block IP addresses that post or comment this number of times within the above number of seconds.';
$lang->cmd_ipv4_block_range = 'IPv4 Block Range';
$lang->cmd_ipv6_block_range = 'IPv6 Block Range';
$lang->cmd_block_range_self = 'single IP address only';
$lang->cmd_block_range_help = 'This option allows you to block an entire range of IP addresses when a spammer is found.<br>Caution: if you block an excessively wide range, you may also end up blocking innocent users.';
$lang->cmd_block_range = 'IP addresses with the same %d last blocks';
$lang->unit_write_count = 'times';
$lang->add = 'Add';
$lang->yes = 'Yes';
$lang->no = 'No';
$lang->msg_duplicate = 'The value is invalid.';
$lang->msg_invalid = 'The value is invalid.';
$lang->msg_duplicate = 'Duplicate';
$lang->msg_invalid_ip = 'Invalid IP address format.';
$lang->msg_invalid_word = 'Spam keywords must be between 2 and 40 characters.';
$lang->msg_faillist = '<br />Error (already blocked)<br /> %s ';

View file

@ -28,5 +28,6 @@ $lang->add = '追加';
$lang->yes = 'はい';
$lang->no = 'いいえ';
$lang->msg_duplicate = '既に存在します。';
$lang->msg_invalid = '形式が有効しません。';
$lang->msg_invalid_ip = 'IPアドレスの形式が正しくありません。';
$lang->msg_invalid_word = 'スパムキーワードは2〜40文字の範囲で指定します。';
$lang->msg_faillist = '<br />失敗(既に存在します。) <br /> %s ';

View file

@ -13,20 +13,29 @@ $lang->word = '키워드';
$lang->hit = '히트';
$lang->latest_hit = '최근 히트';
$lang->about_interval = '지정된 시간 내에 글을 등록하지 못하게 합니다.';
$lang->about_limit_count = '지정된 시간 내에 제한수를 넘겨서 글 작성을 시도하면 스팸으로 인식, 해당 IP의 글 작성, 댓글 작성, 트랙백 발송, 쪽지 발송 등을 금지합니다.';
$lang->about_denied_ip = '\'스팸 IP // 메모\' 형식으로 입력하세요. 여러개의 항목은 줄을 바꾸어 입력하세요.';
$lang->about_denied_word = '여러개의 항목은 줄을 바꾸어 입력하세요. (글자 제한 2~40 byte)';
$lang->about_check_trackback = '한 글에 한 IP에만 트랙백을 허용할 수 있습니다.';
$lang->msg_alert_limited_by_config = '%s 초 이내에 글 작성은 금지 됩니다. 계속 시도하면 금지 IP에 등록될 수 있습니다.';
$lang->msg_alert_limited_message_by_config = '%s 초 이내에 쪽지 발송은 금지 됩니다. 계속 시도하면 금지 IP에 등록될 수 있습니다.';
$lang->msg_alert_denied_word = '"%s"는 사용 금지된 단어입니다.';
$lang->msg_alert_registered_denied_ip = '금지 IP에 등록되어 정상적인 활동에 제한을 받게 됐습니다. 사이트 관리자에게 문의 바랍니다.';
$lang->about_denied_ip = '한 줄에 하나씩 IP 주소 또는 대역을 입력하세요. &quot;//&quot; 또는 &quot;#&quot; 뒷부분은 설명으로 저장됩니다. 예: 127.0.0.1 //설명, 127.0.0.1 #설명<br>IP 대역 표기법은 <a href="https://github.com/rhymix/rhymix-docs/blob/master/ko/misc/ipfilter.md" target="_blank">매뉴얼</a>을 참고하십시오.';
$lang->about_denied_word = '한 줄에 하나씩 스팸 키워드를 입력하세요. (2~40자)';
$lang->msg_alert_limited_by_config = '%d초 이내에 연속 글 작성은 금지됩니다. 계속 시도하면 IP가 차단될 수 있습니다.';
$lang->msg_alert_limited_message_by_config = '%d초 이내에 연속 쪽지 발송은 금지됩니다. 계속 시도하면 IP가 차단될 수 있습니다.';
$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 = '아래에 지정한 시간 내에 다수의 글이나 댓글을 작성하면 스패머로 간주하고 글, 댓글 작성과 엮인글 발송, 쪽지 발송을 차단합니다.';
$lang->cmd_check_trackback = '트랙백 스팸 차단';
$lang->cmd_check_trackback_help = '하나의 글에 2회 이상 엮인글을 등록하면 스패머로 간주하고 엮인글을 차단합니다.<br>트랙백 모듈이 설치되어 있는 경우에만 적용됩니다.';
$lang->cmd_limits_interval = '글, 댓글 제한 시간';
$lang->cmd_limits_interval_help = '지정한 시간 내에 아래의 갯수만큼 글이나 댓글을 작성하면 스패머로 간주합니다.';
$lang->cmd_limits_count = '글, 댓글 작성 갯수';
$lang->cmd_limits_count_help = '위에서 지정한 시간 내에 이 갯수만큼 글이나 댓글을 작성하면 스패머로 간주합니다.';
$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 = '마지막 %d자리가 같은 IP를 모두 차단';
$lang->unit_write_count = '회';
$lang->add = '추가';
$lang->yes = '예';
$lang->no = '아니오';
$lang->msg_duplicate = '이미 존재합니다.';
$lang->msg_invalid = '형식이 유효하지 않습니다.';
$lang->msg_faillist = '<br />실패(이미 존재합니다.) <br /> %s ';
$lang->msg_invalid_ip = 'IP 주소 형식이 올바르지 않습니다.';
$lang->msg_invalid_word = '스팸 키워드는 2~40자 사이여야 합니다.';
$lang->msg_faillist = '<br />실패 (이미 차단되어 있습니다)<br /> %s ';

View file

@ -1,5 +1,5 @@
<table name="spamfilter_denied_ip">
<column name="ipaddress" type="varchar" size="250" notnull="notnull" primary_key="primary_key" />
<column name="description" type="varchar" size="250" />
<column name="ipaddress" type="varchar" size="60" utf8mb4="false" notnull="notnull" primary_key="primary_key" />
<column name="description" type="varchar" size="255" />
<column name="regdate" type="date" index="idx_regdate" />
</table>

View file

@ -1,5 +1,5 @@
<table name="spamfilter_denied_word">
<column name="word" type="varchar" size="250" notnull="notnull" primary_key="primary_key" />
<column name="word" type="varchar" size="250" utf8mb4="false" notnull="notnull" primary_key="primary_key" />
<column name="hit" type="number" notnull="notnull" default="0" index="idx_hit" />
<column name="latest_hit" type="date" index="idx_latest_hit" />
<column name="regdate" type="date" index="idx_regdate" />

View file

@ -17,16 +17,34 @@ 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', 'limits_interval', 'limits_count', '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 = '';
}
$args->limits_interval = intval($args->limits_interval);
$args->limits_count = intval($args->limits_count);
// 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);
}
@ -114,27 +132,38 @@ class spamfilterAdminController extends spamfilter
*/
function insertWord($word_list)
{
$word_list = str_replace("\r","",$word_list);
$word_list = explode("\n",$word_list);
foreach($word_list as $word)
if (!is_array($word_list))
{
if(!preg_match("/^(.{2,40}[\r\n]+)*.{2,40}$/", $word))
$word_list = array_map('trim', explode("\n", $word_list));
}
$fail_list = '';
$output = null;
foreach ($word_list as $word)
{
if ($word === '')
{
return new Object(-1, 'msg_invalid');
continue;
}
if (mb_strlen($word, 'UTF-8') < 2 || mb_strlen($word, 'UTF-8') > 40)
{
return new Object(-1, 'msg_invalid_word');
}
$args = new stdClass;
$args->word = $word;
$output = executeQuery('spamfilter.insertDeniedWord', $args);
if (!$output->toBool())
{
$fail_list .= $args->word . '<br />';
}
}
$fail_word = '';
foreach($word_list as $word)
if ($output)
{
$args = new stdClass;
if(trim($word)) $args->word = $word;
$output = executeQuery('spamfilter.insertDeniedWord', $args);
if(!$output->toBool()) $fail_word .= $word.'<br />';
$output->add('fail_list', $fail_list);
}
$output->add('fail_list',$fail_word);
return $output;
}

View file

@ -53,6 +53,7 @@ class spamfilterController extends spamfilter
{
$text = $obj->title . ' ' . $obj->content . ' ' . $obj->nick_name . ' ' . $obj->homepage . ' ' . $obj->tags;
}
$text = utf8_trim(utf8_normalize_spaces(htmlspecialchars_decode(strip_tags($text))));
$output = $oFilterModel->isDeniedWord($text);
if(!$output->toBool()) return $output;
// Check the specified time beside the modificaiton time
@ -89,7 +90,6 @@ class spamfilterController extends spamfilter
$output = $oFilterModel->isDeniedIP();
if(!$output->toBool()) return $output;
// Check if there is a ban on the word
$text = '';
if($is_logged)
{
$text = $obj->content;
@ -98,6 +98,7 @@ class spamfilterController extends spamfilter
{
$text = $obj->content . ' ' . $obj->nick_name . ' ' . $obj->homepage;
}
$text = utf8_trim(utf8_normalize_spaces(htmlspecialchars_decode(strip_tags($text))));
$output = $oFilterModel->isDeniedWord($text);
if(!$output->toBool()) return $output;
// If the specified time check is not modified
@ -128,32 +129,24 @@ class spamfilterController extends spamfilter
// Check if the IP is prohibited
$output = $oFilterModel->isDeniedIP();
if(!$output->toBool()) return $output;
// Check if there is a ban on the word
$text = $obj->blog_name . ' ' . $obj->title . ' ' . $obj->excerpt . ' ' . $obj->url;
$output = $oFilterModel->isDeniedWord($text);
if(!$output->toBool()) return $output;
// Start Filtering
$oTrackbackModel = getModel('trackback');
$oTrackbackController = getController('trackback');
list($ipA,$ipB,$ipC,$ipD) = explode('.',$_SERVER['REMOTE_ADDR']);
$ipaddress = $ipA.'.'.$ipB.'.'.$ipC;
// In case the title and the blog name are indentical, investigate the IP address of the last 6 hours, delete and ban it.
if($obj->title == $obj->excerpt)
if (is_object($oTrackbackController) && method_exists($oTrackbackController, 'deleteTrackbackSender'))
{
$oTrackbackController->deleteTrackbackSender(60*60*6, $ipaddress, $obj->url, $obj->blog_name, $obj->title, $obj->excerpt);
$this->insertIP($ipaddress.'.*', 'AUTO-DENIED : trackback.insertTrackback');
return new Object(-1,'msg_alert_trackback_denied');
// In case the title and the blog name are indentical, investigate the IP address of the last 6 hours, delete and ban it.
if($obj->title == $obj->excerpt)
{
$oTrackbackController->deleteTrackbackSender(60*60*6, \RX_CLIENT_IP, $obj->url, $obj->blog_name, $obj->title, $obj->excerpt);
$this->insertIP(\RX_CLIENT_IP, 'AUTO-DENIED : trackback.insertTrackback');
return new Object(-1, 'msg_alert_trackback_denied');
}
}
// If trackbacks have been registered by one C-class IP address more than once for the last 30 minutes, ban the IP address and delete all the posts
/* 호스팅 환경을 감안하여 일단 부분은 동작하지 않도록 주석 처리
$count = $oTrackbackModel->getRegistedTrackback(30*60, $ipaddress, $obj->url, $obj->blog_name, $obj->title, $obj->excerpt);
if($count > 1) {
$oTrackbackController->deleteTrackbackSender(3*60, $ipaddress, $obj->url, $obj->blog_name, $obj->title, $obj->excerpt);
$this->insertIP($ipaddress.'.*');
return new Object(-1,'msg_alert_trackback_denied');
}
*/
return new Object();
}
@ -164,25 +157,49 @@ class spamfilterController extends spamfilter
*/
function insertIP($ipaddress_list, $description = null)
{
$regExr = "/^((\d{1,3}(?:.(\d{1,3}|\*)){3})\s*(\/\/(.*)\s*)?)*\s*$/";
if(!preg_match($regExr,$ipaddress_list)) return new Object(-1, 'msg_invalid');
$ipaddress_list = str_replace("\r","",$ipaddress_list);
$ipaddress_list = explode("\n",$ipaddress_list);
foreach($ipaddress_list as $ipaddressValue)
if (!is_array($ipaddress_list))
{
$args = new stdClass();
preg_match("/(\d{1,3}(?:.(\d{1,3}|\*)){3})\s*(\/\/(.*)\s*)?/",$ipaddressValue,$matches);
if($ipaddress=trim($matches[1]))
$ipaddress_list = array_map('trim', explode("\n", $ipaddress_list));
}
$fail_list = '';
$output = null;
foreach ($ipaddress_list as $ipaddress)
{
if ($ipaddress === '')
{
continue;
}
$args = new stdClass;
if (preg_match('@^(.+?)(?://|#)(.*)$@', $ipaddress, $matches))
{
$args->ipaddress = trim($matches[1]);
$args->description = trim($matches[2]);
}
else
{
$args->ipaddress = $ipaddress;
if(!$description && $matches[4]) $args->description = $matches[4];
else $args->description = $description;
$args->description = $description;
}
if (!Rhymix\Framework\Filters\IpFilter::validateRange($args->ipaddress))
{
return new Object(-1, 'msg_invalid_ip');
}
$output = executeQuery('spamfilter.insertDeniedIP', $args);
if(!$output->toBool()) $fail_list .= $ipaddress.'<br/>';
if (!$output->toBool())
{
$fail_list .= $args->ipaddress . '<br />';
}
}
$output->add('fail_list',$fail_list);
if ($output)
{
$output->add('fail_list', $fail_list);
}
return $output;
}

View file

@ -32,9 +32,8 @@ class spamfilterModel extends spamfilter
$args = new stdClass();
$args->sort_index = "regdate";
$args->page = Context::get('page')?Context::get('page'):1;
$output = executeQuery('spamfilter.getDeniedIPList', $args);
$output = executeQueryArray('spamfilter.getDeniedIPList', $args);
if(!$output->data) return;
if(!is_array($output->data)) return array($output->data);
return $output->data;
}
@ -43,18 +42,20 @@ class spamfilterModel extends spamfilter
*/
function isDeniedIP()
{
$ipaddress = $_SERVER['REMOTE_ADDR'];
$ip_list = $this->getDeniedIPList();
if(!count($ip_list)) return new Object();
$count = count($ip_list);
for($i=0;$i<$count;$i++)
$ip_ranges = array();
foreach ($ip_list as $ip_range)
{
$ip = str_replace('.', '\.', str_replace('*','(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)',$ip_list[$i]->ipaddress));
if(preg_match('/^'.$ip.'$/', $ipaddress, $matches)) return new Object(-1,'msg_alert_registered_denied_ip');
$ip_ranges[] = $ip_range->ipaddress;
}
if (Rhymix\Framework\Filters\IpFilter::inRanges(\RX_CLIENT_IP, $ip_ranges))
{
return new Object(-1, 'msg_alert_registered_denied_ip');
}
return new Object();
}
@ -79,11 +80,10 @@ class spamfilterModel extends spamfilter
$word_list = $this->getDeniedWordList();
if(!count($word_list)) return new Object();
$count = count($word_list);
for($i=0;$i<$count;$i++)
foreach ($word_list as $word_item)
{
$word = $word_list[$i]->word;
if(preg_match('/'.preg_quote($word,'/').'/is', $text))
$word = $word_item->word;
if (strpos($text, $word) !== false)
{
$args = new stdClass();
$args->word = $word;
@ -103,19 +103,28 @@ class spamfilterModel extends spamfilter
$config = $this->getConfig();
if($config->limits != 'Y') return new Object();
$limit_count = '3';
$interval = '10';
$limit_count = $config->limits_count ?: 3;
$interval = $config->limits_interval ?: 10;
$count = $this->getLogCount($interval);
$ipaddress = $_SERVER['REMOTE_ADDR'];
// 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($ipaddress, '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)
{
@ -142,9 +151,14 @@ class spamfilterModel extends spamfilter
function isInsertedTrackback($document_srl)
{
$oTrackbackModel = getModel('trackback');
$count = $oTrackbackModel->getTrackbackCountByIPAddress($document_srl, $_SERVER['REMOTE_ADDR']);
if($count>0) return new Object(-1, 'msg_alert_trackback_denied');
if (is_object($oTrackbackModel) && method_exists($oTrackbackModel, 'getTrackbackCountByIPAddress'))
{
$count = $oTrackbackModel->getTrackbackCountByIPAddress($document_srl, \RX_CLIENT_IP);
if ($count > 0)
{
return new Object(-1, 'msg_alert_trackback_denied');
}
}
return new Object();
}
@ -153,11 +167,11 @@ class spamfilterModel extends spamfilter
*/
function getLogCount($time = 60, $ipaddress='')
{
if(!$ipaddress) $ipaddress = $_SERVER['REMOTE_ADDR'];
if(!$ipaddress) $ipaddress = \RX_CLIENT_IP;
$args = new stdClass();
$args->ipaddress = $ipaddress;
$args->regdate = date("YmdHis", $_SERVER['REQUEST_TIME']-$time);
$args->regdate = date("YmdHis", time() - $time);
$output = executeQuery('spamfilter.getLogCount', $args);
$count = $output->data->count;
return $count;

View file

@ -5,32 +5,78 @@
<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="limits_interval" class="x_control-label">{$lang->cmd_limits_interval}</label>
<div class="x_controls">
<input type="number" name="limits_interval" id="limits_interval" value="{intval($config->limits_interval) ?: 10}" /> {$lang->unit_sec}
<p class="x_help-block">{$lang->cmd_limits_interval_help}</p>
</div>
</div>
<div class="x_control-group">
<label for="limits_count" class="x_control-label">{$lang->cmd_limits_count}</label>
<div class="x_controls">
<input type="number" name="limits_count" id="limits_count" value="{intval($config->limits_count) ?: 3}" /> {$lang->unit_write_count}
<p class="x_help-block">{$lang->cmd_limits_count_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">

View file

@ -35,12 +35,13 @@
</tbody>
</table>
</form>
<form action="./" style="margin-right:14px" method="post">
<form action="./" style="margin-right:14px" method="post" class="x_form-horizontal">
<input type="hidden" name="act" value="procSpamfilterAdminInsertDeniedIP" />
<input type="hidden" name="module" value="spamfilter" />
<input type="hidden" name="xe_validator_id" value="modules/spamfilter/tpl/1" />
<input type="hidden" name="active" value="ip" />
<textarea name="ipaddress_list" title="{$lang->add_denied_ip}: {$lang->about_denied_ip}" rows="4" cols="42" style="width:100%" placeholder="{$lang->about_denied_ip}"></textarea>
<textarea name="ipaddress_list" title="{$lang->add_denied_ip}" rows="4" cols="42" style="width:100%"></textarea>
<p class="x_help-block">{$lang->about_denied_ip}</p>
<span class="x_pull-right" style="margin-right:-14px">
<button type="submit" class="x_btn x_btn-primary">{$lang->add_denied_ip}</button>
</span>

View file

@ -37,12 +37,13 @@
</tbody>
</table>
</form>
<form action="./" style="margin-right:14px" method="post">
<form action="./" style="margin-right:14px" method="post" class="x_form-horizontal">
<input type="hidden" name="act" value="procSpamfilterAdminInsertDeniedWord" />
<input type="hidden" name="module" value="spamfilter" />
<input type="hidden" name="active" value="word" />
<input type="hidden" name="xe_validator_id" value="modules/spamfilter/tpl/1" />
<textarea name="word_list" title="{$lang->add_denied_word}: {$lang->about_denied_word}" placeholder="{$lang->about_denied_word}" rows="4" cols="42" style="width:100%"></textarea>
<textarea name="word_list" title="{$lang->add_denied_word}" rows="4" cols="42" style="width:100%"></textarea>
<p class="x_help-block">{$lang->about_denied_word}</p>
<span class="x_pull-right" style="margin-right:-14px">
<button type="submit" class="x_btn x_btn-primary">{$lang->add_denied_word}</button>
</span>

View file

@ -10,6 +10,9 @@ class IpFilterTest extends \Codeception\TestCase\Test
$this->assertFalse(Rhymix\Framework\Filters\IpFilter::inRange('172.34.0.0', '172.16.0.0/12'));
$this->assertTrue(Rhymix\Framework\Filters\IpFilter::inRange('192.168.18.214', '192.168.16.0/22'));
$this->assertFalse(Rhymix\Framework\Filters\IpFilter::inRange('192.168.18.214', '192.168.16.0/23'));
$this->assertTrue(Rhymix\Framework\Filters\IpFilter::inRange('192.168.18.214', '192.168.19.7/23'));
$this->assertTrue(Rhymix\Framework\Filters\IpFilter::inRange('192.168.18.214', '192.168.16.211/22'));
$this->assertFalse(Rhymix\Framework\Filters\IpFilter::inRange('192.168.18.214', '192.168.17.255/23'));
}
public function testIPv6CIDR()
@ -18,14 +21,18 @@ class IpFilterTest extends \Codeception\TestCase\Test
$this->assertFalse(Rhymix\Framework\Filters\IpFilter::inRange('::1', '::2'));
$this->assertTrue(Rhymix\Framework\Filters\IpFilter::inRange('2400:cb00::1234', '2400:cb00::/32'));
$this->assertFalse(Rhymix\Framework\Filters\IpFilter::inRange('2405:8100::1234', '2400:cb00::/32'));
$this->assertTrue(Rhymix\Framework\Filters\IpFilter::inRange('2400:cb00::1234', '2400:cb00::ffff:1234/96'));
$this->assertFalse(Rhymix\Framework\Filters\IpFilter::inRange('2405:8100::1234', '2400:cb00::ffff:1234/96'));
}
public function testIPv4Wildcard()
{
$this->assertTrue(Rhymix\Framework\Filters\IpFilter::inRange('192.168.134.241', '192.168.134.*'));
$this->assertTrue(Rhymix\Framework\Filters\IpFilter::inRange('192.168.134.241', '192.168.*.*'));
$this->assertTrue(Rhymix\Framework\Filters\IpFilter::inRange('192.168.134.241', '192.168.*'));
$this->assertFalse(Rhymix\Framework\Filters\IpFilter::inRange('192.168.134.241', '192.168.136.*'));
$this->assertFalse(Rhymix\Framework\Filters\IpFilter::inRange('192.168.134.241', '192.172.*.*'));
$this->assertFalse(Rhymix\Framework\Filters\IpFilter::inRange('192.168.134.241', '192.172.*'));
}
public function testIPv4Hyphen()