ronin-web 0.3.0.pre2 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +11 -0
  3. data/.github/workflows/ruby.yml +31 -0
  4. data/.gitignore +13 -0
  5. data/.mailmap +1 -0
  6. data/.ruby-version +1 -0
  7. data/COPYING.txt +3 -3
  8. data/ChangeLog.md +115 -67
  9. data/Gemfile +42 -37
  10. data/README.md +159 -144
  11. data/Rakefile +16 -7
  12. data/bin/ronin-web +10 -18
  13. data/data/new/nokogiri.rb.erb +12 -0
  14. data/data/new/server.rb.erb +22 -0
  15. data/data/new/spider.rb.erb +26 -0
  16. data/data/new/webapp/.gitignore +15 -0
  17. data/data/new/webapp/.ruby-version.erb +1 -0
  18. data/data/new/webapp/Dockerfile.erb +11 -0
  19. data/data/new/webapp/Gemfile +6 -0
  20. data/data/new/webapp/app.rb.erb +15 -0
  21. data/data/new/webapp/config.ru +4 -0
  22. data/data/new/webapp/docker-compose.yml.erb +9 -0
  23. data/gemspec.yml +32 -17
  24. data/lib/ronin/web/cli/command.rb +36 -0
  25. data/lib/ronin/web/cli/commands/diff.rb +106 -0
  26. data/lib/ronin/web/cli/commands/html.rb +174 -0
  27. data/lib/ronin/web/cli/commands/irb.rb +56 -0
  28. data/lib/ronin/web/cli/commands/new/nokogiri.rb +85 -0
  29. data/lib/ronin/web/cli/commands/new/server.rb +96 -0
  30. data/lib/ronin/web/cli/commands/new/spider.rb +315 -0
  31. data/lib/ronin/web/cli/commands/new/webapp.rb +123 -0
  32. data/lib/ronin/web/cli/commands/new.rb +64 -0
  33. data/lib/ronin/web/cli/commands/reverse_proxy.rb +215 -0
  34. data/lib/ronin/web/cli/commands/server.rb +155 -0
  35. data/lib/ronin/web/cli/commands/spider.rb +822 -0
  36. data/lib/ronin/web/cli/ruby_shell.rb +50 -0
  37. data/lib/ronin/web/cli.rb +44 -0
  38. data/lib/ronin/web/html.rb +85 -0
  39. data/lib/ronin/web/mechanize.rb +79 -0
  40. data/lib/ronin/web/root.rb +27 -0
  41. data/lib/ronin/web/version.rb +7 -10
  42. data/lib/ronin/web/xml.rb +85 -0
  43. data/lib/ronin/web.rb +372 -13
  44. data/man/ronin-web-diff.1 +41 -0
  45. data/man/ronin-web-diff.1.md +30 -0
  46. data/man/ronin-web-html.1 +89 -0
  47. data/man/ronin-web-html.1.md +66 -0
  48. data/man/ronin-web-irb.1 +31 -0
  49. data/man/ronin-web-irb.1.md +22 -0
  50. data/man/ronin-web-new-nokogiri.1 +41 -0
  51. data/man/ronin-web-new-nokogiri.1.md +30 -0
  52. data/man/ronin-web-new-server.1 +45 -0
  53. data/man/ronin-web-new-server.1.md +33 -0
  54. data/man/ronin-web-new-spider.1 +173 -0
  55. data/man/ronin-web-new-spider.1.md +129 -0
  56. data/man/ronin-web-new-webapp.1 +53 -0
  57. data/man/ronin-web-new-webapp.1.md +39 -0
  58. data/man/ronin-web-new.1 +59 -0
  59. data/man/ronin-web-new.1.md +44 -0
  60. data/man/ronin-web-reverse-proxy.1 +63 -0
  61. data/man/ronin-web-reverse-proxy.1.md +47 -0
  62. data/man/ronin-web-server.1 +59 -0
  63. data/man/ronin-web-server.1.md +43 -0
  64. data/man/ronin-web-spider.1 +225 -0
  65. data/man/ronin-web-spider.1.md +168 -0
  66. data/man/ronin-web.1 +41 -0
  67. data/man/ronin-web.1.md +30 -0
  68. data/ronin-web.gemspec +57 -11
  69. data/spec/cli/ruby_shell_spec.rb +14 -0
  70. data/spec/html_spec.rb +43 -0
  71. data/spec/mechanize_spec.rb +72 -0
  72. data/spec/spec_helper.rb +5 -3
  73. data/spec/web_spec.rb +97 -0
  74. data/spec/xml_spec.rb +42 -0
  75. metadata +237 -217
  76. data/.gemtest +0 -0
  77. data/lib/ronin/network/mixins/web.rb +0 -256
  78. data/lib/ronin/web/extensions/nokogiri/xml/attr.rb +0 -47
  79. data/lib/ronin/web/extensions/nokogiri/xml/document.rb +0 -48
  80. data/lib/ronin/web/extensions/nokogiri/xml/element.rb +0 -57
  81. data/lib/ronin/web/extensions/nokogiri/xml/node.rb +0 -86
  82. data/lib/ronin/web/extensions/nokogiri/xml/text.rb +0 -47
  83. data/lib/ronin/web/extensions/nokogiri/xml.rb +0 -27
  84. data/lib/ronin/web/extensions/nokogiri.rb +0 -23
  85. data/lib/ronin/web/extensions.rb +0 -23
  86. data/lib/ronin/web/middleware/base.rb +0 -144
  87. data/lib/ronin/web/middleware/directories.rb +0 -179
  88. data/lib/ronin/web/middleware/files.rb +0 -144
  89. data/lib/ronin/web/middleware/filters/campaign_filter.rb +0 -77
  90. data/lib/ronin/web/middleware/filters/ip_filter.rb +0 -73
  91. data/lib/ronin/web/middleware/filters/path_filter.rb +0 -73
  92. data/lib/ronin/web/middleware/filters/referer_filter.rb +0 -71
  93. data/lib/ronin/web/middleware/filters/user_agent_filter.rb +0 -71
  94. data/lib/ronin/web/middleware/filters/vhost_filter.rb +0 -71
  95. data/lib/ronin/web/middleware/filters.rb +0 -28
  96. data/lib/ronin/web/middleware/helpers.rb +0 -145
  97. data/lib/ronin/web/middleware/proxy.rb +0 -265
  98. data/lib/ronin/web/middleware/proxy_request.rb +0 -262
  99. data/lib/ronin/web/middleware/request.rb +0 -79
  100. data/lib/ronin/web/middleware/response.rb +0 -33
  101. data/lib/ronin/web/middleware/router.rb +0 -167
  102. data/lib/ronin/web/middleware/rule.rb +0 -103
  103. data/lib/ronin/web/middleware.rb +0 -27
  104. data/lib/ronin/web/proxy/app.rb +0 -32
  105. data/lib/ronin/web/proxy/base.rb +0 -46
  106. data/lib/ronin/web/proxy/web.rb +0 -46
  107. data/lib/ronin/web/proxy.rb +0 -25
  108. data/lib/ronin/web/server/app.rb +0 -32
  109. data/lib/ronin/web/server/base.rb +0 -461
  110. data/lib/ronin/web/server/web.rb +0 -66
  111. data/lib/ronin/web/server.rb +0 -25
  112. data/lib/ronin/web/spider.rb +0 -115
  113. data/lib/ronin/web/web.rb +0 -573
  114. data/spec/helpers/output.rb +0 -3
  115. data/spec/web/extensions/nokogiri_spec.rb +0 -38
  116. data/spec/web/helpers/rack_app.rb +0 -31
  117. data/spec/web/helpers/root/test1/index.html +0 -1
  118. data/spec/web/helpers/root/test1/test1.txt +0 -1
  119. data/spec/web/helpers/root/test1.txt +0 -1
  120. data/spec/web/helpers/root/test2/test2.txt +0 -1
  121. data/spec/web/helpers/root/test2.txt +0 -1
  122. data/spec/web/helpers/root/test3/test3.txt +0 -1
  123. data/spec/web/helpers/root/test3.txt +0 -1
  124. data/spec/web/helpers/root.rb +0 -15
  125. data/spec/web/middleware/directories_spec.rb +0 -86
  126. data/spec/web/middleware/files_spec.rb +0 -57
  127. data/spec/web/middleware/filters/campaign_filter_spec.rb +0 -30
  128. data/spec/web/middleware/filters/ip_filter_spec.rb +0 -25
  129. data/spec/web/middleware/filters/path_filter_spec.rb +0 -29
  130. data/spec/web/middleware/filters/referer_filter_spec.rb +0 -25
  131. data/spec/web/middleware/filters/user_agent_filter_spec.rb +0 -25
  132. data/spec/web/middleware/filters/vhost_filter_spec.rb +0 -23
  133. data/spec/web/middleware/proxy_spec.rb +0 -67
  134. data/spec/web/middleware/response_spec.rb +0 -20
  135. data/spec/web/middleware/router_spec.rb +0 -65
  136. data/spec/web/middleware/rule_spec.rb +0 -37
  137. data/spec/web/proxy/base_spec.rb +0 -8
  138. data/spec/web/server/base_spec.rb +0 -77
  139. data/spec/web/server/classes/public1/static1.txt +0 -1
  140. data/spec/web/server/classes/public2/static2.txt +0 -1
  141. data/spec/web/server/classes/sub_app.rb +0 -13
  142. data/spec/web/server/classes/test_app.rb +0 -20
  143. data/spec/web/web_spec.rb +0 -157
