killshot 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +6 -0
- data/bin/killshot +31 -0
- data/killshot.gemspec +27 -0
- data/lib/killshot.rb +61 -0
- data/lib/killshot/version.rb +3 -0
- data/test/link_test.rb +44 -0
- metadata +162 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
killshot (0.0.2)
|
5
|
+
anemone
|
6
|
+
colored
|
7
|
+
nokogiri
|
8
|
+
trollop
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
anemone (0.7.2)
|
14
|
+
nokogiri (>= 1.3.0)
|
15
|
+
robotex (>= 1.0.0)
|
16
|
+
colored (1.2)
|
17
|
+
nokogiri (1.5.9)
|
18
|
+
rake (0.9.2)
|
19
|
+
robotex (1.0.0)
|
20
|
+
trollop (2.0)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
bundler (~> 1.3)
|
27
|
+
killshot!
|
28
|
+
rake
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Steve Jothen
|
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,50 @@
|
|
1
|
+
# Killshot
|
2
|
+
|
3
|
+
Use Killshot to find hotlinks on your domain.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'killshot'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install killshot
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Example usage:
|
22
|
+
|
23
|
+
```sh
|
24
|
+
$ killshot -r http://www.example.com -w example.com www.example.com
|
25
|
+
```
|
26
|
+
|
27
|
+
Note: Root host will be used as the default whitelist if none is specified.
|
28
|
+
|
29
|
+
### Options
|
30
|
+
|
31
|
+
```
|
32
|
+
--root, -r <s>: URL where we start crawling
|
33
|
+
--whitelist, -w <s+>: List of allowed domains
|
34
|
+
--version, -v: Print version and exit
|
35
|
+
--help, -h: Show this message
|
36
|
+
```
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
Copyright (c) Stephen Michael Jothen
|
41
|
+
|
42
|
+
Licensed under the MIT License
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/killshot
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'trollop'
|
4
|
+
require 'colored'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
opts = Trollop::options do
|
8
|
+
version "killshot 0.0.1 (c) Stephen Michael Jothen"
|
9
|
+
banner <<-EOS
|
10
|
+
Killshot helps you find, and kill any hotlinks on a given domain.
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
EOS
|
14
|
+
|
15
|
+
opt :root, "URL where we start crawling", :type => :string
|
16
|
+
opt :whitelist, "List of allowed domains", :type => :strings
|
17
|
+
end
|
18
|
+
|
19
|
+
Trollop::die :root, "must be given" if opts[:root].nil?
|
20
|
+
|
21
|
+
default_whitelist = Array(URI(opts[:root]).host)
|
22
|
+
opts[:whitelist] = default_whitelist if opts[:whitelist].nil?
|
23
|
+
|
24
|
+
require 'killshot'
|
25
|
+
|
26
|
+
crawler = Killshot::Crawler.new(opts[:root], opts[:whitelist])
|
27
|
+
printer = Killshot::Printer.new
|
28
|
+
|
29
|
+
printer.start
|
30
|
+
crawler.crawl { |url, img| printer.print(url, img) }
|
31
|
+
printer.finish
|
data/killshot.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'killshot/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'killshot'
|
8
|
+
spec.version = Killshot::VERSION
|
9
|
+
spec.authors = ['Steve Jothen']
|
10
|
+
spec.email = ['sjothen@gmail.com']
|
11
|
+
spec.description = %q{Find hotlinks on a given domain}
|
12
|
+
spec.summary = %q{Killshot idenfities any hotlinks on a given domain against a user specified whitelist}
|
13
|
+
spec.homepage = 'https://github.com/sjothen/killshot'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = %w(killshot)
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = %w(lib)
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_dependency 'anemone'
|
24
|
+
spec.add_dependency 'trollop'
|
25
|
+
spec.add_dependency 'nokogiri'
|
26
|
+
spec.add_dependency 'colored'
|
27
|
+
end
|
data/lib/killshot.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'killshot/version'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'anemone'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'uri'
|
6
|
+
require 'set'
|
7
|
+
|
8
|
+
module Killshot
|
9
|
+
class Crawler
|
10
|
+
attr_reader :root, :whitelist
|
11
|
+
|
12
|
+
def initialize(root, whitelist)
|
13
|
+
@root = root
|
14
|
+
@whitelist = Set.new(whitelist)
|
15
|
+
end
|
16
|
+
|
17
|
+
def crawl(&block)
|
18
|
+
Anemone.crawl(root) do |anemone|
|
19
|
+
anemone.on_every_page do |page|
|
20
|
+
find_hotlinks(page) do |url, hotlink|
|
21
|
+
block.call(url, hotlink)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def hotlink?(imgsrc)
|
30
|
+
uri = URI(URI::escape(imgsrc))
|
31
|
+
# Check if absolute, ignore relative links
|
32
|
+
uri.absolute? && !whitelist.member?(uri.host)
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_hotlinks(page, &block)
|
36
|
+
doc = Nokogiri::HTML(page.body)
|
37
|
+
doc.xpath("//img").each do |img|
|
38
|
+
block.call(page.url.to_s, img['src']) if hotlink?(img['src'])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Printer
|
44
|
+
def initialize
|
45
|
+
@count = 0
|
46
|
+
end
|
47
|
+
|
48
|
+
def print(url, img)
|
49
|
+
@count = @count + 1
|
50
|
+
puts "#@count. #{img.red} from #{url.green}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def start
|
54
|
+
puts "Searching for hotlinks..."
|
55
|
+
end
|
56
|
+
|
57
|
+
def finish
|
58
|
+
puts "Done. Found #@count hotlinks."
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/test/link_test.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "minitest/autorun"
|
3
|
+
require "killshot"
|
4
|
+
|
5
|
+
# Modified from http://blog.jayfields.com/2007/11/ruby-testing-private-methods.html
|
6
|
+
class Class
|
7
|
+
def publicize
|
8
|
+
saved_private_instance_methods = self.private_instance_methods
|
9
|
+
self.class_eval { public(*saved_private_instance_methods) }
|
10
|
+
yield self
|
11
|
+
self.class_eval { private(*saved_private_instance_methods) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class TestHotlinks < MiniTest::Unit::TestCase
|
16
|
+
def test_hotlink
|
17
|
+
Killshot::Crawler.publicize do |klass|
|
18
|
+
ks = klass.new("http://blah.com", ["blah.com"])
|
19
|
+
|
20
|
+
assert ks.hotlink?("http://notblah.com")
|
21
|
+
assert ks.hotlink?("http://abc.com/url")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_hotlink_whitelist
|
26
|
+
Killshot::Crawler.publicize do |klass|
|
27
|
+
ks = klass.new("http://blah.com", ["blah.com", "notblah.com", "abc.com"])
|
28
|
+
|
29
|
+
refute ks.hotlink?("http://notblah.com")
|
30
|
+
refute ks.hotlink?("http://abc.com/url")
|
31
|
+
refute ks.hotlink?("http://blah.com")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_nothotlinks
|
36
|
+
Killshot::Crawler.publicize do |klass|
|
37
|
+
ks = klass.new("http://blah.com", ["blah.com"])
|
38
|
+
|
39
|
+
refute ks.hotlink?("http://blah.com/test1/test2/")
|
40
|
+
refute ks.hotlink?("/relative/url")
|
41
|
+
refute ks.hotlink?("relative-url.html")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: killshot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Steve Jothen
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-04-12 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: bundler
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 3
|
33
|
+
version: "1.3"
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: anemone
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
type: :runtime
|
63
|
+
version_requirements: *id003
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: trollop
|
66
|
+
prerelease: false
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
type: :runtime
|
77
|
+
version_requirements: *id004
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: nokogiri
|
80
|
+
prerelease: false
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
type: :runtime
|
91
|
+
version_requirements: *id005
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: colored
|
94
|
+
prerelease: false
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
type: :runtime
|
105
|
+
version_requirements: *id006
|
106
|
+
description: Find hotlinks on a given domain
|
107
|
+
email:
|
108
|
+
- sjothen@gmail.com
|
109
|
+
executables:
|
110
|
+
- killshot
|
111
|
+
extensions: []
|
112
|
+
|
113
|
+
extra_rdoc_files: []
|
114
|
+
|
115
|
+
files:
|
116
|
+
- .gitignore
|
117
|
+
- Gemfile
|
118
|
+
- Gemfile.lock
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- bin/killshot
|
123
|
+
- killshot.gemspec
|
124
|
+
- lib/killshot.rb
|
125
|
+
- lib/killshot/version.rb
|
126
|
+
- test/link_test.rb
|
127
|
+
has_rdoc: true
|
128
|
+
homepage: https://github.com/sjothen/killshot
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
hash: 3
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
version: "0"
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
hash: 3
|
151
|
+
segments:
|
152
|
+
- 0
|
153
|
+
version: "0"
|
154
|
+
requirements: []
|
155
|
+
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 1.6.2
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: Killshot idenfities any hotlinks on a given domain against a user specified whitelist
|
161
|
+
test_files:
|
162
|
+
- test/link_test.rb
|