Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/util/db_manager.rb
Views: 11779
module Msf1module Util2module DBManager3# Creates search conditions to match the specified search string against all of the model's columns.4#5# @param model - An ActiveRecord model object6# @param search - A string regex search7# @param column_name_skip_list - An array of strings containing column names to skip8# @return Arel::Nodes::Or object that represents a search of all of the model's columns9def self.create_all_column_search_conditions(model, search, column_name_skip_list=nil)10search = "(?mi)#{search}"11# remove skip columns12columns = model.columns.reject { |column|13column_name_skip_list && column_name_skip_list.include?(column.name)14}1516condition_set = columns.map { |column|17Arel::Nodes::Regexp.new(Arel::Nodes::NamedFunction.new("CAST", [model.arel_table[column.name].as("TEXT")]),18Arel::Nodes.build_quoted(search))19}20Arel::Nodes::Grouping.new(condition_set.reduce { |conditions, condition| conditions.or(condition).expr })21end2223# Processes the workspace value in the opts hash from a request. This method throws an exception if24# :workspace was not present but required was true, deletes the workspace from the hash, and25# looks up the workspace object by name, which it returns.26#27# @param [Hash] opts The opts hash passed in from the data request. Should contain :workspace if required is true.28# @param [Msf::Framework] framework A framework object containing a valid database connection.29# @param [Bool] required true if the :workspace key is required for this data operation. false if it is only optional.30# @raise [ArgumentError] opts must include a valid :workspace31# @raise [RuntimeError] couldn't find workspace32# @return [Mdm::Workspace] The workspace object that was referenced by name in opts.33def self.process_opts_workspace(opts, framework, required = true)34wspace = opts[:workspace]35if required && (wspace.nil? || (wspace.kind_of?(String) && wspace.empty?))36raise ArgumentError.new("opts must include a valid :workspace")37end3839case wspace40when Hash41workspace_name = wspace[:name]42when String43workspace_name = wspace44when Mdm::Workspace45workspace_name = wspace.name46else47workspace_name = nil48end4950wspace = framework.db.find_workspace(workspace_name) unless workspace_name.nil?51raise "Couldn't find workspace #{workspace_name}" if wspace.nil? && required5253wspace54end5556end57end58end596061