ronin-web 0.3.0.rc1 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) 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 -70
  9. data/Gemfile +42 -37
  10. data/README.md +159 -145
  11. data/Rakefile +12 -3
  12. data/bin/ronin-web +9 -17
  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 -14
  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 +34 -36
  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 +39 -109
  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 +236 -224
  76. data/.gemtest +0 -0
  77. data/data/ronin/web/user_agents.yml +0 -247
  78. data/lib/ronin/network/mixins/web.rb +0 -258
  79. data/lib/ronin/web/config.rb +0 -34
  80. data/lib/ronin/web/extensions/nokogiri/xml/attr.rb +0 -47
  81. data/lib/ronin/web/extensions/nokogiri/xml/document.rb +0 -48
  82. data/lib/ronin/web/extensions/nokogiri/xml/element.rb +0 -57
  83. data/lib/ronin/web/extensions/nokogiri/xml/node.rb +0 -86
  84. data/lib/ronin/web/extensions/nokogiri/xml/text.rb +0 -47
  85. data/lib/ronin/web/extensions/nokogiri/xml.rb +0 -27
  86. data/lib/ronin/web/extensions/nokogiri.rb +0 -23
  87. data/lib/ronin/web/extensions.rb +0 -23
  88. data/lib/ronin/web/middleware/base.rb +0 -144
  89. data/lib/ronin/web/middleware/directories.rb +0 -179
  90. data/lib/ronin/web/middleware/files.rb +0 -144
  91. data/lib/ronin/web/middleware/filters/campaign_filter.rb +0 -77
  92. data/lib/ronin/web/middleware/filters/ip_filter.rb +0 -73
  93. data/lib/ronin/web/middleware/filters/path_filter.rb +0 -73
  94. data/lib/ronin/web/middleware/filters/referer_filter.rb +0 -71
  95. data/lib/ronin/web/middleware/filters/user_agent_filter.rb +0 -71
  96. data/lib/ronin/web/middleware/filters/vhost_filter.rb +0 -71
  97. data/lib/ronin/web/middleware/filters.rb +0 -28
  98. data/lib/ronin/web/middleware/helpers.rb +0 -145
  99. data/lib/ronin/web/middleware/proxy.rb +0 -265
  100. data/lib/ronin/web/middleware/proxy_request.rb +0 -262
  101. data/lib/ronin/web/middleware/request.rb +0 -79
  102. data/lib/ronin/web/middleware/response.rb +0 -33
  103. data/lib/ronin/web/middleware/router.rb +0 -167
  104. data/lib/ronin/web/middleware/rule.rb +0 -103
  105. data/lib/ronin/web/middleware.rb +0 -27
  106. data/lib/ronin/web/proxy/app.rb +0 -32
  107. data/lib/ronin/web/proxy/base.rb +0 -46
  108. data/lib/ronin/web/proxy/web.rb +0 -46
  109. data/lib/ronin/web/proxy.rb +0 -25
  110. data/lib/ronin/web/server/app.rb +0 -32
  111. data/lib/ronin/web/server/base.rb +0 -461
  112. data/lib/ronin/web/server/web.rb +0 -66
  113. data/lib/ronin/web/server.rb +0 -25
  114. data/lib/ronin/web/spider.rb +0 -120
  115. data/lib/ronin/web/user_agents.rb +0 -196
  116. data/lib/ronin/web/web.rb +0 -560
  117. data/spec/helpers/output.rb +0 -3
  118. data/spec/web/extensions/nokogiri_spec.rb +0 -38
  119. data/spec/web/helpers/rack_app.rb +0 -24
  120. data/spec/web/helpers/root/test1/index.html +0 -1
  121. data/spec/web/helpers/root/test1/test1.txt +0 -1
  122. data/spec/web/helpers/root/test1.txt +0 -1
  123. data/spec/web/helpers/root/test2/test2.txt +0 -1
  124. data/spec/web/helpers/root/test2.txt +0 -1
  125. data/spec/web/helpers/root/test3/test3.txt +0 -1
  126. data/spec/web/helpers/root/test3.txt +0 -1
  127. data/spec/web/helpers/root.rb +0 -15
  128. data/spec/web/mechanize_spec.rb +0 -62
  129. data/spec/web/middleware/directories_spec.rb +0 -86
  130. data/spec/web/middleware/files_spec.rb +0 -57
  131. data/spec/web/middleware/filters/campaign_filter_spec.rb +0 -30
  132. data/spec/web/middleware/filters/ip_filter_spec.rb +0 -25
  133. data/spec/web/middleware/filters/path_filter_spec.rb +0 -29
  134. data/spec/web/middleware/filters/referer_filter_spec.rb +0 -25
  135. data/spec/web/middleware/filters/user_agent_filter_spec.rb +0 -25
  136. data/spec/web/middleware/filters/vhost_filter_spec.rb +0 -23
  137. data/spec/web/middleware/proxy_spec.rb +0 -67
  138. data/spec/web/middleware/response_spec.rb +0 -20
  139. data/spec/web/middleware/router_spec.rb +0 -65
  140. data/spec/web/middleware/rule_spec.rb +0 -37
  141. data/spec/web/proxy/base_spec.rb +0 -8
  142. data/spec/web/server/base_spec.rb +0 -77
  143. data/spec/web/server/classes/public1/static1.txt +0 -1
  144. data/spec/web/server/classes/public2/static2.txt +0 -1
  145. data/spec/web/server/classes/sub_app.rb +0 -13
  146. data/spec/web/server/classes/test_app.rb +0 -20
  147. data/spec/web/user_agents_spec.rb +0 -56
  148. data/spec/web/web_spec.rb +0 -101
