Преглед изворни кода

fix #1090 支持评论黑名单管理

magicblack пре 1 година
родитељ
комит
2cd0cf0ca5

+ 52 - 0
application/admin/controller/Comment.php

@@ -115,5 +115,57 @@ class Comment extends Base
         return $this->error(lang('param_err'));
     }
 
+    /**
+     * 黑名单关键字配置
+     */
+    public function blacklist()
+    {
+        if ($this->request->isPost()) {
+            $keywords = $this->request->post('keywords');
+            // 按行分割关键字
+            $keywords_array = array_filter(explode("\n", $keywords));
+            // 过滤空行
+            $keywords_array = array_map('trim', $keywords_array);
+            $blcaks = config('blacks');
+            $blcaks['black_keyword_list'] = $keywords_array;
+            $res = mac_arr2file( APP_PATH .'extra/blacks.php', $blcaks);
+            if($res===false){
+                return $this->error(lang('write_err_config'));
+            }
+            return $this->success(lang('save_ok'));
+        }
+        $blcaks = config('blacks');
+        $black_keyword_list = implode("\n", $blcaks['black_keyword_list']);
+        $this->assign('black_keyword_list', $black_keyword_list);
+        return $this->fetch('admin@comment/blacklist');
+    }
+    /**
+     * 黑名单IP配置
+     */
+    public function blacklist_ip()
+    {
+        if ($this->request->isPost()) {
+            $keywords = $this->request->post('ip');
+            // 按行分割关键字
+            $keywords_array = array_filter(explode("\n", $keywords));
+            // 过滤空行
+            $keywords_array = array_map('trim', $keywords_array);
+            //使用mac_string_is_ip方法过滤掉非ip的内容
+            $keywords_array = array_filter($keywords_array, function ($value) {
+                return mac_string_is_ip($value);
+            });
+            $blcaks = config('blacks');
+            $blcaks['black_ip_list'] = $keywords_array;
+            $res = mac_arr2file( APP_PATH .'extra/blacks.php', $blcaks);
+            if($res===false){
+                return $this->error(lang('write_err_config'));
+            }
+            return $this->success(lang('save_ok'));
+        }
+        $blcaks = config('blacks');
+        $black_keyword_list = implode("\n", $blcaks['black_ip_list']);
+        $this->assign('black_ip_list', $black_keyword_list);
+        return $this->fetch('admin@comment/blacklist_ip');
+    }
 
 }

+ 26 - 0
application/admin/view/comment/blacklist.html

@@ -0,0 +1,26 @@
+{include file="../../../application/admin/view/public/head" /}
+<div class="page-container p10">
+
+
+  <form class="layui-form layui-form-pane" method="post" action="{:url('comment/blacklist')}">
+    <div class="layui-form-item">
+      <label class="layui-form-label">{:lang('blacklist_keywords')}</label>
+      <div class="layui-input-block">
+        <textarea style="height: 500px" name="keywords" placeholder="{:lang('index/blacklist_placeholder')}" class="layui-textarea" >{$black_keyword_list}</textarea>
+      </div>
+    </div>
+    <div class="layui-form-item center">
+      <div class="layui-input-block">
+        <button type="submit" class="layui-btn" lay-submit>{:lang('save')}</button>
+        <button type="reset" class="layui-btn layui-btn-primary">{:lang('btn_reset')}</button>
+      </div>
+    </div>
+  </form>
+</div>
+
+
+{include file="../../../application/admin/view/public/foot" /}
+
+
+</body>
+</html>

+ 26 - 0
application/admin/view/comment/blacklist_ip.html

@@ -0,0 +1,26 @@
+{include file="../../../application/admin/view/public/head" /}
+<div class="page-container p10">
+
+
+  <form class="layui-form layui-form-pane" method="post" action="{:url('comment/blacklist_ip')}">
+    <div class="layui-form-item">
+      <label class="layui-form-label">{:lang('blacklist_ip')}</label>
+      <div class="layui-input-block">
+        <textarea style="height: 500px" name="ip" placeholder="{:lang('index/blacklist_placeholder_ip')}" class="layui-textarea" >{$black_ip_list}</textarea>
+      </div>
+    </div>
+    <div class="layui-form-item center">
+      <div class="layui-input-block">
+        <button type="submit" class="layui-btn" lay-submit>{:lang('save')}</button>
+        <button type="reset" class="layui-btn layui-btn-primary">{:lang('btn_reset')}</button>
+      </div>
+    </div>
+  </form>
+</div>
+
+
+{include file="../../../application/admin/view/public/foot" /}
+
+
+</body>
+</html>

