From 175cae50473957f24b22b73f36bc667b0f340f41 Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Fri, 15 Apr 2011 18:54:27 +0000 Subject: [PATCH] Add associations between Host, Session & SessionEvent model objects. git-svn-id: file:///home/svn/framework3/trunk@12325 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/core/model/host.rb | 1 + lib/msf/core/model/session.rb | 10 +++++++++- lib/msf/core/model/session_event.rb | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) 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