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.
Files changed (110) hide show
  1. data/.document +4 -0
  2. data/.gemtest +0 -0
  3. data/.rspec +1 -0
  4. data/.yardopts +1 -0
  5. data/COPYING.txt +674 -0
  6. data/{History.txt → ChangeLog.md} +39 -8
  7. data/Gemfile +49 -0
  8. data/{README.txt → README.md} +56 -40
  9. data/Rakefile +25 -24
  10. data/bin/ronin-web +18 -5
  11. data/gemspec.yml +30 -0
  12. data/lib/ronin/network/{helpers → mixins}/web.rb +74 -39
  13. data/lib/ronin/web.rb +7 -6
  14. data/lib/ronin/web/extensions.rb +7 -6
  15. data/lib/ronin/web/extensions/nokogiri.rb +22 -0
  16. data/lib/ronin/web/extensions/nokogiri/xml.rb +22 -0
  17. data/lib/ronin/web/extensions/nokogiri/xml/attr.rb +35 -1
  18. data/lib/ronin/web/extensions/nokogiri/xml/document.rb +34 -4
  19. data/lib/ronin/web/extensions/nokogiri/xml/element.rb +36 -2
  20. data/lib/ronin/web/extensions/nokogiri/xml/node.rb +59 -20
  21. data/lib/ronin/web/extensions/nokogiri/xml/text.rb +36 -2
  22. data/lib/ronin/web/middleware.rb +27 -0
  23. data/lib/ronin/web/middleware/base.rb +144 -0
  24. data/lib/ronin/web/middleware/directories.rb +177 -0
  25. data/lib/ronin/web/middleware/files.rb +142 -0
  26. data/lib/ronin/web/middleware/filters.rb +28 -0
  27. data/lib/ronin/web/middleware/filters/campaign_filter.rb +77 -0
  28. data/lib/ronin/web/middleware/filters/ip_filter.rb +73 -0
  29. data/lib/ronin/web/middleware/filters/path_filter.rb +73 -0
  30. data/lib/ronin/web/middleware/filters/referer_filter.rb +71 -0
  31. data/lib/ronin/web/middleware/filters/user_agent_filter.rb +71 -0
  32. data/lib/ronin/web/middleware/filters/vhost_filter.rb +71 -0
  33. data/lib/ronin/web/middleware/helpers.rb +145 -0
  34. data/lib/ronin/web/middleware/proxy.rb +265 -0
  35. data/lib/ronin/web/middleware/proxy_request.rb +262 -0
  36. data/lib/ronin/web/middleware/request.rb +58 -0
  37. data/lib/ronin/web/middleware/response.rb +33 -0
  38. data/lib/ronin/web/middleware/router.rb +167 -0
  39. data/lib/ronin/web/middleware/rule.rb +103 -0
  40. data/lib/ronin/web/proxy.rb +7 -6
  41. data/lib/ronin/web/proxy/app.rb +7 -6
  42. data/lib/ronin/web/proxy/base.rb +14 -9
  43. data/lib/ronin/web/proxy/web.rb +9 -6
  44. data/lib/ronin/web/server.rb +7 -6
  45. data/lib/ronin/web/server/app.rb +7 -6
  46. data/lib/ronin/web/server/base.rb +209 -82
  47. data/lib/ronin/web/server/web.rb +10 -6
  48. data/lib/ronin/web/spider.rb +38 -26
  49. data/lib/ronin/web/version.rb +8 -7
  50. data/lib/ronin/web/web.rb +122 -80
  51. data/ronin-web.gemspec +15 -0
  52. data/spec/helpers/output.rb +3 -0
  53. data/spec/spec_helper.rb +2 -3
  54. data/spec/web/extensions/nokogiri_spec.rb +7 -7
  55. data/spec/web/{server/helpers/server.rb → helpers/rack_app.rb} +3 -14
  56. data/spec/web/helpers/root.rb +15 -0
  57. data/spec/web/helpers/root/test1.txt +1 -0
  58. data/spec/web/helpers/root/test1/index.html +1 -0
  59. data/spec/web/helpers/root/test1/test1.txt +1 -0
  60. data/spec/web/helpers/root/test2.txt +1 -0
  61. data/spec/web/helpers/root/test2/test2.txt +1 -0
  62. data/spec/web/helpers/root/test3.txt +1 -0
  63. data/spec/web/helpers/root/test3/test3.txt +1 -0
  64. data/spec/web/middleware/directories_spec.rb +86 -0
  65. data/spec/web/middleware/files_spec.rb +57 -0
  66. data/spec/web/middleware/filters/campaign_filter_spec.rb +30 -0
  67. data/spec/web/middleware/filters/ip_filter_spec.rb +25 -0
  68. data/spec/web/middleware/filters/path_filter_spec.rb +29 -0
  69. data/spec/web/middleware/filters/referer_filter_spec.rb +25 -0
  70. data/spec/web/middleware/filters/user_agent_filter_spec.rb +25 -0
  71. data/spec/web/middleware/filters/vhost_filter_spec.rb +23 -0
  72. data/spec/web/middleware/proxy_spec.rb +67 -0
  73. data/spec/web/middleware/response_spec.rb +20 -0
  74. data/spec/web/middleware/router_spec.rb +65 -0
  75. data/spec/web/middleware/rule_spec.rb +37 -0
  76. data/spec/web/proxy/base_spec.rb +1 -2
  77. data/spec/web/server/base_spec.rb +4 -13
  78. data/spec/web/server/classes/sub_app.rb +2 -2
  79. data/spec/web/server/classes/test_app.rb +1 -1
  80. data/spec/web/web_spec.rb +57 -67
  81. metadata +171 -146
  82. data.tar.gz.sig +0 -0
  83. data/Manifest.txt +0 -64
  84. data/lib/ronin/scanners/web.rb +0 -52
  85. data/lib/ronin/web/server/files.rb +0 -92
  86. data/lib/ronin/web/server/helpers.rb +0 -25
  87. data/lib/ronin/web/server/helpers/files.rb +0 -126
  88. data/lib/ronin/web/server/helpers/hosts.rb +0 -72
  89. data/lib/ronin/web/server/helpers/proxy.rb +0 -153
  90. data/lib/ronin/web/server/helpers/rendering.rb +0 -36
  91. data/lib/ronin/web/server/hosts.rb +0 -86
  92. data/lib/ronin/web/server/proxy.rb +0 -116
  93. data/spec/scanners/web_spec.rb +0 -24
  94. data/spec/web/helpers/root/index.html +0 -1
  95. data/spec/web/helpers/root/test.txt +0 -1
  96. data/spec/web/helpers/server.rb +0 -10
  97. data/spec/web/server/classes/files/dir/file.txt +0 -1
  98. data/spec/web/server/classes/files/dir/index.html +0 -1
  99. data/spec/web/server/classes/files/dir2/file2.txt +0 -1
  100. data/spec/web/server/classes/files/dir3/page.xml +0 -4
  101. data/spec/web/server/classes/files/file.txt +0 -1
  102. data/spec/web/server/classes/files_app.rb +0 -27
  103. data/spec/web/server/classes/hosts_app.rb +0 -40
  104. data/spec/web/server/classes/proxy_app.rb +0 -45
  105. data/spec/web/server/files_spec.rb +0 -74
  106. data/spec/web/server/hosts_spec.rb +0 -55
  107. data/spec/web/server/proxy_spec.rb +0 -49
  108. data/tasks/spec.rb +0 -10
  109. data/tasks/yard.rb +0 -13
  110. metadata.gz.sig +0 -3
