antispam 0.1.4 → 0.1.5

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: '06962cddbbfd16f9f59e18277630d9c597865483df7f72a5b33bdeccfab15c98'
4
- data.tar.gz: ce7b03a25d08d79271e61f7081d73922602c84201f7867d32a818fc9ff3b67e2
3
+ metadata.gz: 278c21161c08ebd08f8376df6ddb57fcda33d20d7ae9e9d804a7b3785c23cbae
4
+ data.tar.gz: dab176fb46e3d5ecaa6d2c304262adfc4bf612f413b392270e3b44ef03de7147
5
5
  SHA512:
6
- metadata.gz: 63cb93116a4a5d5409ce5a6643071f5edc267f245251a97e06be683ec036126b245ca621c57656848812436a4761f3adc7c8e1980b451264a6942c3e8442d14b
7
- data.tar.gz: 04ca386da73cd5b9d273476ecbe624c1045f1d2933c58eab9bd4948b49806745d399b5aa4351d575ce9ad2bc75a945d8d4732336663bf13be7dd74972320dcf2
6
+ metadata.gz: 3491eb8c49c91b0cc468440cde3b965ac359d6e3d561e8893a5e48079da0441a2128dd9cb118d30b79e147b8ad79d87ce2df78fcd074217880b1c6f9c4e60748
7
+ data.tar.gz: b1d49d286f4bc2d6885e40e7f20b0bd9cdec2f57c608dd443b9c060a8a49ca7799e69f05a0e3e5f422071f385a34fcd39e442a2ee5b5a89f0dfd56425574da5c
data/README.md CHANGED
@@ -1,72 +1,72 @@
1
- # Antispam
2
- The antispam gem helps prevent spam in your Rails applications by
3
- checking against various antispam blacklists on the web.
4
- You can configure which spam blacklists are checked in your application configuration.
5
-
6
- ## Usage
7
-
8
- The gem is used by adding this to your ApplicationController.rb
9
-
10
- ```
11
- before_action do
12
- check_ip_against_database(ip_blacklists: {default: 'yourcodehere'}, verbose: true)
13
- end
14
- ```
15
-
16
- Once the filter is setup, everything else is handled for your application.
17
- The gem will run during any request that is not a GET request.
18
-
19
- Blacklist database lookups are cached for 24 hours, and cached results won't need
20
- to slowdown your app by additional http requests on the backend.
21
-
22
- The gem needs to create some database tables to function; these store the cached
23
- blacklist database lookups, and any actions caused by the gem.
24
-
25
- You need to add this to your routes.rb
26
- ```
27
- mount Antispam::Engine => "/antispam"
28
- ```
29
- You can see what IP addresses have been blocked by going to /antispam/blocks
30
- but your applicationcontroller must respond to ```is_admin?``` function.
31
-
32
-
33
- ## Installation
34
- Add this line to your application's Gemfile:
35
-
36
- ```ruby
37
- gem 'antispam'
38
- ```
39
-
40
- And then execute:
41
- ```bash
42
- $ bundle
43
- ```
44
-
45
- Or install it yourself as:
46
- ```bash
47
- $ gem install antispam
48
- $ rails antispam:install:migrations
49
- $ rails db:migrate SCOPE=antispam
50
- ```
51
- The gem depends on image_processing, which depends on vips. We are using vips to
52
- generate captcha images.
53
- ```
54
- sudo apt install libvips-tools
55
- ```
56
-
57
- ## Development
58
-
59
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
60
-
61
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
62
-
63
- ## Contributing
64
-
65
- Bug reports and pull requests are welcome on GitHub at https://github.com/ryankopf/antispam. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/antispam/blob/master/CODE_OF_CONDUCT.md).
66
-
67
- ## License
68
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
69
-
70
- ## Code of Conduct
71
-
72
- Everyone interacting in the Antispam project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ryankopf/antispam/blob/master/CODE_OF_CONDUCT.md).
1
+ # Antispam
2
+ The antispam gem helps prevent spam in your Rails applications by
3
+ checking against various antispam blacklists on the web.
4
+ You can configure which spam blacklists are checked in your application configuration.
5
+
6
+ ## Usage
7
+
8
+ The gem is used by adding this to your ApplicationController.rb
9
+
10
+ ```
11
+ before_action do
12
+ check_ip_against_database(ip_blacklists: {default: 'yourcodehere'}, verbose: true)
13
+ end
14
+ ```
15
+
16
+ Once the filter is setup, everything else is handled for your application.
17
+ The gem will run during any request that is not a GET request.
18
+
19
+ Blacklist database lookups are cached for 24 hours, and cached results won't need
20
+ to slowdown your app by additional http requests on the backend.
21
+
22
+ The gem needs to create some database tables to function; these store the cached
23
+ blacklist database lookups, and any actions caused by the gem.
24
+
25
+ You need to add this to your routes.rb
26
+ ```
27
+ mount Antispam::Engine => "/antispam"
28
+ ```
29
+ You can see what IP addresses have been blocked by going to /antispam/blocks
30
+ but your applicationcontroller must respond to ```is_admin?``` function.
31
+
32
+
33
+ ## Installation
34
+ Add this line to your application's Gemfile:
35
+
36
+ ```ruby
37
+ gem 'antispam'
38
+ ```
39
+
40
+ And then execute:
41
+ ```bash
42
+ $ bundle
43
+ ```
44
+
45
+ Or install it yourself as:
46
+ ```bash
47
+ $ gem install antispam
48
+ $ rails antispam:install:migrations
49
+ $ rails db:migrate SCOPE=antispam
50
+ ```
51
+ The gem depends on image_processing, which depends on vips. We are using vips to
52
+ generate captcha images.
53
+ ```
54
+ sudo apt install libvips-tools
55
+ ```
56
+
57
+ ## Development
58
+
59
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
60
+
61
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
62
+
63
+ ## Contributing
64
+
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ryankopf/antispam. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/antispam/blob/master/CODE_OF_CONDUCT.md).
66
+
67
+ ## License
68
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
69
+
70
+ ## Code of Conduct
71
+
72
+ Everyone interacting in the Antispam project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ryankopf/antispam/blob/master/CODE_OF_CONDUCT.md).
@@ -1,11 +1,11 @@
1
- module Antispam
2
- class ApplicationController < ::ApplicationController
3
- def must_be_admin
4
- begin
5
- render plain: 'Not available.' unless is_admin?
6
- rescue
7
- render plain: 'Not available.'
8
- end
9
- end
10
- end
11
- end
1
+ module Antispam
2
+ class ApplicationController < ::ApplicationController
3
+ def must_be_admin
4
+ begin
5
+ render plain: 'Not available.' unless is_admin?
6
+ rescue
7
+ render plain: 'Not available.'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,28 +1,28 @@
1
- require_dependency "antispam/application_controller"
2
-
3
- module Antispam
4
- class BlocksController < ApplicationController
5
- before_action :must_be_admin
6
- before_action :set_block, only: [:show]
7
-
8
- # GET /blocks
9
- def index
10
- @blocks = Block.all
11
- end
12
-
13
- # GET /blocks/1
14
- def show
15
- end
16
-
17
- private
18
- # Use callbacks to share common setup or constraints between actions.
19
- def set_block
20
- @block = Block.find(params[:id])
21
- end
22
-
23
- # Only allow a list of trusted parameters through.
24
- def block_params
25
- params.require(:block).permit(:ip, :provider, :controllername, :actionname)
26
- end
27
- end
28
- end
1
+ require_dependency "antispam/application_controller"
2
+
3
+ module Antispam
4
+ class BlocksController < ApplicationController
5
+ before_action :must_be_admin
6
+ before_action :set_block, only: [:show]
7
+
8
+ # GET /blocks
9
+ def index
10
+ @blocks = Block.all
11
+ end
12
+
13
+ # GET /blocks/1
14
+ def show
15
+ end
16
+
17
+ private
18
+ # Use callbacks to share common setup or constraints between actions.
19
+ def set_block
20
+ @block = Block.find(params[:id])
21
+ end
22
+
23
+ # Only allow a list of trusted parameters through.
24
+ def block_params
25
+ params.require(:block).permit(:ip, :provider, :controllername, :actionname)
26
+ end
27
+ end
28
+ end
@@ -1,49 +1,49 @@
1
- require_dependency "antispam/application_controller"
2
-
3
- module Antispam
4
- class ChallengesController < ApplicationController
5
- before_action :set_challenge, only: [:show, :edit, :update, :destroy]
6
-
7
- # GET /challenges/1
8
- def show
9
- respond_to do |format|
10
- format.jpeg do
11
- image = @challenge.get_image
12
- render content_type: 'image/jpeg', plain: image.jpegsave_buffer
13
- end
14
- end
15
- end
16
-
17
- # GET /challenges/new
18
- def new
19
- # use in the future for changing code
20
- end
21
-
22
- # PATCH/PUT /challenges/1
23
- def update
24
- if @challenge.validate?(params[:challenge][:answer])
25
- a = Antispam::Ip.find_or_create_by(address: request.remote_ip, provider: 'httpbl')
26
- before = a.threat
27
- a.threat = [(a.threat || 0) - 25, 0].max
28
- c = Clear.create(ip: request.remote_ip, answer: params[:challenge][:answer], result: 'Passed', threat_before: before, threat_after: a.threat)
29
- a.expires_at = 1.hour.from_now
30
- a.save
31
- redirect_to '/'
32
- else
33
- c = Clear.create(ip: request.remote_ip, answer: params[:challenge][:answer], result: 'Failed')
34
- redirect_to '/antispam/validate', notice: 'Invalid answer.'
35
- end
36
- end
37
-
38
- private
39
- # Use callbacks to share common setup or constraints between actions.
40
- def set_challenge
41
- @challenge = Challenge.find(params[:id])
42
- end
43
-
44
- # Only allow a list of trusted parameters through.
45
- def challenge_params
46
- params.require(:challenge).permit(:answer, :code)
47
- end
48
- end
49
- end
1
+ require_dependency "antispam/application_controller"
2
+
3
+ module Antispam
4
+ class ChallengesController < ApplicationController
5
+ before_action :set_challenge, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /challenges/1
8
+ def show
9
+ respond_to do |format|
10
+ format.jpeg do
11
+ image = @challenge.get_image
12
+ render content_type: 'image/jpeg', plain: image.jpegsave_buffer
13
+ end
14
+ end
15
+ end
16
+
17
+ # GET /challenges/new
18
+ def new
19
+ # use in the future for changing code
20
+ end
21
+
22
+ # PATCH/PUT /challenges/1
23
+ def update
24
+ if @challenge.validate?(params[:challenge][:answer])
25
+ a = Antispam::Ip.find_or_create_by(address: request.remote_ip, provider: 'httpbl')
26
+ before = a.threat
27
+ a.threat = [(a.threat || 0) - 25, 0].max
28
+ c = Clear.create(ip: request.remote_ip, answer: params[:challenge][:answer], result: 'Passed', threat_before: before, threat_after: a.threat)
29
+ a.expires_at = 1.hour.from_now
30
+ a.save
31
+ redirect_to '/'
32
+ else
33
+ c = Clear.create(ip: request.remote_ip, answer: params[:challenge][:answer], result: 'Failed')
34
+ redirect_to '/antispam/validate', notice: 'Invalid answer.'
35
+ end
36
+ end
37
+
38
+ private
39
+ # Use callbacks to share common setup or constraints between actions.
40
+ def set_challenge
41
+ @challenge = Challenge.find(params[:id])
42
+ end
43
+
44
+ # Only allow a list of trusted parameters through.
45
+ def challenge_params
46
+ params.require(:challenge).permit(:answer, :code)
47
+ end
48
+ end
49
+ end
@@ -1,28 +1,28 @@
1
- require_dependency "antispam/application_controller"
2
-
3
- module Antispam
4
- class ClearsController < ApplicationController
5
- before_action :must_be_admin
6
- before_action :set_clear, only: [:show, :edit, :update, :destroy]
7
-
8
- # GET /clears
9
- def index
10
- @clears = Clear.all
11
- end
12
-
13
- # GET /clears/1
14
- def show
15
- end
16
-
17
- private
18
- # Use callbacks to share common setup or constraints between actions.
19
- def set_clear
20
- @clear = Clear.find(params[:id])
21
- end
22
-
23
- # Only allow a list of trusted parameters through.
24
- def clear_params
25
- params.require(:clear).permit(:ip, :result, :answer, :threat_before, :threat_after)
26
- end
27
- end
28
- end
1
+ require_dependency "antispam/application_controller"
2
+
3
+ module Antispam
4
+ class ClearsController < ApplicationController
5
+ before_action :must_be_admin
6
+ before_action :set_clear, only: [:show, :edit, :update, :destroy]
7
+
8
+ # GET /clears
9
+ def index
10
+ @clears = Clear.all
11
+ end
12
+
13
+ # GET /clears/1
14
+ def show
15
+ end
16
+
17
+ private
18
+ # Use callbacks to share common setup or constraints between actions.
19
+ def set_clear
20
+ @clear = Clear.find(params[:id])
21
+ end
22
+
23
+ # Only allow a list of trusted parameters through.
24
+ def clear_params
25
+ params.require(:clear).permit(:ip, :result, :answer, :threat_before, :threat_after)
26
+ end
27
+ end
28
+ end
@@ -1,39 +1,39 @@
1
- <p id="notice"><%= notice %></p>
2
-
3
- <div class="row">
4
- <div class="cx">
5
- <h1>Blocks</h1>
6
-
7
- <table>
8
- <thead>
9
- <tr>
10
- <th>Ip</th>
11
- <th>Provider</th>
12
- <th>Controllername</th>
13
- <th>Actionname</th>
14
- <th>Threat</th>
15
- <th colspan="3"></th>
16
- </tr>
17
- </thead>
18
-
19
- <tbody>
20
- <% Antispam::Block.all.order(created_at: :desc).limit(50).each do |block| %>
21
- <tr>
22
- <td><%= block.ip %></td>
23
- <td><%= block.provider %></td>
24
- <td><%= block.controllername %></td>
25
- <td><%= block.actionname %></td>
26
- <td><%= block.threat %></td>
27
- <td><%= time_ago_in_words block.created_at %> ago</td>
28
- <!-- <td><%#= link_to 'Show', block %></td>-->
29
- <!-- <td><%#= link_to 'Edit', edit_block_path(block) %></td>-->
30
- <!-- <td><%#= link_to 'Destroy', block, method: :delete, data: { confirm: 'Are you sure?' } %></td>-->
31
- </tr>
32
- <% end %>
33
- </tbody>
34
- </table>
35
- </div>
36
- <div class="cx">
37
- <%= render template: '/antispam/clears/index.html' %>
38
- </div>
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <div class="row">
4
+ <div class="cx">
5
+ <h1>Blocks</h1>
6
+
7
+ <table>
8
+ <thead>
9
+ <tr>
10
+ <th>Ip</th>
11
+ <th>Provider</th>
12
+ <th>Controllername</th>
13
+ <th>Actionname</th>
14
+ <th>Threat</th>
15
+ <th colspan="3"></th>
16
+ </tr>
17
+ </thead>
18
+
19
+ <tbody>
20
+ <% Antispam::Block.all.order(created_at: :desc).limit(50).each do |block| %>
21
+ <tr>
22
+ <td><%= block.ip %></td>
23
+ <td><%= block.provider %></td>
24
+ <td><%= block.controllername %></td>
25
+ <td><%= block.actionname %></td>
26
+ <td><%= block.threat %></td>
27
+ <td><%= time_ago_in_words block.created_at %> ago</td>
28
+ <!-- <td><%#= link_to 'Show', block %></td>-->
29
+ <!-- <td><%#= link_to 'Edit', edit_block_path(block) %></td>-->
30
+ <!-- <td><%#= link_to 'Destroy', block, method: :delete, data: { confirm: 'Are you sure?' } %></td>-->
31
+ </tr>
32
+ <% end %>
33
+ </tbody>
34
+ </table>
35
+ </div>
36
+ <div class="cx">
37
+ <%= render template: '/antispam/clears/index.html' %>
38
+ </div>
39
39
  </div>
