Class: Ronin::Wordlists::CacheDir Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ronin/wordlists/cache_dir.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents the cache directory.

Constant Summary collapse

PATH =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The ~/.cache/ronin-wordlists/ directory where all repos are stored.

Core::Home.cache_dir('ronin-wordlists')
WORDLIST_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Mapping of wordlist type: values and their classes.

{
  git:  WordlistRepo,
  file: WordlistFile
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = PATH) ⇒ CacheDir

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the repository cache.

Parameters:

  • path (String) (defaults to: PATH)

    The path to the repository cache directory.



60
61
62
63
64
65
66
67
# File 'lib/ronin/wordlists/cache_dir.rb', line 60

def initialize(path=PATH)
  @path = path

  @manifest_file = File.join(@path,'manifest.yml')
  @wordlist_dir  = WordlistDir.new(File.join(@path,'wordlists'))

  @manifest = load_manifest
end

Instance Attribute Details

#pathString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The path to the cache directory.

Returns:

  • (String)


47
48
49
# File 'lib/ronin/wordlists/cache_dir.rb', line 47

def path
  @path
end

#wordlist_dirWrodlistDir (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The directory containing the downloaded wordlists.

Returns:

  • (WrodlistDir)


52
53
54
# File 'lib/ronin/wordlists/cache_dir.rb', line 52

def wordlist_dir
  @wordlist_dir
end

Instance Method Details

#[](name) ⇒ WordlistRepo, WordlistFile

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Accesses a wordlist file or repository from the cache directory.

Parameters:

  • name (String)

    The name of the wordlist file or repository.

Returns:

Raises:

  • (WordlistNotFound)

    No wordlist with the given name exists in the cache directory.

  • (InvalidManifestFile)

    The ~/.cache/ronin-wordlists/manifest.yml file contained invalid YAML data.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/ronin/wordlists/cache_dir.rb', line 91

def [](name)
  unless ( = @manifest[name])
    raise(WordlistNotFound,"wordlist not downloaded: #{name.inspect}")
  end

  type = .fetch(:type) do
    raise(InvalidManifestFile,"entry #{name.inspect} is missing a :type attribute")
  end

  url  = .fetch(:url) do
    raise(InvalidManifestFile,"entry #{name.inspect} is missing a :url attribute")
  end

  filename = .fetch(:filename) do
    raise(InvalidManifestFile,"entry #{name.inspect} is missing a :filename attribute")
  end

  path = File.join(@wordlist_dir.path,filename)

  wordlist_class = WORDLIST_TYPES.fetch(type) do
    raise(InvalidManifestFile,"unsupported wordlist type: #{type.inspect}")
  end

  return wordlist_class.new(path, url: url)
end

#download(url) ⇒ WordlistFile, WordlistRepo

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Downloads a wordlist into the cache directory.

Parameters:

  • url (String, URI::HTTP)

    The wordlist URL.

Returns:



173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/ronin/wordlists/cache_dir.rb', line 173

def download(url)
  wordlist = @wordlist_dir.download(url)

  update_manifest do |manifest|
    manifest[wordlist.name] = {
      type:     wordlist.type,
      filename: wordlist.filename,
      url:      wordlist.url.to_s
    }
  end

  return wordlist
end

#each {|name, wordlist| ... } ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Enumerates over every wordlist in the cache directory.

Yields:

  • (name, wordlist)

Yield Parameters:

Returns:

  • (Enumerator)

    If no block is given an enumerator will be returned.



127
128
129
130
131
132
133
# File 'lib/ronin/wordlists/cache_dir.rb', line 127

def each
  return enum_for unless block_given?

  @manifest.each_key do |name|
    yield self[name]
  end
end

#list(name = '*') ⇒ Array<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Lists the wordlists in the cache directory.

Parameters:

  • name (String) (defaults to: '*')

    Optional file name to search for.

Returns:

  • (Array<String>)

    The wordlist files within the wordlist directory.



144
145
146
# File 'lib/ronin/wordlists/cache_dir.rb', line 144

def list(name='*')
  @wordlist_dir.list(name)
end

#open(name) ⇒ Wordlist::File

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Opens a wordlist from the wordlist directory.

Parameters:

  • name (String)

    The wordlist file name.

Returns:

  • (Wordlist::File)

    The opened wordlist file.

Raises:



160
161
162
# File 'lib/ronin/wordlists/cache_dir.rb', line 160

def open(name)
  @wordlist_dir.open(name)
end

#purgeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Purge all wordlists from the cache directory.



212
213
214
# File 'lib/ronin/wordlists/cache_dir.rb', line 212

def purge
  FileUtils.rm_rf(@path)
end

#remove(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deletes a wordlist from the cache directory.

Parameters:

  • name (String)

    The wordlist file or directory name to delete.



200
201
202
203
204
205
206
207
# File 'lib/ronin/wordlists/cache_dir.rb', line 200

def remove(name)
  wordlist = self[name]
  wordlist.delete

  update_manifest do |manifest|
    manifest.delete(name)
  end
end

#updateObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Updates the wordlists in the cache directory.



190
191
192
# File 'lib/ronin/wordlists/cache_dir.rb', line 190

def update
  each(&:update)
end