MDM cache update

unstable
Samuel Huckins 2012-08-15 10:16:47 -05:00
parent 0a6e0b2415
commit a8ea014f25
4 changed files with 24 additions and 6 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env ruby_noexec_wrapper
#!/Users/shuckins/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
#
# This file was generated by RubyGems.
#
@ -10,9 +10,13 @@ require 'rubygems'
version = ">= 0"
if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
version = $1
ARGV.shift
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/
version = $1
ARGV.shift
end
end
gem 'metasploit_data_models', version

View File

@ -3,6 +3,7 @@ module MetasploitDataModels::ActiveRecordModels::Host
base.class_eval{
belongs_to :workspace, :class_name => "Mdm::Workspace"
# hosts_tags are cleaned up in before_destroy:
has_many :hosts_tags, :class_name => "Mdm::HostTag"
has_many :tags, :through => :hosts_tags, :class_name => "Mdm::Tag"
has_many :services, :dependent => :destroy, :class_name => "Mdm::Service", :order => "services.port, services.proto"
@ -24,6 +25,8 @@ module MetasploitDataModels::ActiveRecordModels::Host
validates_exclusion_of :address, :in => ['127.0.0.1']
validates_uniqueness_of :address, :scope => :workspace_id, :unless => Proc.new { |host| host.ip_address_invalid? }
before_destroy :cleanup_tags
# This is replicated by the IpAddressValidator class. Had to put it here as well to avoid
# SQL errors when checking address uniqueness.
def ip_address_invalid?
@ -57,10 +60,13 @@ module MetasploitDataModels::ActiveRecordModels::Host
accepts_nested_attributes_for :services, :reject_if => lambda { |s| s[:port].blank? }, :allow_destroy => true
def before_destroy
def cleanup_tags
# No need to keep tags with no hosts
tags.each do |tag|
tag.destroy if tag.hosts == [self]
end
# Clean up association table records
Mdm::HostTag.delete_all("host_id = #{self.id}")
end
# Determine if the fingerprint data is readable. If not, it nearly always

View File

@ -11,9 +11,17 @@ module MetasploitDataModels::ActiveRecordModels::Tag
}
validates :desc, :length => {:maximum => 8191, :message => "desc must be less than 8k."}
before_destroy :cleanup_hosts
def to_s
name
end
def cleanup_hosts
# Clean up association table records
Mdm::HostTag.delete_all("tag_id = #{self.id}")
end
}
end
end

View File

@ -6,7 +6,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Trevor Rosen"]
s.date = "2012-06-25"
s.date = "2012-08-15"
s.description = "Implements minimal ActiveRecord models and database helper code used in both the Metasploit Framework (MSF) and Metasploit commercial editions."
s.email = ["trevor_rosen@rapid7.com"]
s.executables = ["mdm_console"]