antispam 0.1.5 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +46 -5
- data/app/controllers/antispam/challenges_controller.rb +1 -0
- data/app/views/antispam/blocks/index.html.erb +1 -1
- data/lib/antispam/blacklists/httpbl.rb +7 -6
- data/lib/antispam/checker.rb +20 -0
- data/lib/antispam/results.rb +10 -0
- data/lib/antispam/spamcheckers/defendium.rb +29 -0
- data/lib/antispam/tools.rb +4 -2
- data/lib/antispam/version.rb +1 -1
- data/lib/antispam.rb +3 -0
- metadata +22 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 636c6cfd1e3a5c84182eaa1e19966e553a2098c4f3a01a049cdbe4613165a52e
|
4
|
+
data.tar.gz: 8a53d23ef78da214962bd81411a97a720d5eba3a15817d3f7ccd5bfac81719ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4d6e23e0432af6b62b7cd9e469c2393a9e4f4513b13d93d282e6841062bd706d70fa44dd6bed0d79658da80ff52827ee8ba9d63baa0a84df2112a7fd313b3dd
|
7
|
+
data.tar.gz: 9ca4921062395565e50fa29daf9d56bd3e691b5a675fb34bc4d6ec5e1378da1f3be5b19bdc73294be7fcb55b8e3d766819c140ef45b602d8904818eccf10f187
|
data/README.md
CHANGED
@@ -1,9 +1,29 @@
|
|
1
1
|
# Antispam
|
2
2
|
The antispam gem helps prevent spam in your Rails applications by
|
3
|
-
|
4
|
-
|
3
|
+
providing tools that check spam against powerful spam-prevention
|
4
|
+
databases, accessible for free.
|
5
5
|
|
6
|
-
|
6
|
+
The first feature checks against an IP database of spam, allowing you
|
7
|
+
to stop spammers who are prolific and have been detected on other websites.
|
8
|
+
It uses the blazing fast Defendium API to quickly determine if submitted
|
9
|
+
content is spam or not.
|
10
|
+
|
11
|
+
The second feature allows you to submit user-provided content to a spam
|
12
|
+
checking service that uses machine learning and a database of content to
|
13
|
+
determine whether the user's submitted content is spam.
|
14
|
+
|
15
|
+
## Spam Content Checking - Usage
|
16
|
+
|
17
|
+
```
|
18
|
+
result = Antispam::Checker.check(content: @comment.body)
|
19
|
+
if result.is_spam?
|
20
|
+
@comment.save
|
21
|
+
else
|
22
|
+
redirect_to "/access_denied"
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
## Bad IP Checking - Usage
|
7
27
|
|
8
28
|
The gem is used by adding this to your ApplicationController.rb
|
9
29
|
|
@@ -13,8 +33,18 @@ before_action do
|
|
13
33
|
end
|
14
34
|
```
|
15
35
|
|
36
|
+
Codes are from the [httpbl](https://www.projecthoneypot.org/httpbl.php) at projecthoneypot.org
|
37
|
+
|
16
38
|
Once the filter is setup, everything else is handled for your application.
|
17
|
-
|
39
|
+
By default the gem will run during any request that is not a GET request.
|
40
|
+
|
41
|
+
You can change the filter to run during other requests.
|
42
|
+
|
43
|
+
```
|
44
|
+
before_action do
|
45
|
+
check_ip_against_database(ip_blacklists: {default: 'yourcodehere'}, methods: [:get,:post,:put,:patch,:delete])
|
46
|
+
end
|
47
|
+
```
|
18
48
|
|
19
49
|
Blacklist database lookups are cached for 24 hours, and cached results won't need
|
20
50
|
to slowdown your app by additional http requests on the backend.
|
@@ -27,7 +57,7 @@ You need to add this to your routes.rb
|
|
27
57
|
mount Antispam::Engine => "/antispam"
|
28
58
|
```
|
29
59
|
You can see what IP addresses have been blocked by going to /antispam/blocks
|
30
|
-
but your
|
60
|
+
but your ApplicationController.rb must respond to ```is_admin?``` function.
|
31
61
|
|
32
62
|
|
33
63
|
## Installation
|
@@ -70,3 +100,14 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
70
100
|
## Code of Conduct
|
71
101
|
|
72
102
|
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).
|
103
|
+
|
104
|
+
## NO WARRANTY
|
105
|
+
|
106
|
+
THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY KIND,
|
107
|
+
EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO,
|
108
|
+
ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO SPECIFICATIONS,
|
109
|
+
ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
|
110
|
+
OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL BE
|
111
|
+
ERROR FREE, OR ANY WARRANTY THAT DOCUMENTATION, IF PROVIDED, WILL CONFORM TO
|
112
|
+
THE SUBJECT SOFTWARE. THIS SOFTWARE IS PROVIDED "AS IS." IF YOUR JURISDICTION
|
113
|
+
DOES NOT ALLOW THESE LIMITATIONS THEN YOU MAY NOT USE THE SOFTWARE.
|
@@ -15,19 +15,20 @@ module Antispam
|
|
15
15
|
address = Resolv::getaddress(host)
|
16
16
|
z,days,threat,iptype = address.split('.')
|
17
17
|
Rails.logger.info "Spam located: #{iptype} type at #{threat} threat. (#{ip} - #{address})" if verbose
|
18
|
+
threat = threat.to_i
|
18
19
|
# Create or update
|
19
|
-
if (threat
|
20
|
-
Rails.logger.info "Spamcheck: Very high, over 30!"
|
20
|
+
if (threat > 30)
|
21
|
+
Rails.logger.info "Spamcheck: Very high, over 30!" if verbose
|
21
22
|
end
|
22
23
|
rescue Exception => e
|
23
24
|
case e
|
24
25
|
when Resolv::ResolvError #Not spam! This blacklist gives an error when there's no spam threat.
|
25
|
-
Rails.logger.info "Spamcheck: OK! Resolve error means the httpbl does not consider this spam."
|
26
|
+
Rails.logger.info "Spamcheck: OK! Resolve error means the httpbl does not consider this spam." if verbose
|
26
27
|
when Interrupt #Something broke while trying to check blacklist.
|
27
|
-
Rails.logger.info "Spamcheck: Interrupt when trying to resolve http blacklist. Possible timeout?"
|
28
|
+
Rails.logger.info "Spamcheck: Interrupt when trying to resolve http blacklist. Possible timeout?" if verbose
|
28
29
|
else # Time Out
|
29
|
-
Rails.logger.info "Spamcheck: There was an error, possibly a time out, when checking this IP."
|
30
|
-
Rails.logger.info e.to_s
|
30
|
+
Rails.logger.info "Spamcheck: There was an error, possibly a time out, when checking this IP." if verbose
|
31
|
+
Rails.logger.info e.to_s if verbose
|
31
32
|
end
|
32
33
|
end
|
33
34
|
update_old_result(ip, threat)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Antispam
|
2
|
+
module Checker
|
3
|
+
# Checks content for spam
|
4
|
+
# check(options, spamcheck_providers)
|
5
|
+
# Usage: check({content: "No spam here"}, {defendium: 'MY_API_KEY'}})
|
6
|
+
def self.check(options = {}, spamcheck_providers = {defendium: 'YOUR_KEY'})
|
7
|
+
Rails.logger.info "Content was nil for spamcheck." if options[:content].nil? && options[:verbose]
|
8
|
+
return if options[:content].nil?
|
9
|
+
Rails.logger.info "Spamcheckers should be a hash" if (!(options[:spamcheck_providers].is_a? Hash)) && options[:verbose]
|
10
|
+
results = []
|
11
|
+
spamcheck_providers.each do |spamchecker_name, spamchecker_api_key|
|
12
|
+
if spamchecker_name == :defendium
|
13
|
+
results.append Antispam::Spamcheckers::Defendium.check(options[:content], spamchecker_api_key, options[:verbose])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
result = Antispam::SpamcheckResult.new(results)
|
17
|
+
return result
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#require 'resolv'
|
2
|
+
module Antispam
|
3
|
+
module Spamcheckers
|
4
|
+
class Defendium
|
5
|
+
def self.check(content, key, verbose)
|
6
|
+
# nethttp2.rb
|
7
|
+
require 'uri'
|
8
|
+
require 'net/http'
|
9
|
+
|
10
|
+
uri = URI('https://api.defendium.com/check')
|
11
|
+
params = { secret_key: key, content: content }
|
12
|
+
uri.query = URI.encode_www_form(params)
|
13
|
+
|
14
|
+
res = Net::HTTP.get_response(uri)
|
15
|
+
if res.is_a?(Net::HTTPSuccess)
|
16
|
+
result = res.body.to_json
|
17
|
+
if result["warnings"]
|
18
|
+
Rails.logger.info result["warnings"]
|
19
|
+
end
|
20
|
+
if result["result"]
|
21
|
+
return 1
|
22
|
+
else
|
23
|
+
return 0
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/antispam/tools.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Antispam
|
2
2
|
module Tools
|
3
|
-
#
|
3
|
+
# Checks spam against an IP database of spammers.
|
4
|
+
# Usage: before_action :check_ip_against_database
|
4
5
|
def check_ip_against_database(options = {ip_blacklists: {default: ''}})
|
5
6
|
if (options[:methods])
|
6
7
|
return if request.get? unless options[:methods].include?(:get)
|
@@ -28,9 +29,10 @@ module Antispam
|
|
28
29
|
end
|
29
30
|
Rails.logger.info "Completed IP database check. #{ip}" if options[:verbose]
|
30
31
|
end
|
32
|
+
# Checks the specific blacklists
|
31
33
|
def check_ip_against_blacklists(ip, lists, verbose)
|
32
34
|
lists.each do |provider_name, provider_api_key|
|
33
|
-
|
35
|
+
Rails.logger.info "Checking provider: #{provider_name}" if verbose
|
34
36
|
if provider_name == :httpbl
|
35
37
|
result = Antispam::Blacklists::Httpbl.check(ip, provider_api_key, verbose)
|
36
38
|
Rails.logger.info(result) if verbose
|
data/lib/antispam/version.rb
CHANGED
data/lib/antispam.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require "antispam/version"
|
2
2
|
require "antispam/engine"
|
3
3
|
require "antispam/tools"
|
4
|
+
require "antispam/checker"
|
4
5
|
require "antispam/blacklists/httpbl"
|
6
|
+
require "antispam/spamcheckers/defendium"
|
7
|
+
require "antispam/results"
|
5
8
|
|
6
9
|
module Antispam
|
7
10
|
ActiveSupport.on_load(:action_controller) do
|
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
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Kopf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 6.
|
19
|
+
version: 6.1.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.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: image_processing
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: net-http
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: Antispam checks DNS blacklists and helps prevent spam on your site.
|
42
56
|
email:
|
43
57
|
- antispam@ryankopf.com
|
@@ -102,7 +116,10 @@ files:
|
|
102
116
|
- db/migrate/20210131165122_add_threat_to_antispam_blocks.rb
|
103
117
|
- lib/antispam.rb
|
104
118
|
- lib/antispam/blacklists/httpbl.rb
|
119
|
+
- lib/antispam/checker.rb
|
105
120
|
- lib/antispam/engine.rb
|
121
|
+
- lib/antispam/results.rb
|
122
|
+
- lib/antispam/spamcheckers/defendium.rb
|
106
123
|
- lib/antispam/tools.rb
|
107
124
|
- lib/antispam/version.rb
|
108
125
|
- lib/tasks/antispam_tasks.rake
|
@@ -129,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
146
|
- !ruby/object:Gem::Version
|
130
147
|
version: '0'
|
131
148
|
requirements: []
|
132
|
-
rubygems_version: 3.
|
149
|
+
rubygems_version: 3.4.4
|
133
150
|
signing_key:
|
134
151
|
specification_version: 4
|
135
152
|
summary: A spam prevention gem.
|