From 539b54850978b6e8b550fbae9e50da8dcdfba22b Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Mon, 19 Dec 2022 02:18:53 +0900 Subject: [PATCH] Fix #1882 add toggle to change if spamfilter rule applies to member --- modules/spamfilter/conf/module.xml | 2 + .../queries/updateDeniedIPAttributes.xml | 11 ++ .../queries/updateDeniedWordAttributes.xml | 12 ++ .../spamfilter.admin.controller.php | 109 ++++++++++++++---- modules/spamfilter/tpl/denied_ip_list.html | 2 +- modules/spamfilter/tpl/denied_word_list.html | 4 +- modules/spamfilter/tpl/js/spamfilter_admin.js | 42 +++++++ 7 files changed, 155 insertions(+), 27 deletions(-) create mode 100644 modules/spamfilter/queries/updateDeniedIPAttributes.xml create mode 100644 modules/spamfilter/queries/updateDeniedWordAttributes.xml diff --git a/modules/spamfilter/conf/module.xml b/modules/spamfilter/conf/module.xml index 1577ae051..a7071cb3c 100644 --- a/modules/spamfilter/conf/module.xml +++ b/modules/spamfilter/conf/module.xml @@ -8,8 +8,10 @@ + + diff --git a/modules/spamfilter/queries/updateDeniedIPAttributes.xml b/modules/spamfilter/queries/updateDeniedIPAttributes.xml new file mode 100644 index 000000000..32076f11a --- /dev/null +++ b/modules/spamfilter/queries/updateDeniedIPAttributes.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/modules/spamfilter/queries/updateDeniedWordAttributes.xml b/modules/spamfilter/queries/updateDeniedWordAttributes.xml new file mode 100644 index 000000000..b3ffcf137 --- /dev/null +++ b/modules/spamfilter/queries/updateDeniedWordAttributes.xml @@ -0,0 +1,12 @@ + + +
+ + + + + + + + + diff --git a/modules/spamfilter/spamfilter.admin.controller.php b/modules/spamfilter/spamfilter.admin.controller.php index 0a266f65b..ed5aa7d58 100644 --- a/modules/spamfilter/spamfilter.admin.controller.php +++ b/modules/spamfilter/spamfilter.admin.controller.php @@ -10,11 +10,11 @@ class spamfilterAdminController extends spamfilter /** * @brief Initialization */ - function init() + public function init() { } - function procSpamfilterAdminInsertConfig() + public function procSpamfilterAdminInsertConfig() { // Get current config $config = ModuleModel::getModuleConfig('spamfilter') ?: new stdClass; @@ -56,7 +56,7 @@ class spamfilterAdminController extends spamfilter $this->setRedirectUrl($returnUrl); } - function procSpamfilterAdminInsertConfigCaptcha() + public function procSpamfilterAdminInsertConfigCaptcha() { // Get current config $config = ModuleModel::getModuleConfig('spamfilter') ?: new stdClass; @@ -113,7 +113,7 @@ class spamfilterAdminController extends spamfilter $this->setRedirectUrl($returnUrl); } - function procSpamfilterAdminInsertDeniedIP() + public function procSpamfilterAdminInsertDeniedIP() { //스팸IP 추가 $ipaddress_list = Context::get('ipaddress_list'); @@ -130,8 +130,49 @@ class spamfilterAdminController extends spamfilter $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispSpamfilterAdminDeniedIPList'); $this->setRedirectUrl($returnUrl); } + + public function procSpamfilterAdminUpdateDeniedIP() + { + $ipaddress = Context::get('ipaddress'); + if (!$ipaddress) + { + throw new Rhymix\Framework\Exceptions\InvalidRequest; + } + + $args = new \stdClass; + $args->ipaddress = $ipaddress; + + $except_member = Context::get('except_member'); + if (!empty($except_member)) + { + $args->except_member = $except_member === 'Y' ? 'Y' : 'N'; + } + else + { + throw new Rhymix\Framework\Exceptions\InvalidRequest; + } + + $output = executeQuery('spamfilter.updateDeniedIPAttributes', $args); + if (!$output->toBool()) + { + return $output; + } + + Rhymix\Framework\Cache::delete('spamfilter:denied_ip_list'); + } - function procSpamfilterAdminInsertDeniedWord() + public function procSpamfilterAdminDeleteDeniedIP() + { + $ipAddressList = Context::get('ipaddress'); + if($ipAddressList) $this->deleteIP($ipAddressList); + + $this->setMessage(lang('success_deleted')); + + $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispSpamfilterAdminDeniedIPList'); + return $this->setRedirectUrl($returnUrl); + } + + public function procSpamfilterAdminInsertDeniedWord() { //스팸 키워드 추가 $word_list = Context::get('word_list'); @@ -148,24 +189,44 @@ class spamfilterAdminController extends spamfilter $this->setRedirectUrl($returnUrl); } - /** - * @brief Delete the banned IP - */ - function procSpamfilterAdminDeleteDeniedIP() + public function procSpamfilterAdminUpdateDeniedWord() { - $ipAddressList = Context::get('ipaddress'); - if($ipAddressList) $this->deleteIP($ipAddressList); - - $this->setMessage(lang('success_deleted')); - - $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispSpamfilterAdminDeniedIPList'); - return $this->setRedirectUrl($returnUrl); + $word = Context::get('word'); + if (!$word) + { + throw new Rhymix\Framework\Exceptions\InvalidRequest; + } + + $args = new \stdClass; + $args->word = $word; + + $except_member = Context::get('except_member'); + if (!empty($except_member)) + { + $args->except_member = $except_member === 'Y' ? 'Y' : 'N'; + } + + $filter_html = Context::get('filter_html'); + if (!empty($filter_html)) + { + $args->filter_html = $filter_html === 'Y' ? 'Y' : 'N'; + } + + if (!isset($args->except_member) && !isset($args->filter_html)) + { + throw new Rhymix\Framework\Exceptions\InvalidRequest; + } + + $output = executeQuery('spamfilter.updateDeniedWordAttributes', $args); + if (!$output->toBool()) + { + return $output; + } + + Rhymix\Framework\Cache::delete('spamfilter:denied_word_list'); } - - /** - * @brief Delete the prohibited Word - */ - function procSpamfilterAdminDeleteDeniedWord() + + public function procSpamfilterAdminDeleteDeniedWord() { $wordList = Context::get('word'); $this->deleteWord($wordList); @@ -180,7 +241,7 @@ class spamfilterAdminController extends spamfilter * @brief Delete IP * Remove the IP address which was previously registered as a spammers */ - function deleteIP($ipaddress) + public function deleteIP($ipaddress) { if(!$ipaddress) return; @@ -196,7 +257,7 @@ class spamfilterAdminController extends spamfilter * @brief Register the spam word * The post, which contains the newly registered spam word, should be considered as a spam */ - function insertWord($word_list) + public function insertWord($word_list) { if (!is_array($word_list)) { @@ -250,7 +311,7 @@ class spamfilterAdminController extends spamfilter * @brief Remove the spam word * Remove the word which was previously registered as a spam word */ - function deleteWord($word) + public function deleteWord($word) { if(!$word) return; $args = new stdClass; diff --git a/modules/spamfilter/tpl/denied_ip_list.html b/modules/spamfilter/tpl/denied_ip_list.html index 19608f879..de9bdac77 100644 --- a/modules/spamfilter/tpl/denied_ip_list.html +++ b/modules/spamfilter/tpl/denied_ip_list.html @@ -24,7 +24,7 @@ - + diff --git a/modules/spamfilter/tpl/denied_word_list.html b/modules/spamfilter/tpl/denied_word_list.html index 49133761a..e1f0b9904 100644 --- a/modules/spamfilter/tpl/denied_word_list.html +++ b/modules/spamfilter/tpl/denied_word_list.html @@ -25,8 +25,8 @@ - - + + diff --git a/modules/spamfilter/tpl/js/spamfilter_admin.js b/modules/spamfilter/tpl/js/spamfilter_admin.js index 7f56490f5..eba33db93 100644 --- a/modules/spamfilter/tpl/js/spamfilter_admin.js +++ b/modules/spamfilter/tpl/js/spamfilter_admin.js @@ -17,3 +17,45 @@ function doDeleteDeniedWord(word) { fo_obj.act.value = "procSpamfilterAdminDeleteDeniedWord"; fo_obj.submit(); } + +/** + * Toggle attributes. + */ +$(function() { + + $('.denied_ip_toggle_except_member').on('click', function(e) { + e.preventDefault(); + var that = $(this); + var new_value = that.text() === 'Y' ? 'N' : 'Y'; + exec_json('spamfilter.procSpamfilterAdminUpdateDeniedIP', { + ipaddress: that.data('ipaddress'), + except_member: new_value + }, function() { + that.text(new_value); + }); + }); + + $('.denied_word_toggle_except_member').on('click', function(e) { + e.preventDefault(); + var that = $(this); + var new_value = that.text() === 'Y' ? 'N' : 'Y'; + exec_json('spamfilter.procSpamfilterAdminUpdateDeniedWord', { + word: that.data('word'), + except_member: new_value + }, function() { + that.text(new_value); + }); + }); + + $('.denied_word_toggle_filter_html').on('click', function(e) { + e.preventDefault(); + var that = $(this); + var new_value = that.text() === 'Y' ? 'N' : 'Y'; + exec_json('spamfilter.procSpamfilterAdminUpdateDeniedWord', { + word: that.data('word'), + filter_html: new_value + }, function() { + that.text(new_value); + }); + }); +});
{$ip_info->ipaddress} {$ip_info->description}{$ip_info->except_member}{$ip_info->except_member} {zdate($ip_info->latest_hit,'Y-m-d H:i')}- {$ip_info->hit} {zdate($ip_info->regdate,'Y-m-d')}
{$word_info->word} {$lang->cmd_spamfilter_is_regexp} {$word_info->description}{$word_info->except_member}{$word_info->filter_html}{$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')}