lib/ronin/config.rb in ronin-0.3.0 vs lib/ronin/config.rb in ronin-1.0.0.pre1

- old
+ new

@@ -1,9 +1,9 @@ # # Ronin - A Ruby platform for exploit development and security research. # -# Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com) +# Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. @@ -16,49 +16,55 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # +require 'data_paths' require 'fileutils' module Ronin module Config + include DataPaths + # The users home directory HOME = File.expand_path(ENV['HOME'] || ENV['HOMEPATH']) # Ronin home directory - PATH = FileUtils.mkdir_p(File.join(HOME,'.ronin')) + PATH = File.join(HOME,'.ronin') - # Main configuration file - CONFIG_PATH = File.join(PATH,'config.rb') - # Configuration files directory - CONFIG_DIR = FileUtils.mkdir_p(File.join(PATH,'config')) + CONFIG_DIR = File.join(PATH,'config') + # Directory which repositories are installed into + REPOS_DIR = File.join(PATH,'repos') + # Temporary file directory - TMP_DIR = FileUtils.mkdir_p(File.join(PATH,'tmp')) + TMP_DIR = File.join(PATH,'tmp') + # Directory for storing files for campaigns + CAMPAIGNS_DIR = File.join(PATH,'campaigns') + + FileUtils.mkdir(PATH) unless File.directory?(PATH) + FileUtils.mkdir(CONFIG_DIR) unless File.directory?(PATH) + FileUtils.mkdir(TMP_DIR) unless File.directory?(TMP_DIR) + FileUtils.mkdir(CAMPAIGNS_DIR) unless File.directory?(CAMPAIGNS_DIR) + # # Loads the Ronin configuration file. # - # @param [String, nil] name + # @param [Symbol, String, nil] name # The optional name of the file to load within +CONFIG_DIR+. - # If no name is given, +CONFIG_PATH+ will simply be loaded. # - # @example Load the main config file at <tt>~/.ronin/config.rb</tt> + # @example Load the config file at `~/.ronin/config/ronin.rb` # Config.load # # => true # - # @example Load a specific config file in <tt>~/.ronin/config/</tt> + # @example Load a specific config file in `~/.ronin/config/` # Config.load :sql # # => true # - def Config.load(name=nil) - if name - path = File.expand_path(File.join(CONFIG_DIR,name.to_s)) - else - path = CONFIG_PATH - end + def Config.load(name=:ronin) + path = File.expand_path(File.join(CONFIG_DIR,name.to_s)) require path if File.file?(path) end #