antispam 0.2.0 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -20
  3. data/README.md +141 -128
  4. data/Rakefile +18 -18
  5. data/app/assets/config/antispam_manifest.js +1 -1
  6. data/app/assets/stylesheets/antispam/application.css +15 -15
  7. data/app/assets/stylesheets/antispam/blocks.css +4 -4
  8. data/app/assets/stylesheets/antispam/challenges.css +4 -4
  9. data/app/assets/stylesheets/antispam/clears.css +4 -4
  10. data/app/assets/stylesheets/scaffold.css +80 -80
  11. data/app/controllers/antispam/application_controller.rb +11 -11
  12. data/app/controllers/antispam/blocks_controller.rb +28 -28
  13. data/app/controllers/antispam/challenges_controller.rb +50 -50
  14. data/app/controllers/antispam/clears_controller.rb +28 -28
  15. data/app/controllers/antispam/validate_controller.rb +12 -12
  16. data/app/helpers/antispam/application_helper.rb +4 -4
  17. data/app/helpers/antispam/blocks_helper.rb +4 -4
  18. data/app/helpers/antispam/challenges_helper.rb +4 -4
  19. data/app/helpers/antispam/clears_helper.rb +4 -4
  20. data/app/jobs/antispam/application_job.rb +4 -4
  21. data/app/mailers/antispam/application_mailer.rb +6 -6
  22. data/app/models/antispam/application_record.rb +5 -5
  23. data/app/models/antispam/block.rb +4 -4
  24. data/app/models/antispam/challenge.rb +26 -26
  25. data/app/models/antispam/clear.rb +4 -4
  26. data/app/models/antispam/ip.rb +11 -6
  27. data/app/views/antispam/blocks/index.html.erb +38 -38
  28. data/app/views/antispam/blocks/show.html.erb +24 -24
  29. data/app/views/antispam/challenges/_form.html.erb +32 -32
  30. data/app/views/antispam/challenges/edit.html.erb +6 -6
  31. data/app/views/antispam/challenges/index.html.erb +31 -31
  32. data/app/views/antispam/challenges/new.html.erb +5 -5
  33. data/app/views/antispam/challenges/show.html.erb +19 -19
  34. data/app/views/antispam/clears/index.html.erb +32 -32
  35. data/app/views/antispam/clears/show.html.erb +29 -29
  36. data/app/views/antispam/validate/index.html.erb +16 -14
  37. data/app/views/layouts/antispam/application.html.erb +25 -15
  38. data/config/routes.rb +7 -7
  39. data/db/migrate/20210130213708_create_antispam_ips.rb +12 -12
  40. data/db/migrate/20210130214835_create_antispam_challenges.rb +11 -11
  41. data/db/migrate/20210130234107_create_antispam_blocks.rb +12 -12
  42. data/db/migrate/20210130235537_create_antispam_clears.rb +13 -13
  43. data/db/migrate/20210131165122_add_threat_to_antispam_blocks.rb +5 -5
  44. data/lib/antispam/blacklists/httpbl.rb +49 -49
  45. data/lib/antispam/checker.rb +30 -30
  46. data/lib/antispam/engine.rb +5 -5
  47. data/lib/antispam/results.rb +18 -18
  48. data/lib/antispam/spamcheckers/defendium.rb +29 -29
  49. data/lib/antispam/tools.rb +59 -59
  50. data/lib/antispam/version.rb +3 -3
  51. data/lib/antispam.rb +21 -17
  52. data/lib/tasks/antispam_tasks.rake +4 -4
  53. metadata +6 -6
@@ -1,30 +1,30 @@
1
- #require 'resolv'
2
- module Antispam
3
- module Spamcheckers
4
- class Defendium
5
- # Returns a boolean, 1 for spam, 0 for not spam.
6
- def self.check(content, key, verbose)
7
- # nethttp2.rb
8
- require 'uri'
9
- require 'net/http'
10
-
11
- uri = URI('https://api.defendium.com/check')
12
- params = { secret_key: key, content: content }
13
- uri.query = URI.encode_www_form(params)
14
-
15
- res = Net::HTTP.get_response(uri)
16
- if res.is_a?(Net::HTTPSuccess)
17
- result = res.body.to_json
18
- if result["warnings"]
19
- Rails.logger.info result["warnings"]
20
- end
21
- if result["result"]
22
- return 1
23
- else
24
- return 0
25
- end
26
- end
27
- end
28
- end
29
- end
1
+ #require 'resolv'
2
+ module Antispam
3
+ module Spamcheckers
4
+ class Defendium
5
+ # Returns a boolean, 1 for spam, 0 for not spam.
6
+ def self.check(content, key, verbose)
7
+ # nethttp2.rb
8
+ require 'uri'
9
+ require 'net/http'
10
+
11
+ uri = URI('https://api.defendium.com/check')
12
+ params = { secret_key: key, content: content }
13
+ uri.query = URI.encode_www_form(params)
14
+
15
+ res = Net::HTTP.get_response(uri)
16
+ if res.is_a?(Net::HTTPSuccess)
17
+ result = res.body.to_json
18
+ if result["warnings"]
19
+ Rails.logger.info result["warnings"]
20
+ end
21
+ if result["result"]
22
+ return 1
23
+ else
24
+ return 0
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
30
  end
@@ -1,59 +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 == "validate"
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
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
@@ -1,3 +1,3 @@
1
- module Antispam
2
- VERSION = '0.2.0'
3
- end
1
+ module Antispam
2
+ VERSION = '0.2.4'
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
- # self refers to ActionController::Base here
12
- # This way is removed because below may be more compatible.
13
- # self.include Antispam::Tools
14
- # Would the below be a better (clearer? more compatible?) way to do this?
15
- ActionController::Base.send(:include, Antispam::Tools)
16
- end
17
- end
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.2.0
4
+ version: 0.2.4
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: 2023-01-25 00:00:00.000000000 Z
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.4.4
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: []