rack-pesticide 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.md +29 -0
- data/Rakefile +41 -0
- data/data/pests.txt +13 -0
- data/lib/rack-pesticide.rb +1 -0
- data/lib/rack/pesticide.rb +37 -0
- data/lib/rack/pesticide/version.rb +5 -0
- data/rack-pesticide.gemspec +33 -0
- data/spec/pest_spec.rb +82 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a759411e967f9fcf012e492628b75d75db9edbab
|
4
|
+
data.tar.gz: 479693fcdff7d7b0aae6b739557b8c63c019c038
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ccbaa818aa1168da6e3f65e65e2abf0f73849ce662bff7aaec0846928354d792a3e40d3d9ac44bbe6f3079f0d6fc2c3e913cb517bab7130312c2043fffbc5363
|
7
|
+
data.tar.gz: 8f2c05084f5d3777dcb3bff98263421677e4f205777b0b3c37fa59d214e0347550e6a31687556ea1d6451774e4b201056f93cfa193200aa57c36e1e7f393f6c6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Michael Dippery <michael@monkey-robot.com>
|
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,29 @@
|
|
1
|
+
# Rack Pesticide
|
2
|
+
|
3
|
+
Rack Pesticide blocks annoying and shady crawlers and websites that pollute
|
4
|
+
your logs with their HTTP referrer information.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'rack-pesticide', :git => 'https://github.com/mdippery/rack-pesticide.git'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Simply add these two lines of code to your `config.ru` file:
|
19
|
+
|
20
|
+
require 'rack-pesticide'
|
21
|
+
use Rack::Pesticide
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. [Fork it](http://github.com/mdippery/rack-pesticide/fork)
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new pull request
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'rack/pesticide/version'
|
4
|
+
|
5
|
+
GEMNAME = 'rack-pesticide'
|
6
|
+
GEMVER = Rack::Pesticide::VERSION
|
7
|
+
GEMSPEC = `git ls-files | grep gemspec`.chomp
|
8
|
+
GEM = "#{GEMNAME}-#{GEMVER}.gem"
|
9
|
+
|
10
|
+
desc "Build #{GEMNAME}.gem"
|
11
|
+
task :build => :perms do
|
12
|
+
system "gem", "build", GEMSPEC
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Ensure correct permissions for #{GEMNAME}.gem"
|
16
|
+
task :perms do
|
17
|
+
system "chmod", "-R", "a+rX", *`git ls-files`.chomp.split("\n")
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Tag the latest version of #{GEMNAME}"
|
21
|
+
task :tag do
|
22
|
+
system "git", "tag", "-s", "-m", "#{GEMNAME} v#{GEMVER}", "v#{GEMVER}"
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Install #{GEMNAME}"
|
26
|
+
task :install => :build do
|
27
|
+
system "gem", "install", GEM
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Push gem to RubyGems"
|
31
|
+
task :release => [:tag, :build] do
|
32
|
+
fail 'Cannot release a dev version' if GEMVER.end_with?('dev')
|
33
|
+
system "gem", "push", GEM
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Clean built products"
|
37
|
+
task :clean do
|
38
|
+
rm Dir.glob("*.gem"), :verbose => true
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :build
|
data/data/pests.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
semalt\.com\/crawler\.php
|
2
|
+
semaltmedia\.com
|
3
|
+
buttons-for-website\.com
|
4
|
+
makemoneyonline\.com
|
5
|
+
buttons-for-your-website\.com
|
6
|
+
best-seo-offer\.com
|
7
|
+
100dollars-seo\.com
|
8
|
+
videos-for-your-business\.com
|
9
|
+
video--production\.com
|
10
|
+
justprofit\.xyz
|
11
|
+
phatvidz\.com
|
12
|
+
free-video-tool\.com
|
13
|
+
1-free-share-buttons\.com
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack/pesticide'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Rack
|
2
|
+
class Pesticide
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
if pest?(env)
|
9
|
+
forbidden
|
10
|
+
else
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def forbidden
|
18
|
+
[403, {"Content-Type" => "text/plain"}, ["Pest, be gone!\r\n"]]
|
19
|
+
end
|
20
|
+
|
21
|
+
def pest?(env)
|
22
|
+
referer = env['HTTP_REFERER'] || ''
|
23
|
+
pests.map { |p| referer =~ p }.any?
|
24
|
+
end
|
25
|
+
|
26
|
+
def pests
|
27
|
+
@pests ||= load_pests
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_pests
|
31
|
+
path = ::File.expand_path('../../../data/pests.txt', __FILE__)
|
32
|
+
::File.open(path, 'r') do |fh|
|
33
|
+
fh.each_line.map { |line| /#{line.chomp}/ }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'rack/pesticide/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "rack-pesticide"
|
10
|
+
spec.version = Rack::Pesticide::VERSION
|
11
|
+
spec.licenses = ["MIT"]
|
12
|
+
spec.authors = ["Michael Dippery"]
|
13
|
+
spec.email = ["michael@monkey-robot.com"]
|
14
|
+
spec.homepage = "https://github.com/mdippery/rack-pesticide"
|
15
|
+
spec.description = %q{Block crawlers who spam your site with fake HTTP referers}
|
16
|
+
spec.summary = %q{Rack middleware to block annoying and pesky HTTP referers}
|
17
|
+
|
18
|
+
spec.metadata = {
|
19
|
+
'build_date' => Time.now.strftime("%Y-%m-%d %H:%M:%S %Z"),
|
20
|
+
'commit' => `git describe`.chomp,
|
21
|
+
'commit_hash' => `git rev-parse HEAD`.chomp,
|
22
|
+
}
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0")
|
25
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
26
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.required_ruby_version = '>= 1.9.3'
|
30
|
+
|
31
|
+
spec.add_development_dependency("rack")
|
32
|
+
spec.add_development_dependency("rspec", "~> 3.3")
|
33
|
+
end
|
data/spec/pest_spec.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'rack-pesticide'
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
|
6
|
+
describe "rack-pesticide" do
|
7
|
+
def app
|
8
|
+
Rack::Pesticide.new(nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#pest?" do
|
12
|
+
it "should allow 'good' referers" do
|
13
|
+
env = {'HTTP_REFERER' => 'http://reddit.com/'}
|
14
|
+
expect(app.send(:pest?, env)).to be false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should block the semalt.com crawler" do
|
18
|
+
env = {'HTTP_REFERER' => 'http://semalt.com/crawler.php'}
|
19
|
+
expect(app.send(:pest?, env)).to be true
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should block buttons-for-website.com" do
|
23
|
+
env = {'HTTP_REFERER' => 'http://buttons-for-website.com/'}
|
24
|
+
expect(app.send(:pest?, env)).to be true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should block makemoneyonline.com" do
|
28
|
+
env = {'HTTP_REFERER' => 'http://make-money-online.7makemoneyonline.com/money.php?u=http://monkey-robot.com'}
|
29
|
+
expect(app.send(:pest?, env)).to be true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should block best-seo-offer.com" do
|
33
|
+
env = {'HTTP_REFERER' => 'http://best-seo-offer.com/try.php?u=http://monkey-robot.com'}
|
34
|
+
expect(app.send(:pest?, env)).to be true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should block buttons-for-your-website.com" do
|
38
|
+
env = {'HTTP_REFERER' => 'http://buttons-for-your-website.com/'}
|
39
|
+
expect(app.send(:pest?, env)).to be true
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should block 100dollars-seo.com" do
|
43
|
+
env = {'HTTP_REFERER' => 'http://100dollars-seo.com/try.php?u=http://monkey-robot.com'}
|
44
|
+
expect(app.send(:pest?, env)).to be true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should block videos-for-your-business.com" do
|
48
|
+
env = {'HTTP_REFERER' => 'http://videos-for-your-business.com/'}
|
49
|
+
expect(app.send(:pest?, env)).to be true
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should block semaltmedia.com" do
|
53
|
+
env = {'HTTP_REFERER' => 'http://semaltmedia.com/'}
|
54
|
+
expect(app.send(:pest?, env)).to be true
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should block video--production.com" do
|
58
|
+
env = {'HTTP_REFERER' => 'http://video--production.com/'}
|
59
|
+
expect(app.send(:pest?, env)).to be true
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should block justprofit.xyz" do
|
63
|
+
env = {'HTTP_REFERER' => 'http://justprofit.xyz/'}
|
64
|
+
expect(app.send(:pest?, env)).to be true
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should block phatvids.com" do
|
68
|
+
env = {'HTTP_REFERER' => 'http://phatvidz.com/'}
|
69
|
+
expect(app.send(:pest?, env)).to be true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should block free-video-tool.com" do
|
73
|
+
env = {'HTTP_REFERER' => 'https://free-video-tool.com/'}
|
74
|
+
expect(app.send(:pest?, env)).to be true
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should block 1-free-share-buttons.com" do
|
78
|
+
env = {'HTTP_REFERER' => '1-free-share-buttons.com/'}
|
79
|
+
expect(app.send(:pest?, env)).to be true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-pesticide
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Dippery
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.3'
|
41
|
+
description: Block crawlers who spam your site with fake HTTP referers
|
42
|
+
email:
|
43
|
+
- michael@monkey-robot.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- data/pests.txt
|
54
|
+
- lib/rack-pesticide.rb
|
55
|
+
- lib/rack/pesticide.rb
|
56
|
+
- lib/rack/pesticide/version.rb
|
57
|
+
- rack-pesticide.gemspec
|
58
|
+
- spec/pest_spec.rb
|
59
|
+
homepage: https://github.com/mdippery/rack-pesticide
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata:
|
63
|
+
build_date: 2016-09-07 19:09:27 PDT
|
64
|
+
commit: v1.0.4
|
65
|
+
commit_hash: 95da3e572b86014e3f96c73a05f025bb22114d9d
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.9.3
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.5.1
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Rack middleware to block annoying and pesky HTTP referers
|
86
|
+
test_files:
|
87
|
+
- spec/pest_spec.rb
|