module Wpxf::Cli::ModuleCache

A mixin to handle the database caching of module data.

Attributes

current_version_number[RW]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/wpxf/cli/module_cache.rb, line 7
def initialize
  super
  self.current_version_number = Wpxf.version
end

Public Instance Methods

cache_valid?() click to toggle source
# File lib/wpxf/cli/module_cache.rb, line 12
def cache_valid?
  last_version_log = Wpxf::Models::Log.first(key: 'version')
  return false if last_version_log.nil?

  current_version = Gem::Version.new(current_version_number)
  last_version = Gem::Version.new(last_version_log.value)

  current_version == last_version
end
create_module_models(type) click to toggle source
# File lib/wpxf/cli/module_cache.rb, line 22
def create_module_models(type)
  namespace = type == 'exploit' ? Wpxf::Exploit : Wpxf::Auxiliary
  namespace.module_list.each do |mod|
    instance = mod[:class].new

    Wpxf::Models::Module.create(
      path: mod[:name],
      name: instance.module_name,
      type: type,
      class_name: mod[:class].to_s
    )
  end
end
rebuild_cache() click to toggle source
# File lib/wpxf/cli/module_cache.rb, line 44
def rebuild_cache
  print_warning 'Refreshing the module cache...'

  Wpxf::Models::Module.truncate
  Wpxf.load_custom_modules

  create_module_models 'exploit'
  create_module_models 'auxiliary'

  refresh_version_log
  reset_context_stack
end
refresh_version_log() click to toggle source
# File lib/wpxf/cli/module_cache.rb, line 36
def refresh_version_log
  log = Wpxf::Models::Log.first(key: 'version')
  log = Wpxf::Models::Log.new if log.nil?
  log.key = 'version'
  log.value = current_version_number
  log.save
end