Add optional parameter to skip columns

GSoC/Meterpreter_Web_Console
Matthew Kienow 2018-03-30 19:23:41 -04:00
parent f10924a5c0
commit 4c536a1819
No known key found for this signature in database
GPG Key ID: 40787F8B1EAC6E41
1 changed files with 9 additions and 3 deletions

View File

@ -5,13 +5,19 @@ module Msf
#
# @param model - An ActiveRecord model object
# @param search - A string regex search
# @param column_name_skip_list - An array of strings containing column names to skip
# @return Arel::Nodes::Or object that represents a search of all of the model's columns
def self.create_all_column_search_conditions(model, search)
def self.create_all_column_search_conditions(model, search, column_name_skip_list=nil)
search = "(?mi)#{search}"
condition_set = model.columns.map do |column|
# remove skip columns
columns = model.columns.reject { |column|
column_name_skip_list && column_name_skip_list.include?(column.name)
}
condition_set = columns.map { |column|
Arel::Nodes::Regexp.new(Arel::Nodes::NamedFunction.new("CAST", [model.arel_table[column.name].as("TEXT")]),
Arel::Nodes.build_quoted(search))
end
}
condition_set.reduce { |conditions, condition| conditions.or(condition).expr }
end
end