@@ -2,21 +2,22 @@
2
2
  # Ronin Web - A Ruby library for Ronin that provides support for web
3
3
  # scraping and spidering functionality.
4
4
  #
5
- # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
- # This program is free software; you can redistribute it and/or modify
7
+ # This file is part of Ronin Web.
8
+ #
9
+ # Ronin is free software: you can redistribute it and/or modify
8
10
  # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
11
+ # the Free Software Foundation, either version 3 of the License, or
10
12
  # (at your option) any later version.
11
13
  #
12
- # This program is distributed in the hope that it will be useful,
14
+ # Ronin is distributed in the hope that it will be useful,
13
15
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
16
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
17
  # GNU General Public License for more details.
16
18
  #
17
19
  # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
20
21
  #
21
22
 
22
23
  require 'ronin/web/server/app'
@@ -46,8 +47,11 @@ module Ronin
46
47
  # end
47
48
  #
48
49
  # @see Server::Base.run!
50
+ #
49
51
  # @since 0.2.0
50
52
  #
53
+ # @api public
54
+ #
51
55
  def Web.server(options={},&block)
52
56
  unless class_variable_defined?('@@ronin_web_server')
53
57
  @@ronin_web_server = Server::App
@@ -2,21 +2,22 @@
2
2
  # Ronin Web - A Ruby library for Ronin that provides support for web