@@ -1,144 +0,0 @@
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/helpers'
24
- require 'ronin/ui/output/helpers'
25
-
26
- module Ronin
27
- module Web
28
- module Middleware
29
- #
30
- # Baase-class for all Ronin Web Middleware.
31
- #
32
- class Base
33
-
34
- include Helpers
35
- include UI::Output::Helpers
36
-
37
- # The default status code to return
38
- DEFAULT_STATUS = 200
39
-
40
- # The status code to return
41
- attr_accessor :default_status
42
-
43
- # The default headers to return
44
- attr_reader :default_headers
45
-
46
- #
47
- # Creates a new middleware object.
48
- #
49
- # @param [#call] app
50
- # The application the middleware will sit in front of.
51
- #
52
- # @param [Hash] options
53
- # Additional options.
54
- #
55
- # @option options [Integer] :default_status (DEFAULT_STATUS)
56
- # The status code to return.
57
- #
58
- # @option options [Hash] :default_headers
59
- # The headers to return.
60
- #
61
- # @yield [middleware]
62
- # If a block is given, it will be passed the new middleware.
63
- #
64
- # @yieldparam [Base] middleware
65
- # The new middleware object.
66
- #
67
- # @since 0.3.0
68
- #
69
- # @api semipublic
70
- #
71
- def initialize(app,options={})
72
- @app = app
73
-
74
- @default_status = (options[:default_status] || DEFAULT_STATUS)
75
- @default_headers = {}
76
-
77
- if options.has_key?(:default_headers)
78
- @default_headers.merge!(options[:default_headers])
79
- end
80
-
81
- yield self if block_given?
82
- end
83
-
84
- #
85
- # Passes the request to the application.
86
- #
87
- # @param [Hash, Rack::Request] env
88
- # The request.
89
- #
90
- # @return [Rack::Response]
91
- # The response.
92
- #
93
- # @since 0.3.0
94
- #
95
- # @api semipublic
96
- #
97
- def call(env)
98
- @app.call(env)
99
- end
100
-
101
- protected
102
-
103
- #
104
- # Creates a new response.
105
- #
106
- # @param [String, Array, IO] body
107
- # The body for the response.
108
- #
109
- # @param [Hash] headers
110
- # Additional headers for the response.
111
- #
112
- # @param [Integer] status
113
- # The HTTP Status Code for the response.
114
- #
115
- # @yield [response]
116
- # If a block is given, it will be passed the new response.
117
- #
118
- # @yieldparam [Response] response
119
- # The new response.
120
- #
121
- # @return [Array]
122
- # The new response.
123
- #
124
- # @example Create a response.
125
- # response ['Hello'], {'Content-Type' => 'text/txt'}, 200
126
- #
127
- # @example Create a response with just a String.
128
- # response 'Hello'
129
- #
130
- # @since 0.3.0
131
- #
132
- # @api semipublic
133
- #
134
- def response(body=[],headers={},status=nil)
135
- status ||= @default_status
136
- headers = @default_headers.merge(headers)
137
-
138
- return super(body,headers,status)
139
- end
140
-
141
- end
142
- end
143
- end
144
- end
@@ -1,179 +0,0 @@
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
- require 'set'
26
-
27
- module Ronin
28
- module Web
29
- module Middleware
30
- #
31
- # A Rack middleware to host local directories at specific remote
32
- # paths.
33
- #
34
- # use Ronin::Web::Middleware::Directories do |dirs|
35
- # dirs.map '/downloads', '/tmp/ronin_downloads'
36
- # end
37
- #
38
- class Directories < Base
39
-
40
- # The predefined index file names
41
- INDEX_NAMES = %w[index.html index.xhtml index.htm]
42
-
43
- # The mapping of remote paths to local directories
44
- attr_reader :paths
45
-
46
- #
47
- # Creates a new {Directories} middleware.
48
- #
49
- # @param [#call] app
50
- # The application the middleware sits in front of.
51
- #
52
- # @param [Hash] options
53
- # Additional options.
54
- #
55
- # @option options [Hash{String => String}] :paths
56
- # The mapping of remote paths to local directories.
57
- #
58
- # @yield [directories]
59
- # If a block is given, it will be passed the new directories
60
- # middleware.
61
- #
62
- # @yieldparam [Directories] directories
63
- # The new directories middleware object.
64
- #
65
- # @since 0.3.0
66
- #
67
- # @api public
68
- #
69
- def initialize(app,options={},&block)
70
- @paths = {}
71
- @paths_order = []
72
-
73
- if options.has_key?(:paths)
74
- options[:paths].each do |remote_path,local_dir|
75
- map(remote_path,local_dir)
76
- end
77
- end
78
-
79
- super(app,&block)
80
- end
81
-
82
- #
83
- # The names of index files.
84
- #
85
- # @return [Set]
86
- # The set of index file names.
87
- #
88
- # @since 0.3.0
89
- #
90
- # @api public
91
- #
92
- def Directories.index_names
93
- @@directories_index_names ||= Set.new(INDEX_NAMES)
94
- end
95
-
96
- #
97
- # Maps a remote path to a local directory.
98
- #
99
- # @param [String] remote_path
100
- # The remote path to map.
101
- #
102
- # @param [String] local_dir
103
- # The local directory that the remote path will map to.
104
- #
105
- # @return [true]
106
- #
107
- # @since 0.3.0
108
- #
109
- # @api public
110
- #
111
- def map(remote_path,local_dir)
112
- @paths[remote_path] = local_dir
113
-
114
- # sort paths by number of sub-directories
115
- @paths_order = @paths.keys.sort_by do |path|
116
- -(path.split('/').length)
117
- end
118
-
119
- return true
120
- end
121
-
122
- #
123
- # Returns a file from a local directory, if the directory
124
- # was mapped to a remote path.
125
- #
126
- # @param [Hash, Rack::Request] env
127
- # The request.
128
- #
129
- # @return [Array, Response]
130
- # The response.
131
- #
132
- # @since 0.3.0
133
- #
134
- # @api public
135
- #
136
- def call(env)
137
- path = sanitize_path(env['PATH_INFO'])
138
-
139
- # finds the remote directory that the paths starts with or is
140
- # equal to.
141
- remote_path = @paths_order.find do |remote_path|
142
- if remote_path == '/'
143
- true
144
- elsif path[0,remote_path.length] == remote_path
145
- (path[remote_path.length] == '/') ||
146
- (path.length == remote_path.length)
147
- end
148
- end
149
-
150
- if remote_path
151
- local_dir = @paths[remote_path]
152
- sub_path = path[remote_path.length..-1]
153
-
154
- return_file = proc { |local_path|
155
- if File.file?(local_path)
156
- request = Request.new(env)
157
-
158
- print_info "Returning file #{local_path.dump} for #{request.address}"
159
- return response_for(local_path)
160
- end
161
- }
162
-
163
- if sub_path.empty?
164
- # attempt to find an index file in the directory
165
- Directories.index_names.each do |index|
166
- return_file.call(File.join(local_dir,index))
167
- end
168
- else
169
- return_file.call(File.join(local_dir,sub_path))
170
- end
171
- end
172
-
173
- super(env)
174
- end
175
-
176
- end
177
- end
178
- end
179
- end
@@ -1,144 +0,0 @@
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
- request = Request.new(env)
132
-
133
- print_info "Returning file #{local_path.dump} for #{request.address}"
134
- return response_for(local_path)
135
- end
136
- end
137
-
138
- super(env)
139
- end
140
-
141
- end
142
- end
143
- end
144
- end
@@ -1,77 +0,0 @@
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
@@ -1,73 +0,0 @@
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
@@ -1,73 +0,0 @@
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