Module: Passdb

Defined in:
lib/passdb.rb,
lib/passdb/cli.rb,
lib/passdb/entry.rb,
lib/passdb/version.rb

Defined Under Namespace

Modules: VERSION Classes: CLI, Entry

Constant Summary collapse

URL =
'http://cirt.net/passwords'

Class Method Summary collapse

Class Method Details

.search(args = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/passdb.rb', line 10

def self.search(args={})
  type, query = args.first

  if ![:vendor, :criteria].include?(type) || query.nil?
    raise ArgumentError, "Either :vendor or :criteria are required!"
  end

  results = []
  entry = nil
  url = "#{URL}?#{type}=#{query}"
  doc = Nokogiri::HTML(open(url))

  doc.xpath('/html/body/div/div[2]/div[3]/div/center/table/tr').each do |tr|
    next if tr.search('script').any?

    if tr.search('td').size == 1
      if entry
        results << entry
      end
      entry = Entry.new
      entry.name = tr.search('td').search('i').text
    else
      name, value = tr.search('td')
      entry.attributes[ name.search('b').text ] = value.text 
    end
  end

  if entry
    results << entry
  end

  return results
end