3
3
  # scraping and spidering functionality.
4
4
  #
5
- # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
- # This program is free software; you can redistribute it and/or modify
7
+ # This file is part of Ronin Web.
8
+ #
9
+ # Ronin is free software: you can redistribute it and/or modify
8
10
  # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
11
+ # the Free Software Foundation, either version 3 of the License, or
10
12
  # (at your option) any later version.
11
13
  #
12
- # This program is distributed in the hope that it will be useful,
14
+ # Ronin is distributed in the hope that it will be useful,
13
15
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
16
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
17
  # GNU General Public License for more details.
16
18
  #
17
19
  # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
20
21
  #
21
22
 
22
23
  require 'ronin/web/web'
@@ -26,6 +27,10 @@ require 'spidr/agent'
26
27
 
27
28
  module Ronin
28
29
  module Web
30
+ #
31
+ # Extends [Spidr::Agent](http://rubydoc.info/gems/spidr/Agent) with
32
+ # [Ronin::UI::Output::Helpers](http://rubydoc.info/gems/ronin/Ronin/UI/Output/Helpers).
33
+ #
29
34
  class Spider < Spidr::Agent
30
35
 
31
36
  include UI::Output::Helpers
@@ -39,7 +44,7 @@ module Ronin
39
44
  # @option options [Hash] :proxy (Web.proxy)
40
45
  # The proxy to use while spidering.
41
46
  #
42
- # @option options [String] :user_agent
47
+ # @option options [String] :user_agent (Web.user_agent)
43
48
  # The User-Agent string to send.
44
49
  #
45
50
  # @option options [String] :referer
@@ -48,32 +53,37 @@ module Ronin
48
53
  # @option options [Integer] :delay (0)
49
54
  # Duration in seconds to pause between spidering each link.
50
55
  #
51
- # @option options [String, Regexp] :host
56
+ # @option options [Array] :schemes (['http', 'https'])
57
+ # The list of acceptable URI schemes to visit.
58
+ # The `https` scheme will be ignored if `net/https` cannot be
59
+ # loaded.
60
+ #
61
+ # @option options [String] :host
52
62
  # The host-name to visit.
53
63
  #
54
- # @option options [Array] :hosts
55
- # Patterns of host-names to visit.
64
+ # @option options [Array<String, Regexp, Proc>] :hosts
65
+ # The patterns which match the host-names to visit.
56
66
  #
57
- # @option options [Array] :ignore_hosts
58
- # Patterns of host-names not to visit.
67
+ # @option options [Array<String, Regexp, Proc>] :ignore_hosts
68
+ # The patterns which match the host-names to not visit.
59
69
  #
60
- # @option options [Array] :ports
61
- # Ports to visit.
70
+ # @option options [Array<Integer, Regexp, Proc>] :ports
71
+ # The patterns which match the ports to visit.
62
72
  #
63
- # @option options [Array] :ignore_ports
64
- # Ports not to visit.
73
+ # @option options [Array<Integer, Regexp, Proc>] :ignore_ports
74
+ # The patterns which match the ports to not visit.
65
75
  #
66
- # @option options [Array] :links
67
- # Patterns of links to visit.
76
+ # @option options [Array<String, Regexp, Proc>] :links
77
+ # The patterns which match the links to visit.
68
78
  #
69
- # @option options [Array] :ignore_links
70
- # Patterns of links not to visit.
79
+ # @option options [Array<String, Regexp, Proc>] :ignore_links
80
+ # The patterns which match the links to not visit.
71
81
  #
72
- # @option options [Array] :ext
73
- # Patterns of file extensions to accept.
82
+ # @option options [Array<String, Regexp, Proc>] :exts
83
+ # The patterns which match the URI path extensions to visit.
74
84
  #
75
- # @option options [Array] :ignore_exts
76
- # Patterns of file extensions to ignore.
85
+ # @option options [Array<String, Regexp, Proc>] :ignore_exts
86
+ # The patterns which match the URI path extensions to not visit.
77
87
  #
