ronin-support 0.1.0 → 0.2.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. data/ChangeLog.md +24 -0
  2. data/Gemfile +9 -1
  3. data/README.md +6 -3
  4. data/gemspec.yml +3 -1
  5. data/lib/ronin/extensions.rb +2 -1
  6. data/lib/ronin/extensions/file.rb +4 -0
  7. data/lib/ronin/extensions/ip_addr.rb +8 -0
  8. data/lib/ronin/extensions/kernel.rb +2 -0
  9. data/lib/ronin/extensions/string.rb +50 -11
  10. data/lib/ronin/formatting/extensions/binary.rb +2 -0
  11. data/lib/ronin/formatting/extensions/binary/file.rb +12 -1
  12. data/lib/ronin/formatting/extensions/binary/integer.rb +6 -0
  13. data/lib/ronin/formatting/extensions/binary/string.rb +20 -0
  14. data/lib/ronin/formatting/extensions/digest/file.rb +14 -0
  15. data/lib/ronin/formatting/extensions/digest/string.rb +8 -0
  16. data/lib/ronin/formatting/extensions/html.rb +21 -0
  17. data/lib/ronin/formatting/extensions/html/integer.rb +126 -0
  18. data/lib/ronin/formatting/extensions/html/string.rb +184 -0
  19. data/lib/ronin/formatting/extensions/http/integer.rb +7 -1
  20. data/lib/ronin/formatting/extensions/http/string.rb +10 -0
  21. data/lib/ronin/formatting/extensions/text.rb +2 -0
  22. data/lib/ronin/formatting/extensions/text/array.rb +10 -0
  23. data/lib/ronin/formatting/extensions/text/string.rb +44 -12
  24. data/lib/ronin/formatting/html.rb +20 -0
  25. data/lib/ronin/mixin.rb +89 -0
  26. data/lib/ronin/network/extensions/esmtp/net.rb +6 -0
  27. data/lib/ronin/network/extensions/http/net.rb +124 -51
  28. data/lib/ronin/network/extensions/imap/net.rb +4 -0
  29. data/lib/ronin/network/extensions/pop3/net.rb +4 -0
  30. data/lib/ronin/network/extensions/smtp/net.rb +73 -2
  31. data/lib/ronin/network/extensions/ssl/net.rb +4 -0
  32. data/lib/ronin/network/extensions/tcp/net.rb +16 -0
  33. data/lib/ronin/network/extensions/telnet/net.rb +4 -0
  34. data/lib/ronin/network/extensions/udp/net.rb +12 -0
  35. data/lib/ronin/network/http/http.rb +50 -29
  36. data/lib/ronin/network/http/proxy.rb +26 -0
  37. data/lib/ronin/network/imap.rb +4 -0
  38. data/lib/ronin/network/network.rb +2 -0
  39. data/lib/ronin/network/pop3.rb +4 -0
  40. data/lib/ronin/network/smtp/email.rb +43 -14
  41. data/lib/ronin/network/smtp/smtp.rb +6 -0
  42. data/lib/ronin/network/ssl.rb +2 -0
  43. data/lib/ronin/network/telnet.rb +16 -0
  44. data/lib/ronin/path.rb +6 -0
  45. data/lib/ronin/support/inflector.rb +3 -1
  46. data/lib/ronin/support/version.rb +1 -1
  47. data/lib/ronin/templates/erb.rb +4 -0
  48. data/lib/ronin/templates/template.rb +10 -0
  49. data/spec/extensions/string_spec.rb +4 -4
  50. data/spec/formatting/html/integer_spec.rb +66 -0
  51. data/spec/formatting/html/string_spec.rb +103 -0
  52. data/spec/formatting/http/string_spec.rb +1 -1
  53. data/spec/formatting/text/string_spec.rb +18 -66
  54. data/spec/mixin_spec.rb +53 -0
  55. data/spec/network/http/http_spec.rb +0 -7
  56. data/spec/network/http/proxy_spec.rb +2 -2
  57. data/spec/network/smtp/email_spec.rb +100 -0
  58. data/spec/path_spec.rb +13 -13
  59. data/spec/templates/helpers/data.rb +1 -1
  60. metadata +52 -33