@@ -1,32 +1,32 @@
1
- <p id="notice"><%= notice %></p>
2
-
3
- <h1>Clears</h1>
4
-
5
- <table>
6
- <thead>
7
- <tr>
8
- <th>Ip</th>
9
- <th>Result</th>
10
- <th>Answer</th>
11
- <th>Threat before</th>
12
- <th>Threat after</th>
13
- <th colspan="3"></th>
14
- </tr>
15
- </thead>
16
-
17
- <tbody>
18
- <% Antispam::Clear.all.order(created_at: :desc).limit(50).each do |clear| %>
19
- <tr>
20
- <td><%= clear.ip %></td>
21
- <td><%= clear.result %></td>
22
- <td><%= clear.answer %></td>
23
- <td><%= clear.threat_before %></td>
24
- <td><%= clear.threat_after %></td>
25
- <td><%= time_ago_in_words clear.created_at %> ago</td>
26
- <!-- <td><%#= link_to 'Show', clear %></td>-->
27
- <!-- <td><%#= link_to 'Edit', edit_clear_path(clear) %></td>-->
28
- <!-- <td><%#= link_to 'Destroy', clear, method: :delete, data: { confirm: 'Are you sure?' } %></td>-->
29
- </tr>
30
- <% end %>
31
- </tbody>
32
- </table>
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1>Clears</h1>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th>Ip</th>
9
+ <th>Result</th>
10
+ <th>Answer</th>
11
+ <th>Threat before</th>
12
+ <th>Threat after</th>
13
+ <th colspan="3"></th>
14
+ </tr>
15
+ </thead>
16
+
17
+ <tbody>
18
+ <% Antispam::Clear.all.order(created_at: :desc).limit(50).each do |clear| %>
19
+ <tr>
20
+ <td><%= clear.ip %></td>
21
+ <td><%= clear.result %></td>
22
+ <td><%= clear.answer %></td>
23
+ <td><%= clear.threat_before %></td>
24
+ <td><%= clear.threat_after %></td>
25
+ <td><%= time_ago_in_words clear.created_at %> ago</td>
26
+ <!-- <td><%#= link_to 'Show', clear %></td>-->
27
+ <!-- <td><%#= link_to 'Edit', edit_clear_path(clear) %></td>-->
28
+ <!-- <td><%#= link_to 'Destroy', clear, method: :delete, data: { confirm: 'Are you sure?' } %></td>-->
29
+ </tr>
30
+ <% end %>
31
+ </tbody>
32
+ </table>
@@ -1,15 +1,15 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Antispam</title>
5
- <%= csrf_meta_tags %>
6
- <%= csp_meta_tag %>
7
- <style>.row { width:100%;display: flex;} .cx { width: 50%; }</style>
8
- <%#= stylesheet_link_tag "antispam/application", media: "all" %>
9
- </head>
10
- <body>
11
-
12
- <%= yield %>
13
-
14
- </body>
15
- </html>
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Antispam</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+ <style>.row { width:100%;display: flex;} .cx { width: 50%; }</style>
8
+ <%#= stylesheet_link_tag "antispam/application", media: "all" %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
@@ -1,5 +1,5 @@
1
- class AddThreatToAntispamBlocks < ActiveRecord::Migration[6.1]
2
- def change
3
- add_column :antispam_blocks, :threat, :integer
4
- end
5
- end
1
+ class AddThreatToAntispamBlocks < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :antispam_blocks, :threat, :integer
4
+ end
5
+ end
data/lib/antispam.rb CHANGED
@@ -1,11 +1,14 @@
1
- require "antispam/version"
2
- require "antispam/engine"
3
- require "antispam/tools"
4
- require "antispam/blacklists/httpbl"
5
-
6
- module Antispam
7
- ActiveSupport.on_load(:action_controller) do
8
- # self refers to ActionController::Base here
9
- self.include Antispam::Tools
10
- end
11
- end
1
+ require "antispam/version"
2
+ require "antispam/engine"
3
+ require "antispam/tools"
4
+ require "antispam/blacklists/httpbl"
5
+
6
+ module Antispam
7
+ ActiveSupport.on_load(:action_controller) do
8
+ # self refers to ActionController::Base here
9
+ # This way is removed because below may be more compatible.
10
+ # self.include Antispam::Tools
11
+ # Would the below be a better (clearer? more compatible?) way to do this?
12
+ ActionController::Base.send(:include, Antispam::Tools)
13
+ end
14
+ end
@@ -2,15 +2,19 @@ require 'resolv'
2
2
  module Antispam