78
88
  # @yield [spider]
79
89
  # If a block is given, it will be passed the newly created spider.
@@ -83,7 +93,9 @@ module Ronin
83
93
  #
84
94
  # @see http://spidr.rubyforge.org/docs/classes/Spidr/Agent.html
85
95
  #
86
- def initialize(options={},&block)
96
+ # @api public
97
+ #
98
+ def initialize(options={})
87
99
  options = {
88
100
  :proxy => Web.proxy,
89
101
  :user_agent => Web.user_agent
@@ -95,7 +107,7 @@ module Ronin
95
107
  print_info("Spidering #{url}")
96
108
  end
97
109
 
98
- block.call(self) if block
110
+ yield self if block_given?
99
111
  end
100
112
 
101
113
  end
@@ -2,26 +2,27 @@
2
2
  # Ronin Web - A Ruby library for Ronin that provides support for web
3
3
  # scraping and spidering functionality.
4
4
  #
5
- # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
- # This program is free software; you can redistribute it and/or modify
7
+ # This file is part of Ronin Web.
8
+ #
9
+ # Ronin is free software: you can redistribute it and/or modify
8
10
  # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
11
+ # the Free Software Foundation, either version 3 of the License, or
10
12
  # (at your option) any later version.
11
13
  #
12
- # This program is distributed in the hope that it will be useful,
14
+ # Ronin is distributed in the hope that it will be useful,
13
15
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
16
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
17
  # GNU General Public License for more details.
16
18
  #
17
19
  # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
20
21
  #
21
22
 
22
23
  module Ronin
23
24
  module Web
24
25
  # Ronin Web Version
25
- VERSION = '0.2.1'
26
+ VERSION = '0.3.0.pre1'
26
27
  end
27
28
  end
@@ -2,24 +2,26 @@
2
2
  # Ronin Web - A Ruby library for Ronin that provides support for web
3
3
  # scraping and spidering functionality.
4
4
  #
5
- # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
- # This program is free software; you can redistribute it and/or modify
7
+ # This file is part of Ronin Web.
8
+ #
9
+ # Ronin is free software: you can redistribute it and/or modify
8
10
  # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
11
+ # the Free Software Foundation, either version 3 of the License, or
10
12
  # (at your option) any later version.
11
13
  #
12
- # This program is distributed in the hope that it will be useful,
14
+ # Ronin is distributed in the hope that it will be useful,
13
15
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
16
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
17
  # GNU General Public License for more details.
16
18
  #
17
19
  # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
20
21
  #
21
22
 
22
- require 'ronin/network/http'
23
+ require 'ronin/network/http/proxy'
24
+ require 'ronin/network/http/http'
23
25
 
24
26
  require 'uri/http'
25
27
  require 'nokogiri'
@@ -41,12 +43,17 @@ module Ronin
41
43
  # @yieldparam [Nokogiri::HTML::Document] doc
42
44
  # The new HTML document object.
43
45
  #
44
- # @return [Nokogiri::HTML::Document] The new HTML document object.
46
+ # @return [Nokogiri::HTML::Document]
47
+ # The new HTML document object.
48
+ #
49
+ # @see http://rubydoc.info/gems/nokogiri/Nokogiri/HTML/Document
45
50
  #
46
- def Web.html(body,&block)
51
+ # @api public
52
+ #
53
+ def Web.html(body)
47
54
  doc = Nokogiri::HTML(body)
48
55
 
49
- block.call(doc) if block
56
+ yield doc if block_given?
50
57
  return doc
51
58
  end
52
59
 
@@ -70,6 +77,10 @@ module Ronin
70
77
  # }
71
78
  # end
72
79
  #
80
+ # @see http://rubydoc.info/gems/nokogiri/Nokogiri/HTML/Builder
81
+ #
82
+ # @api public
83
+ #
73
84
  def Web.build_html(&block)
74
85
  Nokogiri::HTML::Builder.new(&block)
75
86
  end
@@ -87,12 +98,17 @@ module Ronin
87
98
  # @yieldparam [Nokogiri::XML::Document] doc
88
99
  # The new XML document object.
89
100
  #
90
- # @return [Nokogiri::XML::Document] The new XML document object.
101
+ # @return [Nokogiri::XML::Document]
102
+ # The new XML document object.
103
+ #
104
+ # @see http://rubydoc.info/gems/nokogiri/Nokogiri/XML/Document
91
105
  #
92
- def Web.xml(body,&block)
106
+ # @api public
107
+ #
108
+ def Web.xml(body)
93
109
  doc = Nokogiri::XML(body)
94
110
 
95
- block.call(doc) if block
111
+ yield doc if block_given?
96
112
  return doc
97
113
  end
98
114
 
@@ -113,72 +129,73 @@ module Ronin
113
129
  # }
114
130
  # end
115
131
  #
132
+ # @see http://rubydoc.info/gems/nokogiri/Nokogiri/XML/Builder
133
+ #
134
+ # @api public
135
+ #
116
136
  def Web.build_xml(&block)
117
137
  Nokogiri::XML::Builder.new(&block)
118
138
  end
119
139
 
120
140
  #
121
- # Proxy information for Ronin::Web to use.
141
+ # Proxy information for {Web} to use.
122
142
  #
123
143
  # @return [Network::HTTP::Proxy]
124
144
  # The Ronin Web proxy information.
125
145
  #
126
- # @see Ronin::Network::HTTP.proxy
146
+ # @see http://rubydoc.info/gems/ronin-support/Ronin/Network/HTTP#proxy-class_method
147
+ #
148
+ # @api public
127
149
  #
128
150
  def Web.proxy
129
- Network::HTTP.proxy
151
+ (@proxy ||= nil) || Network::HTTP.proxy
130
152
  end
131
153
 
132
154
  #
133
- # Creates a HTTP URI based on a Hash of proxy information.
155
+ # Sets the proxy used by {Web}.
134
156
  #
135
- # @param [Network::HTTP::Proxy, Hash, String] proxy_info
136
- # The proxy information.
157
+ # @param [Network::HTTP::Proxy, URI::HTTP, Hash, String] new_proxy
158
+ # The new proxy information to use.
137
159
  #
138
- # @return [URI::HTTP, nil]
139
- # The HTTP URI that represents the proxy. If the proxy is diabled,
140
- # +nil+ will be returned.
160
+ # @return [Network::HTTP::Proxy]
161
+ # The new proxy.
141
162
  #
142
- # @example
143
- # Web.proxy_url
144
- # # => "http://www.example.com:8080"
163
+ # @since 0.3.0
145
164
  #
146
- # @example
147
- # Web.proxy_url({:host => 'www.example.com', :port => 8081})
148
- # # => "http://www.example.com:8081"
165
+ # @api public
149
166
  #
150
- # @example
151
- # Web.proxy_url('www.example.com:9000')
152
- # # => "http://www.example.com:9000"
153
- #
154
- def Web.proxy_url(proxy_info=Web.proxy)
155
- proxy = if proxy_info.kind_of?(Hash)
156
- Network::HTTP::Proxy.new(proxy_info)
157
- else
158
- Network::HTTP::Proxy.parse(proxy_info)
159
- end
160
-
161
- return proxy.url
167
+ def Web.proxy=(new_proxy)
168
+ @proxy = Network::HTTP::Proxy.create(new_proxy)
162
169
  end
163
170
 
164
171
  #
165
172
  # @return [Array]
166
173
  # The supported Web User-Agent Aliases.
167
174
  #
175
+ # @see http://rubydoc.info/gems/mechanize/Mechanize#AGENT_ALIASES-constant
176
+ #
177
+ # @api public
178
+ #
168
179
  def Web.user_agent_aliases
169
- WWW::Mechanize::AGENT_ALIASES
180
+ Mechanize::AGENT_ALIASES
170
181
  end
171
182
 
183
+ #
184
+ # The User-Agent string used by {Web}.
172
185
  #
173
186
  # @return [String, nil]
174
187
  # The Ronin Web User-Agent
175
188
  #
189
+ # @see http://rubydoc.info/gems/ronin-support/Ronin/Network/HTTP#user_agent-class_method
190
+ #
191
+ # @api public
192
+ #
176
193
  def Web.user_agent
177
- Network::HTTP.user_agent
194
+ (@user_agent ||= nil) || Network::HTTP.user_agent
178
195
  end
179
196
 
180
197
  #
181
- # Sets the Ronin Web User-Agent.
198
+ # Sets the User-Agent string used by {Web}.
182
199
  #
183
200
  # @param [String] new_agent
184
201
  # The User-Agent string to use.
@@ -186,8 +203,10 @@ module Ronin
186
203
  # @return [String]
187
204
  # The new User-Agent string.
188
205
  #
206
+ # @api public
207
+ #
189
208
  def Web.user_agent=(new_agent)
190
- Network::HTTP.user_agent = new_agent
209
+ @user_agent = new_agent
191
210
  end
192
211
 
193
212
  #
@@ -199,8 +218,12 @@ module Ronin
199
218
  # @return [String]
200
219
  # The new User-Agent string.
201
220
  #
221
+ # @see user_agent_aliases
222
+ #
223
+ # @api public
224
+ #
202
225
  def Web.user_agent_alias=(name)
203
- Network::HTTP.user_agent = Web.user_agent_aliases[name.to_s]
226
+ @user_agent = Web.user_agent_aliases[name.to_s]
204
227
  end
205
228
 
206
229
  #
@@ -246,9 +269,15 @@ module Ronin
246
269
  # @example Open a given URL, using a custom User-Agent string.
247
270
  # Web.open('http://www.wired.com/', :user_agent => 'the future')
248
271
  #
272
+ # @see http://rubydoc.info/stdlib/open-uri/frames
273
+ #
274
+ # @api public
275
+ #
249
276
  def Web.open(url,options={})
250
277
  user_agent_alias = options.delete(:user_agent_alias)
251
- proxy = (options.delete(:proxy) || Web.proxy)
278
+ proxy = Network::HTTP::Proxy.create(
279
+ options.delete(:proxy) || Web.proxy
280
+ )
252
281
  user = options.delete(:user)
253
282
  password = options.delete(:password)
254
283
  content_length_proc = options.delete(:content_length_proc)
@@ -261,7 +290,7 @@ module Ronin
261
290
  end
262
291
 
263
292
  if proxy[:host]
264
- headers[:proxy] = Web.proxy_url(proxy)
293
+ headers[:proxy] = proxy.url
265
294
  end
266
295
 
267
296
  if user
@@ -299,10 +328,10 @@ module Ronin
299
328
  # If a block is given, it will be passed the newly created Mechanize
300
329
  # agent.
301
330
  #
302
- # @yieldparam [WWW::Mechanize] agent
331
+ # @yieldparam [Mechanize] agent
303
332
  # The new Mechanize agent.
304
333
  #
305
- # @return [WWW::Mechanize]
334
+ # @return [Mechanize]
306
335
  # The new Mechanize agent.
307
336
  #
308
337
  # @example Create a new agent.
@@ -314,10 +343,12 @@ module Ronin
314
343
  # @example Create a new agent, with a custom User-Agent string.
315
344
  # Web.agent(:user_agent => 'wooden pants')
316
345
  #
317
- # @see http://mechanize.rubyforge.org/mechanize/WWW/Mechanize.html
346
+ # @see http://rubydoc.info/gems/mechanize/Mechanize
347
+ #
348
+ # @api public
318
349
  #
319
- def Web.agent(options={},&block)
320
- agent = WWW::Mechanize.new
350
+ def Web.agent(options={})
351
+ agent = Mechanize.new
321
352
 
322
353
  if options[:user_agent_alias]
323
354
  agent.user_agent_alias = options[:user_agent_alias]
@@ -327,21 +358,18 @@ module Ronin
327
358
  agent.user_agent = Web.user_agent
328
359
  end
329
360
 
330
- proxy = if options[:proxy].kind_of?(Hash)
331
- options[:proxy]
332
- elsif options[:proxy].kind_of?(String)
333
- Network::HTTP::Proxy.parse(options[:proxy])
334
- elsif options[:proxy].nil?
335
- Web.proxy
336
- else
337
- raise(RuntimeError,"the given :proxy option is neither a Proxy, Hash or String",caller)
338
- end
361
+ proxy = Network::HTTP::Proxy.new(options[:proxy] || Web.proxy)
339
362
 
340
363
  if proxy[:host]
341
- agent.set_proxy(proxy[:host],proxy[:port],proxy[:user],proxy[:password])
364
+ agent.set_proxy(
365
+ proxy[:host],
366
+ proxy[:port],
367
+ proxy[:user],
368
+ proxy[:password]
369
+ )
342
370
  end
343
371
 
344
- block.call(agent) if block
372
+ yield agent if block_given?
345
373
  return agent
346
374
  end
347
375
 
@@ -367,15 +395,15 @@ module Ronin
367
395
  # If a block is given, it will be passed the page for the requested
368
396
  # URL.
369
397
  #
370
- # @yieldparam [WWW::Mechanize::Page] page
398
+ # @yieldparam [Mechanize::Page] page
371
399
  # The requested page.
372
400
  #
373
- # @return [WWW::Mechanize::Page]
401
+ # @return [Mechanize::Page]
374
402
  # The requested page.
375
403
  #
376
404
  # @example
377
405
  # Web.get('http://www.rubyinside.com')
378
- # # => WWW::Mechanize::Page
406
+ # # => Mechanize::Page
379
407
  #
380
408
  # @example
381
409
  # Web.get('http://www.rubyinside.com') do |page|
@@ -384,12 +412,14 @@ module Ronin
384
412
  # end
385
413
  # end
386
414
  #
387
- # @see http://mechanize.rubyforge.org/mechanize/WWW/Mechanize/Page.html
415
+ # @see http://rubydoc.info/gems/mechanize/Mechanize/Page
416
+ #
417
+ # @api public
388
418
  #
389
- def Web.get(url,options={},&block)
419
+ def Web.get(url,options={})
390
420
  page = Web.agent(options).get(url)
391
421
 
392
- block.call(page) if block
422
+ yield page if block_given?
393
423
  return page
394
424
  end
395
425
 
@@ -429,10 +459,14 @@ module Ronin
429
459
  # puts body
430
460
  # end
431
461
  #
432
- def Web.get_body(url,options={},&block)
462
+ # @see get
463
+ #
464
+ # @api public
465
+ #
466
+ def Web.get_body(url,options={})
433
467
  body = Web.get(url,options).body
434
468
 
435
- block.call(body) if block
469
+ yield body if block_given?
436
470
  return body
437
471
  end
438
472
 
@@ -461,23 +495,27 @@ module Ronin
461
495
  # If a block is given, it will be passed the page for the requested
462
496
  # URL.
463
497
  #
464
- # @yieldparam [WWW::Mechanize::Page] page
498
+ # @yieldparam [Mechanize::Page] page
465
499
  # The requested page.
466
500
  #
467
- # @return [WWW::Mechanize::Page]
501
+ # @return [Mechanize::Page]
468
502
  # The requested page.
469
503
  #
470
504
  # @example
471
505
  # Web.post('http://www.rubyinside.com')
472
- # # => WWW::Mechanize::Page
506
+ # # => Mechanize::Page
473
507
  #
474
- def Web.post(url,options={},&block)
508
+ # @see http://rubydoc.info/gems/mechanize/Mechanize/Page
509
+ #
510
+ # @api public
511
+ #
512
+ def Web.post(url,options={})
475
513
  query = {}
476
514
  query.merge!(options[:query]) if options[:query]
477
515
 
478
516
  page = Web.agent(options).post(url,query)
479
517
 
480
- block.call(page) if block
518
+ yield page if block_given?
481
519
  return page
482
520
  end
483
521
 
@@ -506,10 +544,10 @@ module Ronin
506
544
  # @yield [body]
507
545
  # If a block is given, it will be passed the body of the page.
508
546
  #
509
- # @yieldparam [WWW::Mechanize::Page] page
547
+ # @yieldparam [Mechanize::Page] page
510
548
  # The body of the requested page.
511
549
  #
512
- # @return [WWW::Mechanize::Page]
550
+ # @return [Mechanize::Page]
513
551
  # The body of the requested page.
514
552
  #
515
553
  # @example
@@ -521,10 +559,14 @@ module Ronin
521
559
  # puts body
522
560
  # end
523
561
  #
524
- def Web.post_body(url,options={},&block)
562
+ # @see post
563
+ #
564
+ # @api public
565
+ #
566
+ def Web.post_body(url,options={})
525
567
  body = Web.post(url,options).body
526
568
 
527
- block.call(body) if block
569
+ yield body if block_given?
528
570
  return body
529
571
  end
530
572
  end