antispam 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +72 -72
- data/app/controllers/antispam/application_controller.rb +8 -1
- data/app/controllers/antispam/blocks_controller.rb +28 -70
- data/app/controllers/antispam/challenges_controller.rb +49 -49
- data/app/controllers/antispam/clears_controller.rb +28 -63
- data/app/views/antispam/blocks/index.html.erb +38 -36
- data/app/views/antispam/clears/index.html.erb +32 -32
- data/app/views/layouts/antispam/application.html.erb +15 -15
- data/db/migrate/20210131165122_add_threat_to_antispam_blocks.rb +5 -0
- data/lib/antispam.rb +4 -1
- data/lib/antispam/blacklists/httpbl.rb +7 -3
- data/lib/antispam/tools.rb +13 -7
- data/lib/antispam/version.rb +1 -1
- metadata +7 -12
- data/app/views/antispam/blocks/_form.html.erb +0 -37
- data/app/views/antispam/blocks/edit.html.erb +0 -6
- data/app/views/antispam/blocks/new.html.erb +0 -5
- data/app/views/antispam/clears/_form.html.erb +0 -42
- data/app/views/antispam/clears/edit.html.erb +0 -6
- data/app/views/antispam/clears/new.html.erb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 278c21161c08ebd08f8376df6ddb57fcda33d20d7ae9e9d804a7b3785c23cbae
|
4
|
+
data.tar.gz: dab176fb46e3d5ecaa6d2c304262adfc4bf612f413b392270e3b44ef03de7147
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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,4 +1,11 @@
|
|
1
1
|
module Antispam
|
2
|
-
class ApplicationController <
|
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
|
3
10
|
end
|
4
11
|
end
|
@@ -1,70 +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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
#
|
30
|
-
# if @block.save
|
31
|
-
# redirect_to @block, notice: 'Block was successfully created.'
|
32
|
-
# else
|
33
|
-
# render :new
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
#
|
37
|
-
# # PATCH/PUT /blocks/1
|
38
|
-
# def update
|
39
|
-
# if @block.update(block_params)
|
40
|
-
# redirect_to @block, notice: 'Block was successfully updated.'
|
41
|
-
# else
|
42
|
-
# render :edit
|
43
|
-
# end
|
44
|
-
# end
|
45
|
-
#
|
46
|
-
# # DELETE /blocks/1
|
47
|
-
# def destroy
|
48
|
-
# @block.destroy
|
49
|
-
# redirect_to blocks_url, notice: 'Block was successfully destroyed.'
|
50
|
-
# end
|
51
|
-
|
52
|
-
private
|
53
|
-
# Use callbacks to share common setup or constraints between actions.
|
54
|
-
def set_block
|
55
|
-
@block = Block.find(params[:id])
|
56
|
-
end
|
57
|
-
|
58
|
-
# Only allow a list of trusted parameters through.
|
59
|
-
def block_params
|
60
|
-
params.require(:block).permit(:ip, :provider, :controllername, :actionname)
|
61
|
-
end
|
62
|
-
def must_be_admin
|
63
|
-
begin
|
64
|
-
return false unless user_has_role?("admin")
|
65
|
-
rescue
|
66
|
-
return false
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
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,63 +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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
#
|
30
|
-
# if @clear.save
|
31
|
-
# redirect_to @clear, notice: 'Clear was successfully created.'
|
32
|
-
# else
|
33
|
-
# render :new
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
#
|
37
|
-
# # PATCH/PUT /clears/1
|
38
|
-
# def update
|
39
|
-
# if @clear.update(clear_params)
|
40
|
-
# redirect_to @clear, notice: 'Clear was successfully updated.'
|
41
|
-
# else
|
42
|
-
# render :edit
|
43
|
-
# end
|
44
|
-
# end
|
45
|
-
#
|
46
|
-
# # DELETE /clears/1
|
47
|
-
# def destroy
|
48
|
-
# @clear.destroy
|
49
|
-
# redirect_to clears_url, notice: 'Clear was successfully destroyed.'
|
50
|
-
# end
|
51
|
-
|
52
|
-
private
|
53
|
-
# Use callbacks to share common setup or constraints between actions.
|
54
|
-
def set_clear
|
55
|
-
@clear = Clear.find(params[:id])
|
56
|
-
end
|
57
|
-
|
58
|
-
# Only allow a list of trusted parameters through.
|
59
|
-
def clear_params
|
60
|
-
params.require(:clear).permit(:ip, :result, :answer, :threat_before, :threat_after)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
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,37 +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
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
<td><%= block.
|
23
|
-
<td><%= block.
|
24
|
-
<td><%= block.
|
25
|
-
<td><%=
|
26
|
-
|
27
|
-
|
28
|
-
<!-- <td><%#= link_to '
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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>
|
37
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(
|
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>
|
data/lib/antispam.rb
CHANGED
@@ -6,6 +6,9 @@ require "antispam/blacklists/httpbl"
|
|
6
6
|
module Antispam
|
7
7
|
ActiveSupport.on_load(:action_controller) do
|
8
8
|
# self refers to ActionController::Base here
|
9
|
-
|
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)
|
10
13
|
end
|
11
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
|
-
|
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!"
|
data/lib/antispam/tools.rb
CHANGED
@@ -2,7 +2,15 @@ module Antispam
|
|
2
2
|
module Tools
|
3
3
|
# before_action :check_ip_against_database
|
4
4
|
def check_ip_against_database(options = {ip_blacklists: {default: ''}})
|
5
|
-
|
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
|
6
14
|
return if skip_if_user_whitelisted
|
7
15
|
return if controller_name == "validate"
|
8
16
|
ip = request.remote_ip
|
@@ -18,18 +26,16 @@ module Antispam
|
|
18
26
|
if (options[:scrutinize_countries_except])
|
19
27
|
|
20
28
|
end
|
21
|
-
Rails.logger.info "
|
22
|
-
puts "Got to this function. #{ip}"
|
29
|
+
Rails.logger.info "Completed IP database check. #{ip}" if options[:verbose]
|
23
30
|
end
|
24
31
|
def check_ip_against_blacklists(ip, lists, verbose)
|
25
32
|
lists.each do |provider_name, provider_api_key|
|
26
33
|
puts "Checking provider: #{provider_name}" if verbose
|
27
34
|
if provider_name == :httpbl
|
28
|
-
result = Antispam::Blacklists::Httpbl.check(ip, provider_api_key)
|
29
|
-
|
30
|
-
result = 31
|
35
|
+
result = Antispam::Blacklists::Httpbl.check(ip, provider_api_key, verbose)
|
36
|
+
Rails.logger.info(result) if verbose
|
31
37
|
if (result > 30)
|
32
|
-
Block.create(ip: ip, provider: provider_name)
|
38
|
+
Block.create(ip: ip, provider: provider_name, threat: result)
|
33
39
|
redirect_to '/antispam/validate'
|
34
40
|
end
|
35
41
|
end
|
data/lib/antispam/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: antispam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
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-
|
11
|
+
date: 2021-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 6.
|
19
|
+
version: 6.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 6.
|
26
|
+
version: 6.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: image_processing
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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
|
@@ -105,6 +99,7 @@ files:
|
|
105
99
|
- db/migrate/20210130214835_create_antispam_challenges.rb
|
106
100
|
- db/migrate/20210130234107_create_antispam_blocks.rb
|
107
101
|
- db/migrate/20210130235537_create_antispam_clears.rb
|
102
|
+
- db/migrate/20210131165122_add_threat_to_antispam_blocks.rb
|
108
103
|
- lib/antispam.rb
|
109
104
|
- lib/antispam/blacklists/httpbl.rb
|
110
105
|
- lib/antispam/engine.rb
|
@@ -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,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 %>
|