3
3
  module Blacklists
4
4
  class Httpbl
5
- def self.check(ip, key)
5
+ def self.check(ip, key, verbose)
6
6
  threat = 0
7
7
  begin
8
- return get_old_result(ip) if get_old_result(ip)
8
+ old_result = get_old_result(ip)
9
+ if old_result
10
+ Rails.logger.info "Returning old result for #{ip}." if verbose
11
+ return get_old_result(ip)
12
+ end
9
13
  check = ip.split('.').reverse.join('.')
10
14
  host = key + '.' + check + ".dnsbl.httpbl.org"
11
15
  address = Resolv::getaddress(host)
12
16
  z,days,threat,iptype = address.split('.')
13
- Rails.logger.info "Spam located: #{iptype} type at #{threat} threat. (#{ip} - #{address})"
17
+ Rails.logger.info "Spam located: #{iptype} type at #{threat} threat. (#{ip} - #{address})" if verbose
14
18
  # Create or update
15
19
  if (threat.to_i > 30)
16
20
  Rails.logger.info "Spamcheck: Very high, over 30!"
@@ -1,48 +1,55 @@
1
- module Antispam
2
- module Tools
3
- # before_action :check_ip_against_database
4
- def check_ip_against_database(options = {ip_blacklists: {default: ''}})
5
- return if request.get?
6
- return if skip_if_user_whitelisted
7
- return if controller_name == "validate"
8
- ip = request.remote_ip
9
- # First, check IP blacklists.
10
- if (options[:ip_blacklists])
11
- if options[:ip_blacklists][:default]
12
- options[:ip_blacklists][:httpbl] = options[:ip_blacklists][:default]
13
- options[:ip_blacklists].delete(:default)
14
- end
15
- check_ip_against_blacklists(ip, options[:ip_blacklists], options[:verbose])
16
- end
17
- # Second, check for weird countries.
18
- if (options[:scrutinize_countries_except])
19
-
20
- end
21
- Rails.logger.info "Got to this function. #{ip}"
22
- puts "Got to this function. #{ip}"
23
- end
24
- def check_ip_against_blacklists(ip, lists, verbose)
25
- lists.each do |provider_name, provider_api_key|
26
- puts "Checking provider: #{provider_name}" if verbose
27
- if provider_name == :httpbl
28
- result = Antispam::Blacklists::Httpbl.check(ip, provider_api_key)
29
- puts result if verbose
30
- if (result > 30)
31
- Block.create(ip: ip, provider: provider_name, threat: result)
32
- redirect_to '/antispam/validate'
33
- end
34
- end
35
- end
36
- end
37
-
38
- def skip_if_user_whitelisted
39
- if respond_to? :current_user
40
- if current_user && current_user.respond_to?(:antispam_whitelisted?)
41
- return true if current_user.antispam_whitelisted?
42
- end
43
- end
44
- end
45
-
46
-
47
- end
48
- end
1
+ module Antispam
2
+ module Tools
3
+ # before_action :check_ip_against_database
4
+ def check_ip_against_database(options = {ip_blacklists: {default: ''}})
5
+ if (options[:methods])
6
+ return if request.get? unless options[:methods].include?(:get)
7
+ return if request.post? unless options[:methods].include?(:post)
8
+ return if request.put? unless options[:methods].include?(:put)
9
+ return if request.patch? unless options[:methods].include?(:patch)
10
+ return if request.delete? unless options[:methods].include?(:delete)
11
+ else
12
+ return if request.get?
13
+ end
14
+ return if skip_if_user_whitelisted
15
+ return if controller_name == "validate"
16
+ ip = request.remote_ip
17
+ # First, check IP blacklists.
18
+ if (options[:ip_blacklists])
19
+ if options[:ip_blacklists][:default]
20
+ options[:ip_blacklists][:httpbl] = options[:ip_blacklists][:default]
21
+ options[:ip_blacklists].delete(:default)
22
+ end
23
+ check_ip_against_blacklists(ip, options[:ip_blacklists], options[:verbose])
24
+ end
25
+ # Second, check for weird countries.
26
+ if (options[:scrutinize_countries_except])
27
+
28
+ end
29
+ Rails.logger.info "Completed IP database check. #{ip}" if options[:verbose]
30
+ end
31
+ def check_ip_against_blacklists(ip, lists, verbose)
32
+ lists.each do |provider_name, provider_api_key|
33
+ puts "Checking provider: #{provider_name}" if verbose
34
+ if provider_name == :httpbl
35
+ result = Antispam::Blacklists::Httpbl.check(ip, provider_api_key, verbose)
36
+ Rails.logger.info(result) if verbose
37
+ if (result > 30)
38
+ Block.create(ip: ip, provider: provider_name, threat: result)
39
+ redirect_to '/antispam/validate'
40
+ end
41
+ end
42
+ end
43
+ end
44
+
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
+
53
+
54
+ end
55
+ end
@@ -1,3 +1,3 @@
1
- module Antispam
2
- VERSION = '0.1.4'
3
- end
1
+ module Antispam
2
+ VERSION = '0.1.5'
3
+ 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.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Kopf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-31 00:00:00.000000000 Z
11
+ date: 2021-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -83,20 +83,14 @@ files:
83
83
  - app/models/antispam/challenge.rb
