1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-26 23:33:03 +00:00

feat: add option to set a specific path for a wallet

This commit is contained in:
Adrien Waksberg 2017-04-08 17:15:05 +02:00
parent 55c07b90af
commit 25baa260e3
5 changed files with 76 additions and 10 deletions

View file

@ -56,6 +56,14 @@ OptionParser.new do |opts|
options[:list_keys] = true
end
opts.on('-p', '--path PATH', I18n.t('option.path')) do |path|
options[:path] = path
end
opts.on('-P', '--default-path', I18n.t('option.default_path')) do
options[:path] = 'default'
end
opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet|
options[:wallet] = wallet
end
@ -68,6 +76,9 @@ cli.load_config
if options.key?(:list)
cli.list_wallet
elsif options.key?(:path)
cli.get_wallet(options[:wallet])
cli.set_wallet_path(options[:path])
else
cli.get_wallet(options[:wallet])
cli.decrypt

View file

@ -45,6 +45,7 @@ en:
alpha: "Use letter to generate a password"
config: "Specify the configuration file to use"
clipboard: "Disable the clipboard feature"
default_path: "Move the wallet in default directory"
default_wallet: "Specify the default wallet to use"
delete_gpg_key: "Delete the wallet's share with an other GPG key"
disable_alpha: "Don't use letter to generate a password"
@ -68,6 +69,7 @@ en:
list: "List the wallets"
list_keys: "List the GPG keys in wallet"
numeric: "Use number to generate a password"
path: "Move the wallet in new specify directory"
pattern: "Given search pattern"
pinmode: "Enable pinentry mode (available with gpg >= 2.1)"
random_password: "Generate a random password"
@ -120,6 +122,8 @@ en:
not_valid: "No data to import!"
set_config:
valid: "The config file has been edited!"
set_wallet_path:
valid: "The wallet has well moved!"
setup_config:
title: "Setup a new config file"
lang: "Choose your language (en, fr, ...) [default=%{lang}]: "

View file

@ -45,6 +45,7 @@ fr:
alpha: "Utilise des lettres dans la génération d'un mot de passe"
config: "Spécifie le fichier de configuration à utiliser"
clipboard: "Désactive la fonction presse papier"
default_path: "Déplace le portefeuille dans le dossier par défaut"
default_wallet: "Spécifie le porte-feuille à utiliser par défaut"
delete_gpg_key: "Supprime le partage le portefeuille avec une autre clé GPG"
disable_alpha: "Désactive l'utilisation des lettres dans la génération d'un mot de passe"
@ -68,6 +69,7 @@ fr:
list: "Liste les portefeuilles"
list_keys: "Liste les clés GPG dans le portefeuille"
numeric: "Utilise des chiffre dans la génération d'un mot de passe"
path: "Déplace le portefeuille dans un nouveau dossier"
pattern: "Motif de donnée à chercher"
pinmode: "Active le mode pinentry (valable avec gpg >= 2.1)"
random_password: "Génére un mot de passe aléatoire"
@ -120,6 +122,8 @@ fr:
not_valid: "Aucune donnée à importer!"
set_config:
valid: "Le fichier de configuration a bien été modifié!"
set_wallet_path:
valid: "Le portefeuille a bien été déplacé!"
setup_config:
title: "Création d'un nouveau fichier de configuration"
lang: "Choisissez votre langue (en, fr, ...) [défaut=%{lang}]: "

View file

@ -45,6 +45,17 @@ module MPW
exit 2
end
# Change the wallet path
# @args: path -> the new path
def set_wallet_path(path)
@config.set_wallet_path(path, @wallet)
puts I18n.t('form.set_wallet_path.valid').to_s.green
rescue => e
puts "#{I18n.t('display.error')} #19: #{e}".red
exit 2
end
# Create a new config file
# @args: options -> set param
def setup(options)
@ -315,19 +326,25 @@ module MPW
# Display the wallet
# @args: wallet -> the wallet name
def get_wallet(wallet = nil)
@wallet_file =
@wallet =
if wallet.to_s.empty?
wallets = Dir.glob("#{@config.wallet_dir}/*.mpw")
if wallets.length == 1
wallets[0]
File.basename(wallets[0], '.mpw')
elsif !@config.default_wallet.to_s.empty?
"#{@config.wallet_dir}/#{@config.default_wallet}.mpw"
@config.default_wallet
else
"#{@config.wallet_dir}/default.mpw"
'default'
end
else
"#{@config.wallet_dir}/#{wallet}.mpw"
wallet
end
@wallet_file =
if @config.wallet_paths.key?(@wallet)
"#{@config.wallet_paths[@wallet]}/#{@wallet}.mpw"
else
"#{@config.wallet_dir}/#{@wallet}.mpw"
end
end

View file

@ -30,6 +30,7 @@ module MPW
attr_accessor :config_dir
attr_accessor :default_wallet
attr_accessor :wallet_dir
attr_accessor :wallet_paths
attr_accessor :gpg_exe
attr_accessor :password
attr_accessor :pinmode
@ -38,7 +39,6 @@ module MPW
# @args: config_file -> the specify config file
def initialize(config_file = nil)
@config_file = config_file
@config_dir =
if /darwin/ =~ RUBY_PLATFORM
"#{Dir.home}/Library/Preferences/mpw"
@ -48,7 +48,7 @@ module MPW
"#{Dir.home}/.config/mpw"
end
@config_file = "#{@config_dir}/mpw.cfg" if @config_file.nil? || @config_file.empty?
@config_file = "#{@config_dir}/mpw.cfg" if @config_file.to_s.empty?
end
# Create a new config file
@ -85,7 +85,8 @@ module MPW
'default_wallet' => default_wallet,
'gpg_exe' => gpg_exe,
'password' => password,
'pinmode' => pinmode }
'pinmode' => pinmode,
'wallet_paths' => @wallet_paths }
FileUtils.mkdir_p(@config_dir, mode: 0700)
FileUtils.mkdir_p(wallet_dir, mode: 0700)
@ -132,6 +133,7 @@ module MPW
@gpg_key = config['gpg_key']
@lang = config['lang']
@wallet_dir = config['wallet_dir']
@wallet_paths = config['wallet_paths'] || {}
@default_wallet = config['default_wallet']
@gpg_exe = config['gpg_exe']
@password = config['password'] || {}
@ -154,5 +156,33 @@ module MPW
false
end
# Change the path of one wallet
# @args: path -> the new directory path
# wallet -> the wallet name
def set_wallet_path(path, wallet)
path = @wallet_dir if path == 'default'
return if path == @wallet_dir && File.exist?("#{@wallet_dir}/#{wallet}.mpw")
return if path == @wallet_paths[wallet]
old_wallet_file =
if @wallet_paths.key?(wallet)
"#{@wallet_paths[wallet]}/#{wallet}.mpw"
else
"#{@wallet_dir}/#{wallet}.mpw"
end
FileUtils.mkdir_p(path) unless Dir.exist?(path)
FileUtils.mv(old_wallet_file, "#{path}/#{wallet}.mpw") if File.exist?(old_wallet_file)
if path == @wallet_dir
@wallet_paths.delete(wallet)
else
@wallet_paths[wallet] = path
end
setup
end
end
end