@@ -48,6 +48,8 @@ module Ronin
48
48
  # @option options [String] :password
49
49
  # The password to authenticate with.
50
50
  #
51
+ # @api public
52
+ #
51
53
  def initialize(options={})
52
54
  super(
53
55
  options[:host],
@@ -75,6 +77,8 @@ module Ronin
75
77
  # @example
76
78
  # Proxy.parse('http://201.26.192.61:8080')
77
79
  #
80
+ # @api public
81
+ #
78
82
  def self.parse(proxy)
79
83
  proxy = proxy.to_s.gsub(/^http(s)?:\/*/,'')
80
84
 
@@ -110,6 +114,8 @@ module Ronin
110
114
  # The given proxy information was not a {Proxy}, `URI::HTTP`,
111
115
  # `Hash` or {String}.
112
116
  #
117
+ # @api public
118
+ #
113
119
  def self.create(proxy)
114
120
  case proxy
115
121
  when Proxy
@@ -138,6 +144,8 @@ module Ronin
138
144
  # @return [Boolean]
139
145
  # Specifies if the proxy can proxy requests.
140
146
  #
147
+ # @api public
148
+ #
141
149
  def valid?
142
150
  begin
143
151
  Net.http_get_body(
@@ -156,6 +164,8 @@ module Ronin
156
164
  # The extra number of seconds it takes the proxy to process the
157
165
  # request, compared to sending the request directly.
158
166
  #
167
+ # @api public
168
+ #
159
169
  def latency
160
170
  time = lambda { |proxy|
161
171
  t1 = Time.now
@@ -183,6 +193,8 @@ module Ronin
183
193
  # @return [String]
184
194
  # The IP address the proxy uses for our requests.
185
195
  #
196
+ # @api public
197
+ #
186
198
  def proxied_ip
187
199
  IPAddr.extract(Net.http_get_body(
188
200
  :url => Network::IP_URL,
@@ -196,6 +208,8 @@ module Ronin
196
208
  # @return [Boolean]
197
209
  # Specifies whether the proxy will forward our IP address.
198
210
  #
211
+ # @api public
212
+ #
199
213
  def transparent?
200
214
  Network.ip == proxied_ip
201
215
  end
@@ -206,6 +220,8 @@ module Ronin
206
220
  # @return [Boolean]
207
221
  # Specifies whether the proxy will hide our IP address.
208
222
  #
223
+ # @api public
224
+ #
209
225
  def anonymous?
210
226
  !(transparent?)
211
227
  end
@@ -213,6 +229,8 @@ module Ronin
213
229
  #
214
230
  # Disables the Proxy object.
215
231
  #
232
+ # @api public
233
+ #
216
234
  def disable!
217
235
  self.host = nil
218
236
  self.port = nil
@@ -229,6 +247,8 @@ module Ronin
229
247
  # Specifies whether the proxy object is usable by
230
248
  # Net::HTTP::Proxy.
231
249
  #
250
+ # @api public
251
+ #
232
252
  def enabled?
233
253
  !(self.host.nil?)
234
254
  end
@@ -240,6 +260,8 @@ module Ronin
240
260
  # The HTTP URI representing the proxy. If the proxy is disabled,
241
261
  # then `nil` will be returned.
242
262
  #
263
+ # @api public
264
+ #
243
265
  def url
244
266
  return nil unless enabled?
245
267
 
@@ -264,6 +286,8 @@ module Ronin
264
286
  # @return [String]
265
287
  # The host-name of the proxy.
266
288
  #
289
+ # @api public
290
+ #
267
291
  def to_s
268
292
  self.host.to_s
269
293
  end
@@ -274,6 +298,8 @@ module Ronin
274
298
  # @return [String]
275
299
  # The inspection of the proxy object.
276
300
  #
301
+ # @api public
302
+ #
277
303
  def inspect
278
304
  unless self.host
279
305
  str = 'disabled'
@@ -32,6 +32,8 @@ module Ronin
32
32
  # @return [Integer]
33
33
  # The default Ronin IMAP port.
34
34
  #
35
+ # @api public
36
+ #
35
37
  def IMAP.default_port
36
38
  @default_port ||= DEFAULT_PORT
37
39
  end
@@ -42,6 +44,8 @@ module Ronin
42
44
  # @param [Integer] port
43
45
  # The new default Ronin IMAP port.
44
46
  #
47
+ # @api public
48
+ #
45
49
  def IMAP.default_port=(port)
46
50
  @default_port = port
47
51
  end
@@ -35,6 +35,8 @@ module Ronin
35
35
  # @return [String]
36
36
  # The external IP Address according to {http://checkip.dyndns.org}.
37
37
  #
38
+ # @api public
39
+ #
38
40
  def Network.ip
39
41
  IPAddr.extract(Net::HTTP.get(IP_URL)).first
40
42
  end
@@ -32,6 +32,8 @@ module Ronin
32
32
  # @return [Integer]
33
33
  # The default Ronin POP3 port.
34
34
  #
35
+ # @api public
36
+ #
35
37
  def POP3.default_port
36
38
  @default_port ||= DEFAULT_PORT
37
39
  end
@@ -42,6 +44,8 @@ module Ronin
42
44
  # @param [Integer] port
43
45
  # The new default Ronin POP3 port.
44
46
  #
47
+ # @api public
48
+ #
45
49
  def POP3.default_port=(port)
46
50
  @default_port = port
47
51
  end
@@ -25,6 +25,8 @@ module Ronin
25
25
  #
26
26
  class Email
27
27
 
28
+ CRLF = "\n\r"
29
+
28
30
  # Sender of the email
29
31
  attr_accessor :from
30
32
 
@@ -40,6 +42,9 @@ module Ronin
40
42
  # Unique message-id string
41
43
  attr_accessor :message_id
42
44
 
45
+ # Additional headers
46
+ attr_reader :headers
47
+
43
48
  # Body of the email
44
49
  attr_accessor :body
45
50
 
@@ -52,7 +57,7 @@ module Ronin
52
57
  # @option options [String] :from
53
58
  # The address the email is from.
54
59
  #
55
- # @option options [String] :to
60
+ # @option options [Array, String] :to
56
61
  # The address that the email should be sent to.
57
62
  #
58
63
  # @option options [String] :subject
@@ -64,6 +69,9 @@ module Ronin
64
69
  # @option options [String, Time] :date (Time.now)
65
70
  # The date the email was sent on.
66
71
  #
72
+ # @option options [Hash<String => String}] :headers
73
+ # Additional headers.
74
+ #
67
75
  # @option options [String, Array<String>] :body
68
76
  # The body of the email.
69
77
  #
@@ -74,18 +82,29 @@ module Ronin
74
82
  # @yieldparam [Email] email
75
83
  # The newly created email object.
76
84
  #
85
+ # @api public
86
+ #
77
87
  def initialize(options={})
78
88
  @from = options[:from]
79
89
  @to = options[:to]
80
90
  @subject = options[:subject]
81
- @date = options[:date] || Time.now
91
+ @date = options.fetch(:date,Time.now)
82
92
  @message_id = options[:message_id]
93
+ @headers = {}
94
+
95
+ if options[:headers]
96
+ @headers.merge!(options[:headers])
97
+ end
98
+
83
99
  @body = []
84
100
 
85
- if options[:body].kind_of?(Array)
86
- @body += options[:body]
87
- else
88
- @body << options[:body]
101
+ if options[:body]
102
+ case options[:body]
103
+ when Array
104
+ @body += options[:body]
105
+ else
106
+ @body << options[:body]
107
+ end
89
108
  end
90
109
 
91
110
  yield self if block_given?
@@ -99,25 +118,31 @@ module Ronin
99
118
  #
100
119
  # @see http://www.ruby-doc.org/stdlib/libdoc/net/smtp/rdoc/classes/Net/SMTP.html
101
120
  #
121
+ # @api public
122
+ #
102
123
  def to_s
103
124
  address = lambda { |info|
104
- if info.kind_of?(Array)
105
- return "#{info[0]} <#{info[1]}>"
106
- elsif info.kind_of?(Hash)
107
- return "#{info[:name]} <#{info[:email]}>"
125
+ case info
126
+ when Array
127
+ "#{info[0]} <#{info[1]}>"
108
128
  else
109
- return info
129
+ info
110
130
  end
111
131
  }
112
132
 
113
133
  message = []
114
134
 
115
135
  if @from
116
- message << "From: #{address.call(@from)}"
136
+ message << "From: #{@from}"
117
137
  end
118
138
 
119
139
  if @to
120
- message << "To: #{address.call(@to)}"
140
+ message << case @to
141
+ when Array
142
+ "To: #{@to.join(', ')}"
143
+ else
144
+ "To: #{@to}"
145
+ end
121
146
  end
122
147
 
123
148
  if @subject
@@ -132,10 +157,14 @@ module Ronin
132
157
  message << "Message-Id: <#{@message_id}>"
133
158
  end
134
159
 
160
+ @headers.each do |name,value|
161
+ message << "#{name}: #{value}"
162
+ end
163
+
135
164
  message << ''
136
165
  message += @body
137
166
 
138
- return message.join("\n")
167
+ return message.join(CRLF)
139
168
  end
140
169
 
141
170
  end
@@ -32,6 +32,8 @@ module Ronin
32
32
  # @return [Integer]
33
33
  # The default Ronin SMTP port.
34
34
  #
35
+ # @api public
36
+ #
35
37
  def SMTP.default_port
36
38
  @default_port ||= DEFAULT_PORT
37
39
  end
@@ -42,6 +44,8 @@ module Ronin
42
44
  # @param [Integer] port
43
45
  # The new default Ronin SMTP port.
44
46
  #
47
+ # @api public
48
+ #
45
49
  def SMTP.default_port=(port)
46
50
  @default_port = port
47
51
  end
@@ -61,6 +65,8 @@ module Ronin
61
65
  #
62
66
  # @see Ronin::Network::SMTP::Email
63
67
  #
68
+ # @api public
69
+ #
64
70
  def SMTP.message(options={},&block)
65
71
  Email.new(options,&block).to_s
66
72
  end
@@ -34,6 +34,8 @@ module Ronin
34
34
  # @return [Integer]
35
35
  # The verify mode number used by OpenSSL.
36
36
  #
37
+ # @api private
38
+ #
37
39
  def SSL.verify(mode=nil)
38
40
  verify_mode = 'VERIFY_' + (mode || :none).to_s.upcase
39
41
 
@@ -38,6 +38,8 @@ module Ronin
38
38
  # @return [Integer]
39
39
  # The default Ronin Telnet port.
40
40
  #
41
+ # @api public
42
+ #
41
43
  def Telnet.default_port
42
44
  @default_port ||= DEFAULT_PORT
43
45
  end
@@ -48,6 +50,8 @@ module Ronin
48
50
  # @param [Integer] port
49
51
  # The new default Ronin Telnet port.
50
52
  #
53
+ # @api public
54
+ #
51
55
  def Telnet.default_port=(port)
52
56
  @default_port = port
53
57
  end
@@ -56,6 +60,8 @@ module Ronin
56
60
  # @return [Regexp]
57
61
  # The default Ronin Telnet prompt pattern.
58
62
  #
63
+ # @api public
64
+ #
59
65
  def Telnet.default_prompt
60
66
  @default_prompt ||= DEFAULT_PROMPT
61
67
  end
@@ -66,6 +72,8 @@ module Ronin
66
72
  # @param [Regexp] prompt
67
73
  # The new default Ronin Telnet prompt pattern.
68
74
  #
75
+ # @api public
76
+ #
69
77
  def Telnet.default_prompt=(prompt)
70
78
  @default_prompt = prompt
71
79
  end
@@ -74,6 +82,8 @@ module Ronin
74
82
  # @return [Integer]
75
83
  # The default Ronin Telnet timeout.
76
84
  #
85
+ # @api public
86
+ #
77
87
  def Telnet.default_timeout
78
88
  @default_timeout ||= DEFAULT_TIMEOUT
79
89
  end
@@ -84,6 +94,8 @@ module Ronin
84
94
  # @param [Integer] timeout
85
95
  # The new default Ronin Telnet timeout.
86
96
  #
97
+ # @api public
98
+ #
87
99
  def Telnet.default_timeout=(timeout)
88
100
  @default_timeout = timeout
89
101
  end
@@ -92,6 +104,8 @@ module Ronin
92
104
  # @return [Telnet, IO, nil]
93
105
  # The Ronin Telnet proxy.
94
106
  #
107
+ # @api public
108
+ #
95
109
  def Telnet.proxy
96
110
  @proxy ||= nil
97
111
  end
@@ -102,6 +116,8 @@ module Ronin
102
116
  # @param [Telnet, IO, nil] new_proxy
103
117
  # The new Ronin Telnet proxy.
104
118
  #
119
+ # @api public
120
+ #
105
121
  def Telnet.proxy=(new_proxy)
106
122
  @proxy = new_proxy
107
123
  end
@@ -41,6 +41,8 @@ module Ronin
41
41
  # @return [Path]
42
42
  # The root path.
43
43
  #
44
+ # @api public
45
+ #
44
46
  def Path.root
45
47
  Path.new('/')
46
48
  end
@@ -69,6 +71,8 @@ module Ronin
69
71
  # # => [#<Ronin::Path:..>, #<Ronin::Path:../..>,
70
72
  # #<Ronin::Path:../../..>]
71
73
  #
74
+ # @api public
75
+ #
72
76
  def self.up(n,separator=File::SEPARATOR)
73
77
  case n
74
78
  when Integer
@@ -105,6 +109,8 @@ module Ronin
105
109
  # Path.up(7).join('etc/passwd')
106
110
  # # => #<Ronin::Path:../../../../../../../etc/passwd>
107
111
  #
112
+ # @api public
113
+ #
108
114
  def join(*names)
109
115
  names.map! { |name| name.to_s }
110
116
 
@@ -22,7 +22,7 @@ module Ronin
22
22
  # The Inflectors supported by ronin-support
23
23
  INFLECTORS = {
24
24
  :datamapper => {
25
- :path => 'dm-core/support/inflector',
25
+ :path => 'dm-core',
26
26
  :const => 'DataMapper::Inflector'
27
27
  },
28
28
  :active_support => {
@@ -55,6 +55,8 @@ module Ronin
55
55
  # @raise [NameError]
56
56
  # The constant could not be found.
57
57
  #
58
+ # @api private
59
+ #
58
60
  def Support.load_inflector!(name)
59
61
  name = name.to_sym
60
62
 
@@ -20,6 +20,6 @@
20
20
  module Ronin
21
21
  module Support
22
22
  # ronin-support version
23
- VERSION = '0.1.0'
23
+ VERSION = '0.2.0.rc1'
24
24
  end
25
25
  end
@@ -47,6 +47,8 @@ module Ronin
47
47
  # }
48
48
  # # => "\nUSER: lolcats\nPASSWORD: staclol\n"
49
49
  #
50
+ # @api public
51
+ #
50
52
  def erb(template)
51
53
  ERB.new(template).result(binding)
52
54
  end
@@ -63,6 +65,8 @@ module Ronin
63
65
  # @example
64
66
  # erb_file 'path/to/template.erb'
65
67
  #
68
+ # @api public
69
+ #
66
70
  def erb_file(template_path)
67
71
  read_template(template_path) do |template|
68
72
  erb(template)