From 337a0be8fc708fadae473671f2a1e900c3ad627c Mon Sep 17 00:00:00 2001 From: James Lee Date: Mon, 27 Sep 2010 04:12:04 +0000 Subject: [PATCH] adjust templates, move SerializedPrefs into its own file git-svn-id: file:///home/svn/framework3/trunk@10494 4d416f70-5f16-0410-b530-b9f4589650da --- .../20100926214000_add_template_prefs.rb | 11 ++++++++ lib/msf/core/model.rb | 4 ++- lib/msf/core/model/campaign.rb | 22 ---------------- lib/msf/core/model/email_template.rb | 7 ++++++ lib/msf/core/model/serialized_prefs.rb | 25 +++++++++++++++++++ lib/msf/core/model/web_template.rb | 7 ++++++ 6 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 data/sql/migrate/20100926214000_add_template_prefs.rb create mode 100644 lib/msf/core/model/serialized_prefs.rb diff --git a/data/sql/migrate/20100926214000_add_template_prefs.rb b/data/sql/migrate/20100926214000_add_template_prefs.rb new file mode 100644 index 0000000000..70b84d0734 --- /dev/null +++ b/data/sql/migrate/20100926214000_add_template_prefs.rb @@ -0,0 +1,11 @@ +class AddTemplatePrefs < ActiveRecord::Migration + def self.up + remove_column :email_templates, :generate_exe + add_column :email_templates, :prefs, :text + add_column :web_templates, :prefs, :text + end + def self.down + remove_column :email_templates, :prefs + remove_column :web_templates, :prefs + end +end diff --git a/lib/msf/core/model.rb b/lib/msf/core/model.rb index 54395b6d91..e7b63dd9b2 100644 --- a/lib/msf/core/model.rb +++ b/lib/msf/core/model.rb @@ -1,3 +1,6 @@ + +require 'msf/core/model/serialized_prefs' + require 'msf/core/model/activerecord_patches' require 'msf/core/model/user' @@ -24,4 +27,3 @@ require 'msf/core/model/campaign' require 'msf/core/model/email_address' require 'msf/core/model/email_template' require 'msf/core/model/web_template' - diff --git a/lib/msf/core/model/campaign.rb b/lib/msf/core/model/campaign.rb index ea42fef82b..661f8aadc1 100644 --- a/lib/msf/core/model/campaign.rb +++ b/lib/msf/core/model/campaign.rb @@ -1,28 +1,6 @@ module Msf class DBManager -module SerializedPrefs - def serialized_prefs_attr_accessor(*args) - args.each do |method_name| - method_declarations = %Q^ - def #{method_name} - return if not self.prefs - self.prefs[:#{method_name}] - end - - def #{method_name}=(value) - temp = self.prefs || {} - temp[:#{method_name}] = value - self.prefs = temp - end -^ - class_eval method_declarations - end - end - -end - - class Campaign < ActiveRecord::Base has_one :email_template has_one :web_template diff --git a/lib/msf/core/model/email_template.rb b/lib/msf/core/model/email_template.rb index eaa517cfb7..f0c4f777fc 100644 --- a/lib/msf/core/model/email_template.rb +++ b/lib/msf/core/model/email_template.rb @@ -4,6 +4,13 @@ class DBManager class EmailTemplate < ActiveRecord::Base belongs_to :campaign has_and_belongs_to_many :attachments + + extend SerializedPrefs + + serialize :prefs + + serialized_prefs_attr_accessor :exploit_name, :exploit_opts + serialized_prefs_attr_accessor :generate_exe end end diff --git a/lib/msf/core/model/serialized_prefs.rb b/lib/msf/core/model/serialized_prefs.rb new file mode 100644 index 0000000000..fd55d46571 --- /dev/null +++ b/lib/msf/core/model/serialized_prefs.rb @@ -0,0 +1,25 @@ +module Msf +class DBManager + +module SerializedPrefs + def serialized_prefs_attr_accessor(*args) + args.each do |method_name| + method_declarations = %Q^ + def #{method_name} + return if not self.prefs + self.prefs[:#{method_name}] + end + + def #{method_name}=(value) + temp = self.prefs || {} + temp[:#{method_name}] = value + self.prefs = temp + end +^ + class_eval method_declarations + end + end + +end +end +end diff --git a/lib/msf/core/model/web_template.rb b/lib/msf/core/model/web_template.rb index dc4e803e49..aa5eae41e4 100644 --- a/lib/msf/core/model/web_template.rb +++ b/lib/msf/core/model/web_template.rb @@ -3,6 +3,13 @@ class DBManager class WebTemplate < ActiveRecord::Base belongs_to :campaign + + extend SerializedPrefs + + serialize :prefs + + serialized_prefs_attr_accessor :exploit_type + serialized_prefs_attr_accessor :exploit_name, :exploit_opts end end