Add several columns to spamfilter IP & word tables for feature consistency and extensibility #1882

This commit is contained in:
Kijin Sung 2022-12-19 01:45:10 +09:00
parent e1f98e573c
commit 020b85168c
11 changed files with 94 additions and 30 deletions

View file

@ -16,14 +16,16 @@ $lang->latest_hit = 'Latest Hits';
$lang->custom_message = 'Error Message';
$lang->about_custom_message = 'You can customize the error message that will be displayed if a spam keyword is found.<br>%s can be used as a placeholder for the keyword. If not used, the keyword will be hidden.';
$lang->about_interval = 'All articles attempted for posting within the assigned time will be blocked.';
$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 180 characters.<br>Formats such as /spam(key|word)?/ will be treated as a regular expression, and must use the proper syntax.<br>Spam keywords are not case sensitive.';
$lang->msg_denied_word_is_regexp = 'REGEXP';
$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 // or #.';
$lang->about_denied_word = 'Please enter one keyword (2 to 180 characters) per line. Comments may start with #.<br>Formats such as /spam(key|word)?/ will be treated as a regular expression, and must use the proper syntax.<br>Spam keywords are not case sensitive.';
$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_spamfilter_except_member = 'Except Members';
$lang->cmd_spamfilter_filter_html = 'HTML';
$lang->cmd_spamfilter_is_regexp = 'REGEXP';
$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';

View file

@ -16,14 +16,16 @@ $lang->latest_hit = '최근 히트';
$lang->custom_message = '차단 메시지 설정';
$lang->about_custom_message = '스팸 키워드 발견시 표시할 에러 메시지를 지정할 수 있습니다.<br>%s를 넣으면 그 자리에 해당 키워드를 표시하고, 그렇지 않으면 키워드를 숨깁니다.';
$lang->about_interval = '지정된 시간 내에 글을 등록하지 못하게 합니다.';
$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~180자)<br>/스팸(키+|워드)?/ 와 같은 형태로 입력하면 정규식으로 간주하며, 올바른 정규식 문법을 사용해야 합니다.<br>대소문자는 구분하지 않습니다.';
$lang->msg_denied_word_is_regexp = '정규식';
$lang->about_denied_ip = '한 줄에 하나씩 IP 주소 또는 대역을 입력하세요. &quot;//&quot; 또는 &quot;#&quot; 뒷부분은 설명으로 저장됩니다.<br>예: 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~180자)를 입력하세요. &quot;#&quot; 뒷부분은 설명으로 입력됩니다.<br>/스팸(키+|워드)?/ 와 같은 형태로 입력하면 정규식으로 간주하며, 올바른 정규식 문법을 사용해야 합니다.<br>대소문자는 구분하지 않습니다.';
$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_spamfilter_except_member = '회원 제외';
$lang->cmd_spamfilter_filter_html = 'HTML';
$lang->cmd_spamfilter_is_regexp = '정규식';
$lang->cmd_interval = '글, 댓글 스팸 차단';
$lang->cmd_interval_help = '지정한 시간 내에 다수의 글이나 댓글을 작성하면 스패머로 간주하고 글, 댓글 작성과 엮인글 발송, 쪽지 발송을 차단합니다.';
$lang->cmd_check_trackback = '트랙백 스팸 차단';

View file

@ -4,6 +4,8 @@
</tables>
<columns>
<column name="ipaddress" var="ipaddress" notnull="notnull" />
<column name="hit" default="0" />
<column name="except_member" var="except_member" />
<column name="description" var="description" />
<column name="regdate" var="regdate" default="curdate()" />
</columns>

View file

@ -4,7 +4,11 @@
</tables>
<columns>
<column name="word" var="word" notnull="notnull" />
<column name="hit" default="0" />
<column name="except_member" var="except_member" />
<column name="filter_html" var="filter_html" />
<column name="is_regexp" var="is_regexp" />
<column name="description" var="description" />
<column name="regdate" var="regdate" default="curdate()" />
<column name="hit" var="0" />
</columns>
</query>

View file

@ -2,6 +2,7 @@
<column name="ipaddress" type="varchar" size="60" 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="except_member" type="char" size="1" default="N" />
<column name="description" type="varchar" size="191" />
<column name="regdate" type="date" index="idx_regdate" />
</table>

View file

