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

set wallet config

This commit is contained in:
Adrien Waksberg 2016-10-20 18:25:30 +02:00
parent 580c5b4193
commit 337f1e2314
5 changed files with 71 additions and 35 deletions

View file

@ -25,6 +25,7 @@ require 'mpw/cli'
# --------------------------------------------------------- # # --------------------------------------------------------- #
options = {} options = {}
values = {}
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "#{I18n.t('option.usage')}: mpw wallet [options]" opts.banner = "#{I18n.t('option.usage')}: mpw wallet [options]"
@ -38,6 +39,34 @@ OptionParser.new do |opts|
exit 0 exit 0
end end
opts.on('--host NAME', I18n.t('option.host')) do |host|
values[:host] = host
end
opts.on('-l', '--list', I18n.t('option.list')) do |list|
options[:list] = true
end
opts.on('--password', I18n.t('option.password')) do
values[:password] = true
end
opts.on('--path PATH', I18n.t('option.path')) do |path|
values[:path] = path
end
opts.on('--port NUMBER', I18n.t('option.port')) do |port|
values[:port] = port
end
opts.on('--protocol NAME', I18n.t('option.protocol')) do |protocol|
values[:protocol] = protocol
end
opts.on('--user NAME', I18n.t('option.user')) do |user|
values[:user] = user
end
opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet| opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet|
options[:wallet] = wallet options[:wallet] = wallet
end end
@ -46,4 +75,10 @@ end.parse!
config = MPW::Config.new(options[:config]) config = MPW::Config.new(options[:config])
cli = MPW::Cli.new(config, options[:sync]) cli = MPW::Cli.new(config, options[:sync])
cli.list_wallet if not options[:list].nil?
cli.list_wallet
else
cli.get_wallet(options[:wallet])
cli.decrypt
cli.setup_wallet_config(values)
end

View file

@ -47,19 +47,26 @@ en:
gpg_key: "Specify a GPG key (ex: user@example.com)" gpg_key: "Specify a GPG key (ex: user@example.com)"
group: "Search the items with specified group" group: "Search the items with specified group"
help: "Show this help message" help: "Show this help message"
host: "Specify the server for the synchronization"
init: "Initialize mpw" init: "Initialize mpw"
import: "Import item since a yaml file" import: "Import item since a yaml file"
key: "Specify the key name" key: "Specify the key name"
lang: "Set the software language" lang: "Set the software language"
list: "List the wallets"
no_sync: "Disable synchronization with the server" no_sync: "Disable synchronization with the server"
numeric: "Use number to generate a password" numeric: "Use number to generate a password"
password: "Change the password for the synchronization"
path: "Specify the remote path"
pattern: "Given search pattern" pattern: "Given search pattern"
port: "Specify the connection port"
protocol: "Specify the protocol for the connection"
setup: "Create a new configuration file" setup: "Create a new configuration file"
setup_wallet: "Create a new configuration file for a wallet" setup_wallet: "Create a new configuration file for a wallet"
special_chars: "Use special char to generate a password" special_chars: "Use special char to generate a password"
show: "Search and show the items" show: "Search and show the items"
show_all: "List all items" show_all: "List all items"
usage: "Usage" usage: "Usage"
user: "Specify the user for the connection"
wallet: "Specify a wallet to use" wallet: "Specify a wallet to use"
wallet_dir: "Set the wallets folder" wallet_dir: "Set the wallets folder"

View file

@ -47,19 +47,26 @@ fr:
gpg_key: "Spécifie une clé GPG (ex: user@example.com)" gpg_key: "Spécifie une clé GPG (ex: user@example.com)"
group: "Recherche les éléments appartenant au groupe spécifié" group: "Recherche les éléments appartenant au groupe spécifié"
help: "Affiche ce message d'aide" help: "Affiche ce message d'aide"
host: "Spécifie le serveur pour la synchronisation"
import: "Importe des éléments depuis un fichier yaml" import: "Importe des éléments depuis un fichier yaml"
init: "Initialise mpw" init: "Initialise mpw"
key: "Spécifie le nom d'une clé" key: "Spécifie le nom d'une clé"
lang: "Spécifie la langue du logiciel (ex: fr)" lang: "Spécifie la langue du logiciel (ex: fr)"
list: "Liste les portefeuilles"
no_sync: "Désactive la synchronisation avec le serveur" no_sync: "Désactive la synchronisation avec le serveur"
numeric: "Utilise des chiffre dans la génération d'un mot de passe" numeric: "Utilise des chiffre dans la génération d'un mot de passe"
password: "Changer le mot de passe de connexion"
path: "Spécifie le chemin distant"
pattern: "Motif de donnée à chercher" pattern: "Motif de donnée à chercher"
port: "Spécifie le port de connexion"
protocol: "Spécifie le protocol utilisé pour la connexion"
setup: "Création d'un nouveau fichier de configuration" setup: "Création d'un nouveau fichier de configuration"
setup_wallet: "Création d'un nouveau fichier de configuration pour un portefeuille" setup_wallet: "Création d'un nouveau fichier de configuration pour un portefeuille"
special_chars: "Utilise des charactères speciaux dans la génération d'un mot de passe" special_chars: "Utilise des charactères speciaux dans la génération d'un mot de passe"
show: "Recherche et affiche les éléments" show: "Recherche et affiche les éléments"
show_all: "Liste tous les éléments" show_all: "Liste tous les éléments"
usage: "Utilisation" usage: "Utilisation"
user: "Spécifie l'identifiant de connection"
wallet: "Spécifie le portefeuille à utiliser" wallet: "Spécifie le portefeuille à utiliser"
wallet_dir: "Spécifie le répertoire des portefeuilles" wallet_dir: "Spécifie le répertoire des portefeuilles"

