ronin 0.1.2 → 0.1.3

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 (169) hide show
  1. data/History.txt +58 -25
  2. data/Manifest.txt +15 -16
  3. data/README.txt +16 -11
  4. data/Rakefile +9 -7
  5. data/TODO.txt +6 -1
  6. data/lib/ronin.rb +1 -1
  7. data/lib/ronin/arch.rb +7 -15
  8. data/lib/ronin/author.rb +1 -1
  9. data/lib/ronin/cache.rb +1 -1
  10. data/lib/ronin/cache/cache.rb +1 -1
  11. data/lib/ronin/cache/config.rb +1 -1
  12. data/lib/ronin/cache/exceptions.rb +1 -1
  13. data/lib/ronin/cache/exceptions/extension_not_found.rb +1 -1
  14. data/lib/ronin/cache/exceptions/overlay_cached.rb +1 -1
  15. data/lib/ronin/cache/exceptions/overlay_not_found.rb +1 -1
  16. data/lib/ronin/cache/extension.rb +15 -190
  17. data/lib/ronin/cache/extension_cache.rb +2 -2
  18. data/lib/ronin/cache/maintainer.rb +1 -1
  19. data/lib/ronin/cache/overlay.rb +8 -7
  20. data/lib/ronin/cache/overlay_cache.rb +1 -1
  21. data/lib/ronin/cache/ronin.rb +1 -1
  22. data/lib/ronin/chars.rb +1 -1
  23. data/lib/ronin/chars/char_set.rb +1 -1
  24. data/lib/ronin/chars/chars.rb +1 -1
  25. data/lib/ronin/code/emittable.rb +1 -1
  26. data/lib/ronin/code/reference.rb +1 -1
  27. data/lib/ronin/code/symbol_table.rb +1 -1
  28. data/lib/ronin/code/token.rb +1 -1
  29. data/lib/ronin/config.rb +16 -9
  30. data/lib/ronin/database.rb +2 -113
  31. data/lib/ronin/database/database.rb +124 -0
  32. data/lib/ronin/{exceptions/unknown_context.rb → database/exceptions.rb} +2 -5
  33. data/lib/ronin/{exceptions/context_not_found.rb → database/exceptions/invalid_config.rb} +4 -2
  34. data/lib/ronin/extensions.rb +1 -1
  35. data/lib/ronin/extensions/hash.rb +1 -1
  36. data/lib/ronin/extensions/meta.rb +1 -1
  37. data/lib/ronin/extensions/string.rb +1 -1
  38. data/lib/ronin/extensions/uri.rb +1 -1
  39. data/lib/ronin/extensions/uri/http.rb +1 -1
  40. data/lib/ronin/extensions/uri/query_params.rb +1 -1
  41. data/lib/ronin/formatting.rb +1 -1
  42. data/lib/ronin/formatting/binary.rb +1 -1
  43. data/lib/ronin/formatting/digest.rb +1 -1
  44. data/lib/ronin/formatting/extensions.rb +1 -1
  45. data/lib/ronin/formatting/extensions/binary.rb +1 -1
  46. data/lib/ronin/formatting/extensions/binary/integer.rb +1 -1
  47. data/lib/ronin/formatting/extensions/binary/string.rb +1 -1
  48. data/lib/ronin/formatting/extensions/digest.rb +1 -1
  49. data/lib/ronin/formatting/extensions/digest/string.rb +1 -1
  50. data/lib/ronin/formatting/extensions/html.rb +1 -1
  51. data/lib/ronin/formatting/extensions/html/string.rb +1 -1
  52. data/lib/ronin/formatting/extensions/http.rb +1 -1
  53. data/lib/ronin/formatting/extensions/http/string.rb +1 -1
  54. data/lib/ronin/formatting/extensions/text.rb +1 -1
  55. data/lib/ronin/formatting/extensions/text/string.rb +1 -1
  56. data/lib/ronin/formatting/html.rb +1 -1
  57. data/lib/ronin/formatting/http.rb +1 -1
  58. data/lib/ronin/formatting/text.rb +1 -1
  59. data/lib/ronin/{pending_context.rb → has_license.rb} +21 -22
  60. data/lib/ronin/hexdump.rb +1 -1
  61. data/lib/ronin/hexdump/extensions.rb +1 -1
  62. data/lib/ronin/hexdump/extensions/file.rb +1 -1
  63. data/lib/ronin/hexdump/extensions/kernel.rb +1 -1
  64. data/lib/ronin/hexdump/hexdump.rb +1 -1
  65. data/lib/ronin/license.rb +10 -15
  66. data/lib/ronin/model.rb +14 -12
  67. data/lib/ronin/models.rb +2 -2
  68. data/lib/ronin/network.rb +1 -1
  69. data/lib/ronin/network/esmtp.rb +1 -1
  70. data/lib/ronin/network/extensions.rb +1 -1
  71. data/lib/ronin/network/extensions/esmtp.rb +1 -1
  72. data/lib/ronin/network/extensions/esmtp/net.rb +1 -1
  73. data/lib/ronin/network/extensions/http.rb +1 -1
  74. data/lib/ronin/network/extensions/http/net.rb +1 -1
  75. data/lib/ronin/network/extensions/imap.rb +1 -1
  76. data/lib/ronin/network/extensions/imap/net.rb +1 -1
  77. data/lib/ronin/network/extensions/pop3.rb +1 -1
  78. data/lib/ronin/network/extensions/pop3/net.rb +1 -1
  79. data/lib/ronin/network/extensions/smtp.rb +1 -1
  80. data/lib/ronin/network/extensions/smtp/net.rb +1 -1
  81. data/lib/ronin/network/extensions/tcp.rb +1 -1
  82. data/lib/ronin/network/extensions/tcp/net.rb +17 -1
  83. data/lib/ronin/network/extensions/telnet.rb +1 -1
  84. data/lib/ronin/network/extensions/telnet/net.rb +1 -1
  85. data/lib/ronin/network/extensions/udp.rb +1 -1
  86. data/lib/ronin/network/extensions/udp/net.rb +1 -1
  87. data/lib/ronin/network/http.rb +1 -1
  88. data/lib/ronin/network/http/exceptions.rb +1 -1
  89. data/lib/ronin/network/http/exceptions/unknown_request.rb +1 -1
  90. data/lib/ronin/network/imap.rb +1 -1
  91. data/lib/ronin/network/pop3.rb +1 -1
  92. data/lib/ronin/network/smtp.rb +1 -1
  93. data/lib/ronin/network/smtp/email.rb +1 -1
  94. data/lib/ronin/network/smtp/smtp.rb +1 -1
  95. data/lib/ronin/network/tcp.rb +1 -1
  96. data/lib/ronin/network/telnet.rb +1 -1
  97. data/lib/ronin/network/udp.rb +1 -1
  98. data/lib/ronin/objectify.rb +24 -0
  99. data/lib/ronin/{exceptions/invalid_database_config.rb → objectify/exceptions.rb} +3 -5
  100. data/lib/ronin/{exceptions → objectify/exceptions}/object_context_not_found.rb +1 -1
  101. data/lib/ronin/{exceptions → objectify/exceptions}/unknown_object_context.rb +1 -1
  102. data/lib/ronin/{object_context.rb → objectify/objectify.rb} +54 -45
  103. data/lib/ronin/path.rb +1 -1
  104. data/lib/ronin/platform.rb +3 -1
  105. data/lib/ronin/product.rb +2 -1
  106. data/lib/ronin/ronin.rb +10 -10
  107. data/lib/ronin/rpc.rb +1 -1
  108. data/lib/ronin/rpc/call.rb +1 -1
  109. data/lib/ronin/rpc/client.rb +1 -1
  110. data/lib/ronin/rpc/console.rb +1 -1
  111. data/lib/ronin/rpc/exceptions.rb +1 -1
  112. data/lib/ronin/rpc/exceptions/not_implemented.rb +1 -1
  113. data/lib/ronin/rpc/exceptions/response_missing.rb +1 -1
  114. data/lib/ronin/rpc/response.rb +1 -1
  115. data/lib/ronin/rpc/service.rb +1 -1
  116. data/lib/ronin/rpc/shell.rb +1 -1
  117. data/lib/ronin/sessions.rb +1 -1
  118. data/lib/ronin/sessions/esmtp.rb +6 -8
  119. data/lib/ronin/sessions/http.rb +1 -1
  120. data/lib/ronin/sessions/imap.rb +6 -8
  121. data/lib/ronin/sessions/pop3.rb +6 -8
  122. data/lib/ronin/sessions/session.rb +1 -1
  123. data/lib/ronin/sessions/smtp.rb +6 -8
  124. data/lib/ronin/sessions/tcp.rb +48 -36
  125. data/lib/ronin/sessions/telnet.rb +7 -10
  126. data/lib/ronin/sessions/udp.rb +28 -29
  127. data/lib/ronin/sessions/web.rb +5 -7
  128. data/lib/ronin/target.rb +1 -0
  129. data/lib/ronin/translators/translator.rb +1 -1
  130. data/lib/ronin/ui/command_line.rb +1 -1
  131. data/lib/ronin/ui/command_line/command.rb +1 -1
  132. data/lib/ronin/ui/command_line/command_line.rb +7 -2
  133. data/lib/ronin/ui/command_line/commands.rb +2 -2
  134. data/lib/ronin/ui/command_line/commands/add.rb +8 -8
  135. data/lib/ronin/ui/command_line/commands/default.rb +1 -1
  136. data/lib/ronin/ui/command_line/commands/extension.rb +13 -26
  137. data/lib/ronin/ui/command_line/commands/help.rb +1 -1
  138. data/lib/ronin/ui/command_line/commands/install.rb +7 -7
  139. data/lib/ronin/ui/command_line/commands/list.rb +13 -7
  140. data/lib/ronin/ui/command_line/commands/overlay.rb +1 -1
  141. data/lib/ronin/ui/command_line/commands/remove.rb +4 -4
  142. data/lib/ronin/ui/command_line/commands/uninstall.rb +4 -4
  143. data/lib/ronin/ui/command_line/commands/update.rb +3 -3
  144. data/lib/ronin/ui/command_line/exceptions.rb +1 -1
  145. data/lib/ronin/ui/command_line/exceptions/unknown_command.rb +1 -1
  146. data/lib/ronin/ui/command_line/options.rb +1 -1
  147. data/lib/ronin/ui/command_line/param_parser.rb +73 -0
  148. data/lib/ronin/ui/console.rb +1 -1
  149. data/lib/ronin/ui/shell.rb +1 -1
  150. data/lib/ronin/version.rb +2 -2
  151. data/lib/ronin/web.rb +1 -1
  152. data/lib/ronin/web/web.rb +1 -1
  153. data/spec/chars/char_set_spec.rb +116 -118
  154. data/spec/chars/chars_spec.rb +54 -63
  155. data/spec/formatting/{binary_spec.rb → binary/integer_spec.rb} +0 -19
  156. data/spec/formatting/binary/string_spec.rb +32 -0
  157. data/spec/{object_context/object_context_spec.rb → objectify/objectify_spec.rb} +5 -3
  158. data/spec/path_spec.rb +21 -23
  159. data/spec/translators/translator_spec.rb +38 -40
  160. data/spec/ui/command_line/param_parser_spec.rb +58 -0
  161. data/static/extension.rb +9 -0
  162. metadata +43 -24
  163. data/lib/ronin/context.rb +0 -236
  164. data/spec/context/context_spec.rb +0 -84
  165. data/spec/context/helpers/book_context.rb +0 -15
  166. data/spec/context/helpers/book_review_context.rb +0 -21
  167. data/spec/context/helpers/contexts/neuromancer_review.rb +0 -15
  168. data/spec/context/helpers/contexts/snow_crash.rb +0 -8
  169. data/static/extension.rb.erb +0 -16