84
84
  - app/models/antispam/clear.rb
85
85
  - app/models/antispam/ip.rb
86
- - app/views/antispam/blocks/_form.html.erb
87
- - app/views/antispam/blocks/edit.html.erb
88
86
  - app/views/antispam/blocks/index.html.erb
89
- - app/views/antispam/blocks/new.html.erb
90
87
  - app/views/antispam/blocks/show.html.erb
91
88
  - app/views/antispam/challenges/_form.html.erb
92
89
  - app/views/antispam/challenges/edit.html.erb
93
90
  - app/views/antispam/challenges/index.html.erb
94
91
  - app/views/antispam/challenges/new.html.erb
95
92
  - app/views/antispam/challenges/show.html.erb
96
- - app/views/antispam/clears/_form.html.erb
97
- - app/views/antispam/clears/edit.html.erb
98
93
  - app/views/antispam/clears/index.html.erb
99
- - app/views/antispam/clears/new.html.erb
100
94
  - app/views/antispam/clears/show.html.erb
101
95
  - app/views/antispam/validate/index.html.erb
102
96
  - app/views/layouts/antispam/application.html.erb
@@ -1,37 +0,0 @@
1
- <%= form_with(model: block) do |form| %>
2
- <% if block.errors.any? %>
3
- <div id="error_explanation">
4
- <h2><%= pluralize(block.errors.count, "error") %> prohibited this block from being saved:</h2>
5
-
6
- <ul>
7
- <% block.errors.each do |error| %>
8
- <li><%= error.full_message %></li>
9
- <% end %>
10
- </ul>
11
- </div>
12
- <% end %>
13
-
14
- <div class="field">
15
- <%= form.label :ip %>
16
- <%= form.text_field :ip %>
17
- </div>
18
-
19
- <div class="field">
20
- <%= form.label :provider %>
21
- <%= form.text_field :provider %>
22
- </div>
23
-
24
- <div class="field">
25
- <%= form.label :controllername %>
26
- <%= form.text_field :controllername %>
27
- </div>
28
-
29
- <div class="field">
30
- <%= form.label :actionname %>
31
- <%= form.text_field :actionname %>
32
- </div>
33
-
34
- <div class="actions">
35
- <%= form.submit %>
36
- </div>
37
- <% end %>
@@ -1,6 +0,0 @@
1
- <h1>Editing Block</h1>
2
-
3
- <%= render 'form', block: @block %>
4
-
5
- <%= link_to 'Show', @block %> |
6
- <%= link_to 'Back', blocks_path %>
@@ -1,5 +0,0 @@
1
- <h1>New Block</h1>
2
-
3
- <%= render 'form', block: @block %>
4
-
5
- <%= link_to 'Back', blocks_path %>
@@ -1,42 +0,0 @@
1
- <%= form_with(model: clear) do |form| %>
2
- <% if clear.errors.any? %>
3
- <div id="error_explanation">
4
- <h2><%= pluralize(clear.errors.count, "error") %> prohibited this clear from being saved:</h2>
5
-
6
- <ul>
7
- <% clear.errors.each do |error| %>
8
- <li><%= error.full_message %></li>
9
- <% end %>
10
- </ul>
11
- </div>
12
- <% end %>
13
-
14
- <div class="field">
15
- <%= form.label :ip %>
16
- <%= form.text_field :ip %>
17
- </div>
18
-
19
- <div class="field">
20
- <%= form.label :result %>
21
- <%= form.text_field :result %>
22
- </div>
23
-
24
- <div class="field">
25
- <%= form.label :answer %>
26
- <%= form.text_field :answer %>
27
- </div>
28
-
29
- <div class="field">
30
- <%= form.label :threat_before %>
31
- <%= form.number_field :threat_before %>
32
- </div>
33
-
34
- <div class="field">
35
- <%= form.label :threat_after %>
36
- <%= form.number_field :threat_after %>
37
- </div>
38
-
39
- <div class="actions">
40
- <%= form.submit %>
41
- </div>
42
- <% end %>
@@ -1,6 +0,0 @@
1
- <h1>Editing Clear</h1>
2
-
3
- <%= render 'form', clear: @clear %>
4
-
5
- <%= link_to 'Show', @clear %> |
6
- <%= link_to 'Back', clears_path %>
@@ -1,5 +0,0 @@
1
- <h1>New Clear</h1>
2
-
3
- <%= render 'form', clear: @clear %>
4
-
5
- <%= link_to 'Back', clears_path %>