guardian-forms 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/.rvmrc +0 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/guardian.gemspec +19 -0
- data/lib/guardian.rb +26 -0
- data/lib/guardian/engine.rb +4 -0
- data/lib/guardian/version.rb +3 -0
- data/vendor/assets/.DS_Store +0 -0
- data/vendor/assets/javascripts/jquery.guardian.js +29 -0
- metadata +75 -0
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rvmrc
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Forrest Grant
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
Guardian
|
2
|
+
====================
|
3
|
+
|
4
|
+
Guardian protects web forms from spam. By adding a hidden input field that counts up, guardian will reject submissions with a duration less than any threshold we deem appropriate (defualt is 2 seconds).
|
5
|
+
|
6
|
+
|
7
|
+
## Install
|
8
|
+
### RubyGems.org
|
9
|
+
$ gem install guardian-forms
|
10
|
+
|
11
|
+
### from source
|
12
|
+
$ git clone http://github.com/forrestgrant/guardian
|
13
|
+
$ cd guardian
|
14
|
+
$ rake build
|
15
|
+
$ rake install
|
16
|
+
|
17
|
+
Usage
|
18
|
+
==========
|
19
|
+
|
20
|
+
Set a before filter in your controller
|
21
|
+
|
22
|
+
before_filter :guard
|
23
|
+
|
24
|
+
Or
|
25
|
+
|
26
|
+
before_filter { |c| c.guard({:threshold => 5})} # 5 seconds
|
27
|
+
|
28
|
+
Add guardian to `application.js`
|
29
|
+
|
30
|
+
//= require jquery.guardian
|
31
|
+
|
32
|
+
Set Guard specific forms in views
|
33
|
+
|
34
|
+
$('form').guard();
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/guardian.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'guardian/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "guardian-forms"
|
8
|
+
gem.version = Guardian::VERSION
|
9
|
+
gem.authors = ["Forrest Grant"]
|
10
|
+
gem.email = ["forrest@forrestgrant.com"]
|
11
|
+
gem.description = "Protect web forms form spam."
|
12
|
+
gem.summary = "Protect your forms from spam, by adding a duration field, if it takes less than 2 seconds to submit the form, it is likely spam."
|
13
|
+
gem.homepage = "https://github.com/forrestgrant/guardian"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
data/lib/guardian.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "guardian/version"
|
2
|
+
require 'guardian/engine'
|
3
|
+
ActionController::Base.send(:include, Guardian)
|
4
|
+
|
5
|
+
module Guardian
|
6
|
+
|
7
|
+
def guard(vars = { :threshold => 2})
|
8
|
+
if guarded?(params)
|
9
|
+
if params[:duration].to_i < vars[:threshold]
|
10
|
+
logger.info "\n"
|
11
|
+
logger.info "+++++++++++++++++++++++++++++++++++++"
|
12
|
+
logger.info "GUARDIAN IS REJECTION FORM SUBMISSION"
|
13
|
+
logger.info "Page duration: #{params[:duration]}"
|
14
|
+
logger.info "Threhold: #{vars[:threshold]}"
|
15
|
+
logger.info "+++++++++++++++++++++++++++++++++++++"
|
16
|
+
logger.info "\n"
|
17
|
+
redirect_to "/"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def guarded?(params)
|
23
|
+
params.keys.include?('duration')
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
Binary file
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/*
|
2
|
+
* Guardian - jQuery plugin for protecting forms from spam
|
3
|
+
*
|
4
|
+
* Copyright (c) 2012 Forrest Grant
|
5
|
+
*
|
6
|
+
* Dual licensed under the MIT and GPL licenses:
|
7
|
+
* http://www.opensource.org/licenses/mit-license.php
|
8
|
+
* http://www.gnu.org/licenses/gpl.html
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
|
12
|
+
(function($){
|
13
|
+
$.fn.guard = function(options) {
|
14
|
+
var defaults = {
|
15
|
+
threshold: 2
|
16
|
+
};
|
17
|
+
var options = $.extend(defaults, options);
|
18
|
+
this.each(function() {
|
19
|
+
$(this).append($('<input type="hidden" name="duration" id="guardian-duration" value="0" />'));
|
20
|
+
setInterval((function() {
|
21
|
+
$('input[name=duration]').val(parseInt($('input[name=duration]').val()) + 1);
|
22
|
+
}), 1000);
|
23
|
+
$(this).submit(function(e){
|
24
|
+
if (parseInt($('#guardian-duration').val()) < options.threshold) e.preventDefault();
|
25
|
+
});
|
26
|
+
});
|
27
|
+
return this;
|
28
|
+
};
|
29
|
+
})(jQuery);
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guardian-forms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Forrest Grant
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2013-05-03 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Protect web forms form spam.
|
22
|
+
email:
|
23
|
+
- forrest@forrestgrant.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .DS_Store
|
32
|
+
- .gitignore
|
33
|
+
- .rvmrc
|
34
|
+
- Gemfile
|
35
|
+
- LICENSE.txt
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- guardian.gemspec
|
39
|
+
- lib/guardian.rb
|
40
|
+
- lib/guardian/engine.rb
|
41
|
+
- lib/guardian/version.rb
|
42
|
+
- vendor/assets/.DS_Store
|
43
|
+
- vendor/assets/javascripts/jquery.guardian.js
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: https://github.com/forrestgrant/guardian
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.3.6
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Protect your forms from spam, by adding a duration field, if it takes less than 2 seconds to submit the form, it is likely spam.
|
74
|
+
test_files: []
|
75
|
+
|