Files
metasploit-gs/lib/msf/core/db_manager/ref.rb
T

48 lines
983 B
Ruby
Raw Normal View History

2014-10-13 10:06:37 -05:00
module Msf::DBManager::Ref
#
# Find or create a reference matching this name
#
def find_or_create_ref(opts)
ret = {}
::ActiveRecord::Base.connection_pool.with_connection {
if opts[:id] && !opts[:id].to_s.empty?
2019-01-03 10:47:27 -06:00
return Mdm::Ref.find(opts[:id])
end
if opts[:ref]
2019-01-03 10:47:27 -06:00
return get_ref(opts[:name])
end
ref = ::Mdm::Ref.where(name: opts[:name]).first_or_initialize
2017-11-16 22:56:55 +01:00
begin
framework.events.on_db_ref(ref) if ref
rescue ::Exception => e
wlog("Exception in on_db_ref event handler: #{e.class}: #{e}")
wlog("Call Stack\n#{e.backtrace.join("\n")}")
end
2014-10-13 10:06:37 -05:00
if ref and ref.changed?
ref.save!
end
2019-01-03 10:47:27 -06:00
ref
2014-10-13 10:06:37 -05:00
}
end
def get_ref(name)
::ActiveRecord::Base.connection_pool.with_connection {
::Mdm::Ref.find_by_name(name)
}
end
#
# Find a reference matching this name
#
def has_ref?(name)
::ActiveRecord::Base.connection_pool.with_connection {
Mdm::Ref.find_by_name(name)
}
end
2018-12-12 11:48:38 -06:00
end