<commit_before># NOTE: this AR model is called "Project" on the Pro side

module MetasploitDataModels::ActiveRecordModels::Workspace
  def self.included(base)
    base.class_eval{
      include Msf::DBManager::DBSave

      # Usage of the evil eval avoids dynamic constant assignment
      # exception when this module is included
      eval('DEFAULT = "default"') unless defined? DEFAULT

      has_many :hosts, :dependent => :destroy, :class_name => "Mdm::Host"
      has_many :services, :through => :hosts, :class_name => "Mdm::Service", :foreign_key => "service_id"
      has_many :notes, :dependent => :delete_all, :class_name => "Mdm::Note"
      has_many :loots, :through => :hosts, :dependent => :destroy, :class_name => "Mdm::Loot"
      has_many :events, :dependent => :delete_all, :class_name => "Mdm::Event"
      has_many :reports, :dependent => :destroy, :class_name => "Mdm::Report"
      has_many :report_templates, :dependent => :destroy, :class_name => "Mdm::ReportTemplate"
      has_many :tasks, :dependent => :destroy, :class_name => "Mdm::Task", :order => "created_at DESC"
      has_many :clients, :through => :hosts, :class_name => "Mdm::Client"
      has_many :vulns, :through => :hosts, :class_name => "Mdm::Vuln"
      has_many :creds, :through => :services, :dependent => :destroy, :class_name => "Mdm::Cred"
      has_many :imported_creds, :dependent => :destroy, :class_name => "Mdm::ImportedCred"
      has_many :exploited_hosts, :through => :hosts, :class_name => "Mdm::ExploitedHost"
      has_many :sessions, :through => :hosts, :class_name => "Mdm::Session"
      has_many :cred_files, :dependent => :destroy, :class_name => "Mdm::CredFile"
      has_many :listeners, :dependent => :destroy, :class_name => "Mdm::Listener"
      has_many :campaigns, :dependent => :destroy, :class_name => "Campaign"
      has_many :web_templates, :through => :campaigns, :class_name => "Mdm::WebTemplate"
      belongs_to :owner, :class_name => "Mdm::User", :foreign_key => "owner_id"
      has_and_belongs_to_many :users, :join_table => "project_members", :uniq => true, :class_name => "Mdm::User"

      before_save :normalize

      validates :name, :presence => true, :uniqueness => true, :length => {:maximum => 255}
      validates :description, :length => {:maximum => 4096}
      validate :boundary_must_be_ip_range

      def web_sites
        query = <<-EOQ
          SELECT DISTINCT web_sites.*
            FROM hosts, services, web_sites
            WHERE hosts.workspace_id = #{id} AND
            services.host_id = hosts.id AND
            web_sites.service_id = services.id<commit_msg>Moved campaign association to Rails app<commit_after># NOTE: this AR model is called "Project" on the Pro side

module MetasploitDataModels::ActiveRecordModels::Workspace
  def self.included(base)
    base.class_eval{
      include Msf::DBManager::DBSave

      # Usage of the evil eval avoids dynamic constant assignment
      # exception when this module is included
      eval('DEFAULT = "default"') unless defined? DEFAULT

      has_many :hosts, :dependent => :destroy, :class_name => "Mdm::Host"
      has_many :services, :through => :hosts, :class_name => "Mdm::Service", :foreign_key => "service_id"
      has_many :notes, :dependent => :delete_all, :class_name => "Mdm::Note"
      has_many :loots, :through => :hosts, :dependent => :destroy, :class_name => "Mdm::Loot"
      has_many :events, :dependent => :delete_all, :class_name => "Mdm::Event"
      has_many :reports, :dependent => :destroy, :class_name => "Mdm::Report"
      has_many :report_templates, :dependent => :destroy, :class_name => "Mdm::ReportTemplate"
      has_many :tasks, :dependent => :destroy, :class_name => "Mdm::Task", :order => "created_at DESC"
      has_many :clients, :through => :hosts, :class_name => "Mdm::Client"
      has_many :vulns, :through => :hosts, :class_name => "Mdm::Vuln"
      has_many :creds, :through => :services, :dependent => :destroy, :class_name => "Mdm::Cred"
      has_many :imported_creds, :dependent => :destroy, :class_name => "Mdm::ImportedCred"
      has_many :exploited_hosts, :through => :hosts, :class_name => "Mdm::ExploitedHost"
      has_many :sessions, :through => :hosts, :class_name => "Mdm::Session"
      has_many :cred_files, :dependent => :destroy, :class_name => "Mdm::CredFile"
      has_many :listeners, :dependent => :destroy, :class_name => "Mdm::Listener"
      has_many :web_templates, :through => :campaigns, :class_name => "Mdm::WebTemplate"
      belongs_to :owner, :class_name => "Mdm::User", :foreign_key => "owner_id"
      has_and_belongs_to_many :users, :join_table => "project_members", :uniq => true, :class_name => "Mdm::User"

      before_save :normalize

      validates :name, :presence => true, :uniqueness => true, :length => {:maximum => 255}
      validates :description, :length => {:maximum => 4096}
      validate :boundary_must_be_ip_range

      def web_sites
        query = <<-EOQ
          SELECT DISTINCT web_sites.*
            FROM hosts, services, web_sites
            WHERE hosts.workspace_id = #{id} AND
            services.host_id = hosts.id AND
            web_sites.service_id = services.id
{'fraction_non_alphanumeric': 0.14607824243592216, 'fraction_numerical': 0.0026980150317980345, 'mean_word_length': 3.971264367816092, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6645564', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1648, 'n_words': 414}