View file

@ -95,27 +95,17 @@ class Cli
end end
# Setup wallet config for sync # Setup wallet config for sync
# @args: wallet -> the wallet name # @args: options -> value to change
def setup_wallet_config(wallet = nil) def setup_wallet_config(options={})
#config = {} if not options[:password].nil?
#config['sync'] = {} options[:password] = ask(I18n.t('form.setup_wallet.password')) {|q| q.echo = false}
end
#puts '--------------------' #wallet_file = wallet.nil? ? "#{@config.wallet_dir}/default.mpw" : "#{@config.wallet_dir}/#{wallet}.mpw"
#config['sync']['type'] = ask(I18n.t('form.setup_wallet.sync_type')).to_s
#if ['ftp', 'ssh'].include?(config['sync']['type'].downcase) @mpw = MPW.new(@config.key, @wallet_file, @password, @config.gpg_exe)
# config['sync']['host'] = ask(I18n.t('form.setup_wallet.sync_host')).to_s
# config['sync']['port'] = ask(I18n.t('form.setup_wallet.sync_port')).to_s
# config['sync']['user'] = ask(I18n.t('form.setup_wallet.sync_user')).to_s
# config['sync']['password'] = ask(I18n.t('form.setup_wallet.sync_pwd')).to_s
# config['sync']['path'] = ask(I18n.t('form.setup_wallet.sync_path')).to_s
#end
wallet_file = wallet.nil? ? "#{@config.wallet_dir}/default.mpw" : "#{@config.wallet_dir}/#{wallet}.mpw"
@mpw = MPW.new(@config.key, wallet_file, @password, @config.gpg_exe)
@mpw.read_data @mpw.read_data
@mpw.set_config @mpw.set_config(options)
@mpw.write_data @mpw.write_data
puts "#{I18n.t('form.setup_wallet.valid')}".green puts "#{I18n.t('form.setup_wallet.valid')}".green

View file

@ -210,19 +210,16 @@ class MPW
# Set config # Set config
# args: config -> a hash with config options # args: config -> a hash with config options
def set_config(config=nil) def set_config(options={})
@config = {} if @config.nil? @config = {} if @config.nil?
@config['sync'] = {} if @config['sync'].nil?
return if config.to_s.empty? @config['protocol'] = options[:protocol] if options.has_key?(:protocol)
@config['host'] = options[:host] if options.has_key?(:host)
@config['sync']['type'] = config['sync']['type'] @config['port'] = options[:port] if options.has_key?(:port)
@config['sync']['host'] = config['sync']['host'] @config['user'] = options[:user] if options.has_key?(:user)
@config['sync']['port'] = config['sync']['port'] @config['password'] = options[:password] if options.has_key?(:password)
@config['sync']['user'] = config['sync']['user'] @config['path'] = options[:path] if options.has_key?(:path)
@config['sync']['password'] = config['sync']['password'] @config['last_sync'] = @config['last_sync'].nil? ? 0 : @config['last_sync']
@config['sync']['path'] = config['sync']['path']
@config['sync']['last_sync'] = @config['sync']['last_sync'].nil? ? 0 : @config['sync']['last_sync']
end end
# Add a new item # Add a new item
@ -276,7 +273,7 @@ class MPW
# Get last sync # Get last sync
def get_last_sync def get_last_sync
return @config['sync']['last_sync'].to_i return @config['last_sync'].to_i
rescue rescue
return 0 return 0
end end
@ -284,12 +281,12 @@ class MPW
# Sync data with remote file # Sync data with remote file
# @args: force -> force the sync # @args: force -> force the sync
def sync(force=false) def sync(force=false)
return if @config.empty? or @config['sync']['type'].to_s.empty? return if @config.empty? or @config['protocol'].to_s.empty?
return if get_last_sync + 300 > Time.now.to_i and not force return if get_last_sync + 300 > Time.now.to_i and not force
tmp_file = "#{@wallet_file}.sync" tmp_file = "#{@wallet_file}.sync"
case @config['sync']['type'] case @config['protocol']
when 'sftp', 'scp', 'ssh' when 'sftp', 'scp', 'ssh'
require "mpw/sync/ssh" require "mpw/sync/ssh"
sync = SyncSSH.new(@config['sync']) sync = SyncSSH.new(@config['sync'])
@ -367,7 +364,7 @@ class MPW
item.set_last_sync item.set_last_sync
end end
@config['sync']['last_sync'] = Time.now.to_i @config['last_sync'] = Time.now.to_i
write_data write_data
sync.update(@wallet_file) sync.update(@wallet_file)