#!/usr/bin/env ruby
# frozen_string_literal: true
# Ruby internal
require 'pp'
# Project internal
require 'pass_station'
require 'pass_station/output'
# External
require 'docopt'
require 'paint'
doc = <<~DOCOPT
Pass Station v#{PassStation::VERSION}
Usage:
pass-station list [--sort
--output ] [--source --debug]
pass-station search [--field --sort --sensitive --output ] [--source --no-color --debug]
pass-station update ([--force] | --check) [--debug]
pass-station -h | --help
pass-station --version
List options: list all default credentials
Output options: can be used with list and search commands
-o , --output Output format: JSON, CSV, YAML, table, pretty-table [default: pretty-table]
-s , --sort Sort by column (see documentation, columns depends on the database source)
Search options:
--field Search in column: column name (see documentation, columns depends on the database source) or all
--sensitive Search is case sensitive (case insensitive by default)
Update options: update the password database (replace Pass Station DB with upstream DB, use with care)
-f, --force Bypass hash checking
-c, --check Check for possible update
Other options:
--source Credentials source database: 1 (Default Credentials Cheat Sheet), 2 (Many passwords) [default: 1]
--no-color Disable colorized output
--debug Display arguments
-h, --help Show this screen
--version Show version
DOCOPT
begin
args = Docopt.docopt(doc, version: PassStation::VERSION)
Paint.mode = 0 if args['--no-color']
pp args if args['--debug']
if args['update']
if args['']
PassStation::DB::UPSTREAM_DATABASE[:MAPPING].each do |k, v|
opts = {}
opts[:sha256] = args['--force'] ? nil : PassStation::DB::UPSTREAM_DATABASE[v][:HASH]
puts "[+] Updating database: #{v}"
opts[:source_db] = k
path = PassStation::DB.download_upstream(args[''], opts)
if path
puts "[+] Database updated: #{v} (#{path})"
else
puts "[+] Database #{v} already up to date"
end
end
elsif args['--check']
if PassStation::DB.check_for_update
puts '[+] Update available'
else
puts '[+] No update available'
end
end
elsif args['list']
db = args['--source'].nil? ? nil : args['--source'].to_i
ps = PassStation::DB.new(db)
args['--sort'].nil? ? ps.parse : ps.parse(args['--sort'].to_sym)
puts ps.output_list(args['--output'])
elsif args['search']
db = args['--source'].nil? ? nil : args['--source'].to_i
ps = PassStation::DB.new(db)
args['--sort'].nil? ? ps.parse : ps.parse(args['--sort'].to_sym)
field = args['--field'].nil? ? nil : args['--field'].to_sym
ps.search(args[''], field, sensitive: args['--sensitive'])
output = ps.output_search(args['--output'])
puts '[-] No result' if output.empty?
puts ps.highlight_found(args[''], output, args['--sensitive'])
end
rescue Docopt::Exit => e
puts e.message
end