ronin 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.gitignore +11 -0
  2. data/ChangeLog.md +28 -10
  3. data/Gemfile +1 -1
  4. data/README.md +14 -41
  5. data/Rakefile +3 -0
  6. data/gemspec.yml +14 -15
  7. data/lib/bond/completions/ronin.rb +0 -5
  8. data/lib/ronin/address.rb +17 -0
  9. data/lib/ronin/author.rb +1 -1
  10. data/lib/ronin/database/database.rb +11 -3
  11. data/lib/ronin/email_address.rb +33 -0
  12. data/lib/ronin/host_name.rb +57 -6
  13. data/lib/ronin/ip_address.rb +49 -5
  14. data/lib/ronin/license.rb +1 -1
  15. data/lib/ronin/mac_address.rb +39 -1
  16. data/lib/ronin/model/has_license.rb +12 -3
  17. data/lib/ronin/model/importable.rb +65 -0
  18. data/lib/ronin/repository.rb +12 -4
  19. data/lib/ronin/spec/database.rb +1 -1
  20. data/lib/ronin/tcp_port.rb +3 -12
  21. data/lib/ronin/udp_port.rb +2 -11
  22. data/lib/ronin/ui/cli/commands/emails.rb +0 -45
  23. data/lib/ronin/ui/cli/commands/hosts.rb +4 -31
  24. data/lib/ronin/ui/cli/commands/ips.rb +4 -30
  25. data/lib/ronin/ui/cli/commands/urls.rb +5 -45
  26. data/lib/ronin/ui/cli/model_command.rb +17 -27
  27. data/lib/ronin/ui/cli/resources_command.rb +25 -1
  28. data/lib/ronin/ui/cli/script_command.rb +1 -1
  29. data/lib/ronin/ui/console/context.rb +1 -1
  30. data/lib/ronin/url.rb +43 -1
  31. data/lib/ronin/version.rb +1 -1
  32. data/ronin.gemspec +1 -1
  33. data/spec/email_address_spec.rb +20 -0
  34. data/spec/host_name_spec.rb +20 -0
  35. data/spec/ip_address_spec.rb +104 -0
  36. data/spec/mac_address_spec.rb +20 -0
  37. data/spec/url_spec.rb +24 -0
  38. metadata +118 -155
  39. data/lib/ronin/network/mixins.rb +0 -27
  40. data/lib/ronin/network/mixins/esmtp.rb +0 -165
  41. data/lib/ronin/network/mixins/http.rb +0 -723
  42. data/lib/ronin/network/mixins/imap.rb +0 -151
  43. data/lib/ronin/network/mixins/pop3.rb +0 -141
  44. data/lib/ronin/network/mixins/smtp.rb +0 -159
  45. data/lib/ronin/network/mixins/tcp.rb +0 -331
  46. data/lib/ronin/network/mixins/telnet.rb +0 -199
  47. data/lib/ronin/network/mixins/udp.rb +0 -227
  48. data/lib/ronin/spec/ui/output.rb +0 -28
  49. data/lib/ronin/ui/output.rb +0 -21
  50. data/lib/ronin/ui/output/helpers.rb +0 -248
  51. data/lib/ronin/ui/output/output.rb +0 -146
  52. data/lib/ronin/ui/output/terminal.rb +0 -21
  53. data/lib/ronin/ui/output/terminal/color.rb +0 -118
  54. data/lib/ronin/ui/output/terminal/raw.rb +0 -103
  55. data/lib/ronin/ui/shell.rb +0 -92
  56. data/spec/ip_address.rb +0 -84
  57. data/spec/ui/output_spec.rb +0 -32