@@ -3,7 +3,7 @@
3
3
  # Ronin - A Ruby platform designed for information security and data
4
4
  # exploration tasks.
5
5
  #
6
- # Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -37,7 +37,7 @@ module Ronin
37
37
  hash[name] = load_extension(key.to_s)
38
38
  end
39
39
 
40
- catch('EXIT') do
40
+ at_exit do
41
41
  each_extension { |ext| ext.perform_teardown }
42
42
  end
43
43
 
@@ -3,7 +3,7 @@
3
3
  # Ronin - A Ruby platform designed for information security and data
4
4
  # exploration tasks.
5
5
  #
6
- # Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -3,7 +3,7 @@
3
3
  # Ronin - A Ruby platform designed for information security and data
4
4
  # exploration tasks.
5
5
  #
6
- # Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -262,7 +262,7 @@ module Ronin
262
262
  def cache_objects
263
263
  require 'ronin/models'
264
264
 
265
- return ObjectContext.cache_objects_in(objects_dir)
265
+ return Objectify.cache_objects_in(objects_dir)
266
266
  end
267
267
 
268
268
  #
@@ -271,7 +271,7 @@ module Ronin
271
271
  def mirror_objects
272
272
  require 'ronin/models'
273
273
 
274
- return ObjectContext.mirror_objects_in(objects_dir)
274
+ return Objectify.mirror_objects_in(objects_dir)
275
275
  end