data/lib/ronin/web/web.rb DELETED
@@ -1,560 +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/user_agents'
24
- require 'ronin/web/mechanize'
25
- require 'ronin/network/http/proxy'
26
- require 'ronin/network/http/http'
27
-
28
- require 'uri/http'
29
- require 'nokogiri'
30
- require 'open-uri'
31
-
32
- module Ronin
33
- module Web
34
- #
35
- # Parses the body of a document into a HTML document object.
36
- #
37
- # @param [String, IO] body
38
- # The body of the document to parse.
39
- #
40
- # @yield [doc]
41
- # If a block is given, it will be passed the newly created document
42
- # object.
43
- #
44
- # @yieldparam [Nokogiri::HTML::Document] doc
45
- # The new HTML document object.
46
- #
47
- # @return [Nokogiri::HTML::Document]
48
- # The new HTML document object.
49
- #
50
- # @see http://rubydoc.info/gems/nokogiri/Nokogiri/HTML/Document
51
- #
52
- # @api public
53
- #
54
- def Web.html(body)
55
- doc = Nokogiri::HTML(body)
56
-
57
- yield doc if block_given?
58
- return doc
59
- end
60
-
61
- #
62
- # Creates a new Nokogiri::HTML::Builder.
63
- #
64
- # @yield []
65
- # The block that will be used to construct the HTML document.
66
- #
67
- # @return [Nokogiri::HTML::Builder]
68
- # The new HTML builder object.
69
- #
70
- # @example
71
- # Web.build_html do
72
- # html {
73
- # body {
74
- # div(:style => 'display:none;') {
75
- # object(:classid => 'blabla')
76
- # }
77
- # }
78
- # }
79
- # end
80
- #
81
- # @see http://rubydoc.info/gems/nokogiri/Nokogiri/HTML/Builder
82
- #
83
- # @api public
84
- #
85
- def Web.build_html(&block)
86
- Nokogiri::HTML::Builder.new(&block)
87
- end
88
-
89
- #
90
- # Parses the body of a document into a XML document object.
91
- #
92
- # @param [String, IO] body
93
- # The body of the document to parse.
94
- #
95
- # @yield [doc]
96
- # If a block is given, it will be passed the newly created document
97
- # object.
98
- #
99
- # @yieldparam [Nokogiri::XML::Document] doc
100
- # The new XML document object.
101
- #
102
- # @return [Nokogiri::XML::Document]
103
- # The new XML document object.
104
- #
105
- # @see http://rubydoc.info/gems/nokogiri/Nokogiri/XML/Document
106
- #
107
- # @api public
108
- #
109
- def Web.xml(body)
110
- doc = Nokogiri::XML(body)
111
-
112
- yield doc if block_given?
113
- return doc
114
- end
115
-
116
- #
117
- # Creates a new Nokogiri::XML::Builder.
118
- #
119
- # @yield []
120
- # The block that will be used to construct the XML document.
121
- #
122
- # @return [Nokogiri::XML::Builder]
123
- # The new XML builder object.
124
- #
125
- # @example
126
- # Web.build_xml do
127
- # post(:id => 2) {
128
- # title { text('some example') }
129
- # body { text('this is one contrived example.') }
130
- # }
131
- # end
132
- #
133
- # @see http://rubydoc.info/gems/nokogiri/Nokogiri/XML/Builder
134
- #
135
- # @api public
136
- #
137
- def Web.build_xml(&block)
138
- Nokogiri::XML::Builder.new(&block)
139
- end
140
-
141
- #
142
- # Proxy information for {Web} to use.
143
- #
144
- # @return [Network::HTTP::Proxy]
145
- # The Ronin Web proxy information.
146
- #
147
- # @see http://rubydoc.info/gems/ronin-support/Ronin/Network/HTTP#proxy-class_method
148
- #
149
- # @api public
150
- #
151
- def Web.proxy
152
- (@proxy ||= nil) || Network::HTTP.proxy
153
- end
154
-
155
- #
156
- # Sets the proxy used by {Web}.
157
- #
158
- # @param [Network::HTTP::Proxy, URI::HTTP, Hash, String] new_proxy
159
- # The new proxy information to use.
160
- #
161
- # @return [Network::HTTP::Proxy]
162
- # The new proxy.
163
- #
164
- # @since 0.3.0
165
- #
166
- # @api public
167
- #
168
- def Web.proxy=(new_proxy)
169
- @proxy = Network::HTTP::Proxy.create(new_proxy)
170
- end
171
-
172
- #
173
- # A set of common `User-Agent` strings.
174
- #
175
- # @return [UserAgents]
176
- # The set of `User-Agent` strings.
177
- #
178
- # @since 0.3.0
179
- #
180
- # @api public
181
- #
182
- def Web.user_agents
183
- @user_agents ||= UserAgents.new
184
- end
185
-
186
- #
187
- # @return [Array]
188
- # The supported Web User-Agent Aliases.
189
- #
190
- # @see http://rubydoc.info/gems/mechanize/Mechanize#AGENT_ALIASES-constant
191
- #
192
- # @deprecated
193
- # Will be replaced by {user_agents} in 1.0.0.
194
- #
195
- # @api public
196
- #
197
- def Web.user_agent_aliases
198
- Mechanize::AGENT_ALIASES
199
- end
200
-
201
- #
202
- # The User-Agent string used by {Web}.
203
- #
204
- # @return [String, nil]
205
- # The Ronin Web User-Agent
206
- #
207
- # @see http://rubydoc.info/gems/ronin-support/Ronin/Network/HTTP#user_agent-class_method
208
- #
209
- # @api public
210
- #
211
- def Web.user_agent
212
- (@user_agent ||= nil) || Network::HTTP.user_agent
213
- end
214
-
215
- #
216
- # Sets the `User-Agent` string used by {Web}.
217
- #
218
- # @param [String, Symbol, Regexp, nil] value
219
- # The User-Agent string to use.
220
- # Setting {user_agent} to `nil` will disable the `User-Agent` string.
221
- #
222
- # @return [String]
223
- # The new User-Agent string.
224
- #
225
- # @raise [RuntimeError]
226
- # Either no User-Agent group exists with the given `Symbol`,
227
- # or no User-Agent string matched the given `Regexp`.
228
- #
229
- # @api public
230
- #
231
- def Web.user_agent=(value)
232
- @user_agent = case value
233
- when String
234
- user_agents.fetch(value,value)
235
- when nil
236
- nil
237
- else
238
- user_agents.fetch(value)
239
- end
240
- end
241
-
242
- #
243
- # Sets the Ronin Web User-Agent.
244
- #
245
- # @param [String] name
246
- # The User-Agent alias to use.
247
- #
248
- # @return [String]
249
- # The new User-Agent string.
250
- #
251
- # @see user_agent_aliases
252
- #
253
- # @deprecated
254
- # Will be replaced by calling {user_agent=} with a `Symbol`
255
- # and will be removed in 1.0.0.
256
- #
257
- # @api public
258
- #
259
- def Web.user_agent_alias=(name)
260
- @user_agent = Web.user_agent_aliases[name.to_s]
261
- end
262
-
263
- #
264
- # Opens a URL as a temporary file.
265
- #
266
- # @param [Hash] options
267
- # Additional options.
268
- #
269
- # @option options [String] :user_agent
270
- # The User-Agent string to use.
271
- #
272
- # @option options [String] :user_agent_alias
273
- # The User-Agent Alias to use.
274
- #
275
- # @option options [Network::HTTP::Proxy, Hash, String] :proxy
276
- # (Web.proxy)
277
- # Proxy information.
278
- #
279
- # @option options [String] :user
280
- # The HTTP Basic Authentication user name.
281
- #
282
- # @option options [String] :password
283
- # The HTTP Basic Authentication password.
284
- #
285
- # @option options [Proc] :content_length_proc
286
- # A callback which will be passed the content-length of the HTTP
287
- # response.
288
- #
289
- # @option options [Proc] :progress_proc
290
- # A callback which will be passed the size of each fragment, once
291
- # received from the server.
292
- #
293
- # @return [File]
294
- # The contents of the URL.
295
- #
296
- # @example Open a given URL.
297
- # Web.open('http://rubyflow.com/')
298
- #
299
- # @example Open a given URL, using a custom User-Agent alias.
300
- # Web.open('http://tenderlovemaking.com/',
301
- # :user_agent_alias => 'Linux Mozilla')
302
- #
303
- # @example Open a given URL, using a custom User-Agent string.
304
- # Web.open('http://www.wired.com/', :user_agent => 'the future')
305
- #
306
- # @see http://rubydoc.info/stdlib/open-uri/frames
307
- #
308
- # @api public
309
- #
310
- def Web.open(url,options={})
311
- user_agent_alias = options.delete(:user_agent_alias)
312
- proxy = Network::HTTP::Proxy.create(
313
- options.delete(:proxy) || Web.proxy
314
- )
315
- user = options.delete(:user)
316
- password = options.delete(:password)
317
- content_length_proc = options.delete(:content_length_proc)
318
- progress_proc = options.delete(:progress_proc)
319
-
320
- headers = Network::HTTP.headers(options)
321
-
322
- if user_agent_alias
323
- headers['User-Agent'] = Web.user_agent_aliases[user_agent_alias]
324
- end
325
-
326
- if proxy[:host]
327
- headers[:proxy] = proxy.url
328
- end
329
-
330
- if user
331
- headers[:http_basic_authentication] = [user, password]
332
- end
333
-
334
- if content_length_proc
335
- headers[:content_length_proc] = content_length_proc
336
- end
337
-
338
- if progress_proc
339
- headers[:progress_proc] = progress_proc
340
- end
341
-
342
- return Kernel.open(url,headers)
343
- end
344
-
345
- #
346
- # A persistant Mechanize Agent.
347
- #
348
- # @return [Mechanize]
349
- # The persistant Mechanize Agent.
350
- #
351
- # @see Mechanize
352
- #
353
- # @api public
354
- #
355
- def Web.agent(options={})
356
- if options.empty?
357
- @agent ||= Mechanize.new(options)
358
- else
359
- @agent = Mechanize.new(options)
360
- end
361
- end
362
-
363
- #
364
- # Creates a Mechanize Page for the contents at a given URL.
365
- #
366
- # @param [URI::Generic, String] url
367
- # The URL to request.
368
- #
369
- # @param [Hash] options
370
- # Additional options.
371
- #
372
- # @option options [String] :user_agent
373
- # The User-Agent string to use.
374
- #
375
- # @option options [String] :user_agent_alias
376
- # The User-Agent Alias to use.
377
- #
378
- # @option options [Network::HTTP::Proxy, Hash] :proxy (Web.proxy)
379
- # Proxy information.
380
- #
381
- # @yield [page]
382
- # If a block is given, it will be passed the page for the requested
383
- # URL.
384
- #
385
- # @yieldparam [Mechanize::Page] page
386
- # The requested page.
387
- #
388
- # @return [Mechanize::Page]
389
- # The requested page.
390
- #
391
- # @example
392
- # Web.get('http://www.rubyinside.com')
393
- # # => Mechanize::Page
394
- #
395
- # @example
396
- # Web.get('http://www.rubyinside.com') do |page|
397
- # page.search('div.post/h2/a').each do |title|
398
- # puts title.inner_text
399
- # end
400
- # end
401
- #
402
- # @see http://rubydoc.info/gems/mechanize/Mechanize/Page
403
- #
404
- # @api public
405
- #
406
- def Web.get(url,options={})
407
- page = Web.agent(options).get(url)
408
-
409
- yield page if block_given?
410
- return page
411
- end
412
-
413
- #
414
- # Requests the body of the Mechanize Page created from the response
415
- # of the given URL.
416
- #
417
- # @param [URI::Generic, String] url
418
- # The URL to request.
419
- #
420
- # @param [Hash] options
421
- # Additional options.
422
- #
423
- # @option options [String] :user_agent
424
- # The User-Agent string to use.
425
- #
426
- # @option options [String] :user_agent_alias
427
- # The User-Agent Alias to use.
428
- #
429
- # @option options [Network::HTTP::Proxy, Hash] :proxy (Web.proxy)
430
- # Proxy information.
431
- #
432
- # @yield [body]
433
- # If a block is given, it will be passed the body of the page.
434
- #
435
- # @yieldparam [String] body
436
- # The requested body of the page.
437
- #
438
- # @return [String]
439
- # The requested body of the page.
440
- #
441
- # @example
442
- # Web.get_body('http://www.rubyinside.com') # => String
443
- #
444
- # @example
445
- # Web.get_body('http://www.rubyinside.com') do |body|
446
- # puts body
447
- # end
448
- #
449
- # @see get
450
- #
451
- # @api public
452
- #
453
- def Web.get_body(url,options={})
454
- body = Web.get(url,options).body
455
-
456
- yield body if block_given?
457
- return body
458
- end
459
-
460
- #
461
- # Posts to a given URL and creates a Mechanize Page from the response.
462
- #
463
- # @param [URI::Generic, String] url
464
- # The URL to request.
465
- #
466
- # @param [Hash] options
467
- # Additional options.
468
- #
469
- # @option options [Hash] :query
470
- # Additional query parameters to post with.
471
- #
472
- # @option options [String] :user_agent
473
- # The User-Agent string to use.
474
- #
475
- # @option options [String] :user_agent_alias
476
- # The User-Agent Alia to use.
477
- #
478
- # @option options [Network::HTTP::Proxy, Hash] :proxy (Web.proxy)
479
- # Proxy information.
480
- #
481
- # @yield [page]
482
- # If a block is given, it will be passed the page for the requested
483
- # URL.
484
- #
485
- # @yieldparam [Mechanize::Page] page
486
- # The requested page.
487
- #
488
- # @return [Mechanize::Page]
489
- # The requested page.
490
- #
491
- # @example
492
- # Web.post('http://www.rubyinside.com')
493
- # # => Mechanize::Page
494
- #
495
- # @see http://rubydoc.info/gems/mechanize/Mechanize/Page
496
- #
497
- # @api public
498
- #
499
- def Web.post(url,options={})
500
- query = {}
501
- query.merge!(options[:query]) if options[:query]
502
-
503
- page = Web.agent(options).post(url,query)
504
-
505
- yield page if block_given?
506
- return page
507
- end
508
-
509
- #
510
- # Posts to a given URL and returns the body of the Mechanize Page
511
- # created from the response.
512
- #
513
- # @param [URI::Generic, String] url
514
- # The URL to request.
515
- #
516
- # @param [Hash] options
517
- # Additional options.
518
- #
519
- # @option options [Hash] :query
520
- # Additional query parameters to post with.
521
- #
522
- # @option options [String] :user_agent
523
- # The User-Agent string to use.
524
- #
525
- # @option options [String] :user_agent_alias
526
- # The User-Agent Alias to use.
527
- #
528
- # @option options [Network::HTTP::Proxy, Hash] :proxy (Web.proxy)
529
- # Proxy information.
530
- #
531
- # @yield [body]
532
- # If a block is given, it will be passed the body of the page.
533
- #
534
- # @yieldparam [Mechanize::Page] page
535
- # The body of the requested page.
536
- #
537
- # @return [Mechanize::Page]
538
- # The body of the requested page.
539
- #
540
- # @example
541
- # Web.post_body('http://www.rubyinside.com')
542
- # # => String
543
- #
544
- # @example
545
- # Web.post_body('http://www.rubyinside.com') do |body|
546
- # puts body
547
- # end
548
- #
549
- # @see post
550
- #
551
- # @api public
552
- #
553
- def Web.post_body(url,options={})
554
- body = Web.post(url,options).body
555
-
556
- yield body if block_given?
557
- return body
558
- end
559
- end
560
- end
@@ -1,3 +0,0 @@
1
- require 'ronin/ui/output'
2
-
3
- UI::Output.silent = true
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
- require 'ronin/web/extensions/nokogiri'
3
-
4
- require 'nokogiri'
5
-
6
- describe Nokogiri::HTML do
7
- before(:all) do
8
- @doc = Nokogiri::HTML(%{<html><head><title>test</title></head><body><p><b>This is a test</b> html <i>page</i>.</p></body></html>})
9
-
10
- @edited_doc = Nokogiri::HTML(%{<html><head><title>test</title></head><body><p><b>This is a test</b> html page.</p></body></html>})
11
- end
12
-
13
- it "should be able to test if two elements are equal" do
14
- elem1 = @doc.at('b')
15
- elem2 = @edited_doc.at('b')
16
-
17
- elem1.should == elem2
18
- end
19
-
20
- it "should be able to test if two elements are not equal" do
21
- elem1 = @doc.at('p').children.last
22
- elem2 = @edited_doc.at('b')
23
-
24
- elem1.should_not == elem2
25
- end
26
-
27
- it "should be able to traverse over every text node" do
28
- text = []
29
-
30
- @doc.traverse_text { |node| text << node.content }
31
-
32
- text.should == ['test', 'This is a test', ' html ', 'page', '.']
33
- end
34
-
35
- it "should provide a count of all sub-children" do
36
- @doc.total_children.should == 12
37
- end
38
- end
@@ -1,24 +0,0 @@
1
- require 'rack/test'
2
-
3
- module Helpers
4
- module Web
5
- module RackApp
6
- include Rack::Test::Methods
7
-
8
- attr_reader :app
9
-
10
- def app=(server)
11
- @app = server
12
- @app.set :environment, :test
13
- end
14
-
15
- def get_host(path,host,params={},headers={})
16
- get(path,params,headers.merge('HTTP_HOST' => host))
17
- end
18
-
19
- def post_host(path,host,params={},headers={})
20
- post(path,params,headers.merge('HTTP_HOST' => host))
21
- end
22
- end
23
- end
24
- end
@@ -1 +0,0 @@
1
- index1
@@ -1 +0,0 @@
1
- test1
@@ -1 +0,0 @@
1
- test1
@@ -1 +0,0 @@
1
- test2
@@ -1 +0,0 @@
1
- test2
@@ -1 +0,0 @@
1
- test3
@@ -1 +0,0 @@
1
- test3
@@ -1,15 +0,0 @@
1
- module Helpers
2
- module Web
3
- module Root
4
- ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__),'root'))
5
-
6
- def root_path(path=nil)
7
- if path
8
- File.join(ROOT_DIR,path)
9
- else
10
- ROOT_DIR
11
- end
12
- end
13
- end
14
- end
15
- end