antispam 0.1.7 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -20
- data/README.md +129 -113
- data/Rakefile +18 -18
- data/app/assets/config/antispam_manifest.js +1 -1
- data/app/assets/stylesheets/antispam/application.css +15 -15
- data/app/assets/stylesheets/antispam/blocks.css +4 -4
- data/app/assets/stylesheets/antispam/challenges.css +4 -4
- data/app/assets/stylesheets/antispam/clears.css +4 -4
- data/app/assets/stylesheets/scaffold.css +80 -80
- data/app/controllers/antispam/application_controller.rb +11 -11
- data/app/controllers/antispam/blocks_controller.rb +28 -28
- data/app/controllers/antispam/challenges_controller.rb +50 -50
- data/app/controllers/antispam/clears_controller.rb +28 -28
- data/app/controllers/antispam/validate_controller.rb +12 -12
- data/app/helpers/antispam/application_helper.rb +4 -4
- data/app/helpers/antispam/blocks_helper.rb +4 -4
- data/app/helpers/antispam/challenges_helper.rb +4 -4
- data/app/helpers/antispam/clears_helper.rb +4 -4
- data/app/jobs/antispam/application_job.rb +4 -4
- data/app/mailers/antispam/application_mailer.rb +6 -6
- data/app/models/antispam/application_record.rb +5 -5
- data/app/models/antispam/block.rb +4 -4
- data/app/models/antispam/challenge.rb +26 -26
- data/app/models/antispam/clear.rb +4 -4
- data/app/models/antispam/ip.rb +11 -6
- data/app/views/antispam/blocks/index.html.erb +38 -38
- data/app/views/antispam/blocks/show.html.erb +24 -24
- data/app/views/antispam/challenges/_form.html.erb +32 -32
- data/app/views/antispam/challenges/edit.html.erb +6 -6
- data/app/views/antispam/challenges/index.html.erb +31 -31
- data/app/views/antispam/challenges/new.html.erb +5 -5
- data/app/views/antispam/challenges/show.html.erb +19 -19
- data/app/views/antispam/clears/index.html.erb +32 -32
- data/app/views/antispam/clears/show.html.erb +29 -29
- data/app/views/antispam/validate/index.html.erb +16 -14
- data/app/views/layouts/antispam/application.html.erb +25 -15
- data/config/routes.rb +7 -7
- data/db/migrate/20210130213708_create_antispam_ips.rb +12 -12
- data/db/migrate/20210130214835_create_antispam_challenges.rb +11 -11
- data/db/migrate/20210130234107_create_antispam_blocks.rb +12 -12
- data/db/migrate/20210130235537_create_antispam_clears.rb +13 -13
- data/db/migrate/20210131165122_add_threat_to_antispam_blocks.rb +5 -5
- data/lib/antispam/blacklists/httpbl.rb +49 -48
- data/lib/antispam/checker.rb +30 -19
- data/lib/antispam/engine.rb +5 -5
- data/lib/antispam/results.rb +18 -10
- data/lib/antispam/spamcheckers/defendium.rb +29 -28
- data/lib/antispam/tools.rb +59 -57
- data/lib/antispam/version.rb +3 -3
- data/lib/antispam.rb +21 -17
- data/lib/tasks/antispam_tasks.rake +4 -4
- metadata +6 -6
data/lib/antispam/tools.rb
CHANGED
@@ -1,57 +1,59 @@
|
|
1
|
-
module Antispam
|
2
|
-
module Tools
|
3
|
-
# Checks spam against an IP database of spammers.
|
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)
|
12
|
-
else
|
13
|
-
return if request.get?
|
14
|
-
end
|
15
|
-
return if skip_if_user_whitelisted
|
16
|
-
return if controller_name
|
17
|
-
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
|
-
|
29
|
-
end
|
30
|
-
Rails.logger.info "Completed IP database check. #{ip}" if options[:verbose]
|
31
|
-
end
|
32
|
-
# Checks the specific blacklists
|
33
|
-
def check_ip_against_blacklists(ip, lists, verbose)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
1
|
+
module Antispam
|
2
|
+
module Tools
|
3
|
+
# Checks spam against an IP database of spammers.
|
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)
|
12
|
+
else
|
13
|
+
return if request.get?
|
14
|
+
end
|
15
|
+
return if skip_if_user_whitelisted
|
16
|
+
return if controller_name.in?["validate","challenges"]
|
17
|
+
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
|
+
|
29
|
+
end
|
30
|
+
Rails.logger.info "Completed IP database check. #{ip}" if options[:verbose]
|
31
|
+
end
|
32
|
+
# Checks the specific blacklists
|
33
|
+
def check_ip_against_blacklists(ip, lists, verbose)
|
34
|
+
results = []
|
35
|
+
lists.each do |provider_name, provider_api_key|
|
36
|
+
Rails.logger.info "Checking provider: #{provider_name}" if verbose
|
37
|
+
results.append blacklist(provider_name).check(ip, provider_api_key, verbose)
|
38
|
+
end
|
39
|
+
result = Antispam::BlacklistResult.new(results)
|
40
|
+
if result.is_bad?
|
41
|
+
Block.create(ip: ip, provider: lists.keys.first, threat: result)
|
42
|
+
redirect_to '/antispam/validate'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
def skip_if_user_whitelisted
|
46
|
+
if respond_to? :current_user
|
47
|
+
if current_user && current_user.respond_to?(:antispam_whitelisted?)
|
48
|
+
return true if current_user.antispam_whitelisted?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
def blacklist(provider)
|
53
|
+
class_name = provider.to_s.camelize
|
54
|
+
raise Antispam::NoSuchBlacklistError unless Antispam::Blacklists.const_defined? class_name
|
55
|
+
Antispam::Blacklists.const_get class_name
|
56
|
+
end
|
57
|
+
end
|
58
|
+
class NoSuchBlacklistError < StandardError; end
|
59
|
+
end
|
data/lib/antispam/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Antispam
|
2
|
-
VERSION = '0.
|
3
|
-
end
|
1
|
+
module Antispam
|
2
|
+
VERSION = '0.2.3'
|
3
|
+
end
|
data/lib/antispam.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
|
-
require "antispam/version"
|
2
|
-
require "antispam/engine"
|
3
|
-
require "antispam/tools"
|
4
|
-
require "antispam/checker"
|
5
|
-
require "antispam/blacklists/httpbl"
|
6
|
-
require "antispam/spamcheckers/defendium"
|
7
|
-
require "antispam/results"
|
8
|
-
|
9
|
-
module Antispam
|
10
|
-
ActiveSupport.on_load(:action_controller) do
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
ActionController::Base
|
16
|
-
|
17
|
-
|
1
|
+
require "antispam/version"
|
2
|
+
require "antispam/engine"
|
3
|
+
require "antispam/tools"
|
4
|
+
require "antispam/checker"
|
5
|
+
require "antispam/blacklists/httpbl"
|
6
|
+
require "antispam/spamcheckers/defendium"
|
7
|
+
require "antispam/results"
|
8
|
+
|
9
|
+
module Antispam
|
10
|
+
ActiveSupport.on_load(:action_controller) do
|
11
|
+
# Ensure ApplicationController has is_admin? defined
|
12
|
+
unless ApplicationController.method_defined?(:is_admin?)
|
13
|
+
raise "Antispam Error: ApplicationController must define `is_admin?` method to use Antispam."
|
14
|
+
end
|
15
|
+
# self refers to ActionController::Base here
|
16
|
+
# This way is removed because below may be more compatible.
|
17
|
+
# self.include Antispam::Tools
|
18
|
+
# Would the below be a better (clearer? more compatible?) way to do this?
|
19
|
+
ActionController::Base.send(:include, Antispam::Tools)
|
20
|
+
end
|
21
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# desc "Explaining what the task does"
|
2
|
-
# task :antispam do
|
3
|
-
# # Task goes here
|
4
|
-
# end
|
1
|
+
# desc "Explaining what the task does"
|
2
|
+
# task :antispam do
|
3
|
+
# # Task goes here
|
4
|
+
# end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: antispam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Kopf
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -131,7 +131,7 @@ metadata:
|
|
131
131
|
homepage_uri: https://ryankopf.com
|
132
132
|
source_code_uri: https://github.com/ryankopf/antispam
|
133
133
|
changelog_uri: https://github.com/ryankopf/antispam/CHANGELOG.md
|
134
|
-
post_install_message:
|
134
|
+
post_install_message:
|
135
135
|
rdoc_options: []
|
136
136
|
require_paths:
|
137
137
|
- lib
|
@@ -146,8 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
146
|
- !ruby/object:Gem::Version
|
147
147
|
version: '0'
|
148
148
|
requirements: []
|
149
|
-
rubygems_version: 3.
|
150
|
-
signing_key:
|
149
|
+
rubygems_version: 3.5.20
|
150
|
+
signing_key:
|
151
151
|
specification_version: 4
|
152
152
|
summary: A spam prevention gem.
|
153
153
|
test_files: []
|