276
276
 
277
277
  #
@@ -280,7 +280,7 @@ module Ronin
280
280
  def expunge_objects
281
281
  require 'ronin/models'
282
282
 
283
- return ObjectContext.expunge_objects_from(objects_dir)
283
+ return Objectify.expunge_objects_from(objects_dir)
284
284
  end
285
285
 
286
286
  #
@@ -338,7 +338,7 @@ module Ronin
338
338
  # Returns the paths of all extensions within the overlay.
339
339
  #
340
340
  def extension_paths
341
- directories
341
+ directories.reject { |dir| File.basename(dir) == 'objects' }
342
342
  end
343
343
 
344
344
  #
@@ -375,9 +375,10 @@ module Ronin
375
375
  # If a _block_ is given, it will be passed the newly created
376
376
  # extension.
377
377
  #
378
- # repo.extension('awesome') # => Extension
378
+ # overlay.extension('awesome')
379
+ # # => #<Ronin::Cache::Extension: ...>
379
380
  #
380
- # repo.extension('shellcode') do |ext|
381
+ # overlay.extension('shellcode') do |ext|
381
382
  # ...
382
383
  # end
383
384
  #
@@ -3,7 +3,7 @@
3
3
  # Ronin - A Ruby platform designed for information security and data
4
4
  # exploration tasks.
