diff --git a/bin/mpw-wallet b/bin/mpw-wallet index 790509f..0184d85 100644 --- a/bin/mpw-wallet +++ b/bin/mpw-wallet @@ -25,6 +25,7 @@ require 'mpw/cli' # --------------------------------------------------------- # options = {} +values = {} OptionParser.new do |opts| opts.banner = "#{I18n.t('option.usage')}: mpw wallet [options]" @@ -38,6 +39,34 @@ OptionParser.new do |opts| exit 0 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| options[:wallet] = wallet end @@ -46,4 +75,10 @@ end.parse! config = MPW::Config.new(options[:config]) 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 diff --git a/i18n/en.yml b/i18n/en.yml index cf10200..e88f360 100644 --- a/i18n/en.yml +++ b/i18n/en.yml @@ -47,19 +47,26 @@ en: gpg_key: "Specify a GPG key (ex: user@example.com)" group: "Search the items with specified group" help: "Show this help message" + host: "Specify the server for the synchronization" init: "Initialize mpw" import: "Import item since a yaml file" key: "Specify the key name" lang: "Set the software language" + list: "List the wallets" no_sync: "Disable synchronization with the server" numeric: "Use number to generate a password" + password: "Change the password for the synchronization" + path: "Specify the remote path" pattern: "Given search pattern" + port: "Specify the connection port" + protocol: "Specify the protocol for the connection" setup: "Create a new configuration file" setup_wallet: "Create a new configuration file for a wallet" special_chars: "Use special char to generate a password" show: "Search and show the items" show_all: "List all items" usage: "Usage" + user: "Specify the user for the connection" wallet: "Specify a wallet to use" wallet_dir: "Set the wallets folder" diff --git a/i18n/fr.yml b/i18n/fr.yml index 8e878a1..903cba6 100644 --- a/i18n/fr.yml +++ b/i18n/fr.yml @@ -47,19 +47,26 @@ fr: gpg_key: "Spécifie une clé GPG (ex: user@example.com)" group: "Recherche les éléments appartenant au groupe spécifié" help: "Affiche ce message d'aide" + host: "Spécifie le serveur pour la synchronisation" import: "Importe des éléments depuis un fichier yaml" init: "Initialise mpw" key: "Spécifie le nom d'une clé" lang: "Spécifie la langue du logiciel (ex: fr)" + list: "Liste les portefeuilles" no_sync: "Désactive la synchronisation avec le serveur" 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" + 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_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" show: "Recherche et affiche les éléments" show_all: "Liste tous les éléments" usage: "Utilisation" + user: "Spécifie l'identifiant de connection" wallet: "Spécifie le portefeuille à utiliser" wallet_dir: "Spécifie le répertoire des portefeuilles" diff --git a/lib/mpw/cli.rb b/lib/mpw/cli.rb index b52a63b..464d098 100644 --- a/lib/mpw/cli.rb +++ b/lib/mpw/cli.rb @@ -95,27 +95,17 @@ class Cli end # Setup wallet config for sync - # @args: wallet -> the wallet name - def setup_wallet_config(wallet = nil) - #config = {} - #config['sync'] = {} + # @args: options -> value to change + def setup_wallet_config(options={}) + if not options[:password].nil? + options[:password] = ask(I18n.t('form.setup_wallet.password')) {|q| q.echo = false} + end - #puts '--------------------' - #config['sync']['type'] = ask(I18n.t('form.setup_wallet.sync_type')).to_s + #wallet_file = wallet.nil? ? "#{@config.wallet_dir}/default.mpw" : "#{@config.wallet_dir}/#{wallet}.mpw" - #if ['ftp', 'ssh'].include?(config['sync']['type'].downcase) - # 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 = MPW.new(@config.key, @wallet_file, @password, @config.gpg_exe) @mpw.read_data - @mpw.set_config + @mpw.set_config(options) @mpw.write_data puts "#{I18n.t('form.setup_wallet.valid')}".green diff --git a/lib/mpw/mpw.rb b/lib/mpw/mpw.rb index a0c4c6e..0727636 100644 --- a/lib/mpw/mpw.rb +++ b/lib/mpw/mpw.rb @@ -210,19 +210,16 @@ class MPW # Set config # args: config -> a hash with config options - def set_config(config=nil) - @config = {} if @config.nil? - @config['sync'] = {} if @config['sync'].nil? + def set_config(options={}) + @config = {} if @config.nil? - return if config.to_s.empty? - - @config['sync']['type'] = config['sync']['type'] - @config['sync']['host'] = config['sync']['host'] - @config['sync']['port'] = config['sync']['port'] - @config['sync']['user'] = config['sync']['user'] - @config['sync']['password'] = config['sync']['password'] - @config['sync']['path'] = config['sync']['path'] - @config['sync']['last_sync'] = @config['sync']['last_sync'].nil? ? 0 : @config['sync']['last_sync'] + @config['protocol'] = options[:protocol] if options.has_key?(:protocol) + @config['host'] = options[:host] if options.has_key?(:host) + @config['port'] = options[:port] if options.has_key?(:port) + @config['user'] = options[:user] if options.has_key?(:user) + @config['password'] = options[:password] if options.has_key?(:password) + @config['path'] = options[:path] if options.has_key?(:path) + @config['last_sync'] = @config['last_sync'].nil? ? 0 : @config['last_sync'] end # Add a new item @@ -276,7 +273,7 @@ class MPW # Get last sync def get_last_sync - return @config['sync']['last_sync'].to_i + return @config['last_sync'].to_i rescue return 0 end @@ -284,12 +281,12 @@ class MPW # Sync data with remote file # @args: force -> force the sync 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 tmp_file = "#{@wallet_file}.sync" - case @config['sync']['type'] + case @config['protocol'] when 'sftp', 'scp', 'ssh' require "mpw/sync/ssh" sync = SyncSSH.new(@config['sync']) @@ -367,7 +364,7 @@ class MPW item.set_last_sync end - @config['sync']['last_sync'] = Time.now.to_i + @config['last_sync'] = Time.now.to_i write_data sync.update(@wallet_file)