antispam 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +72 -0
- data/Rakefile +18 -0
- data/app/assets/config/antispam_manifest.js +1 -0
- data/app/assets/images/antispam/captcha/a.gif +0 -0
- data/app/assets/images/antispam/captcha/b.gif +0 -0
- data/app/assets/images/antispam/captcha/blank.gif +0 -0
- data/app/assets/images/antispam/captcha/c.gif +0 -0
- data/app/assets/images/antispam/captcha/d.gif +0 -0
- data/app/assets/images/antispam/captcha/e.gif +0 -0
- data/app/assets/images/antispam/captcha/f.gif +0 -0
- data/app/assets/images/antispam/captcha/g.gif +0 -0
- data/app/assets/images/antispam/captcha/h.gif +0 -0
- data/app/assets/images/antispam/captcha/i.gif +0 -0
- data/app/assets/images/antispam/captcha/j.gif +0 -0
- data/app/assets/images/antispam/captcha/k.gif +0 -0
- data/app/assets/images/antispam/captcha/l.gif +0 -0
- data/app/assets/stylesheets/antispam/application.css +15 -0
- data/app/assets/stylesheets/antispam/blocks.css +4 -0
- data/app/assets/stylesheets/antispam/challenges.css +4 -0
- data/app/assets/stylesheets/antispam/clears.css +4 -0
- data/app/assets/stylesheets/scaffold.css +80 -0
- data/app/controllers/antispam/application_controller.rb +4 -0
- data/app/controllers/antispam/blocks_controller.rb +70 -0
- data/app/controllers/antispam/challenges_controller.rb +49 -0
- data/app/controllers/antispam/clears_controller.rb +63 -0
- data/app/controllers/antispam/validate_controller.rb +12 -0
- data/app/helpers/antispam/application_helper.rb +4 -0
- data/app/helpers/antispam/blocks_helper.rb +4 -0
- data/app/helpers/antispam/challenges_helper.rb +4 -0
- data/app/helpers/antispam/clears_helper.rb +4 -0
- data/app/jobs/antispam/application_job.rb +4 -0
- data/app/mailers/antispam/application_mailer.rb +6 -0
- data/app/models/antispam/application_record.rb +5 -0
- data/app/models/antispam/block.rb +4 -0
- data/app/models/antispam/challenge.rb +26 -0
- data/app/models/antispam/clear.rb +4 -0
- data/app/models/antispam/ip.rb +7 -0
- data/app/views/antispam/blocks/_form.html.erb +37 -0
- data/app/views/antispam/blocks/edit.html.erb +6 -0
- data/app/views/antispam/blocks/index.html.erb +37 -0
- data/app/views/antispam/blocks/new.html.erb +5 -0
- data/app/views/antispam/blocks/show.html.erb +24 -0
- data/app/views/antispam/challenges/_form.html.erb +32 -0
- data/app/views/antispam/challenges/edit.html.erb +6 -0
- data/app/views/antispam/challenges/index.html.erb +31 -0
- data/app/views/antispam/challenges/new.html.erb +5 -0
- data/app/views/antispam/challenges/show.html.erb +19 -0
- data/app/views/antispam/clears/_form.html.erb +42 -0
- data/app/views/antispam/clears/edit.html.erb +6 -0
- data/app/views/antispam/clears/index.html.erb +32 -0
- data/app/views/antispam/clears/new.html.erb +5 -0
- data/app/views/antispam/clears/show.html.erb +29 -0
- data/app/views/antispam/validate/index.html.erb +14 -0
- data/app/views/layouts/antispam/application.html.erb +15 -0
- data/config/routes.rb +7 -0
- data/db/migrate/20210130213708_create_antispam_ips.rb +12 -0
- data/db/migrate/20210130214835_create_antispam_challenges.rb +11 -0
- data/db/migrate/20210130234107_create_antispam_blocks.rb +12 -0
- data/db/migrate/20210130235537_create_antispam_clears.rb +13 -0
- data/lib/antispam.rb +11 -0
- data/lib/antispam/blacklists/httpbl.rb +43 -0
- data/lib/antispam/engine.rb +5 -0
- data/lib/antispam/tools.rb +49 -0
- data/lib/antispam/version.rb +3 -0
- data/lib/tasks/antispam_tasks.rake +4 -0
- metadata +141 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
<% @challenge = Antispam::Challenge.create %>
|
2
|
+
<h1>Human Challenge</h1>
|
3
|
+
|
4
|
+
<p>Please prove that you are human.</p>
|
5
|
+
|
6
|
+
<img src="/antispam/challenges/<%= @challenge.id %>.jpg" width="200" height="40">
|
7
|
+
|
8
|
+
<%= form_for @challenge do |f| %>
|
9
|
+
<%= f.hidden_field :id, value: @challenge.id %>
|
10
|
+
<%= f.text_field :answer, value: '' %>
|
11
|
+
<%= submit_tag "Submit" %>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<% flash.each do |type, msg| %><div><%= msg %></div><% end %>
|
@@ -0,0 +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>
|
data/config/routes.rb
ADDED
data/lib/antispam.rb
ADDED
@@ -0,0 +1,11 @@
|
|
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
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'resolv'
|
2
|
+
module Antispam
|
3
|
+
module Blacklists
|
4
|
+
class Httpbl
|
5
|
+
def self.check(ip, key)
|
6
|
+
threat = 0
|
7
|
+
begin
|
8
|
+
return get_old_result(ip) if get_old_result(ip)
|
9
|
+
check = ip.split('.').reverse.join('.')
|
10
|
+
host = key + '.' + check + ".dnsbl.httpbl.org"
|
11
|
+
address = Resolv::getaddress(host)
|
12
|
+
z,days,threat,iptype = address.split('.')
|
13
|
+
Rails.logger.info "Spam located: #{iptype} type at #{threat} threat. (#{ip} - #{address})"
|
14
|
+
# Create or update
|
15
|
+
if (threat.to_i > 30)
|
16
|
+
Rails.logger.info "Spamcheck: Very high, over 30!"
|
17
|
+
end
|
18
|
+
rescue Exception => e
|
19
|
+
case e
|
20
|
+
when Resolv::ResolvError #Not spam! This blacklist gives an error when there's no spam threat.
|
21
|
+
Rails.logger.info "Spamcheck: OK! Resolve error means the httpbl does not consider this spam."
|
22
|
+
when Interrupt #Something broke while trying to check blacklist.
|
23
|
+
Rails.logger.info "Spamcheck: Interrupt when trying to resolve http blacklist. Possible timeout?"
|
24
|
+
else # Time Out
|
25
|
+
Rails.logger.info "Spamcheck: There was an error, possibly a time out, when checking this IP."
|
26
|
+
Rails.logger.info e.to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
update_old_result(ip, threat)
|
30
|
+
return threat
|
31
|
+
end
|
32
|
+
def self.get_old_result(ip)
|
33
|
+
result = Antispam::Ip.find_by(address: ip, provider: 'httpbl')
|
34
|
+
return nil if (result.nil? || result.expired?)
|
35
|
+
return result.threat
|
36
|
+
end
|
37
|
+
def self.update_old_result(ip, threat)
|
38
|
+
result = Antispam::Ip.find_or_create_by(address: ip, provider: 'httpbl')
|
39
|
+
result.update(threat: threat, expires_at: 24.hours.from_now)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,49 @@
|
|
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
|
+
result = 31
|
31
|
+
if (result > 30)
|
32
|
+
Block.create(ip: ip, provider: provider_name)
|
33
|
+
redirect_to '/antispam/validate'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def skip_if_user_whitelisted
|
40
|
+
if respond_to? :current_user
|
41
|
+
if current_user && current_user.respond_to?(:antispam_whitelisted?)
|
42
|
+
return true if current_user.antispam_whitelisted?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: antispam
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Kopf
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-01-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: image_processing
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
description: Antispam checks DNS blacklists and helps prevent spam on your site.
|
42
|
+
email:
|
43
|
+
- antispam@ryankopf.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- app/assets/config/antispam_manifest.js
|
52
|
+
- app/assets/images/antispam/captcha/a.gif
|
53
|
+
- app/assets/images/antispam/captcha/b.gif
|
54
|
+
- app/assets/images/antispam/captcha/blank.gif
|
55
|
+
- app/assets/images/antispam/captcha/c.gif
|
56
|
+
- app/assets/images/antispam/captcha/d.gif
|
57
|
+
- app/assets/images/antispam/captcha/e.gif
|
58
|
+
- app/assets/images/antispam/captcha/f.gif
|
59
|
+
- app/assets/images/antispam/captcha/g.gif
|
60
|
+
- app/assets/images/antispam/captcha/h.gif
|
61
|
+
- app/assets/images/antispam/captcha/i.gif
|
62
|
+
- app/assets/images/antispam/captcha/j.gif
|
63
|
+
- app/assets/images/antispam/captcha/k.gif
|
64
|
+
- app/assets/images/antispam/captcha/l.gif
|
65
|
+
- app/assets/stylesheets/antispam/application.css
|
66
|
+
- app/assets/stylesheets/antispam/blocks.css
|
67
|
+
- app/assets/stylesheets/antispam/challenges.css
|
68
|
+
- app/assets/stylesheets/antispam/clears.css
|
69
|
+
- app/assets/stylesheets/scaffold.css
|
70
|
+
- app/controllers/antispam/application_controller.rb
|
71
|
+
- app/controllers/antispam/blocks_controller.rb
|
72
|
+
- app/controllers/antispam/challenges_controller.rb
|
73
|
+
- app/controllers/antispam/clears_controller.rb
|
74
|
+
- app/controllers/antispam/validate_controller.rb
|
75
|
+
- app/helpers/antispam/application_helper.rb
|
76
|
+
- app/helpers/antispam/blocks_helper.rb
|
77
|
+
- app/helpers/antispam/challenges_helper.rb
|
78
|
+
- app/helpers/antispam/clears_helper.rb
|
79
|
+
- app/jobs/antispam/application_job.rb
|
80
|
+
- app/mailers/antispam/application_mailer.rb
|
81
|
+
- app/models/antispam/application_record.rb
|
82
|
+
- app/models/antispam/block.rb
|
83
|
+
- app/models/antispam/challenge.rb
|
84
|
+
- app/models/antispam/clear.rb
|
85
|
+
- app/models/antispam/ip.rb
|
86
|
+
- app/views/antispam/blocks/_form.html.erb
|
87
|
+
- app/views/antispam/blocks/edit.html.erb
|
88
|
+
- app/views/antispam/blocks/index.html.erb
|
89
|
+
- app/views/antispam/blocks/new.html.erb
|
90
|
+
- app/views/antispam/blocks/show.html.erb
|
91
|
+
- app/views/antispam/challenges/_form.html.erb
|
92
|
+
- app/views/antispam/challenges/edit.html.erb
|
93
|
+
- app/views/antispam/challenges/index.html.erb
|
94
|
+
- app/views/antispam/challenges/new.html.erb
|
95
|
+
- app/views/antispam/challenges/show.html.erb
|
96
|
+
- app/views/antispam/clears/_form.html.erb
|
97
|
+
- app/views/antispam/clears/edit.html.erb
|
98
|
+
- app/views/antispam/clears/index.html.erb
|
99
|
+
- app/views/antispam/clears/new.html.erb
|
100
|
+
- app/views/antispam/clears/show.html.erb
|
101
|
+
- app/views/antispam/validate/index.html.erb
|
102
|
+
- app/views/layouts/antispam/application.html.erb
|
103
|
+
- config/routes.rb
|
104
|
+
- db/migrate/20210130213708_create_antispam_ips.rb
|
105
|
+
- db/migrate/20210130214835_create_antispam_challenges.rb
|
106
|
+
- db/migrate/20210130234107_create_antispam_blocks.rb
|
107
|
+
- db/migrate/20210130235537_create_antispam_clears.rb
|
108
|
+
- lib/antispam.rb
|
109
|
+
- lib/antispam/blacklists/httpbl.rb
|
110
|
+
- lib/antispam/engine.rb
|
111
|
+
- lib/antispam/tools.rb
|
112
|
+
- lib/antispam/version.rb
|
113
|
+
- lib/tasks/antispam_tasks.rake
|
114
|
+
homepage: https://ryankopf.com
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata:
|
118
|
+
allowed_push_host: https://rubygems.org
|
119
|
+
homepage_uri: https://ryankopf.com
|
120
|
+
source_code_uri: https://github.com/ryankopf/antispam
|
121
|
+
changelog_uri: https://github.com/ryankopf/antispam/CHANGELOG.md
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubygems_version: 3.1.4
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: A spam prevention gem.
|
141
|
+
test_files: []
|