5
5
  #
6
- # Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -3,7 +3,7 @@
3
3
  # Ronin - A Ruby platform designed for information security and data
4
4
  # exploration tasks.
5
5
  #
6
- # Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
data/lib/ronin/chars.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # Ronin - A Ruby platform designed for information security and data
4
4
  # exploration tasks.
5
5
  #
6
- # Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -3,7 +3,7 @@
3
3
  # Ronin - A Ruby platform designed for information security and data
4
4
  # exploration tasks.
5
5
  #
6
- # Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -3,7 +3,7 @@
3
3
  # Ronin - A Ruby platform designed for information security and data
4
4
  # exploration tasks.
5
5
  #
6
- # Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -3,7 +3,7 @@
3
3
  # Ronin - A Ruby platform designed for information security and data
4
4
  # exploration tasks.
5
5
  #
6
- # Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -3,7 +3,7 @@
3
3
  # Ronin - A Ruby platform designed for information security and data
4
4
  # exploration tasks.
5
5
  #
6
- # Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -3,7 +3,7 @@
3
3
  # Ronin - A Ruby platform designed for information security and data
4
4
  # exploration tasks.
5
5
  #
6
- # Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -3,7 +3,7 @@
3
3
  # Ronin - A Ruby platform designed for information security and data
4
4
  # exploration tasks.
5
5
  #
6
- # Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
data/lib/ronin/config.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # Ronin - A Ruby platform designed for information security and data
4
4
  # exploration tasks.
5
5
  #
6
- # Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -25,17 +25,20 @@ require 'fileutils'
25
25
 
26
26
  module Ronin
27
27
  module Config
28
+ # The users home directory
29
+ HOME = File.expand_path(ENV['HOME'] || ENV['HOMEPATH'])
30
+
28
31
  # Ronin home directory
29
- PATH = FileUtils.mkdir_p(File.join(ENV['HOME'],'.ronin'))
32
+ PATH = FileUtils.mkdir_p(File.join(HOME,'.ronin'))
30
33
 
31
34
  # Path to static directory
32
35
  STATIC_DIR = File.expand_path(File.join(File.dirname(__FILE__),'..','..','static'))
33
36
 
34
37
  # Main configuration file
35
- CONFIG_PATH = File.expand_path(File.join(PATH,'config.rb'))
38
+ CONFIG_PATH = File.join(PATH,'config.rb')
36
39
 
37
40
  # Configuration files directory
38
- CONFIG_DIR = File.expand_path(File.join(PATH,'config'))
41
+ CONFIG_DIR = FileUtils.mkdir_p(File.join(PATH,'config'))
39
42
 
40
43
  # Temporary file directory
41
44
  TMP_DIR = FileUtils.mkdir_p(File.join(PATH,'tmp'))
@@ -45,15 +48,19 @@ module Ronin
45
48
  # Ronin configuration files directory. If _name_ is not given, than the
46
49
  # main Ronin configuration file will be loaded.
47
50
  #
48
- # # Load the main config file at <tt>~/.ronin/config.rb</tt>
49
- # Config.load # => true
51
+ # Load the main config file at <tt>~/.ronin/config.rb</tt>
52
+ #
53
+ # Config.load
54
+ # # => true
55
+ #
56
+ # Load a specific config file in <tt>~/.ronin/config/</tt>
50
57
  #
