1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-02-21 10:20:05 +00:00

fix spacing

This commit is contained in:
Adrien Waksberg 2017-03-28 23:29:33 +02:00
parent 6a6120ca14
commit 7a831555f4
4 changed files with 47 additions and 47 deletions

View file

@ -68,8 +68,8 @@ class Cli
def setup_gpg_key(gpg_key) def setup_gpg_key(gpg_key)
return if @config.check_gpg_key? return if @config.check_gpg_key?
password = ask(I18n.t('form.setup_gpg_key.password')) {|q| q.echo = false} password = ask(I18n.t('form.setup_gpg_key.password')) { |q| q.echo = false }
confirm = ask(I18n.t('form.setup_gpg_key.confirm_password')) {|q| q.echo = false} confirm = ask(I18n.t('form.setup_gpg_key.confirm_password')) { |q| q.echo = false }
if password != confirm if password != confirm
raise I18n.t('form.setup_gpg_key.error_password') raise I18n.t('form.setup_gpg_key.error_password')
@ -104,7 +104,7 @@ class Cli
# Request the GPG password and decrypt the file # Request the GPG password and decrypt the file
def decrypt def decrypt
unless defined?(@mpw) unless defined?(@mpw)
@password = ask(I18n.t('display.gpg_password')) {|q| q.echo = false} @password = ask(I18n.t('display.gpg_password')) { |q| q.echo = false }
@mpw = MPW.new(@config.gpg_key, @wallet_file, @password, @config.gpg_exe) @mpw = MPW.new(@config.gpg_key, @wallet_file, @password, @config.gpg_exe)
end end
@ -140,7 +140,7 @@ class Cli
end end
# Format items on a table # Format items on a table
def table_items(items=[]) def table_items(items = [])
group = '.' group = '.'
i = 1 i = 1
length_total = 10 length_total = 10
@ -160,7 +160,7 @@ class Cli
v[:length] = item.send(k.to_s).to_s.length + 3 if item.send(k.to_s).to_s.length >= v[:length] v[:length] = item.send(k.to_s).to_s.length + 3 if item.send(k.to_s).to_s.length >= v[:length]
end end
end end
data[:id][:length] = items.length.to_s.length + 2 if items.length.to_s.length > data[:id][:length] data[:id][:length] = items.length.to_s.length + 2 if items.length.to_s.length > data[:id][:length]
data.each_value { |v| length_total += v[:length] } data.each_value { |v| length_total += v[:length] }
items.sort! { |a, b| a.group.to_s.downcase <=> b.group.to_s.downcase } items.sort! { |a, b| a.group.to_s.downcase <=> b.group.to_s.downcase }
@ -221,7 +221,7 @@ class Cli
# Display the query's result # Display the query's result
# @args: options -> the option to search # @args: options -> the option to search
def list(options={}) def list(options = {})
result = @mpw.list(options) result = @mpw.list(options)
if result.empty? if result.empty?
@ -237,16 +237,16 @@ class Cli
def get_item(items) def get_item(items)
return items[0] if items.length == 1 return items[0] if items.length == 1
items.sort! { |a,b| a.group.to_s.downcase <=> b.group.to_s.downcase } items.sort! { |a, b| a.group.to_s.downcase <=> b.group.to_s.downcase }
choice = ask(I18n.t('form.select')).to_i choice = ask(I18n.t('form.select')).to_i
choice >= 1 && choice <= items.length ? items[choice-1] : nil choice >= 1 && choice <= items.length ? items[choice - 1] : nil
end end
# Copy in clipboard the login and password # Copy in clipboard the login and password
# @args: item -> the item # @args: item -> the item
# clipboard -> enable clipboard # clipboard -> enable clipboard
def clipboard(item, clipboard=true) def clipboard(item, clipboard = true)
pid = nil pid = nil
# Security: force quit after 90s # Security: force quit after 90s
@ -321,7 +321,7 @@ class Cli
# Display the wallet # Display the wallet
# @args: wallet -> the wallet name # @args: wallet -> the wallet name
def get_wallet(wallet=nil) def get_wallet(wallet = nil)
if wallet.to_s.empty? if wallet.to_s.empty?
wallets = Dir.glob("#{@config.wallet_dir}/*.mpw") wallets = Dir.glob("#{@config.wallet_dir}/*.mpw")
@ -363,7 +363,7 @@ class Cli
# @args: template -> template name # @args: template -> template name
# item -> the item to edit # item -> the item to edit
# password -> disable field password # password -> disable field password
def text_editor(template_name, item=nil, password=false) def text_editor(template_name, item = nil, password = false)
editor = ENV['EDITOR'] || 'nano' editor = ENV['EDITOR'] || 'nano'
options = {} options = {}
opts = {} opts = {}
@ -382,9 +382,9 @@ class Cli
opts = YAML.load_file(tmp_file) opts = YAML.load_file(tmp_file)
end end
opts.delete_if { |k,v| v.to_s.empty? } opts.delete_if { |k, v| v.to_s.empty? }
opts.each do |k,v| opts.each do |k, v|
options[k.to_sym] = v options[k.to_sym] = v
end end
@ -393,7 +393,7 @@ class Cli
# Form to add a new item # Form to add a new item
# @args: password -> generate a random password # @args: password -> generate a random password
def add(password=false) def add(password = false)
options = text_editor('add_form', nil, password) options = text_editor('add_form', nil, password)
item = Item.new(options) item = Item.new(options)
options[:password] = MPW.password(@config.password) if password options[:password] = MPW.password(@config.password) if password
@ -411,7 +411,7 @@ class Cli
# Update an item # Update an item
# @args: password -> generate a random password # @args: password -> generate a random password
# options -> the option to search # options -> the option to search
def update(password=false, options={}) def update(password = false, options = {})
items = @mpw.list(options) items = @mpw.list(options)
if items.empty? if items.empty?
@ -421,7 +421,7 @@ class Cli
item = get_item(items) item = get_item(items)
options = text_editor('update_form', item, password) options = text_editor('update_form', item, password)
options[:password] = MPW.password(@config.password) if password options[:password] = MPW.password(@config.password) if password
item.update(options) item.update(options)
@mpw.set_password(item.id, options[:password]) if options.key?(:password) @mpw.set_password(item.id, options[:password]) if options.key?(:password)
@ -436,7 +436,7 @@ class Cli
# Remove an item # Remove an item
# @args: options -> the option to search # @args: options -> the option to search
def delete(options={}) def delete(options = {})
items = @mpw.list(options) items = @mpw.list(options)
if items.empty? if items.empty?
@ -461,7 +461,7 @@ class Cli
# Copy a password, otp, login # Copy a password, otp, login
# @args: clipboard -> enable clipboard # @args: clipboard -> enable clipboard
# options -> the option to search # options -> the option to search
def copy(clipboard=true, options={}) def copy(clipboard = true, options = {})
items = @mpw.list(options) items = @mpw.list(options)
if items.empty? if items.empty?
@ -499,7 +499,7 @@ class Cli
) )
end end
File.open(file, 'w') {|f| f << data.to_yaml} File.open(file, 'w') { |f| f << data.to_yaml }
puts I18n.t('form.export.valid', file: file).to_s.green puts I18n.t('form.export.valid', file: file).to_s.green
rescue Exception => e rescue Exception => e

