antispam 0.2.8 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/antispam/tools.rb +25 -21
- data/lib/antispam/version.rb +1 -1
- data/lib/antispam.rb +1 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: deb7098b89c7771c3a67061353ea1333960830b49a5181487ae0ffddb5aaab40
|
4
|
+
data.tar.gz: 7ada271f3c917b2869cb4a92fa7d5b70606d9c5020c4d4eb5e44934d25abcad9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3ef0076d08ed077460f8b98f90b38b4bcada5a6c50916a8fada274afea6c3786f04ce311471aace68a39dd732193c09cb15b2afa43ce5502ee577a5c3fe70e5
|
7
|
+
data.tar.gz: 41eda0779322117d6a2235b5ef8a5303e3ce6d7c9dcb66cecae9b2252d98b793364a9e6014f51858419a84a2f39896b44549462d1e8f91608248c35d2a88e29e
|
data/README.md
CHANGED
@@ -108,7 +108,7 @@ You need to add this to your routes.rb
|
|
108
108
|
Then add to your application controller:
|
109
109
|
```
|
110
110
|
before_action do
|
111
|
-
check_ip_against_database(
|
111
|
+
check_ip_against_database(ip_blacklists: {default: 'your_api_key_here'}, verbose: true)
|
112
112
|
end
|
113
113
|
```
|
114
114
|
|
data/lib/antispam/tools.rb
CHANGED
@@ -2,33 +2,37 @@ module Antispam
|
|
2
2
|
module Tools
|
3
3
|
# Checks spam against an IP database of spammers.
|
4
4
|
# Usage: before_action :check_ip_against_database
|
5
|
-
def check_ip_against_database(
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
def check_ip_against_database(
|
6
|
+
ip_blacklists: { default: '' },
|
7
|
+
methods: nil,
|
8
|
+
scrutinize_countries_except: nil,
|
9
|
+
verbose: false
|
10
|
+
)
|
11
|
+
if methods
|
12
|
+
return if request.get? && !methods.include?(:get)
|
13
|
+
return if request.post? && !methods.include?(:post)
|
14
|
+
return if request.put? && !methods.include?(:put)
|
15
|
+
return if request.patch? && !methods.include?(:patch)
|
16
|
+
return if request.delete? && !methods.include?(:delete)
|
12
17
|
else
|
13
18
|
return if request.get?
|
14
19
|
end
|
20
|
+
|
15
21
|
return if skip_if_user_whitelisted
|
16
|
-
return if controller_name.in?[
|
22
|
+
return if controller_name.in?(%w[validate challenges])
|
23
|
+
|
17
24
|
ip = request.remote_ip
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
check_ip_against_blacklists(ip, options[:ip_blacklists], options[:verbose])
|
25
|
-
end
|
26
|
-
# Second, check for weird countries.
|
27
|
-
if (options[:scrutinize_countries_except])
|
28
|
-
|
25
|
+
|
26
|
+
# Handle IP blacklists
|
27
|
+
if ip_blacklists
|
28
|
+
ip_blacklists[:httpbl] ||= ip_blacklists.delete(:default)
|
29
|
+
check_ip_against_blacklists(ip, ip_blacklists, verbose)
|
29
30
|
end
|
30
|
-
|
31
|
-
|
31
|
+
|
32
|
+
# Country checks, if necessary
|
33
|
+
# (expand logic as needed)
|
34
|
+
Rails.logger.info "Completed IP database check. #{ip}" if verbose
|
35
|
+
end
|
32
36
|
# Checks the specific blacklists
|
33
37
|
def check_ip_against_blacklists(ip, lists, verbose)
|
34
38
|
results = []
|
data/lib/antispam/version.rb
CHANGED
data/lib/antispam.rb
CHANGED
@@ -8,14 +8,6 @@ require "antispam/results"
|
|
8
8
|
|
9
9
|
module Antispam
|
10
10
|
ActiveSupport.on_load(:action_controller_base) do
|
11
|
-
|
12
|
-
# Use ::ApplicationController to reference the top-level class
|
13
|
-
if defined?(::ApplicationController)
|
14
|
-
::ApplicationController.include Antispam::Tools
|
15
|
-
else
|
16
|
-
Rails.application.config.to_prepare do
|
17
|
-
::ApplicationController.include Antispam::Tools
|
18
|
-
end
|
19
|
-
end
|
11
|
+
ActionController::Base.include Antispam::Tools
|
20
12
|
end
|
21
13
|
end
|