@ -2,5 +2,8 @@
<column name="word" type="varchar" size="100" 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="except_member" type="char" size="1" default="N" />
<column name="filter_html" type="char" size="1" default="N" />
<column name="is_regexp" type="char" size="1" default="N" />
<column name="regdate" type="date" index="idx_regdate" />
</table>

View file

@ -211,6 +211,15 @@ class spamfilterAdminController extends spamfilter
{
continue;
}
if (preg_match('/^(.+?)#(.+)$/', $word, $matches))
{
$word = trim($matches[1]);
$description = trim($matches[2]);
}
else
{
$description = null;
}
if (mb_strlen($word, 'UTF-8') < 2 || mb_strlen($word, 'UTF-8') > 180)
{
@ -219,6 +228,8 @@ class spamfilterAdminController extends spamfilter
$args = new stdClass;
$args->word = $word;
$args->description = $description;
$args->is_regexp = preg_match('#^/.+/$#', $word) ? 'Y' : 'N';
$output = executeQuery('spamfilter.insertDeniedWord', $args);
if (!$output->toBool())
{

View file

@ -77,8 +77,13 @@ class spamfilter extends ModuleObject
$oDB = DB::getInstance();
if(!$oDB->isColumnExists('spamfilter_denied_word', 'hit')) return true;
if(!$oDB->isColumnExists('spamfilter_denied_word', 'latest_hit')) return true;
if(!$oDB->isColumnExists('spamfilter_denied_word', 'except_member')) return true;
if(!$oDB->isColumnExists('spamfilter_denied_word', 'filter_html')) return true;
if(!$oDB->isColumnExists('spamfilter_denied_word', 'is_regexp')) return true;
if(!$oDB->isColumnExists('spamfilter_denied_word', 'description')) return true;
if(!$oDB->isColumnExists('spamfilter_denied_ip', 'hit')) return true;
if(!$oDB->isColumnExists('spamfilter_denied_ip', 'latest_hit')) return true;
if(!$oDB->isColumnExists('spamfilter_denied_ip', 'except_member')) return true;
if(!$oDB->isColumnExists('spamfilter_denied_ip', 'description')) return true;
$config = ModuleModel::getModuleConfig('spamfilter') ?: new stdClass;
@ -104,27 +109,48 @@ class spamfilter extends ModuleObject
$oDB = DB::getInstance();
if(!$oDB->isColumnExists('spamfilter_denied_word', 'hit'))
{
$oDB->addColumn('spamfilter_denied_word','hit','number',12,0,true);
$oDB->addColumn('spamfilter_denied_word', 'hit', 'number', null, 0, true, 'word');
$oDB->addIndex('spamfilter_denied_word','idx_hit', 'hit');
}
if(!$oDB->isColumnExists('spamfilter_denied_word', 'latest_hit'))
{
$oDB->addColumn('spamfilter_denied_word','latest_hit','date');
$oDB->addColumn('spamfilter_denied_word', 'latest_hit', 'date', null, null, false, 'hit');
$oDB->addIndex('spamfilter_denied_word','idx_latest_hit', 'latest_hit');
}
if(!$oDB->isColumnExists('spamfilter_denied_word', 'except_member'))
{
$oDB->addColumn('spamfilter_denied_word', 'except_member', 'char', 1, 'N', true, 'latest_hit');
}
if(!$oDB->isColumnExists('spamfilter_denied_word', 'filter_html'))
{
$oDB->addColumn('spamfilter_denied_word', 'filter_html', 'char', 1, 'N', true, 'except_member');
}
if(!$oDB->isColumnExists('spamfilter_denied_word', 'is_regexp'))
{
$oDB->addColumn('spamfilter_denied_word', 'is_regexp', 'char', 1, 'N', true, 'filter_html');
$oDB->query('UPDATE spamfilter_denied_word SET is_regexp = ? WHERE word LIKE ?', ['Y', '/%/']);
}
if(!$oDB->isColumnExists('spamfilter_denied_word', 'description'))
{
$oDB->addColumn('spamfilter_denied_word', 'description', 'varchar', 191, null, false, 'is_regexp');
}
if(!$oDB->isColumnExists('spamfilter_denied_ip', 'hit'))
{
$oDB->addColumn('spamfilter_denied_ip','hit','number',12,0,true);
$oDB->addColumn('spamfilter_denied_ip', 'hit', 'number', null, 0, true, 'ipaddress');
$oDB->addIndex('spamfilter_denied_ip','idx_hit', 'hit');
}
if(!$oDB->isColumnExists('spamfilter_denied_ip', 'latest_hit'))
{
$oDB->addColumn('spamfilter_denied_ip','latest_hit','date');
$oDB->addColumn('spamfilter_denied_ip', 'latest_hit', 'date', null, null, false, 'hit');
$oDB->addIndex('spamfilter_denied_ip','idx_latest_hit', 'latest_hit');
}
if(!$oDB->isColumnExists('spamfilter_denied_ip', 'except_member'))
{
$oDB->addColumn('spamfilter_denied_ip', 'except_member', 'char', 1, 'N', true, 'latest_hit');
}
if(!$oDB->isColumnExists('spamfilter_denied_ip', 'description'))
{
$oDB->addColumn('spamfilter_denied_ip','description','varchar', 250);
$oDB->addColumn('spamfilter_denied_ip', 'description', 'varchar', 191, null, false, 'except_member');
}
$config = ModuleModel::getModuleConfig('spamfilter') ?: new stdClass;

View file

@ -1,5 +1,10 @@
span.is_regexp {
display: inline-block;
margin-left: 4px;
color: red;
background: #888;
color: #fff;
font-size: 10px;
line-height: 12px;
padding: 2px 4px;
border-radius: 2px;
}

View file

@ -13,6 +13,7 @@
<tr>
<th scope="col">IP</th>
<th scope="col">{$lang->description}</th>
<th scope="col">{$lang->cmd_spamfilter_except_member}</th>
<th scope="col"><a href="{getUrl('sort_index', 'latest_hit')}">{$lang->latest_hit} <!--@if($sort_index === 'latest_hit')--><!--@endif--></a></th>
<th scope="col"><a href="{getUrl('sort_index', 'hit')}">{$lang->hit} <!--@if($sort_index === 'hit')--><!--@endif--></a></th>
<th scope="col"><a href="{getUrl('sort_index', 'regdate')}">{$lang->regdate} <!--@if($sort_index === 'regdate' || !$sort_index)--><!--@endif--></a></th>
@ -23,6 +24,7 @@
<tr loop="$ip_list => $ip_info">
<td>{$ip_info->ipaddress}</td>
<td>{$ip_info->description}</td>
<td>{$ip_info->except_member}</td>
<td><!--@if($ip_info->latest_hit)-->{zdate($ip_info->latest_hit,'Y-m-d H:i')}<!--@else-->-<!--@end--></td>
<td>{$ip_info->hit}</td>
<td>{zdate($ip_info->regdate,'Y-m-d')}</td>

View file

@ -12,6 +12,9 @@
<thead>
<tr>
<th scope="col">{$lang->word}</th>
<th scope="col">{$lang->description}</th>
<th scope="col">{$lang->cmd_spamfilter_except_member}</th>
<th scope="col">{$lang->cmd_spamfilter_filter_html}</th>
<th scope="col"><a href="{getUrl('sort_index', 'latest_hit')}">{$lang->latest_hit} <!--@if($sort_index === 'latest_hit')--><!--@endif--></a></th>
<th scope="col"><a href="{getUrl('sort_index', 'hit')}">{$lang->hit} <!--@if($sort_index === 'hit' || !$sort_index)--><!--@endif--></a></th>
<th scope="col"><a href="{getUrl('sort_index', 'regdate')}">{$lang->regdate} <!--@if($sort_index === 'regdate')--><!--@endif--></a></th>
@ -20,7 +23,10 @@
</thead>
<tbody>
<tr loop="$word_list => $word_info">
<td>{$word_info->word} <!--@if(preg_match('#^/.+/$#', $word_info->word))--><span class="is_regexp">[{$lang->msg_denied_word_is_regexp}]</span><!--@end--></td>
<td>{$word_info->word} <!--@if(preg_match('#^/.+/$#', $word_info->word))--><span class="is_regexp">{$lang->cmd_spamfilter_is_regexp}</span><!--@end--></td>
<td>{$word_info->description}</td>
<td>{$word_info->except_member}</td>
<td>{$word_info->filter_html}</td>
<td><!--@if($word_info->latest_hit)-->{zdate($word_info->latest_hit,'Y-m-d H:i')}<!--@else-->-<!--@end--></td>
<td>{$word_info->hit}</td>
<td>{zdate($word_info->regdate,'Y-m-d')}</td>