51
- # # Load a specific config file in <tt>~/.ronin/config/</tt>
52
- # Config.load 'sql' # => true
58
+ # Config.load :sql
59
+ # # => true
53
60
  #
54
61
  def Config.load(name=nil)
55
62
  if name
56
- path = File.expand_path(File.join(CONFIG_DIR,name))
63
+ path = File.expand_path(File.join(CONFIG_DIR,name.to_s))
57
64
  else
58
65
  path = CONFIG_PATH
59
66
  end
@@ -3,7 +3,7 @@
3
3
  # Ronin - A Ruby platform designed for information security and data
4
4
  # exploration tasks.
5
5
  #
6
- # Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
7
  #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of the GNU General Public License as published by
@@ -21,115 +21,4 @@
21
21
  #++
22
22
  #
23
23
 
24
- require 'ronin/exceptions/invalid_database_config'
25
- require 'ronin/arch'
26
- require 'ronin/platform'
27
- require 'ronin/author'
28
- require 'ronin/license'
29
- require 'ronin/product'
30
- require 'ronin/config'
31
-
32
- require 'yaml'
33
- require 'dm-core'
34
-
35
- module Ronin
36
- module Database
37
- # Database configuration file
38
- CONFIG_FILE = File.join(Config::PATH,'database.yml')
39
-
40
- # Database log file
41
- DEFAULT_LOG_PATH = File.join(Config::PATH,'database.log')
42
-
43
- # Database log level
44
- DEFAULT_LOG_LEVEL = :info
45
-
46
- # Default configuration of the database
47
- DEFAULT_CONFIG = {
48
- :adapter => :sqlite3,
49
- :database => File.join(Config::PATH,'database.sqlite3')
50
- }
51
-
52
- #
53
- # Returns the Database configuration that is stored in the
54
- # +CONFIG_FILE+. Defaults to +DEFAULT_CONFIG+ if +CONFIG_FILE+ does not
55
- # exist.
56
- #
57
- def Database.config
58
- unless (class_variable_defined?('@@ronin_database_config'))
59
- @@ronin_database_config = DEFAULT_CONFIG
60
-
61
- if File.file?(CONFIG_FILE)
62
- conf = YAML.load(CONFIG_FILE)
63
-
64
- unless (conf.kind_of?(Hash) || conf.kind_of?(String))
65
- raise(InvalidDatabaseConfig,"#{CONFIG_FILE} must contain either a Hash or a String",caller)
66
- end
67
-
68
- @@ronin_database_config = conf
69
- end
70
- end
71
-
72
- return @@ronin_database_config ||= DEFAULT_CONFIG
73
- end
74
-
75
- #
76
- # Sets the Database configuration to the specified _configuration_.
77
- #
78
- def Database.config=(configuration)
79
- @@ronin_database_config = configuration
80
- end
81
-
82
- #
83
- # Returns the current Database log.
84
- #
85
- def Database.log
86
- @@ronin_database_log ||= nil
87
- end
88
-
89
- #
90
- # Setup the Database log with the given _options_.
91
- #
92
- # _options_ may contain the following keys:
93
- # <tt>:path</tt>:: The path of the log file. Defaults to
94
- # +DEFAULT_LOG_PATH+.
95
- # <tt>:stream</tt>:: The stream to use for the log.
96
- # <tt>:level</tt>:: The level of messages to log.
97
- #
98
- def Database.setup_log(options={})
99
- path = (options[:path] || DEFAULT_LOG_PATH)
100
- stream = (options[:stream] || File.new(path,'w+'))
101
- level = (options[:level] || DEFAULT_LOG_LEVEL)
102
-
103
- return @@ronin_database_log = DataMapper::Logger.new(stream,level)
104
- end
105
-
106
- #
107
- # Sets up the Database with the given _configuration_. If
108
- # _configuration is not given, +DEFAULT_CONFIG+ will be used to setup
109
- # the Database.
110
- #
111
- def Database.setup(configuration=Database.config,&block)
112
- # setup the database log
113
- Database.setup_log unless Database.log
114
-
115
- # setup the database repository
116
- DataMapper.setup(Model::REPOSITORY_NAME, configuration)
117
-
118
- block.call if block
119
-
120
- # sourced from http://gist.github.com/3010
121
- # in order to fix a has-many lazy-loading bug
122
- # in dm-core <= 0.9.4
123
- descendants = DataMapper::Resource.descendants.dup
124
- descendants.each do |model|
125
- descendants.merge(model.descendants) if model.respond_to?(:descendants)
126
- end
127
- descendants.each do |model|
128
- model.relationships.each_value { |r| r.child_key if r.child_model == model }
129
- end
130
-
131
- DataMapper.auto_upgrade!(Model::REPOSITORY_NAME)
132
- return nil
133
- end
134
- end
135
- end
24
+ require 'ronin/database/database'
@@ -0,0 +1,124 @@
1
+ #
2
+ #--
3
+ # Ronin - A Ruby platform designed for information security and data
4
+ # exploration tasks.
5
+ #
6
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ #++
22
+ #
23
+
24
+ require 'ronin/database/exceptions/invalid_config'
25
+ require 'ronin/arch'
26
+ require 'ronin/platform'
27
+ require 'ronin/author'
28
+ require 'ronin/license'
29
+ require 'ronin/product'
30
+ require 'ronin/config'
31
+
32
+ require 'yaml'
33
+ require 'dm-core'
34
+
35
+ module Ronin
36
+ module Database
37
+ # Database configuration file
38
+ CONFIG_FILE = File.join(Config::PATH,'database.yml')
39
+
40
+ # Database log file
41
+ DEFAULT_LOG_PATH = File.join(Config::PATH,'database.log')
42
+
43
+ # Database log level
44
+ DEFAULT_LOG_LEVEL = :info
45
+
46
+ # Default configuration of the database
47
+ DEFAULT_CONFIG = {
48
+ :adapter => :sqlite3,
49
+ :database => File.join(Config::PATH,'database.sqlite3')
50
+ }
51
+
52
+ #
53
+ # Returns the Database configuration that is stored in the
54
+ # +CONFIG_FILE+. Defaults to +DEFAULT_CONFIG+ if +CONFIG_FILE+ does not
55
+ # exist.
56
+ #
57
+ def Database.config
58
+ unless (class_variable_defined?('@@ronin_database_config'))
59
+ @@ronin_database_config = DEFAULT_CONFIG
60
+
61
+ if File.file?(CONFIG_FILE)
62
+ conf = YAML.load(CONFIG_FILE)
63
+
64
+ unless (conf.kind_of?(Hash) || conf.kind_of?(String))
65
+ raise(InvalidConfig,"#{CONFIG_FILE} must contain either a Hash or a String",caller)
66
+ end
67
+
68
+ @@ronin_database_config = conf
69
+ end
70
+ end
71
+
72
+ return @@ronin_database_config ||= DEFAULT_CONFIG
73
+ end
74
+
75
+ #
76
+ # Sets the Database configuration to the specified _configuration_.
77
+ #
78
+ def Database.config=(configuration)
79
+ @@ronin_database_config = configuration
80
+ end
81
+
82
+ #
83
+ # Returns the current Database log.
84
+ #
85
+ def Database.log
86
+ @@ronin_database_log ||= nil
87
+ end
88
+
89
+ #
90
+ # Setup the Database log with the given _options_.
91
+ #
92
+ # _options_ may contain the following keys:
93
+ # <tt>:path</tt>:: The path of the log file. Defaults to
94
+ # +DEFAULT_LOG_PATH+.
95
+ # <tt>:stream</tt>:: The stream to use for the log.
96
+ # <tt>:level</tt>:: The level of messages to log.
97
+ #
98
+ def Database.setup_log(options={})
99
+ path = (options[:path] || DEFAULT_LOG_PATH)
100
+ stream = (options[:stream] || File.new(path,'w+'))
101
+ level = (options[:level] || DEFAULT_LOG_LEVEL)
102
+
103
+ return @@ronin_database_log = DataMapper::Logger.new(stream,level)
104
+ end
105
+
106
+ #
107
+ # Sets up the Database with the given _configuration_. If
108
+ # _configuration is not given, +DEFAULT_CONFIG+ will be used to setup
109
+ # the Database.
110
+ #
111
+ def Database.setup(configuration=Database.config,&block)
112
+ # setup the database log
113
+ Database.setup_log unless Database.log
114
+
115
+ # setup the database repository
116
+ DataMapper.setup(Model::REPOSITORY_NAME, configuration)
117
+
118
+ block.call if block
119
+
120
+ DataMapper.auto_upgrade!(Model::REPOSITORY_NAME)
121
+ return nil
122
+ end
123
+ end
124
+ end