censor_bear 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/censor_bear/log.rb +1 -0
- data/app/views/censor_bear/logs/_log.html.haml +32 -0
- data/app/views/censor_bear/logs/index.html.haml +18 -0
- data/app/views/censor_bear/stop_words/_stop_word.html.haml +1 -1
- data/db/migrate/20211206092626_add_ip_to_censor_bear_logs.rb +6 -0
- data/lib/censor_bear/censor.rb +16 -9
- data/lib/censor_bear/version.rb +1 -1
- data/lib/censor_bear.rb +9 -5
- metadata +5 -3
- data/app/views/censor_bear/logs/index.html.erb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58ec10c9991ef9cd50eee20651e4e4433b09b4c455cfc1089e67da4eb835875a
|
4
|
+
data.tar.gz: a60d24c01590c3c89ff14f376db5ec67b82b494e73aa77bd1cef94df497f05c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e1e3ad9f9afdae97ad89fce16ed0f4faa252595c1219bc9270020c0f049e1a59360b2bcf37964f282c08494b71f1764c9e55f36c47fda95eb431a810fb5c768
|
7
|
+
data.tar.gz: 8f2d44931bbed7280c83548e11a6251dd65ed4f9e6fa84b93e560a81a571ebe966dad3cd5919797c636f4d606cd8c44050a7fdfdbfaae25f9a6811e606b9905f
|
@@ -0,0 +1,32 @@
|
|
1
|
+
%div{class: "flex flex-col"}
|
2
|
+
%div{class: "border rounded-md mb-2 p-2 flex flex-col space-y-1"}
|
3
|
+
%div{class: "flex justify-between"}
|
4
|
+
%div{class: ""}
|
5
|
+
- unless log.scenario.blank?
|
6
|
+
%span{class: "text-sm bg-blue-100 text-blue-600 py-1 px-2 rounded-lg"}= log.scenario.upcase
|
7
|
+
- unless log.stage.blank?
|
8
|
+
%span{class: "text-sm bg-pink-100 text-pink-600 py-1 px-2 rounded-lg"}= log.stage.upcase
|
9
|
+
- unless log.action.blank?
|
10
|
+
%span{class: "text-sm bg-yellow-100 text-yellow-600 py-1 px-2 rounded-lg"}= log.action.upcase
|
11
|
+
- unless log.user_id.blank?
|
12
|
+
%span{class: "text-sm bg-gray-100 text-gray-600 py-1 px-2 rounded-lg font-bold"}="##{log.user_id}"
|
13
|
+
- unless log.ip.blank?
|
14
|
+
%span{class: "text-sm bg-gray-100 text-gray-600 py-1 px-2 rounded-lg"}=log.ip
|
15
|
+
%span{class: "text-sm bg-gray-100 text-gray-600 py-1 px-2 rounded-lg"}= log.created_at
|
16
|
+
%div{class: "flex space-x-2 items-center"}
|
17
|
+
%span
|
18
|
+
= link_to '详情', log
|
19
|
+
%span
|
20
|
+
= button_to '删除', log, method: :delete, data: { confirm: 'Are you sure?', turbo: false }, class: "text-red-600 rounded-md px-2 py-0.5"
|
21
|
+
%div{class: "flex justify-between items-center"}
|
22
|
+
%div{class: "flex flex-col"}
|
23
|
+
%div
|
24
|
+
%div= log.original_content
|
25
|
+
- if log.filtered_content
|
26
|
+
%div{class: "border-t pb-2"}
|
27
|
+
%div= log.filtered_content
|
28
|
+
%div{class: "text-yellow-500 font-meidum text-xl"}
|
29
|
+
- log.mod_words.each do |word|
|
30
|
+
%span [
|
31
|
+
%span= link_to word, stop_words_path(q: word)
|
32
|
+
%span ]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
%div{class: "flex flex-col space-y-2 justify-center"}
|
2
|
+
%div{class: "flex justify-between"}
|
3
|
+
%div
|
4
|
+
= form_with(url: logs_path, method: :get, class: "flex items-center") do |f|
|
5
|
+
%div{class: "space-x-0.5"}
|
6
|
+
= f.text_field :q, value: params[:q], placeholder: "关键词", class: "border rounded-md m py-0.5 px-1"
|
7
|
+
= f.submit "检索", class: "rounded-md px-2 py-1 text-sm bg-black text-white cursor-pointer"
|
8
|
+
= link_to "重置", logs_path, class: "text-sm"
|
9
|
+
|
10
|
+
%div="共 #{@pagy.count} 条"
|
11
|
+
%div
|
12
|
+
- if @logs.blank?
|
13
|
+
%div{class: "flex justify-center text-gray-500 p-8 border rounded-md"} 空空如也
|
14
|
+
- else
|
15
|
+
- @logs.each do |log|
|
16
|
+
= render log
|
17
|
+
%div{class: "flex justify-center"}
|
18
|
+
= raw pagy_nav(@pagy)
|
@@ -24,7 +24,7 @@
|
|
24
24
|
%div{class: "text-center"}=I18n.t("censor_log.action.#{stop_word.dialog}")
|
25
25
|
%div{class: "text-gray-500 text-xs text-center"} 私信处理
|
26
26
|
%div{class: "flex flex-col justify-center border rounded-md p-1"}
|
27
|
-
%div{class: "text-center"}=stop_word.replacement
|
27
|
+
%div{class: "text-center"}=stop_word.replacement || "**"
|
28
28
|
%div{class: "text-gray-500 text-xs text-center"} 过滤词替换
|
29
29
|
%div{class: "flex justify-end space-x-2 text-sm text-blue-600"}
|
30
30
|
%span
|
data/lib/censor_bear/censor.rb
CHANGED
@@ -13,11 +13,14 @@ module CensorBear
|
|
13
13
|
QQ_REG = /(?:[加茄qQ企鹅号码\s]{1,}|[群号]{1,}|[叩叩]{1,}|[抠抠]{1,}|[扣扣]{1,})(?:[\u4e00-\u9eff]*)(?:[:,:]?)([\d\s]{6,})/
|
14
14
|
WX_REG = /(?:[加+微++➕薇?vV威卫星♥❤姓xX信]{2,}|weixin|weix)(?:[,❤️.\s]?)(?:[\u4e00-\u9eff]?)(?:[:,:]?)([\w\s]{6,})/
|
15
15
|
|
16
|
-
def initialize(content, type = 'ugc')
|
16
|
+
def initialize(content, type = 'ugc', options = {})
|
17
17
|
@is_mod = false
|
18
18
|
@mod_words = []
|
19
19
|
@content = content
|
20
20
|
@type = type.to_s
|
21
|
+
@options = options
|
22
|
+
@ip = options[:ip] || nil
|
23
|
+
@user_id = options[:user_id] || nil
|
21
24
|
end
|
22
25
|
|
23
26
|
def check_text
|
@@ -25,12 +28,12 @@ module CensorBear
|
|
25
28
|
return Result.new(@content) unless CensorBear::StopWord::FIELDS.include?(@type)
|
26
29
|
|
27
30
|
if @content.match(QQ_REG)
|
28
|
-
CensorBear.info(@content, @type, 'BANNED', 'qq_regex')
|
31
|
+
CensorBear.info(@content, @type, 'BANNED', 'qq_regex', ip: @ip, user_id: @user_id)
|
29
32
|
raise NotPassedException
|
30
33
|
end
|
31
34
|
|
32
35
|
if @content.match(WX_REG)
|
33
|
-
CensorBear.info(@content, @type, 'BANNED', 'wx_regex')
|
36
|
+
CensorBear.info(@content, @type, 'BANNED', 'wx_regex', ip: @ip, user_id: @user_id)
|
34
37
|
raise NotPassedException
|
35
38
|
end
|
36
39
|
|
@@ -43,7 +46,7 @@ module CensorBear
|
|
43
46
|
end
|
44
47
|
|
45
48
|
# default type = :ugc
|
46
|
-
def check_search
|
49
|
+
def check_search(user = nil, ip = nil)
|
47
50
|
result = false
|
48
51
|
stop_words = CensorBear::StopWord.where("#{@type} != 'IGNORE'")
|
49
52
|
stop_words.each do |word|
|
@@ -51,7 +54,7 @@ module CensorBear
|
|
51
54
|
action = word.send(@type.to_sym).upcase
|
52
55
|
if finder.match(@content)
|
53
56
|
result = true
|
54
|
-
CensorBear.info(@content, @type, action, 'check_search', mod_words: [word.key])
|
57
|
+
CensorBear.info(@content, @type, action, 'check_search', mod_words: [word.key], ip: @ip, user_id: @user_id)
|
55
58
|
break
|
56
59
|
end
|
57
60
|
end
|
@@ -68,18 +71,21 @@ module CensorBear
|
|
68
71
|
@mod_words.push(word.key)
|
69
72
|
case action
|
70
73
|
when 'REPLACE'
|
71
|
-
|
74
|
+
replacement = word.replacement.blank? ? "**" : word.replacement
|
75
|
+
@content = @content.gsub(finder, replacement)
|
72
76
|
CensorBear.info(
|
73
77
|
original_content, @type, action, 'local_check',
|
74
78
|
filtered_content: @content,
|
75
|
-
mod_words: [word.key]
|
79
|
+
mod_words: [word.key],
|
80
|
+
ip: @ip, user_id: @user_id
|
76
81
|
)
|
77
82
|
when 'MOD'
|
78
83
|
@is_mod = true
|
79
84
|
CensorBear.info(
|
80
85
|
original_content, @type, action, 'local_check',
|
81
86
|
filtered_content: nil,
|
82
|
-
mod_words: [word.key]
|
87
|
+
mod_words: [word.key],
|
88
|
+
ip: @ip, user_id: @user_id
|
83
89
|
)
|
84
90
|
when 'BANNED'
|
85
91
|
@is_mod = true
|
@@ -87,7 +93,8 @@ module CensorBear
|
|
87
93
|
CensorBear.info(
|
88
94
|
original_content, @type, action, 'local_check',
|
89
95
|
filtered_content: nil,
|
90
|
-
mod_words: [word.key]
|
96
|
+
mod_words: [word.key],
|
97
|
+
ip: @ip, user_id: @user_id
|
91
98
|
)
|
92
99
|
raise NotPassedException
|
93
100
|
end
|
data/lib/censor_bear/version.rb
CHANGED
data/lib/censor_bear.rb
CHANGED
@@ -27,17 +27,19 @@ module CensorBear
|
|
27
27
|
yield(config)
|
28
28
|
end
|
29
29
|
|
30
|
-
def check_text(content, type = 'ugc')
|
31
|
-
Censor.new(content, type).check_text
|
30
|
+
def check_text(content, type = 'ugc', options = {})
|
31
|
+
Censor.new(content, type, options).check_text
|
32
32
|
end
|
33
33
|
|
34
|
-
def check_search(content)
|
35
|
-
Censor.new(content, "ugc").check_search
|
34
|
+
def check_search(content, options = {})
|
35
|
+
Censor.new(content, "ugc", options).check_search
|
36
36
|
end
|
37
37
|
|
38
38
|
def info(content, scenario, action, stage, options = {})
|
39
39
|
filtered_content = options[:filtered_content] || nil
|
40
40
|
mod_words = options[:mod_words] || []
|
41
|
+
ip = options[:ip] || nil
|
42
|
+
user_id = options[:user_id] || nil
|
41
43
|
|
42
44
|
CensorBear::Log.create(
|
43
45
|
original_content: content,
|
@@ -45,7 +47,9 @@ module CensorBear
|
|
45
47
|
action: action,
|
46
48
|
stage: stage,
|
47
49
|
filtered_content: filtered_content,
|
48
|
-
mod_words: mod_words
|
50
|
+
mod_words: mod_words,
|
51
|
+
ip: ip,
|
52
|
+
user_id: user_id,
|
49
53
|
)
|
50
54
|
end
|
51
55
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: censor_bear
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 42up
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -118,8 +118,9 @@ files:
|
|
118
118
|
- app/models/censor_bear/mod_log.rb
|
119
119
|
- app/models/censor_bear/stop_word.rb
|
120
120
|
- app/views/censor_bear/logs/_form.html.erb
|
121
|
+
- app/views/censor_bear/logs/_log.html.haml
|
121
122
|
- app/views/censor_bear/logs/edit.html.erb
|
122
|
-
- app/views/censor_bear/logs/index.html.
|
123
|
+
- app/views/censor_bear/logs/index.html.haml
|
123
124
|
- app/views/censor_bear/logs/new.html.erb
|
124
125
|
- app/views/censor_bear/logs/show.html.erb
|
125
126
|
- app/views/censor_bear/mod_logs/_form.html.erb
|
@@ -142,6 +143,7 @@ files:
|
|
142
143
|
- db/migrate/20211126133758_create_censor_bear_stop_words.rb
|
143
144
|
- db/migrate/20211129093508_create_censor_bear_logs.rb
|
144
145
|
- db/migrate/20211129110218_create_censor_bear_mod_logs.rb
|
146
|
+
- db/migrate/20211206092626_add_ip_to_censor_bear_logs.rb
|
145
147
|
- lib/censor_bear.rb
|
146
148
|
- lib/censor_bear/censor.rb
|
147
149
|
- lib/censor_bear/configuration.rb
|
@@ -1,42 +0,0 @@
|
|
1
|
-
<p id="notice"><%= notice %></p>
|
2
|
-
|
3
|
-
<h1>Logs</h1>
|
4
|
-
|
5
|
-
<table>
|
6
|
-
<thead>
|
7
|
-
<tr>
|
8
|
-
<th>Orginal content</th>
|
9
|
-
<th>Action</th>
|
10
|
-
<th>Filtered content</th>
|
11
|
-
<th>Mod words</th>
|
12
|
-
<th colspan="3"></th>
|
13
|
-
</tr>
|
14
|
-
</thead>
|
15
|
-
|
16
|
-
<tbody>
|
17
|
-
<% @logs.each do |log| %>
|
18
|
-
<tr>
|
19
|
-
<td><%= log.original_content %></td>
|
20
|
-
<td><%= log.scenario %></td>
|
21
|
-
<td><%= log.stage %></td>
|
22
|
-
<td><%= log.action %></td>
|
23
|
-
<td><%= log.filtered_content %></td>
|
24
|
-
<td><%= log.mod_words %></td>
|
25
|
-
<td><%= link_to 'Show', log %></td>
|
26
|
-
<td><%= link_to 'Edit', edit_log_path(log) %></td>
|
27
|
-
<td><%= button_to 'Destroy', log, method: :delete, data: { confirm: 'Are you sure?', turbo: false } %></td>
|
28
|
-
</tr>
|
29
|
-
<% end %>
|
30
|
-
</tbody>
|
31
|
-
</table>
|
32
|
-
|
33
|
-
|
34
|
-
<br>
|
35
|
-
|
36
|
-
<%= raw pagy_nav(@pagy) %>
|
37
|
-
|
38
|
-
<br>
|
39
|
-
|
40
|
-
<%= link_to 'New Log', new_log_path %>
|
41
|
-
|
42
|
-
|