Class: Ronin::ModuleRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/module_runner.rb

Instance Method Summary collapse

Constructor Details

#initializeModuleRunner

Returns a new instance of ModuleRunner.



23
24
25
26
# File 'lib/ronin/module_runner.rb', line 23

def initialize
  @changes    = false
  @run_list   = Ronin::RunList.new
end

Instance Method Details

#download_and_report_changesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ronin/module_runner.rb', line 28

def download_and_report_changes
  @run_list.items.each do |item|
     @actual_branch = Ronin::Git.branch(item[:name])

    if File.exist?("#{Ronin::Config[:module_path]}/#{item[:name]}")
      if item[:branch] != 'master'
        Ronin::Log.info("Module #{item[:name]} is being pulled from the #{item[:branch]} branch and not master.")
      end

      if @actual_branch == item[:branch]
        Ronin::Log.info("Module #{item[:name]} already cached, pulling updates to #{item[:branch]} from #{item[:repo]}.")
        @updated = Ronin::Git.pull_and_report_updated(item[:name])
        if @updated
          Ronin::Log.info("Module #{item[:name]} has updates.")
          @changes = true if Ronin::Config[:update_on_change]
        end
      else
        Ronin::Log.info("Module #{item[:name]} already cached, but is the wrong branch. Deleting cached copy of branch #{@actual_branch}")
        FileUtils.rm_rf("#{Ronin::Config[:module_path]}/#{item[:name]}/")
        Ronin::Git.clone(item[:name], item[:branch])
        @changes = true if Ronin::Config[:update_on_change]
      end
    else
      Ronin::Log.info("Module #{item[:name]} not cached, cloning branch #{item[:branch]} of #{item[:repo]} to #{Ronin::Config[:module_path]}.")
      Ronin::Git.clone(item[:name], item[:branch])
      @changes = true if Ronin::Config[:update_on_change]
    end
  end
  @changes
end

#purge_unusedObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ronin/module_runner.rb', line 59

def purge_unused
  @local_modules = Dir.entries(Ronin::Config[:module_path]).select { |dir| File.directory?("#{Ronin::Config[:module_path]}/#{dir}") and !(dir =='.' || dir == '..') }
  @modules = @run_list.modules

  @local_modules.each do |mod|
    unless @modules.include?(mod)
      Ronin::Log.info("No module named #{mod} in run list, but it exists in #{Ronin::Config[:module_path]}. Purging it.")
      FileUtils.rm_rf("#{Ronin::Config[:module_path]}/#{mod}/")
    end
  end
end