+ 3 - 0
application/admin/view/comment/index.html

@@ -41,6 +41,9 @@
             <a data-href="{:url('del')}" class="layui-btn layui-btn-primary j-page-btns confirm"><i class="layui-icon">&#xe640;</i>{:lang('del')}</a>
             <a data-href="{:url('index/select')}?tab=comment&col=comment_status&tpl=select_status&url=comment/field" data-width="470" data-height="100" data-checkbox="1" class="layui-btn layui-btn-primary j-select"><i class="layui-icon">&#xe620;</i>{:lang('status')}</a>
             <a data-href="{:url('del')}?all=1" class="layui-btn layui-btn-primary j-ajax" confirm="{:lang('clear_confirm')}"><i class="layui-icon">&#xe640;</i>{:lang('clear')}</a>
+
+            <a  data-href="{:url('comment/blacklist')}" class="layui-btn layui-btn-primary j-iframe"><i class="layui-icon">&#xe63c;</i>{:lang('blacklist_keywords')}</a>
+            <a  data-href="{:url('comment/blacklist_ip')}" class="layui-btn layui-btn-primary j-iframe"><i class="layui-icon">&#xe63c;</i>{:lang('blacklist_ip')}</a>
         </div>
     </div>
 

+ 11 - 0
application/extra/blacks.php

@@ -0,0 +1,11 @@
+<?php
+return array (
+    'black_keyword_list' =>
+        array (
+
+        ),
+    'black_ip_list' =>
+        array (
+
+        ),
+);

+ 17 - 1
application/index/controller/Comment.php

@@ -26,7 +26,7 @@ class Comment extends Base
 
         return $this->label_fetch('comment/index');
     }
-    
+
     public function ajax() {
         $param = mac_param_url();
         $this->assign('param',$param);
@@ -90,6 +90,22 @@ class Comment extends Base
         }
 
         $param['comment_ip'] = mac_get_ip_long();
