From 020b85168cf80282d9bd30512187e67ce01c1733 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Mon, 19 Dec 2022 01:45:10 +0900 Subject: [PATCH] Add several columns to spamfilter IP & word tables for feature consistency and extensibility #1882 --- modules/spamfilter/lang/en.php | 8 +++-- modules/spamfilter/lang/ko.php | 8 +++-- modules/spamfilter/queries/insertDeniedIP.xml | 18 +++++----- .../spamfilter/queries/insertDeniedWord.xml | 20 ++++++----- .../schemas/spamfilter_denied_ip.xml | 1 + .../schemas/spamfilter_denied_word.xml | 3 ++ .../spamfilter.admin.controller.php | 11 ++++++ modules/spamfilter/spamfilter.class.php | 36 ++++++++++++++++--- .../spamfilter/tpl/css/spamfilter_admin.css | 9 +++-- modules/spamfilter/tpl/denied_ip_list.html | 2 ++ modules/spamfilter/tpl/denied_word_list.html | 8 ++++- 11 files changed, 94 insertions(+), 30 deletions(-) diff --git a/modules/spamfilter/lang/en.php b/modules/spamfilter/lang/en.php index a5b3234c6..feca70102 100644 --- a/modules/spamfilter/lang/en.php +++ b/modules/spamfilter/lang/en.php @@ -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.
%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.
Formats such as /spam(key|word)?/ will be treated as a regular expression, and must use the proper syntax.
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 #.
Formats such as /spam(key|word)?/ will be treated as a regular expression, and must use the proper syntax.
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'; diff --git a/modules/spamfilter/lang/ko.php b/modules/spamfilter/lang/ko.php index 5c9d8955d..28aebdd84 100644 --- a/modules/spamfilter/lang/ko.php +++ b/modules/spamfilter/lang/ko.php @@ -16,14 +16,16 @@ $lang->latest_hit = '최근 히트'; $lang->custom_message = '차단 메시지 설정'; $lang->about_custom_message = '스팸 키워드 발견시 표시할 에러 메시지를 지정할 수 있습니다.
%s를 넣으면 그 자리에 해당 키워드를 표시하고, 그렇지 않으면 키워드를 숨깁니다.'; $lang->about_interval = '지정된 시간 내에 글을 등록하지 못하게 합니다.'; -$lang->about_denied_ip = '한 줄에 하나씩 IP 주소 또는 대역을 입력하세요. "//" 또는 "#" 뒷부분은 설명으로 저장됩니다. 예: 127.0.0.1 //설명, 127.0.0.1 #설명
IP 대역 표기법은 매뉴얼을 참고하십시오.'; -$lang->about_denied_word = '한 줄에 하나씩 스팸 키워드를 입력하세요. (2~180자)
/스팸(키+|워드)?/ 와 같은 형태로 입력하면 정규식으로 간주하며, 올바른 정규식 문법을 사용해야 합니다.
대소문자는 구분하지 않습니다.'; -$lang->msg_denied_word_is_regexp = '정규식'; +$lang->about_denied_ip = '한 줄에 하나씩 IP 주소 또는 대역을 입력하세요. "//" 또는 "#" 뒷부분은 설명으로 저장됩니다.
예: 127.0.0.1 // 설명, 127.0.0.1 #설명
IP 대역 표기법은 매뉴얼을 참고하십시오.'; +$lang->about_denied_word = '한 줄에 하나씩 스팸 키워드(2~180자)를 입력하세요. "#" 뒷부분은 설명으로 입력됩니다.
/스팸(키+|워드)?/ 와 같은 형태로 입력하면 정규식으로 간주하며, 올바른 정규식 문법을 사용해야 합니다.
대소문자는 구분하지 않습니다.'; $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 = '트랙백 스팸 차단'; diff --git a/modules/spamfilter/queries/insertDeniedIP.xml b/modules/spamfilter/queries/insertDeniedIP.xml index 700844ae3..7e388a2f1 100644 --- a/modules/spamfilter/queries/insertDeniedIP.xml +++ b/modules/spamfilter/queries/insertDeniedIP.xml @@ -1,10 +1,12 @@ - - - - - - - - + +
+ + + + + + + + diff --git a/modules/spamfilter/queries/insertDeniedWord.xml b/modules/spamfilter/queries/insertDeniedWord.xml index acebcc0b6..4370a464d 100644 --- a/modules/spamfilter/queries/insertDeniedWord.xml +++ b/modules/spamfilter/queries/insertDeniedWord.xml @@ -1,10 +1,14 @@ - -
- - - - - - + +
+ + + + + + + + + + diff --git a/modules/spamfilter/schemas/spamfilter_denied_ip.xml b/modules/spamfilter/schemas/spamfilter_denied_ip.xml index 8235ed25b..0d364a679 100644 --- a/modules/spamfilter/schemas/spamfilter_denied_ip.xml +++ b/modules/spamfilter/schemas/spamfilter_denied_ip.xml @@ -2,6 +2,7 @@ +
diff --git a/modules/spamfilter/schemas/spamfilter_denied_word.xml b/modules/spamfilter/schemas/spamfilter_denied_word.xml index 80ae26195..546d90de5 100644 --- a/modules/spamfilter/schemas/spamfilter_denied_word.xml +++ b/modules/spamfilter/schemas/spamfilter_denied_word.xml @@ -2,5 +2,8 @@ + + + diff --git a/modules/spamfilter/spamfilter.admin.controller.php b/modules/spamfilter/spamfilter.admin.controller.php index 7693e4315..0a266f65b 100644 --- a/modules/spamfilter/spamfilter.admin.controller.php +++ b/modules/spamfilter/spamfilter.admin.controller.php @@ -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()) { diff --git a/modules/spamfilter/spamfilter.class.php b/modules/spamfilter/spamfilter.class.php index e3dc3b600..07599840b 100644 --- a/modules/spamfilter/spamfilter.class.php +++ b/modules/spamfilter/spamfilter.class.php @@ -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; diff --git a/modules/spamfilter/tpl/css/spamfilter_admin.css b/modules/spamfilter/tpl/css/spamfilter_admin.css index 74c6fef0b..9b9723405 100644 --- a/modules/spamfilter/tpl/css/spamfilter_admin.css +++ b/modules/spamfilter/tpl/css/spamfilter_admin.css @@ -1,5 +1,10 @@ span.is_regexp { display: inline-block; margin-left: 4px; - color: red; -} \ No newline at end of file + background: #888; + color: #fff; + font-size: 10px; + line-height: 12px; + padding: 2px 4px; + border-radius: 2px; +} diff --git a/modules/spamfilter/tpl/denied_ip_list.html b/modules/spamfilter/tpl/denied_ip_list.html index 74fe4623d..19608f879 100644 --- a/modules/spamfilter/tpl/denied_ip_list.html +++ b/modules/spamfilter/tpl/denied_ip_list.html @@ -13,6 +13,7 @@ IP {$lang->description} + {$lang->cmd_spamfilter_except_member} {$lang->latest_hit} {$lang->hit} {$lang->regdate} @@ -23,6 +24,7 @@ {$ip_info->ipaddress} {$ip_info->description} + {$ip_info->except_member} {zdate($ip_info->latest_hit,'Y-m-d H:i')}- {$ip_info->hit} {zdate($ip_info->regdate,'Y-m-d')} diff --git a/modules/spamfilter/tpl/denied_word_list.html b/modules/spamfilter/tpl/denied_word_list.html index 27765870f..49133761a 100644 --- a/modules/spamfilter/tpl/denied_word_list.html +++ b/modules/spamfilter/tpl/denied_word_list.html @@ -12,6 +12,9 @@ {$lang->word} + {$lang->description} + {$lang->cmd_spamfilter_except_member} + {$lang->cmd_spamfilter_filter_html} {$lang->latest_hit} {$lang->hit} {$lang->regdate} @@ -20,7 +23,10 @@ - {$word_info->word} [{$lang->msg_denied_word_is_regexp}] + {$word_info->word} {$lang->cmd_spamfilter_is_regexp} + {$word_info->description} + {$word_info->except_member} + {$word_info->filter_html} {zdate($word_info->latest_hit,'Y-m-d H:i')}- {$word_info->hit} {zdate($word_info->regdate,'Y-m-d')}