@@ -1,27 +0,0 @@
1
- #
2
- # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
- #
4
- # This file is part of Ronin.
5
- #
6
- # Ronin is free software: you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation, either version 3 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # Ronin is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
18
- #
19
-
20
- require 'ronin/network/mixins/tcp'
21
- require 'ronin/network/mixins/udp'
22
- require 'ronin/network/mixins/smtp'
23
- require 'ronin/network/mixins/esmtp'
24
- require 'ronin/network/mixins/pop3'
25
- require 'ronin/network/mixins/imap'
26
- require 'ronin/network/mixins/telnet'
27
- require 'ronin/network/mixins/web'
@@ -1,165 +0,0 @@
1
- #
2
- # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
- #
4
- # This file is part of Ronin.
5
- #
6
- # Ronin is free software: you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation, either version 3 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # Ronin is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
18
- #
19
-
20
- require 'ronin/network/esmtp'
21
- require 'ronin/ui/output/helpers'
22
- require 'ronin/mixin'
23
-
24
- require 'parameters'
25
-
26
- module Ronin
27
- module Network
28
- module Mixins
29
- #
30
- # Adds ESMTP convenience methods and connection parameters to a class.
31
- #
32
- # Defines the following parameters:
33
- #
34
- # * `host` (`String`) - ESMTP host.
35
- # * `port` (`Integer`) - ESMTP port.
36
- # * `esmtp_login` (`String`) - ESMTP authentication method to use.
37
- # * `esmtp_user` (`String`) - ESMTP user to login as.
38
- # * `esmtp_password` (`String`) - ESMTP password to login with.
39
- #
40
- module ESMTP
41
- include Mixin
42
-
43
- mixin UI::Output::Helpers, Parameters
44
-
45
- mixin do
46
- # ESMTP host
47
- parameter :host, :type => String,
48
- :description => 'ESMTP host'
49
-
50
- # ESMTP port
51
- parameter :port, :type => Integer,
52
- :description => 'ESMTP port'
53
-
54
- # ESMTP authentication method to use
55
- parameter :esmtp_login, :type => String,
56
- :description => 'ESMTP authentication method to use'
57
-
58
- # ESMTP user to login as
59
- parameter :esmtp_user, :type => String,
60
- :description => 'ESMTP user to login as'
61
-
62
- # ESMTP password to login with
63
- parameter :esmtp_password, :type => String,
64
- :description => 'ESMTP password to login with'
65
- end
66
-
67
- protected
68
-
69
- #
70
- # @see Ronin::Network::SMTP.message.
71
- #
72
- # @api public
73
- #
74
- def esmtp_message(options={},&block)
75
- Network::SMTP.message(options,&block)
76
- end
77
-
78
- #
79
- # Creates a connection to the ESMTP server. The `host`, `port`,
80
- # `esmtp_login`, `esmtp_user` and `esmtp_password` parameters
81
- # will also be used to connect to the ESMTP server.
82
- #
83
- # @param [Hash] options
84
- # Additional options.
85
- #
86
- # @option options [Integer] :port (Ronin::Network::SMTP.default_port)
87
- # The port to connect to.
88
- #
89
- # @option options [String] :helo
90
- # The HELO domain.
91
- #
92
- # @option options [Symbol] :auth
93
- # The type of authentication to use.
94
- # Can be either `:login`, `:plain`, or `:cram_md5`.
95
- #
96
- # @option options [String] :user
97
- # The user-name to authenticate with.
98
- #
99
- # @option options [String] :password
100
- # The password to authenticate with.
101
- #
102
- # @yield [session]
103
- # If a block is given, it will be passed an ESMTP enabled
104
- # session object.
105
- #
106
- # @yieldparam [Net::SMTP] session
107
- # The ESMTP session.
108
- #
109
- # @return [Net::SMTP]
110
- # The ESMTP enabled session.
111
- #
112
- # @api public
113
- #
114
- def esmtp_connect(options={},&block)
115
- options[:port] ||= self.port
116
- options[:login] ||= self.esmtp_login
117
- options[:user] ||= self.esmtp_user
118
- options[:password] ||= self.esmtp_password
119
-
120
- if self.port
121
- print_info "Connecting to #{self.host}:#{self.port} ..."
122
- else
123
- print_info "Connecting to #{self.host} ..."
124
- end
125
-
126
- return ::Net.esmtp_connect(self.host,options,&block)
127
- end
128
-
129
- #
130
- # Starts a session with the ESMTP server. The `host`, `port`,
131
- # `esmtp_login`, `esmtp_user` and `esmtp_password` parameters
132
- # will also be used to connect to the ESMTP server.
133
- #
134
- # @param [Hash] options
135
- # Additional options.
136
- #
137
- # @yield [session]
138
- # If a block is given, it will be passed an ESMTP enabled
139
- # session object. After the block has returned, the session
140
- # will be closed.
141
- #
142
- # @yieldparam [Net::SMTP] session
143
- # The ESMTP session.
144
- #
145
- # @see esmtp_connect
146
- #
147
- # @api public
148
- #
149
- def esmtp_session(options={})
150
- esmtp_connect(options) do |sess|
151
- yield sess if block_given?
152
-
153
- sess.close
154
-
155
- if self.port
156
- print_info "Disconnecting from #{self.host}:#{self.port}"
157
- else
158
- print_info "Disconnecting from #{self.host}"
159
- end
160
- end
161
- end
162
- end
163
- end
164
- end
165
- end
@@ -1,723 +0,0 @@
1
- #
2
- # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
- #
4
- # This file is part of Ronin.
5
- #
6
- # Ronin is free software: you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation, either version 3 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # Ronin is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
18
- #
19
-
20
- require 'ronin/network/http'
21
- require 'ronin/ui/output/helpers'
22
- require 'ronin/mixin'
23
-
24
- require 'parameters'
25
-
26
- module Ronin
27
- module Network
28
- module Mixins
29
- #
30
- # Adds HTTP convenience methods and connection parameters to a class.
31
- #
32
- # Defines the following parameters:
33
- #
34
- # * `host` (`String`) - HTTP host.
35
- # * `port` (`Integer`) - HTTP port. Defaults to `Net::HTTP.default_port`.
36
- # * `http_vhost` (`String`) - HTTP Host header to send.
37
- # * `http_user` (`String`) - HTTP user to authenticate as.
38
- # * `http_password` (`String`) - HTTP password to authenticate with.
39
- # * `http_proxy` - HTTP proxy information.
40
- # * `http_user_agent` (`String`) - HTTP User-Agent header to send.
41
- #
42
- module HTTP
43
- include Mixin
44
-
45
- mixin UI::Output::Helpers, Parameters
46
-
47
- mixin do
48
- # HTTP host
49
- parameter :host, :type => String,
50
- :description => 'HTTP host'
51
-
52
- # HTTP port
53
- parameter :port, :default => Net::HTTP.default_port,
54
- :description => 'HTTP port'
55
-
56
- # HTTP `Host` header to send
57
- parameter :http_vhost, :type => String,
58
- :description => 'HTTP Host header to send'
59
-
60
- # HTTP user to authenticate as
61
- parameter :http_user, :type => String,
62
- :description => 'HTTP user to authenticate as'
63
-
64
- # HTTP password to authenticate with
65
- parameter :http_password, :type => String,
66
- :description => 'HTTP password to authenticate with'
67
-
68
- # HTTP proxy information
69
- parameter :http_proxy, :description => 'HTTP proxy information'
70
-
71
- # HTTP `User-Agent` header to send
72
- parameter :http_user_agent, :type => String,
73
- :description => 'HTTP User-Agent header to send'
74
- end
75
-
76
- protected
77
-
78
- #
79
- # Resets the HTTP proxy settings.
80
- #
81
- # @api public
82
- #
83
- def disable_http_proxy
84
- @http_proxy = nil
85
- end
86
-
87
- #
88
- # Connects to the HTTP server.
89
- #
90
- # @param [Hash] options
91
- # Additional options
92
- #
93
- # @option options [String, URI::HTTP] :url
94
- # The full URL to request.
95
- #
96
- # @option options [String] :user
97
- # The user to authenticate with when connecting to the HTTP
98
- # server.
99
- #
100
- # @option options [String] :password
101
- # The password to authenticate with when connecting to the HTTP
102
- # server.
103
- #
104
- # @option options [String] :host
105
- # The host the HTTP server is running on.
106
- #
107
- # @option options [Integer] :port (Net::HTTP.default_port)
108
- # The port the HTTP server is listening on.
109
- #
110
- # @option options [String] :path
111
- # The path to request from the HTTP server.
112
- #
113
- # @yield [session]
114
- # If a block is given, it will be passes the new HTTP session
115
- # object.
116
- #
117
- # @yieldparam [Net::HTTP] session
118
- # The newly created HTTP session.
119
- #
120
- # @return [Net::HTTP]
121
- # The HTTP session object.
122
- #
123
- # @api public
124
- #
125
- def http_session(options={})
126
- options = http_merge_options(options)
127
- host_port = "#{options[:host]}:#{options[:port]}"
128
-
129
- Net.http_session(options) do |http|
130
- print_info "Starting HTTP Session with #{host_port}"
131
-
132
- yield http
133
-
134
- print_info "Closing HTTP Session with #{host_port}"
135
- end
136
- end
137
-
138
- #
139
- # Connects to the HTTP server and sends an HTTP Request.
140
- #
141
- # @param [Hash] options
142
- # Additional options.
143
- #
144
- # @option options [Hash{String,Symbol => Object}] :headers
145
- # The Hash of the HTTP headers to send with the request.
146
- # May contain either Strings or Symbols, lower-case or
147
- # camel-case keys.
148
- #
149
- # @yield [request, (options)]
150
- # If a block is given, it will be passed the HTTP request object.
151
- # If the block has an arity of 2, it will also be passed the
152
- # expanded version of the given options.
153
- #
154
- # @yieldparam [Net::HTTP::Request] request
155
- # The HTTP request object to use in the request.
156
- #
157
- # @yieldparam [Hash] options
158
- # The expanded version of the given options.
159
- #
160
- # @return [Net::HTTP::Response]
161
- # The response of the HTTP request.
162
- #
163
- # @see #http_session
164
- #
165
- # @api public
166
- #
167
- def http_request(options={},&block)
168
- options = http_merge_options(options)
169
- print_info "HTTP #{options[:method]} #{http_options_to_s(options)}"
170
-
171
- return Net.http_request(options,&block)
172
- end
173
-
174
- #
175
- # Returns the Status Code of the Response.
176
- #
177
- # @param [Hash] options
178
- # Additional options.
179
- #
180
- # @option options [Symbol, String] :method (:head)
181
- # The method to use for the request.
182
- #
183
- # @return [Integer]
184
- # The HTTP Response Status.
185
- #
186
- # @see #http_request
187
- #
188
- # @since 1.1.0
189
- #
190
- # @api public
191
- #
192
- def http_status(options={})
193
- options = http_merge_options(options)
194
-
195
- if (result = Net.http_status(options))
196
- print_debug "HTTP #{result} #{http_options_to_s(options)}"
197
- end
198
-
199
- return result
200
- end
201
-
202
- #
203
- # Checks if the response has an HTTP OK status code.
204
- #
205
- # @param [Hash] options
206
- # Additional options.
207
- #
208
- # @option options [Symbol, String] :method (:head)
209
- # The method to use for the request.
210
- #
211
- # @return [Boolean]
212
- # Specifies wether the response had an HTTP OK status code or not.
213
- #
214
- # @see #http_status
215
- #
216
- # @since 1.1.0
217
- #
218
- # @api public
219
- #
220
- def http_ok?(options={})
221
- options = http_merge_options(options)
222
-
223
- if (result = Net.http_ok?(options))
224
- print_debug "HTTP 200 OK #{http_options_to_s(options)}"
225
- end
226
-
227
- return result
228
- end
229
-
230
- #
231
- # Sends a HTTP Head request and returns the HTTP Server header.
232
- #
233
- # @param [Hash] options
234
- # Additional options.
235
- #
236
- # @option options [Symbol, String] :method (:head)
237
- # The method to use for the request.
238
- #
239
- # @return [String]
240
- # The HTTP `Server` header.
241
- #
242
- # @see #http_request
243
- #
244
- # @since 1.1.0
245
- #
246
- # @api public
247
- #
248
- def http_server(options={})
249
- options = http_merge_options(options)
250
-
251
- if (result = Net.http_server(options))
252
- print_debug "HTTP Server: #{result}"
253
- end
254
-
255
- return result
256
- end
257
-
258
- #
259
- # Sends an HTTP Head request and returns the HTTP X-Powered-By header.
260
- #
261
- # @param [Hash] options
262
- # Additional options.
263
- #
264
- # @option options [Symbol, String] :method (:get)
265
- # The method to use for the request.
266
- #
267
- # @return [String]
268
- # The HTTP `X-Powered-By` header.
269
- #
270
- # @see #http_request
271
- #
272
- # @since 1.1.0
273
- #
274
- # @api public
275
- #
276
- def http_powered_by(options={})
277
- options = http_merge_options(options)
278
-
279
- if (result = Net.http_powered_by(options))
280
- print_debug "HTTP X-Powered-By: #{result}"
281
- end
282
-
283
- return result
284
- end
285
-
286
- #
287
- # Performs an HTTP Copy request.
288
- #
289
- # @yield [response]
290
- # If a block is given, it will be passed the response received
291
- # from the request.
292
- #
293
- # @yieldparam [Net::HTTP::Response] response
294
- # The HTTP response object.
295
- #
296
- # @return [Net::HTTP::Response]
297
- # The response of the HTTP request.
298
- #
299
- # @see #http_request
300
- #
301
- # @api public
302
- #
303
- def http_copy(options={},&block)
304
- options = http_merge_options(options)
305
- print_info "HTTP COPY #{http_options_to_s(options)}"
306
-
307
- return Net.http_copy(options,&block)
308
- end
309
-
310
- #
311
- # Performs an HTTP Delete request.
312
- #
313
- # @yield [response]
314
- # If a block is given, it will be passed the response received
315
- # from the request.
316
- #
317
- # @yieldparam [Net::HTTP::Response] response
318
- # The HTTP response object.
319
- #
320
- # @return [Net::HTTP::Response]
321
- # The response of the HTTP request.
322
- #
323
- # @see #http_request
324
- #
325
- # @api public
326
- #
327
- def http_delete(options={},&block)
328
- options = http_merge_options(options)
329
- print_info "HTTP DELETE #{http_options_to_s(options)}"
330
-
331
- return Net.http_delete(options,&block)
332
- end
333
-
334
- #
335
- # Performs an HTTP Get request.
336
- #
337
- # @yield [response]
338
- # If a block is given, it will be passed the response received
339
- # from the request.
340
- #
341
- # @yieldparam [Net::HTTP::Response] response
342
- # The HTTP response object.
343
- #
344
- # @return [Net::HTTP::Response]
345
- # The response of the HTTP request.
346
- #
347
- # @see #http_request
348
- #
349
- # @api public
350
- #
351
- def http_get(options={},&block)
352
- options = http_merge_options(options)
353
- print_info "HTTP GET #{http_options_to_s(options)}"
354
-
355
- return Net.http_get(options,&block)
356
- end
357
-
358
- #
359
- # Performs an HTTP Get request.
360
- #
361
- # @yield [response]
362
- # If a block is given, it will be passed the response received
363
- # from the request.
364
- #
365
- # @yieldparam [Net::HTTP::Response] response
366
- # The HTTP response object.
367
- #
368
- # @return [String]
369
- # The body of the HTTP Get request.
370
- #
371
- # @see #http_get
372
- #
373
- # @api public
374
- #
375
- def http_get_body(options={},&block)
376
- options = http_merge_options(options)
377
- print_info "HTTP GET #{http_options_to_s(options)}"
378
-
379
- return Net.http_get_body(options,&block)
380
- end
381
-
382
- #
383
- # Performs an HTTP Head request.
384
- #
385
- # @yield [response]
386
- # If a block is given, it will be passed the response received
387
- # from the request.
388
- #
389
- # @yieldparam [Net::HTTP::Response] response
390
- # The HTTP response object.
391
- #
392
- # @return [Net::HTTP::Response]
393
- # The response of the HTTP request.
394
- #
395
- # @see #http_request
396
- #
397
- # @api public
398
- #
399
- def http_head(options={},&block)
400
- options = http_merge_options(options)
401
- print_info "HTTP HEAD #{http_options_to_s(options)}"
402
-
403
- return Net.http_head(options,&block)
404
- end
405
-
406
- #
407
- # Performs an HTTP Lock request.
408
- #
409
- # @yield [response]
410
- # If a block is given, it will be passed the response received
411
- # from the request.
412
- #
413
- # @yieldparam [Net::HTTP::Response] response
414
- # The HTTP response object.
415
- #
416
- # @return [Net::HTTP::Response]
417
- # The response of the HTTP request.
418
- #
419
- # @see #http_request
420
- #
421
- # @api public
422
- #
423
- def http_lock(options={},&block)
424
- options = http_merge_options(options)
425
- print_info "HTTP LOCK #{http_options_to_s(options)}"
426
-
427
- return Net.http_lock(options,&block)
428
- end
429
-
430
- #
431
- # Performs an HTTP Mkcol request.
432
- #
433
- # @yield [response]
434
- # If a block is given, it will be passed the response received
435
- # from the request.
436
- #
437
- # @yieldparam [Net::HTTP::Response] response
438
- # The HTTP response object.
439
- #
440
- # @return [Net::HTTP::Response]
441
- # The response of the HTTP request.
442
- #
443
- # @see #http_request
444
- #
445
- # @api public
446
- #
447
- def http_mkcol(options={},&block)
448
- options = http_merge_options(options)
449
- print_info "HTTP MKCOL #{http_options_to_s(options)}"
450
-
451
- return Net.http_mkcol(options,&block)
452
- end
453
-
454
- #
455
- # Performs an HTTP Move request.
456
- #
457
- # @yield [response]
458
- # If a block is given, it will be passed the response received
459
- # from the request.
460
- #
461
- # @yieldparam [Net::HTTP::Response] response
462
- # The HTTP response object.
463
- #
464
- # @return [Net::HTTP::Response]
465
- # The response of the HTTP request.
466
- #
467
- # @see #http_request
468
- #
469
- # @api public
470
- #
471
- def http_move(options={},&block)
472
- options = http_merge_options(options)
473
- print_info "HTTP MOVE #{http_options_to_s(options)}"
474
-
475
- return Net.http_move(options,&block)
476
- end
477
-
478
- #
479
- # Performs an HTTP Options request.
480
- #
481
- # @yield [response]
482
- # If a block is given, it will be passed the response received
483
- # from the request.
484
- #
485
- # @yieldparam [Net::HTTP::Response] response
486
- # The HTTP response object.
487
- #
488
- # @return [Net::HTTP::Response]
489
- # The response of the HTTP request.
490
- #
491
- # @see #http_request
492
- #
493
- # @api public
494
- #
495
- def http_options(options={},&block)
496
- options = http_merge_options(options)
497
- print_info "HTTP OPTIONS #{http_options_to_s(options)}"
498
-
499
- return Net.http_options(options,&block)
500
- end
501
-
502
- #
503
- # Performs an HTTP Post request.
504
- #
505
- # @param [Hash] options
506
- # Additional options.
507
- #
508
- # @option options [String] :post_data
509
- # The `POSTDATA` to send with the HTTP Post request.
510
- #
511
- # @yield [response]
512
- # If a block is given, it will be passed the response received
513
- # from the request.
514
- #
515
- # @yieldparam [Net::HTTP::Response] response
516
- # The HTTP response object.
517
- #
518
- # @return [Net::HTTP::Response]
519
- # The response of the HTTP request.
520
- #
521
- # @see #http_request
522
- #
523
- # @api public
524
- #
525
- def http_post(options={},&block)
526
- options = http_merge_options(options)
527
- print_info "HTTP POST #{http_options_to_s(options)}"
528
-
529
- return Net.http_post(options,&block)
530
- end
531
-
532
- #
533
- # Performs an HTTP Post request.
534
- #
535
- # @yield [response]
536
- # If a block is given, it will be passed the response received
537
- # from the request.
538
- #
539
- # @yieldparam [Net::HTTP::Response] response
540
- # The HTTP response object.
541
- #
542
- # @return [String]
543
- # The body of the Post request.
544
- #
545
- # @see #http_post
546
- #
547
- # @api public
548
- #
549
- def http_post_body(options={},&block)
550
- options = http_merge_options(options)
551
- print_info "HTTP POST #{http_options_to_s(options)}"
552
-
553
- return Net.http_post_body(options,&block)
554
- end
555
-
556
- #
557
- # Performs an HTTP Propfind request.
558
- #
559
- # @yield [response]
560
- # If a block is given, it will be passed the response received
561
- # from the request.
562
- #
563
- # @yieldparam [Net::HTTP::Response] response
564
- # The HTTP response object.
565
- #
566
- # @return [Net::HTTP::Response]
567
- # The response of the HTTP request.
568
- #
569
- # @see #http_request
570
- #
571
- # @api public
572
- #
573
- def http_prop_find(options={},&block)
574
- options = http_merge_options(options)
575
- print_info "HTTP PROPFIND #{http_options_to_s(options)}"
576
-
577
- return Net.http_prop_find(options,&block)
578
- end
579
-
580
- #
581
- # Performs an HTTP Proppatch request.
582
- #
583
- # @yield [response]
584
- # If a block is given, it will be passed the response received
585
- # from the request.
586
- #
587
- # @yieldparam [Net::HTTP::Response] response
588
- # The HTTP response object.
589
- #
590
- # @return [Net::HTTP::Response]
591
- # The response of the HTTP request.
592
- #
593
- # @see #http_request
594
- #
595
- # @api public
596
- #
597
- def http_prop_patch(options={},&block)
598
- options = http_merge_options(options)
599
- print_info "HTTP PROPPATCH #{http_options_to_s(options)}"
600
-
601
- return Net.http_prop_patch(options,&block)
602
- end
603
-
604
- #
605
- # Performs an HTTP Trace request.
606
- #
607
- # @yield [response]
608
- # If a block is given, it will be passed the response received
609
- # from the request.
610
- #
611
- # @yieldparam [Net::HTTP::Response] response
612
- # The HTTP response object.
613
- #
614
- # @return [Net::HTTP::Response]
615
- # The response of the HTTP request.
616
- #
617
- # @see #http_request
618
- #
619
- # @api public
620
- #
621
- def http_trace(options={},&block)
622
- options = http_merge_options(options)
623
- print_info "HTTP TRACE #{http_options_to_s(options)}"
624
-
625
- return Net.http_trace(options,&block)
626
- end
627
-
628
- #
629
- # Performs an HTTP Unlock request.
630
- #
631
- # @yield [response]
632
- # If a block is given, it will be passed the response received
633
- # from the request.
634
- #
635
- # @yieldparam [Net::HTTP::Response] response
636
- # The HTTP response object.
637
- #
638
- # @return [Net::HTTP::Response]
639
- # The response of the HTTP request.
640
- #
641
- # @see #http_request
642
- #
643
- # @api public
644
- #
645
- def http_unlock(options={},&block)
646
- options = http_merge_options(options)
647
- print_info "HTTP UNLOCK #{http_options_to_s(options)}"
648
-
649
- return Net.http_unlock(options,&block)
650
- end
651
-
652
- private
653
-
654
- #
655
- # Merges the HTTP parameters into the HTTP options.
656
- #
657
- # @param [Hash] options
658
- # The HTTP options to merge into.
659
- #
660
- # @return [Hash]
661
- # The merged HTTP options.
662
- #
663
- # @since 1.0.0
664
- #
665
- # @api private
666
- #
667
- def http_merge_options(options={})
668
- options[:host] ||= self.host if self.host
669
- options[:port] ||= self.port if self.port
670
-
671
- if (self.http_vhost || self.http_user_agent)
672
- headers = options.fetch(:headers,{})
673
-
674
- headers[:host] ||= self.http_vhost if self.http_vhost
675
- headers[:user_agent] ||= self.http_user_agent if self.http_user_agent
676
-
677
- options[:headers] = headers
678
- end
679
-
680
- options[:user] ||= self.http_user if self.http_user
681
- options[:password] ||= self.http_password if self.http_password
682
-
683
- options[:proxy] ||= self.http_proxy if self.http_proxy
684
-
685
- return options
686
- end
687
-
688
- #
689
- # Converts the HTTP options to a printable String.
690
- #
691
- # @param [Hash] options
692
- # HTTP options.
693
- #
694
- # @return [String]
695
- # The printable String.
696
- #
697
- # @since 1.1.0
698
- #
699
- # @api private
700
- #
701
- def http_options_to_s(options)
702
- fields = ["#{options[:host]}:#{options[:port]}"]
703
-
704
- if (options[:user] || options[:password])
705
- fields << "#{options[:user]}:#{options[:password]}"
706
- end
707
-
708
- path = options[:path]
709
- path += "?#{options[:query]}" if options[:query]
710
-
711
- fields << path
712
-
713
- if options[:headers]
714
- fields << ("%p" % options[:headers])
715
- end
716
-
717
- return fields.join(' ')
718
- end
719
-
720
- end
721
- end
722
- end
723
- end