Class: Ronin::ArtifactRunner

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

Instance Method Summary collapse

Constructor Details

#initializeArtifactRunner

Returns a new instance of ArtifactRunner.



26
27
28
29
# File 'lib/ronin/artifact_runner.rb', line 26

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

Instance Method Details

#download_and_report_changesObject



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
58
59
60
61
# File 'lib/ronin/artifact_runner.rb', line 31

def download_and_report_changes
  @items = @run_list.items
  Parallel.each(@items, :in_threads => Ronin::Util.num_cores) do |item|
    @actual_branch = Ronin::Git.branch(item[:name])

    if File.exist?("#{Ronin::Config[:artifact_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[:artifact_path]}/#{item[:name]}/")
        Ronin::Git.clone(item)
        @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[:artifact_path]}.")
      Ronin::Git.clone(item)
      @changes = true if Ronin::Config[:update_on_change]
    end
  end
  @changes
end

#purge_unusedObject



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ronin/artifact_runner.rb', line 63

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

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