rastating/wordpress-exploit-framework

View on GitHub
bin/wpxf

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'wpxf'
require 'wpxf/cli/console'
require 'wpxf/cli/banner'

begin
  Slop.parse do |o|
    o.on '--version', 'print the version' do
      puts Wpxf.version
      exit
    end
  end
rescue Slop::UnknownOption => e
  puts e.message
  exit
end

console = Wpxf::Cli::Console.new
console.check_cache
console.clear

banner = Wpxf::Cli::Banner.new
banner.display

Dir.chdir(Dir.tmpdir) do
  temp_directories = Dir.glob('wpxf_*')
  unless temp_directories.empty?
    print '[!] '.yellow
    puts "#{temp_directories.length} temporary files were found that "\
         'appear to no longer be needed.'
    print '    Would you like to remove these files? [y/n]: '
    temp_directories.each { |d| FileUtils.rm_r(d) } if gets.chomp =~ /^y$/i
    puts
  end
end

found_env_var = false
ENV.each do |name, value|
  next if name.casecmp('wpxf_env').zero?
  match = name.match(/^wpxf_(.+)/i)

  if match
    console.gset match.captures[0], value
    found_env_var = true
  end
end

puts if found_env_var
console.start
console.clear