View file

@ -36,7 +36,7 @@ class Config
# Constructor # Constructor
# @args: config_file -> the specify config file # @args: config_file -> the specify config file
def initialize(config_file=nil) def initialize(config_file = nil)
@config_file = config_file @config_file = config_file
if /darwin/ =~ RUBY_PLATFORM if /darwin/ =~ RUBY_PLATFORM

View file

@ -36,7 +36,7 @@ class Item
# Create a new item # Create a new item
# @args: options -> a hash of parameter # @args: options -> a hash of parameter
# raise an error if the hash hasn't the key name # raise an error if the hash hasn't the key name
def initialize(options={}) def initialize(options = {})
if !options.key?(:host) || options[:host].to_s.empty? if !options.key?(:host) || options[:host].to_s.empty?
raise I18n.t('error.update.host_empty') raise I18n.t('error.update.host_empty')
end end
@ -56,7 +56,7 @@ class Item
# Update the item # Update the item
# @args: options -> a hash of parameter # @args: options -> a hash of parameter
def update(options={}) def update(options = {})
if options.key?(:host) && options[:host].to_s.empty? if options.key?(:host) && options[:host].to_s.empty?
raise I18n.t('error.update.host_empty') raise I18n.t('error.update.host_empty')
end end
@ -96,7 +96,7 @@ class Item
# Generate an random id # Generate an random id
private private
def generate_id def generate_id
([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(16).join ([*('A'..'Z'), *('a'..'z'), *('0'..'9')]).sample(16).join
end end
end end
end end

View file

@ -27,7 +27,7 @@ module MPW
class MPW class MPW
# Constructor # Constructor
def initialize(key, wallet_file, gpg_pass=nil, gpg_exe=nil) def initialize(key, wallet_file, gpg_pass = nil, gpg_exe = nil)
@key = key @key = key
@gpg_pass = gpg_pass @gpg_pass = gpg_pass
@gpg_exe = gpg_exe @gpg_exe = gpg_exe
@ -53,29 +53,29 @@ class MPW
Gem::Package::TarReader.new(File.open(@wallet_file)) do |tar| Gem::Package::TarReader.new(File.open(@wallet_file)) do |tar|
tar.each do |f| tar.each do |f|
case f.full_name case f.full_name
when 'wallet/config.gpg' when 'wallet/config.gpg'
@config = YAML.safe_load(decrypt(f.read)) @config = YAML.safe_load(decrypt(f.read))
when 'wallet/meta.gpg' when 'wallet/meta.gpg'
data = decrypt(f.read) data = decrypt(f.read)
when /^wallet\/keys\/(?<key>.+)\.pub$/ when /^wallet\/keys\/(?<key>.+)\.pub$/
key = Regexp.last_match('key') key = Regexp.last_match('key')
if GPGME::Key.find(:public, key).empty? if GPGME::Key.find(:public, key).empty?
GPGME::Key.import(f.read, armor: true) GPGME::Key.import(f.read, armor: true)
end end
@keys[key] = f.read @keys[key] = f.read
when /^wallet\/passwords\/(?<id>[a-zA-Z0-9]+)\.gpg$/ when /^wallet\/passwords\/(?<id>[a-zA-Z0-9]+)\.gpg$/
@passwords[Regexp.last_match('id')] = f.read @passwords[Regexp.last_match('id')] = f.read
when /^wallet\/otp_keys\/(?<id>[a-zA-Z0-9]+)\.gpg$/ when /^wallet\/otp_keys\/(?<id>[a-zA-Z0-9]+)\.gpg$/
@otp_keys[Regexp.last_match('id')] = f.read @otp_keys[Regexp.last_match('id')] = f.read
else else
next next
end end
end end
end end
@ -220,7 +220,7 @@ class MPW
# Set config # Set config
# args: config -> a hash with config options # args: config -> a hash with config options
def set_config(options={}) def set_config(options = {})
@config = {} if @config.nil? @config = {} if @config.nil?
@config['protocol'] = options[:protocol] if options.key?(:protocol) @config['protocol'] = options[:protocol] if options.key?(:protocol)
@ -243,7 +243,7 @@ class MPW
# Search in some csv data # Search in some csv data
# @args: options -> a hash with paramaters # @args: options -> a hash with paramaters
# @rtrn: a list with the resultat of the search # @rtrn: a list with the resultat of the search
def list(options={}) def list(options = {})
result = [] result = []
search = options[:pattern].to_s.downcase search = options[:pattern].to_s.downcase
@ -305,7 +305,7 @@ class MPW
# Generate a random password # Generate a random password
# @args: options -> :length, :special, :alpha, :numeric # @args: options -> :length, :special, :alpha, :numeric
# @rtrn: a random string # @rtrn: a random string
def self.password(options={}) def self.password(options = {})
if !options.include?(:length) || options[:length].to_i <= 0 if !options.include?(:length) || options[:length].to_i <= 0
length = 8 length = 8
elsif options[:length].to_i >= 32768 elsif options[:length].to_i >= 32768
@ -315,10 +315,10 @@ class MPW
end end
chars = [] chars = []
chars += [*('!'..'?')] - [*('0'..'9')] if options[:special] chars += [*('!'..'?')] - [*('0'..'9')] if options[:special]
chars += [*('A'..'Z'),*('a'..'z')] if options[:alpha] chars += [*('A'..'Z'), *('a'..'z')] if options[:alpha]
chars += [*('0'..'9')] if options[:numeric] chars += [*('0'..'9')] if options[:numeric]
chars = [*('A'..'Z'),*('a'..'z'),*('0'..'9')] if chars.empty? chars = [*('A'..'Z'), *('a'..'z'), *('0'..'9')] if chars.empty?
result = '' result = ''
while length > 62 do while length > 62 do