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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a68d75de5897063bea19649fbf62e3e75c56196412003615d22c1bf6d465150e
4
- data.tar.gz: 5e731f9168becf1eb99e28bcd29b2b2b5d72cd251f6e08bcd2efccecdeb0139b
3
+ metadata.gz: deb7098b89c7771c3a67061353ea1333960830b49a5181487ae0ffddb5aaab40
4
+ data.tar.gz: 7ada271f3c917b2869cb4a92fa7d5b70606d9c5020c4d4eb5e44934d25abcad9
5
5
  SHA512:
6
- metadata.gz: 6a1395289f3440fc68ff37f25bf33611a1d871bd70524d98e20d5ed1152939e94225eadfbf800ed28edadef06b7e14596cfd5ca7a6ec722a5532c81fb882e6f6
7
- data.tar.gz: 1d33c4449ef09163e9454a36db0e82df7b5723ad429b9fef17467181394f6a231d4cf654549e86385f5b1bc7d9aacfb69a9b394bea76fa6e0439b2ab5082d36e
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({ip_blacklists: {default: 'your_api_key_here'}, verbose: true})
111
+ check_ip_against_database(ip_blacklists: {default: 'your_api_key_here'}, verbose: true)
112
112
  end
113
113
  ```
114
114
 
@@ -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(options = {ip_blacklists: {default: ''}})
6
- if (options[:methods])
7
- return if request.get? unless options[:methods].include?(:get)
8
- return if request.post? unless options[:methods].include?(:post)
9
- return if request.put? unless options[:methods].include?(:put)
10
- return if request.patch? unless options[:methods].include?(:patch)
11
- return if request.delete? unless options[:methods].include?(:delete)
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?["validate","challenges"]
22
+ return if controller_name.in?(%w[validate challenges])
23
+
17
24
  ip = request.remote_ip
18
- # First, check IP blacklists.
19
- if (options[:ip_blacklists])
20
- if options[:ip_blacklists][:default]
21
- options[:ip_blacklists][:httpbl] = options[:ip_blacklists][:default]
22
- options[:ip_blacklists].delete(:default)
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
- Rails.logger.info "Completed IP database check. #{ip}" if options[:verbose]
31
- end
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 = []
@@ -1,3 +1,3 @@
1
1
  module Antispam
2
- VERSION = '0.2.8'
2
+ VERSION = '0.2.11'
3
3
  end
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
- # Include Antispam::Tools into the application's ApplicationController
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: antispam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Kopf