2007-01-18 15:31:42 +00:00
|
|
|
# Author: HDM <hdm@metasploit.com> and LMH <lmh@info-pull.com>
|
2006-09-29 13:53:51 +00:00
|
|
|
# Description: Helper methods for the controllers, including search and other
|
|
|
|
|
# functionality.
|
|
|
|
|
|
2006-09-24 00:21:23 +00:00
|
|
|
# Filters added to this controller will be run for all controllers in the application.
|
|
|
|
|
# Likewise, all the methods added will be available for all controllers.
|
|
|
|
|
class ApplicationController < ActionController::Base
|
2006-09-27 05:18:06 +00:00
|
|
|
|
2006-09-29 13:53:51 +00:00
|
|
|
# Search functionality for modules
|
2006-09-27 05:18:06 +00:00
|
|
|
def search_modules(mlist, terms)
|
2006-09-29 04:31:20 +00:00
|
|
|
res = {}
|
2006-09-27 22:02:51 +00:00
|
|
|
|
|
|
|
|
unless terms
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
|
2006-10-16 04:45:42 +00:00
|
|
|
terms.strip!
|
|
|
|
|
|
2006-09-29 04:31:20 +00:00
|
|
|
# Match search terms
|
2006-09-27 05:18:06 +00:00
|
|
|
mlist.each do |m|
|
2006-09-27 22:09:55 +00:00
|
|
|
|
2006-09-29 04:31:20 +00:00
|
|
|
if (terms.length == 0)
|
|
|
|
|
res[m.name]=m
|
|
|
|
|
next
|
|
|
|
|
end
|
2006-10-16 04:45:42 +00:00
|
|
|
|
|
|
|
|
terms.split(/,/).each do |term|
|
|
|
|
|
|
|
|
|
|
if (m.name.downcase.index(term.downcase))
|
|
|
|
|
res[m.name]=m
|
|
|
|
|
break
|
|
|
|
|
end
|
2006-09-27 05:18:06 +00:00
|
|
|
|
2006-10-16 04:45:42 +00:00
|
|
|
if (m.refname.downcase.index(term.downcase))
|
|
|
|
|
res[m.name]=m
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if (m.description.downcase.index(term.downcase))
|
|
|
|
|
res[m.name]=m
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
|
2006-09-27 05:18:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
2006-09-27 22:09:55 +00:00
|
|
|
|
2006-09-29 04:31:20 +00:00
|
|
|
# Sort the modules by name
|
|
|
|
|
list = []
|
|
|
|
|
res.keys.sort.each do |n|
|
|
|
|
|
list << res[n]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
list
|
2006-09-27 05:18:06 +00:00
|
|
|
end
|
|
|
|
|
|
2006-09-29 13:53:51 +00:00
|
|
|
# Returns the module by id of specified type.
|
2006-12-19 14:01:08 +00:00
|
|
|
def get_view_for_module(module_type, module_refname)
|
2006-09-29 13:53:51 +00:00
|
|
|
@tmod = nil
|
|
|
|
|
|
|
|
|
|
# Get available moduls of specified type
|
|
|
|
|
case module_type
|
|
|
|
|
when "exploit"
|
|
|
|
|
@mod_list = Exploit.find_all()
|
|
|
|
|
when "auxiliary"
|
|
|
|
|
@mod_list = Auxiliary.find_all()
|
|
|
|
|
when "payload"
|
|
|
|
|
@mod_list = Payload.find_all()
|
|
|
|
|
when "nop"
|
|
|
|
|
@mod_list = Nop.find_all()
|
|
|
|
|
when "encoder"
|
|
|
|
|
@mod_list = Encoder.find_all()
|
|
|
|
|
else
|
|
|
|
|
return @tmod
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Return the module if found
|
2006-12-19 14:01:08 +00:00
|
|
|
if module_refname
|
2006-09-29 13:53:51 +00:00
|
|
|
@mod_list.each do |m|
|
2006-12-19 14:01:08 +00:00
|
|
|
if m.refname.gsub('/', ':') == module_refname
|
2006-09-29 13:53:51 +00:00
|
|
|
@tmod = m
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return @tmod
|
|
|
|
|
end
|
|
|
|
|
|
2006-09-27 05:18:06 +00:00
|
|
|
end
|