4 # :title: rbot wordlist provider
6 # Author:: Raine Virta <rane@kapsi.fi>
13 def self.wordlist_base
14 @@wordlist_base ||= File.join(Utils.bot.botclass, 'wordlists')
17 def self.get(path, options={})
18 opts = { :spaces => false }.merge(options)
20 wordlist_path = File.join(wordlist_base, path)
21 raise "wordlist not found: #{wordlist_path}" unless File.exist?(wordlist_path)
23 # Location is a directory -> combine all lists beneath it
24 wordlist = if File.directory?(wordlist_path)
26 Find.find(wordlist_path) do |path|
27 next if path == wordlist_path
28 wordlists << path unless File.directory?(path)
31 wordlists.map { |list| File.readlines(list) }.flatten
33 File.readlines(wordlist_path)
36 wordlist.map! { |l| l.strip }
37 wordlist.reject do |word|
38 word =~ /\s/ && !opts[:spaces] ||
43 # Return an array with the list of available wordlists.
45 # pattern:: pattern that should be matched by the wordlist filename
46 def self.list(options={})
47 pattern = options[:pattern] || "**"
48 # refuse patterns that contain ../
49 return [] if pattern =~ /\.\.\//
50 striplen = self.wordlist_base.length+1
51 Dir.glob(File.join(self.wordlist_base, pattern)).map { |name|