anti_spam 0.0.1
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 +17 -0
- data/Rakefile +32 -0
- data/app/assets/javascripts/anti-spam.js.erb +31 -0
- data/lib/anti_spam.rb +6 -0
- data/lib/anti_spam/protect_from_spam.rb +11 -0
- data/lib/anti_spam/rails.rb +6 -0
- data/lib/anti_spam/rails/engine.rb +7 -0
- data/lib/anti_spam/token.rb +7 -0
- data/lib/anti_spam/version.rb +3 -0
- data/lib/tasks/anti_spam_tasks.rake +4 -0
- data/test/anti_spam_test.rb +7 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/javascripts/messages.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/assets/stylesheets/messages.css +4 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/messages_controller.rb +59 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/messages_helper.rb +2 -0
- data/test/dummy/app/models/message.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/messages/_form.html.erb +33 -0
- data/test/dummy/app/views/messages/edit.html.erb +6 -0
- data/test/dummy/app/views/messages/index.html.erb +31 -0
- data/test/dummy/app/views/messages/new.html.erb +5 -0
- data/test/dummy/app/views/messages/show.html.erb +24 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +78 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20141112021629_create_messages.rb +12 -0
- data/test/dummy/db/schema.rb +25 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +137 -0
- data/test/dummy/log/test.log +3129 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/controllers/messages_controller_test.rb +59 -0
- data/test/dummy/test/fixtures/messages.yml +13 -0
- data/test/dummy/test/helpers/messages_helper_test.rb +4 -0
- data/test/dummy/test/models/message_test.rb +7 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/166b59364f163b12a7bdd7b1ebaba578 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/3362193733e25e7ba2d6efc6975ecc5a +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/88a727f64606316cf6a31e02023ddc52 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/b73fe756e2995808bf07769e4310d04d +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d91b21f330b02be1b32de21393a7ba5b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f8d11c580fbdd5f2beeb040aeb8cd5cb +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/12a72027ac2b5c6d58b42d466fdb6ed9 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/3362193733e25e7ba2d6efc6975ecc5a +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/5ee5f7991cf019a63fddbff773165546 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/75c44f500e9640bb837517858e4e4b55 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/799ee96f672c2a1c42be74193e597131 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/88a727f64606316cf6a31e02023ddc52 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/970cd470f2266362c16433a1454eeeb4 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/b73fe756e2995808bf07769e4310d04d +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/c0e7b185844e51ee81edb6b0283952e6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d91b21f330b02be1b32de21393a7ba5b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/test_helper.rb +19 -0
- metadata +281 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0a7b605acb7bde00ad8bcdd41b0cc289e8c34c7f
|
4
|
+
data.tar.gz: 4024a3f209fb37675412182664b653d0f1aa5028
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f7f9da89f1ea4dc71418fbc9685ae43c792f696e409467576b62659af7074ea4e8d3e60a50cd03d7ff7ecb620e3ff9cb4664397b9300e0aefe2de7b9477d93a4
|
7
|
+
data.tar.gz: b0bbdbb57ab30a853526bbbcbbe8a041b0b29f27bcb498c6825d97e0c087a7ec9afdec2ad60d488c96b78a6236057020ead5abe28a34773397ebe7a1d368f817
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 Rogério Chaves
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# anti-spam
|
2
|
+
|
3
|
+
This gem implements a simple anti-spam on Rails projects based on [David Walsh's solution](http://davidwalsh.name/wordpress-comment-spam). Basically, it stops spam comming from bots that doesn't execute JavaScript (most of them), or only execute the page load JavaScript.
|
4
|
+
|
5
|
+
First, include this gem on your Gemfile:
|
6
|
+
|
7
|
+
gem 'anti_spam'
|
8
|
+
|
9
|
+
Add it to your javascript file, usually application.js
|
10
|
+
|
11
|
+
//= require anti-spam
|
12
|
+
|
13
|
+
Then add the protect\_from\_spam filter on the desired actions
|
14
|
+
|
15
|
+
before_action :protect_from_spam, only: [:create, :update]
|
16
|
+
|
17
|
+
That's it! Be aware that users without JavaScript will be considered bots, but nowadays that's very rare, chances are that it's really a bot.
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'AntiSpam'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task default: :test
|
@@ -0,0 +1,31 @@
|
|
1
|
+
(function(){
|
2
|
+
|
3
|
+
var antiSpamizeForms = function(){
|
4
|
+
var forms = document.querySelectorAll("form");
|
5
|
+
for(var i = 0, max = forms.length; i < max; i++){
|
6
|
+
var form = forms[i];
|
7
|
+
form.onsubmit = function(){
|
8
|
+
if(form.querySelectorAll('input.antispam_token').length == 0){
|
9
|
+
var input = document.createElement('input');
|
10
|
+
input.type = 'hidden';
|
11
|
+
input.name = 'antispam_token';
|
12
|
+
input.className = 'antispam_token'
|
13
|
+
input.value = '<%= AntiSpam.token %>';
|
14
|
+
form.appendChild(input);
|
15
|
+
form.submit();
|
16
|
+
return false;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
if(document.attachEvent){
|
23
|
+
document.attachEvent("onreadystatechange", antiSpamizeForms);
|
24
|
+
document.attachEvent("onload", antiSpamizeForms);
|
25
|
+
}else{
|
26
|
+
document.addEventListener('DOMContentLoaded', antiSpamizeForms, false);
|
27
|
+
document.addEventListener('load', antiSpamizeForms, false);
|
28
|
+
document.addEventListener('page:load', antiSpamizeForms, false); // for turbolinks
|
29
|
+
}
|
30
|
+
|
31
|
+
})();
|
data/lib/anti_spam.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module AntiSpam
|
2
|
+
module ProtectFromSpam
|
3
|
+
def protect_from_spam
|
4
|
+
if params[:antispam_token] != AntiSpam.token
|
5
|
+
render text: "Spam not allowed, please enable your JavaScript", status: 403
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
ActionController::Base.send :include, AntiSpam::ProtectFromSpam
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require anti-spam
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,56 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
div.field, div.actions {
|
20
|
+
margin-bottom: 10px;
|
21
|
+
}
|
22
|
+
|
23
|
+
#notice {
|
24
|
+
color: green;
|
25
|
+
}
|
26
|
+
|
27
|
+
.field_with_errors {
|
28
|
+
padding: 2px;
|
29
|
+
background-color: red;
|
30
|
+
display: table;
|
31
|
+
}
|
32
|
+
|
33
|
+
#error_explanation {
|
34
|
+
width: 450px;
|
35
|
+
border: 2px solid red;
|
36
|
+
padding: 7px;
|
37
|
+
padding-bottom: 0;
|
38
|
+
margin-bottom: 20px;
|
39
|
+
background-color: #f0f0f0;
|
40
|
+
}
|
41
|
+
|
42
|
+
#error_explanation h2 {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
padding: 5px 5px 5px 15px;
|
46
|
+
font-size: 12px;
|
47
|
+
margin: -7px;
|
48
|
+
margin-bottom: 0px;
|
49
|
+
background-color: #c00;
|
50
|
+
color: #fff;
|
51
|
+
}
|
52
|
+
|
53
|
+
#error_explanation ul li {
|
54
|
+
font-size: 12px;
|
55
|
+
list-style: square;
|
56
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class MessagesController < ApplicationController
|
2
|
+
before_action :set_message, only: [:show, :edit, :update, :destroy]
|
3
|
+
before_action :protect_from_spam, only: [:create, :update]
|
4
|
+
|
5
|
+
# GET /messages
|
6
|
+
def index
|
7
|
+
@messages = Message.all
|
8
|
+
end
|
9
|
+
|
10
|
+
# GET /messages/1
|
11
|
+
def show
|
12
|
+
end
|
13
|
+
|
14
|
+
# GET /messages/new
|
15
|
+
def new
|
16
|
+
@message = Message.new
|
17
|
+
end
|
18
|
+
|
19
|
+
# GET /messages/1/edit
|
20
|
+
def edit
|
21
|
+
end
|
22
|
+
|
23
|
+
# POST /messages
|
24
|
+
def create
|
25
|
+
@message = Message.new(message_params)
|
26
|
+
|
27
|
+
if @message.save
|
28
|
+
redirect_to @message, notice: 'Message was successfully created.'
|
29
|
+
else
|
30
|
+
render :new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# PATCH/PUT /messages/1
|
35
|
+
def update
|
36
|
+
if @message.update(message_params)
|
37
|
+
redirect_to @message, notice: 'Message was successfully updated.'
|
38
|
+
else
|
39
|
+
render :edit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# DELETE /messages/1
|
44
|
+
def destroy
|
45
|
+
@message.destroy
|
46
|
+
redirect_to messages_url, notice: 'Message was successfully destroyed.'
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
# Use callbacks to share common setup or constraints between actions.
|
51
|
+
def set_message
|
52
|
+
@message = Message.find(params[:id])
|
53
|
+
end
|
54
|
+
|
55
|
+
# Only allow a trusted parameter "white list" through.
|
56
|
+
def message_params
|
57
|
+
params.require(:message).permit(:name, :email, :telephone, :message)
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<%= form_for(@message) do |f| %>
|
2
|
+
<% if @message.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@message.errors.count, "error") %> prohibited this message from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @message.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.label :name %><br>
|
16
|
+
<%= f.text_field :name %>
|
17
|
+
</div>
|
18
|
+
<div class="field">
|
19
|
+
<%= f.label :email %><br>
|
20
|
+
<%= f.text_field :email %>
|
21
|
+
</div>
|
22
|
+
<div class="field">
|
23
|
+
<%= f.label :telephone %><br>
|
24
|
+
<%= f.text_field :telephone %>
|
25
|
+
</div>
|
26
|
+
<div class="field">
|
27
|
+
<%= f.label :message %><br>
|
28
|
+
<%= f.text_area :message %>
|
29
|
+
</div>
|
30
|
+
<div class="actions">
|
31
|
+
<%= f.submit %>
|
32
|
+
</div>
|
33
|
+
<% end %>
|