Files
metasploit-gs/lib/msf/core/db_objects.rb
T

89 lines
1.5 KiB
Ruby
Raw Normal View History

2006-03-21 04:37:48 +00:00
module Msf
##
#
# This module defines all of the DB database tables
# and creates ActiveRecord objects for each one of them
#
##
class DBManager
2006-04-03 04:33:30 +00:00
class Lock
@@mutex = Mutex.new
def self.mutex
@@mutex
end
end
# ActiveRecord/sqlite3 has locking issues when you update a table with a pending select
# This set of instance/class wrappers should prevent a table lock
2006-04-03 04:50:26 +00:00
# Straight up gangsta shit from spoon (ripped from BION)
2006-04-03 04:33:30 +00:00
module DBSave
2006-04-03 04:50:26 +00:00
def save(*args)
Lock.mutex.synchronize do
super(*args)
end
end
2006-04-03 04:33:30 +00:00
2006-04-03 04:50:26 +00:00
def self.included(mod)
class << mod
def find(*args)
Lock.mutex.synchronize do
super(*args)
end
end
end
2006-04-03 04:33:30 +00:00
end
end
2006-03-21 04:37:48 +00:00
# Host object definition
class Host < ActiveRecord::Base
2006-04-03 04:33:30 +00:00
include DBSave
2006-09-16 20:08:13 +00:00
has_many :services
has_many :vulns, :through => :services
2006-03-21 04:37:48 +00:00
end
# Service object definition
class Service < ActiveRecord::Base
2006-04-03 04:33:30 +00:00
include DBSave
2006-09-16 20:08:13 +00:00
has_many :vulns
belongs_to :host
2006-09-17 00:39:23 +00:00
def host
Host.find(:first, :conditions => [ "id = ?", host_id ])
end
2006-04-02 22:33:34 +00:00
end
# Vuln object definition
class Vuln < ActiveRecord::Base
2006-04-03 04:33:30 +00:00
include DBSave
2006-09-16 20:08:13 +00:00
belongs_to :service
has_and_belongs_to_many :refs, :join_table => :vulns_refs
2006-09-17 00:39:23 +00:00
2006-04-02 22:33:34 +00:00
def service
Service.find(:first, :conditions => [ "id = ?", service_id ])
end
2006-09-17 00:39:23 +00:00
2006-04-02 22:33:34 +00:00
def host
Host.find(:first, :conditions => [ "id = ?", service.host_id ])
end
2006-03-21 04:37:48 +00:00
end
2006-09-16 20:08:13 +00:00
# Reference object definition
class Ref < ActiveRecord::Base
include DBSave
2006-09-17 00:39:23 +00:00
has_and_belongs_to_many :vulns, :join_table => :vulns_refs
2006-09-16 20:08:13 +00:00
end
2006-09-17 00:39:23 +00:00
# Reference object definition
class VulnRefs < ActiveRecord::Base
set_table_name 'vulns_refs'
include DBSave
end
2006-09-16 20:08:13 +00:00
2006-03-21 04:37:48 +00:00
end
end