ronin-web 0.2.1 → 0.3.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +4 -0
- data/.gemtest +0 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/COPYING.txt +674 -0
- data/{History.txt → ChangeLog.md} +39 -8
- data/Gemfile +49 -0
- data/{README.txt → README.md} +56 -40
- data/Rakefile +25 -24
- data/bin/ronin-web +18 -5
- data/gemspec.yml +30 -0
- data/lib/ronin/network/{helpers → mixins}/web.rb +74 -39
- data/lib/ronin/web.rb +7 -6
- data/lib/ronin/web/extensions.rb +7 -6
- data/lib/ronin/web/extensions/nokogiri.rb +22 -0
- data/lib/ronin/web/extensions/nokogiri/xml.rb +22 -0
- data/lib/ronin/web/extensions/nokogiri/xml/attr.rb +35 -1
- data/lib/ronin/web/extensions/nokogiri/xml/document.rb +34 -4
- data/lib/ronin/web/extensions/nokogiri/xml/element.rb +36 -2
- data/lib/ronin/web/extensions/nokogiri/xml/node.rb +59 -20
- data/lib/ronin/web/extensions/nokogiri/xml/text.rb +36 -2
- data/lib/ronin/web/middleware.rb +27 -0
- data/lib/ronin/web/middleware/base.rb +144 -0
- data/lib/ronin/web/middleware/directories.rb +177 -0
- data/lib/ronin/web/middleware/files.rb +142 -0
- data/lib/ronin/web/middleware/filters.rb +28 -0
- data/lib/ronin/web/middleware/filters/campaign_filter.rb +77 -0
- data/lib/ronin/web/middleware/filters/ip_filter.rb +73 -0
- data/lib/ronin/web/middleware/filters/path_filter.rb +73 -0
- data/lib/ronin/web/middleware/filters/referer_filter.rb +71 -0
- data/lib/ronin/web/middleware/filters/user_agent_filter.rb +71 -0
- data/lib/ronin/web/middleware/filters/vhost_filter.rb +71 -0
- data/lib/ronin/web/middleware/helpers.rb +145 -0
- data/lib/ronin/web/middleware/proxy.rb +265 -0
- data/lib/ronin/web/middleware/proxy_request.rb +262 -0
- data/lib/ronin/web/middleware/request.rb +58 -0
- data/lib/ronin/web/middleware/response.rb +33 -0
- data/lib/ronin/web/middleware/router.rb +167 -0
- data/lib/ronin/web/middleware/rule.rb +103 -0
- data/lib/ronin/web/proxy.rb +7 -6
- data/lib/ronin/web/proxy/app.rb +7 -6
- data/lib/ronin/web/proxy/base.rb +14 -9
- data/lib/ronin/web/proxy/web.rb +9 -6
- data/lib/ronin/web/server.rb +7 -6
- data/lib/ronin/web/server/app.rb +7 -6
- data/lib/ronin/web/server/base.rb +209 -82
- data/lib/ronin/web/server/web.rb +10 -6
- data/lib/ronin/web/spider.rb +38 -26
- data/lib/ronin/web/version.rb +8 -7
- data/lib/ronin/web/web.rb +122 -80
- data/ronin-web.gemspec +15 -0
- data/spec/helpers/output.rb +3 -0
- data/spec/spec_helper.rb +2 -3
- data/spec/web/extensions/nokogiri_spec.rb +7 -7
- data/spec/web/{server/helpers/server.rb → helpers/rack_app.rb} +3 -14
- data/spec/web/helpers/root.rb +15 -0
- data/spec/web/helpers/root/test1.txt +1 -0
- data/spec/web/helpers/root/test1/index.html +1 -0
- data/spec/web/helpers/root/test1/test1.txt +1 -0
- data/spec/web/helpers/root/test2.txt +1 -0
- data/spec/web/helpers/root/test2/test2.txt +1 -0
- data/spec/web/helpers/root/test3.txt +1 -0
- data/spec/web/helpers/root/test3/test3.txt +1 -0
- data/spec/web/middleware/directories_spec.rb +86 -0
- data/spec/web/middleware/files_spec.rb +57 -0
- data/spec/web/middleware/filters/campaign_filter_spec.rb +30 -0
- data/spec/web/middleware/filters/ip_filter_spec.rb +25 -0
- data/spec/web/middleware/filters/path_filter_spec.rb +29 -0
- data/spec/web/middleware/filters/referer_filter_spec.rb +25 -0
- data/spec/web/middleware/filters/user_agent_filter_spec.rb +25 -0
- data/spec/web/middleware/filters/vhost_filter_spec.rb +23 -0
- data/spec/web/middleware/proxy_spec.rb +67 -0
- data/spec/web/middleware/response_spec.rb +20 -0
- data/spec/web/middleware/router_spec.rb +65 -0
- data/spec/web/middleware/rule_spec.rb +37 -0
- data/spec/web/proxy/base_spec.rb +1 -2
- data/spec/web/server/base_spec.rb +4 -13
- data/spec/web/server/classes/sub_app.rb +2 -2
- data/spec/web/server/classes/test_app.rb +1 -1
- data/spec/web/web_spec.rb +57 -67
- metadata +171 -146
- data.tar.gz.sig +0 -0
- data/Manifest.txt +0 -64
- data/lib/ronin/scanners/web.rb +0 -52
- data/lib/ronin/web/server/files.rb +0 -92
- data/lib/ronin/web/server/helpers.rb +0 -25
- data/lib/ronin/web/server/helpers/files.rb +0 -126
- data/lib/ronin/web/server/helpers/hosts.rb +0 -72
- data/lib/ronin/web/server/helpers/proxy.rb +0 -153
- data/lib/ronin/web/server/helpers/rendering.rb +0 -36
- data/lib/ronin/web/server/hosts.rb +0 -86
- data/lib/ronin/web/server/proxy.rb +0 -116
- data/spec/scanners/web_spec.rb +0 -24
- data/spec/web/helpers/root/index.html +0 -1
- data/spec/web/helpers/root/test.txt +0 -1
- data/spec/web/helpers/server.rb +0 -10
- data/spec/web/server/classes/files/dir/file.txt +0 -1
- data/spec/web/server/classes/files/dir/index.html +0 -1
- data/spec/web/server/classes/files/dir2/file2.txt +0 -1
- data/spec/web/server/classes/files/dir3/page.xml +0 -4
- data/spec/web/server/classes/files/file.txt +0 -1
- data/spec/web/server/classes/files_app.rb +0 -27
- data/spec/web/server/classes/hosts_app.rb +0 -40
- data/spec/web/server/classes/proxy_app.rb +0 -45
- data/spec/web/server/files_spec.rb +0 -74
- data/spec/web/server/hosts_spec.rb +0 -55
- data/spec/web/server/proxy_spec.rb +0 -49
- data/tasks/spec.rb +0 -10
- data/tasks/yard.rb +0 -13
- metadata.gz.sig +0 -3
@@ -0,0 +1,142 @@
|
|
1
|
+
#
|
2
|
+
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
+
# scraping and spidering functionality.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# This file is part of Ronin Web.
|
8
|
+
#
|
9
|
+
# Ronin is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# Ronin is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'ronin/web/middleware/base'
|
24
|
+
|
25
|
+
module Ronin
|
26
|
+
module Web
|
27
|
+
module Middleware
|
28
|
+
#
|
29
|
+
# A Rack middleware to host local files at specific remote paths.
|
30
|
+
#
|
31
|
+
# use Ronin::Web::Middleware::Files do |files|
|
32
|
+
# files.map '/foo.txt', 'foo.txt'
|
33
|
+
# files.map /\.exe$/, 'trojan.exe'
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
class Files < Base
|
37
|
+
|
38
|
+
# The mapping of remote paths to local paths
|
39
|
+
attr_reader :paths
|
40
|
+
|
41
|
+
#
|
42
|
+
# Creates a new {Files} middleware.
|
43
|
+
#
|
44
|
+
# @param [#call] app
|
45
|
+
# The application the middleware sits in front of.
|
46
|
+
#
|
47
|
+
# @param [Hash] options
|
48
|
+
# Additional options.
|
49
|
+
#
|
50
|
+
# @option options [Integer] :status (200)
|
51
|
+
# The status code to return.
|
52
|
+
#
|
53
|
+
# @option options [Hash] :headers
|
54
|
+
# The headers to return.
|
55
|
+
#
|
56
|
+
# @option options [Hash] :paths
|
57
|
+
# The mapping of remote paths to local paths.
|
58
|
+
#
|
59
|
+
# @yield [files]
|
60
|
+
# If a block is given, it will be passed the new files middleware.
|
61
|
+
#
|
62
|
+
# @yieldparam [Files] files
|
63
|
+
# The new files middleware object.
|
64
|
+
#
|
65
|
+
# @since 0.3.0
|
66
|
+
#
|
67
|
+
# @api public
|
68
|
+
#
|
69
|
+
def initialize(app,options={},&block)
|
70
|
+
@paths = {}
|
71
|
+
|
72
|
+
if options.has_key?(:paths)
|
73
|
+
options[:paths].each do |remote_path,local_path|
|
74
|
+
map(remote_path,local_path)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
super(app,&block)
|
79
|
+
end
|
80
|
+
|
81
|
+
#
|
82
|
+
# Maps the local path to a remote path.
|
83
|
+
#
|
84
|
+
# @param [Regexp, String] remote_path
|
85
|
+
# The remote path to expose.
|
86
|
+
#
|
87
|
+
# @param [String] local_path
|
88
|
+
# The local path to host.
|
89
|
+
#
|
90
|
+
# @return [true]
|
91
|
+
#
|
92
|
+
# @example Mapping a path
|
93
|
+
# map '/foo.txt', 'foo.txt'
|
94
|
+
#
|
95
|
+
# @example Mapping multiple paths using a regular expression
|
96
|
+
# map /\.exe$/, 'trojan.exe'
|
97
|
+
#
|
98
|
+
# @since 0.3.0
|
99
|
+
#
|
100
|
+
# @api public
|
101
|
+
#
|
102
|
+
def map(remote_path,local_path)
|
103
|
+
@paths[remote_path] = local_path
|
104
|
+
return true
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
# Returns a local file if it was mapped to a remote path.
|
109
|
+
#
|
110
|
+
# @param [Hash, Rack::Request] env
|
111
|
+
# The request.
|
112
|
+
#
|
113
|
+
# @return [Array, Response]
|
114
|
+
# The response.
|
115
|
+
#
|
116
|
+
# @since 0.3.0
|
117
|
+
#
|
118
|
+
# @api public
|
119
|
+
#
|
120
|
+
def call(env)
|
121
|
+
path = sanitize_path(env['PATH_INFO'])
|
122
|
+
|
123
|
+
@paths.each do |pattern,local_path|
|
124
|
+
matched = if pattern.kind_of?(Regexp)
|
125
|
+
path =~ pattern
|
126
|
+
else
|
127
|
+
path == pattern
|
128
|
+
end
|
129
|
+
|
130
|
+
if matched
|
131
|
+
print_info "Returning file #{local_path.dump}"
|
132
|
+
return response_for(local_path)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
super(env)
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
+
# scraping and spidering functionality.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# This file is part of Ronin Web.
|
8
|
+
#
|
9
|
+
# Ronin is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# Ronin is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'ronin/web/middleware/filters/ip_filter'
|
24
|
+
require 'ronin/web/middleware/filters/campaign_filter'
|
25
|
+
require 'ronin/web/middleware/filters/path_filter'
|
26
|
+
require 'ronin/web/middleware/filters/vhost_filter'
|
27
|
+
require 'ronin/web/middleware/filters/referer_filter'
|
28
|
+
require 'ronin/web/middleware/filters/user_agent_filter'
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
+
# scraping and spidering functionality.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# This file is part of Ronin Web.
|
8
|
+
#
|
9
|
+
# Ronin is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# Ronin is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'ronin/campaign'
|
24
|
+
require 'ronin/ip_address'
|
25
|
+
|
26
|
+
module Ronin
|
27
|
+
module Web
|
28
|
+
module Middleware
|
29
|
+
module Filters
|
30
|
+
#
|
31
|
+
# A Filter used to match requests coming from IP Addresses that are
|
32
|
+
# targeted by a specified Campaign.
|
33
|
+
#
|
34
|
+
class CampaignFilter
|
35
|
+
|
36
|
+
#
|
37
|
+
# Creates a new campaign filter.
|
38
|
+
#
|
39
|
+
# @param [String] name
|
40
|
+
# The name of the campaign to match against.
|
41
|
+
#
|
42
|
+
# @raise [RuntimeError]
|
43
|
+
# No campaign with the given name.
|
44
|
+
#
|
45
|
+
# @since 0.3.0
|
46
|
+
#
|
47
|
+
# @api private
|
48
|
+
#
|
49
|
+
def initialize(name)
|
50
|
+
@name = name.to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Matches the filter against the request.
|
55
|
+
#
|
56
|
+
# @param [Rack::Request] request
|
57
|
+
# The incoming request.
|
58
|
+
#
|
59
|
+
# @return [Boolean]
|
60
|
+
# Specifies whether the filter matched the request.
|
61
|
+
#
|
62
|
+
# @since 0.3.0
|
63
|
+
#
|
64
|
+
# @api private
|
65
|
+
#
|
66
|
+
def match?(request)
|
67
|
+
Campaign.count(
|
68
|
+
:name => @name,
|
69
|
+
Campaign.addresses.address => request.ip
|
70
|
+
) == 1
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
+
# scraping and spidering functionality.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# This file is part of Ronin Web.
|
8
|
+
#
|
9
|
+
# Ronin is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# Ronin is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'ipaddr'
|
24
|
+
|
25
|
+
module Ronin
|
26
|
+
module Web
|
27
|
+
module Middleware
|
28
|
+
module Filters
|
29
|
+
#
|
30
|
+
# A Filter to match requests based on their IP Address.
|
31
|
+
#
|
32
|
+
class IPFilter
|
33
|
+
|
34
|
+
#
|
35
|
+
# Creates a new IP filter.
|
36
|
+
#
|
37
|
+
# @param [String, IPAddr] ip
|
38
|
+
# The IP Address to match against.
|
39
|
+
#
|
40
|
+
# @since 0.3.0
|
41
|
+
#
|
42
|
+
# @api private
|
43
|
+
#
|
44
|
+
def initialize(ip)
|
45
|
+
@ip = unless ip.kind_of?(IPAddr)
|
46
|
+
IPAddr.new(ip.to_s)
|
47
|
+
else
|
48
|
+
ip
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Matches the filter against the request.
|
54
|
+
#
|
55
|
+
# @param [Rack::Request] request
|
56
|
+
# The incoming request.
|
57
|
+
#
|
58
|
+
# @return [Boolean]
|
59
|
+
# Specifies whether the filter matched the request.
|
60
|
+
#
|
61
|
+
# @since 0.3.0
|
62
|
+
#
|
63
|
+
# @api private
|
64
|
+
#
|
65
|
+
def match?(request)
|
66
|
+
@ip.include?(request.ip)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
+
# scraping and spidering functionality.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# This file is part of Ronin Web.
|
8
|
+
#
|
9
|
+
# Ronin is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# Ronin is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
#
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module Web
|
25
|
+
module Middleware
|
26
|
+
module Filters
|
27
|
+
#
|
28
|
+
# A Filter to match requests by their path.
|
29
|
+
#
|
30
|
+
class PathFilter
|
31
|
+
|
32
|
+
#
|
33
|
+
# Creates a new path filter.
|
34
|
+
#
|
35
|
+
# @param [String, Regexp] path
|
36
|
+
# The path pattern to match against.
|
37
|
+
#
|
38
|
+
# @since 0.3.0
|
39
|
+
#
|
40
|
+
# @api private
|
41
|
+
#
|
42
|
+
def initialize(path)
|
43
|
+
@path = path
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Matches the filter against the request.
|
48
|
+
#
|
49
|
+
# @param [Rack::Request] request
|
50
|
+
# The incoming request.
|
51
|
+
#
|
52
|
+
# @return [Boolean]
|
53
|
+
# Specifies whether the filter matched the request.
|
54
|
+
#
|
55
|
+
# @since 0.3.0
|
56
|
+
#
|
57
|
+
# @api private
|
58
|
+
#
|
59
|
+
def match?(request)
|
60
|
+
if @path.kind_of?(Regexp)
|
61
|
+
!((request.path =~ @path).nil?)
|
62
|
+
elsif @path[0,1] == '/'
|
63
|
+
request.path[0,@path.length] == @path
|
64
|
+
else
|
65
|
+
request.path.include?(@path)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#
|
2
|
+
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
+
# scraping and spidering functionality.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# This file is part of Ronin Web.
|
8
|
+
#
|
9
|
+
# Ronin is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# Ronin is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
#
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module Web
|
25
|
+
module Middleware
|
26
|
+
module Filters
|
27
|
+
#
|
28
|
+
# A Filter to match requests based on their HTTP Referer URL.
|
29
|
+
#
|
30
|
+
class RefererFilter
|
31
|
+
|
32
|
+
#
|
33
|
+
# Creates a new HTTP Referer filter.
|
34
|
+
#
|
35
|
+
# @param [String, Regexp] referer
|
36
|
+
# The HTTP Referer URL pattern to match against.
|
37
|
+
#
|
38
|
+
# @since 0.3.0
|
39
|
+
#
|
40
|
+
# @api private
|
41
|
+
#
|
42
|
+
def initialize(referer)
|
43
|
+
@referer = referer
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Matches the filter against the request.
|
48
|
+
#
|
49
|
+
# @param [Rack::Request] request
|
50
|
+
# The incoming request.
|
51
|
+
#
|
52
|
+
# @return [Boolean]
|
53
|
+
# Specifies whether the filter matched the request.
|
54
|
+
#
|
55
|
+
# @since 0.3.0
|
56
|
+
#
|
57
|
+
# @api private
|
58
|
+
#
|
59
|
+
def match?(request)
|
60
|
+
if @referer.kind_of?(Regexp)
|
61
|
+
!((request.referer =~ @referer).nil?)
|
62
|
+
else
|
63
|
+
request.referer == @referer
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|