diff --git a/lib/msf/core/model/host.rb b/lib/msf/core/model/host.rb index 076a3947e0..8e7df025f4 100644 --- a/lib/msf/core/model/host.rb +++ b/lib/msf/core/model/host.rb @@ -11,6 +11,7 @@ class Host < ActiveRecord::Base has_many :vulns, :dependent => :destroy has_many :notes, :dependent => :destroy has_many :loots, :dependent => :destroy, :order => "loots.created_at desc" + has_many :sessions, :dependent => :destroy, :order => "sessions.opened_at" has_many :service_notes, :through => :services has_many :web_sites, :through => :services diff --git a/lib/msf/core/model/session.rb b/lib/msf/core/model/session.rb index 6a3610b86e..df2e2b8e14 100644 --- a/lib/msf/core/model/session.rb +++ b/lib/msf/core/model/session.rb @@ -2,7 +2,15 @@ module Msf class DBManager class Session < ActiveRecord::Base - has_one :host + belongs_to :host + + has_one :workspace, :through => :host + + has_many :events, :class_name => "SessionEvent", :order => "created_at" + + named_scope :alive, :conditions => "closed_at IS NULL" + named_scope :dead, :conditions => "closed_at IS NOT NULL" + serialize :datastore serialize :routes end diff --git a/lib/msf/core/model/session_event.rb b/lib/msf/core/model/session_event.rb index a6536050fa..e797b5c2d8 100644 --- a/lib/msf/core/model/session_event.rb +++ b/lib/msf/core/model/session_event.rb @@ -1,10 +1,10 @@ module Msf class DBManager - # TODO: needs a belongs_to :session when that model gets committed. - class SessionEvent < ActiveRecord::Base include DBSave + + belongs_to :session end end