+        $blcaks = config('blacks');
+        //判断黑名单关键字是否为空 不为空并且大于0则循环判断是否包含黑名单关键字
+        if(!empty($blcaks['black_keyword_list']) && count($blcaks['black_keyword_list']) > 0){
+            foreach ($blcaks['black_keyword_list'] as $key => $value) {
+                if(strpos($param['comment_content'], $value) !== false){
+                    return ['code'=>1007,'msg'=>lang('index/blacklist_keyword')];
+                }
+            }
+        }
+        //判断黑名单IP是否为空 不为空并且大于0则循环判断客户端ip是否包含黑名单ip
+        if(!empty($blcaks['black_ip_list']) && count($blcaks['black_ip_list']) > 0){
+            $client_ip = long2ip($param['comment_ip']);
+            if (in_array($client_ip, $blcaks['black_ip_list'])){
+                return ['code'=>1008,'msg'=>lang('index/blacklist_ip')];
+            }
+        }
 
         $res = model('Comment')->saveData($param);
         if($res['code']>1){

+ 6 - 0
application/lang/de-de.php

@@ -372,6 +372,8 @@ return [
     'pass'=>'passwort',
     'clear_confirm'=>'Bestätigen, um Daten zu löschen? ',
     'audit_confirm'=>'Prüfungsdaten bestätigen? ',
+    'blacklist_keywords' => 'Schlüsselwörter der schwarzen Liste',
+    'blacklist_ip' => 'Blacklist-IP',
 
 
     'clear'=>'clear',
@@ -722,6 +724,10 @@ https://www.baidu.com/123.jpg',
     'index/mid_err'=>'Modell mittlerer Fehler',
     'index/thanks_msg_audit'=>'Vielen Dank, wir werden Ihre Nachricht so schnell wie möglich prüfen! ',
     'index/thanks_msg'=>'Vielen Dank für Ihre Nachricht! ',
+    'index/blacklist_keyword'=>'Ihr Kommentar enthält sensible Wörter, bitte überarbeiten Sie ihn, bevor Sie ihn erneut senden!',
+    'index/blacklist_ip'=>'Kommentare sind nicht erlaubt!',
+    'index/blacklist_placeholder'=>'Bitte geben Sie die Blacklist-Schlüsselwörter ein, jedes Schlüsselwort in einer eigenen Zeile',
+    'index/blacklist_placeholder_ip'=>'Bitte geben Sie die Blacklist-IPs ein, jede IP in einer eigenen Zeile. Einträge, die kein IP-Format haben, werden nach dem Senden gefiltert.',
     'index/zahlung_status'=>'Diese Zahlungsoption ist nicht aktiviert! ',
     'index/zahlung_not'=>'Keine Zahlungsoption gefunden! ',
     'index/zahlung_ok'=>'Zahlung abgeschlossen! ',

+ 6 - 0
application/lang/en-us.php

@@ -372,6 +372,8 @@ return [
     'pass'=>'Password',
     'clear_confirm'=>'Confirm to clear data?',
     'audit_confirm'=>'Confirm to audit data?',
+    'blacklist_keywords' => 'Blacklist keywords',
+    'blacklist_ip' => 'Blacklist IP',
 
     'clear'=>'Clear',
     'del_auto_keep_min'=>'One-click Delete Duplicates [Keep Small ID]',
@@ -722,6 +724,10 @@ https://www.baidu.com/123.jpg',
     'index/mid_err'=>'Model mid error',
     'index/thanks_msg_audit'=>'Thank you, your message will be reviewed soon!',
     'index/thanks_msg'=>'Thank you for your message!',
+    'index/blacklist_keyword'=>'Your comment contains sensitive words, please modify it and resubmit!',
+    'index/blacklist_ip'=>'Comments are not allowed!',
+    'index/blacklist_placeholder'=>'Please enter the blacklist keywords, one keyword per line',
+    'index/blacklist_placeholder_ip'=>'Please enter the blacklist IPs, one IP per line. Submissions not in IP format will be filtered out after submission.',
     'index/payment_status'=>'This payment option is not enabled!',
     'index/payment_not'=>'Payment option not found!',
     'index/payment_ok'=>'Payment completed!',

+ 6 - 0
application/lang/es-es.php

@@ -372,6 +372,8 @@ return [
     'pass'=>'Contraseña',
     'clear_confirm'=>'¿Estás seguro de que quieres borrar los datos?',
     'audit_confirm'=>'¿Estás seguro de que quieres auditar los datos?',
+    'blacklist_keywords' => 'Palabras clave de la lista negra',
+    'blacklist_ip' => 'IP en lista negra',
 
     'clear'=>'Borrar',
     'del_auto_keep_min'=>'Eliminar automáticamente [Mantener ID pequeño]',
@@ -719,6 +721,10 @@ https://www.baidu.com/123.jpg
     'index/mid_err'=>'Error de modelo de ID',
     'index/thanks_msg_audit'=>'Gracias, revisaremos tu comentario lo antes posible.',
     'index/thanks_msg'=>'¡Gracias por tu comentario!',
+    'index/blacklist_keyword'=>'¡Tu comentario contiene palabras sensibles, por favor modifícalo antes de enviarlo de nuevo!',
+    'index/blacklist_ip'=>'Comentarios no permitidos!',
+    'index/blacklist_placeholder'=>'Por favor, ingrese las palabras clave de la lista negra, una por línea',
+    'index/blacklist_placeholder_ip'=>'Por favor, ingrese las IPs de la lista negra, una IP por línea. Las entradas que no estén en formato de IP serán filtradas después de enviar.',
     'index/payment_status'=>'¡Esta opción de pago no está habilitada!',
     'index/payment_not'=>'¡No se encontraron opciones de pago!',
     'index/payment_ok'=>'¡Pago completado!',

+ 6 - 0
application/lang/fr-fr.php

@@ -374,6 +374,8 @@ return [
     'pass' => 'Mot de passe',
     'clear_confirm' => 'Confirmez-vous la suppression des données ?',
     'audit_confirm' => 'Confirmez-vous l\'audit des données ?',
+    'blacklist_keywords' => 'Mots-clés de liste noire',
+    'blacklist_ip' => 'IP liste noire',
 
     'clear' => 'Effacer',
     'del_auto_keep_min' => 'Suppression automatique [conserver les petits ID]',
@@ -723,6 +725,10 @@ https://www.baidu.com/123.jpg',
     'index/mid_err' => 'Erreur de modèle mid',
     'index/thanks_msg_audit' => 'Merci, nous examinerons votre message dès que possible !',
     'index/thanks_msg' => 'Merci pour votre message !',
+    'index/blacklist_keyword'=>'Votre commentaire contient des mots sensibles, veuillez le modifier avant de le soumettre à nouveau!',
+    'index/blacklist_ip'=>'Commentaires interdits!',
+    'index/blacklist_placeholder'=>'Veuillez entrer les mots-clés de la liste noire, un mot-clé par ligne',
+    'index/blacklist_placeholder_ip'=>'Veuillez entrer les IP de la liste noire, une IP par ligne. Les soumissions qui ne sont pas au format IP seront filtrées après l\envoi.',
     'index/payment_status' => 'Cette option de paiement n\'est pas activée !',
     'index/payment_not' => 'Option de paiement introuvable !',
     'index/payment_ok' => 'Paiement terminé !',

+ 6 - 0
application/lang/ja-jp.php

@@ -371,6 +371,8 @@ return [
     'pass'=>'パスワード',
     'clear_confirm'=>'本当にデータをクリアしますか?',
     'audit_confirm'=>'本当にデータを確認しますか?',
+    'blacklist_keywords' => 'ブラックリストキーワード',
+    'blacklist_ip' => 'ブラックリストIP',
 
     'clear'=>'クリア',
     'del_auto_keep_min'=>'重複を削除[小IDを保持]',
@@ -721,6 +723,10 @@ https://www.baidu.com/123.jpg
     'index/mid_err'=>'モデルmidエラー',
     'index/thanks_msg_audit'=>'ありがとうございます。できるだけ早くメッセージを確認します!',
     'index/thanks_msg'=>'メッセージありがとうございます!',
+    'index/blacklist_keyword'=>'あなたのコメントにセンシティブワードが含まれています。修正してから再度提出してください!',
+    'index/blacklist_ip'=>'コメントは禁止されています!',
+    'index/blacklist_placeholder'=>'ブラックリストのキーワードを入力してください。各キーワードは1行ずつ',
+    'index/blacklist_placeholder_ip'=>'ブラックリストのIPを入力してください。各IPは1行ずつ。IP形式でない提出は、送信後にフィルタリングされます.',
     'index/payment_status'=>'この支払いオプションは有効になっていません!',
     'index/payment_not'=>'支払いオプションが見つかりません!',
     'index/payment_ok'=>'支払いが完了しました!',

+ 6 - 0
application/lang/ko-kr.php

@@ -371,6 +371,8 @@ return [
     'pass'=>'비밀번호',
     'clear_confirm'=>'데이터를 지우시겠습니까?',
     'audit_confirm'=>'데이터를 심사하시겠습니까?',
+    'blacklist_keywords' => '블랙리스트 키워드',
+    'blacklist_ip' => '블랙리스트 IP',
 
     'clear'=>'지우기',
     'del_auto_keep_min'=>'중복 삭제[작은 ID 유지]',
@@ -721,6 +723,10 @@ https://www.baidu.com/123.jpg
     'index/mid_err'=>'모델 MID 오류',
     'index/thanks_msg_audit'=>'감사합니다. 메시지를 최대한 빨리 검토하겠습니다!',
     'index/thanks_msg'=>'메시지 감사합니다!',
+    'index/blacklist_keyword'=>'당신의 댓글에 민감한 단어가 포함되어 있습니다. 수정 후 다시 제출해 주세요!',
+    'index/blacklist_ip'=>'댓글 금지!',
+    'index/blacklist_placeholder'=>'블랙리스트 키워드를 입력해주세요. 각 키워드는 한 줄에 하나씩',
+    'index/blacklist_placeholder_ip'=>'블랙리스트 IP를 입력해주세요. 각 IP는 한 줄에 하나씩. IP 형식이 아닌 제출은 제출 후 필터링됩니다.',
     'index/payment_status'=>'이 결제 옵션이 활성화되지 않았습니다!',
     'index/payment_not'=>'결제 옵션을 찾을 수 없습니다!',
     'index/payment_ok'=>'결제 완료!',

+ 6 - 0
application/lang/pt-pt.php

@@ -371,6 +371,8 @@ return [
     'pass'=>'Senha',
     'clear_confirm'=>'Tem certeza de que deseja limpar os dados?',
     'audit_confirm'=>'Tem certeza de que deseja auditar os dados?',
+    'blacklist_keywords' => 'Palavras-chave da lista negra',
+    'blacklist_ip' => 'IP em lista negra',
 
     'clear'=>'Limpar',
     'del_auto_keep_min'=>'Excluir duplicatas [manter ID pequeno]',
@@ -721,6 +723,10 @@ https://www.baidu.com/123.jpg
     'index/mid_err'=>'Erro de mid do modelo',
     'index/thanks_msg_audit'=>'Obrigado, revisaremos sua mensagem o mais rápido possível!',
     'index/thanks_msg'=>'Obrigado pela sua mensagem!',
+    'index/blacklist_keyword'=>'Seu comentário contém palavras sensíveis, por favor, modifique-o e envie novamente!',
+    'index/blacklist_ip'=>'Comentários não são permitidos!',
+    'index/blacklist_placeholder'=>'Por favor, insira as palavras-chave da lista negra, uma palavra-chave por linha',
+    'index/blacklist_placeholder_ip'=>'Por favor, insira os IPs da lista negra, um IP por linha. As submissões que não estejam em formato de IP serão filtradas após a submissão.',
     'index/payment_status'=>'Esta opção de pagamento não está ativada!',
     'index/payment_not'=>'Opção de pagamento não encontrada!',
     'index/payment_ok'=>'Pagamento concluído!',

+ 6 - 0
application/lang/zh-cn.php

@@ -371,6 +371,8 @@ return [
     'pass'=>'密码',
     'clear_confirm'=>'确认清空数据吗?',
     'audit_confirm'=>'确认审核数据吗?',
+    'blacklist_keywords' => '黑名单关键字',
+    'blacklist_ip' => '黑名单IP',
 
     'clear'=>'清空',
     'del_auto_keep_min'=>'一键删重[保留小ID]',
@@ -721,6 +723,10 @@ https://www.baidu.com/123.jpg
     'index/mid_err'=>'模型mid错误',
     'index/thanks_msg_audit'=>'谢谢,我们会尽快审核你的留言!',
     'index/thanks_msg'=>'感谢你的留言!',
+    'index/blacklist_keyword'=>'您的评论有敏感词请修改后再提交!',
+    'index/blacklist_ip'=>'禁止评论!',
+    'index/blacklist_placeholder'=>'请输入黑名单关键字,每个关键字占一行',
+    'index/blacklist_placeholder_ip'=>'请输入黑名单IP,每个IP占一行,非IP格式提交后将会被过滤',
     'index/payment_status'=>'该支付选项未开启!',
     'index/payment_not'=>'未找到支付选项!',
     'index/payment_ok'=>'支付完成!',

+ 6 - 0
application/lang/zh-tw.php

@@ -371,6 +371,8 @@ return [
     'pass'=>'密碼',
     'clear_confirm'=>'確認清空數據嗎?',
     'audit_confirm'=>'確認審核數據嗎?',
+    'blacklist_keywords' => '黑名單關鍵字',
+    'blacklist_ip' => '黑名單IP',
 
     'clear'=>'清空',
     'del_auto_keep_min'=>'一鍵刪重[保留小ID]',
@@ -721,6 +723,10 @@ https://www.baidu.com/123.jpg
     'index/mid_err'=>'模型mid錯誤',
     'index/thanks_msg_audit'=>'謝謝,我們會盡快審核你的留言!',
     'index/thanks_msg'=>'感謝你的留言!',
+    'index/blacklist_keyword'=>'您的評論有敏感詞請修改後再提交!',
+    'index/blacklist_ip'=>'禁止評論!',
+    'index/blacklist_placeholder'=>'請輸入黑名單關鍵字,每個關鍵字佔一行',
+    'index/blacklist_placeholder_ip'=>'請輸入黑名單IP,每個IP佔一行,非IP格式提交後將會被過濾',
     'index/payment_status'=>'該支付選項未開啟!',
     'index/payment_not'=>'未找到支付選項!',
     'index/payment_ok'=>'支付完成!',