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

add share_keys in config

This commit is contained in:
nishiki 2014-02-02 14:20:24 +01:00
parent 851ca63f90
commit 076aedeb3c
4 changed files with 39 additions and 14 deletions

View file

@ -14,6 +14,7 @@ module MPW
attr_accessor :error_msg
attr_accessor :key
attr_accessor :share_keys
attr_accessor :lang
attr_accessor :file_gpg
attr_accessor :timeout_pwd
@ -39,6 +40,7 @@ module MPW
# Create a new config file
# @args: key -> the gpg key to encrypt
# share_keys -> multiple keys to share the password with other people
# lang -> the software language
# file_gpg -> the file who is encrypted
# timeout_pwd -> time to save the password
@ -49,13 +51,22 @@ module MPW
# sync_pwd -> the password for synchronization
# sync_suffix -> the suffix file (optionnal)
# @rtrn: true if le config file is create
def setup(key, lang, file_gpg, timeout_pwd, sync_type=nil, sync_host=nil, sync_port=nil, sync_user=nil, sync_pwd=nil, sync_path=nil)
def setup(key, share_keys, lang, file_gpg, timeout_pwd, sync_type, sync_host, sync_port, sync_user, sync_pwd, sync_path)
if not key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
@error_msg = I18n.t('error.config.key_bad_format')
return false
end
if !share_keys.nil? && !share_keys.empty?
share_keys.split.each do |k|
if not k =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
@error_msg = I18n.t('error.config.key_bad_format')
return false
end
end
end
if file_gpg.empty?
file_gpg = "#{Dir.home}/.mpw.gpg"
end
@ -63,6 +74,7 @@ module MPW
timeout_pwd = timeout_pwd.empty? ? 60 : timeout_pwd.to_i
config = {'config' => {'key' => key,
'share_keys' => share_keys,
'lang' => lang,
'file_gpg' => file_gpg,
'timeout_pwd' => timeout_pwd,
@ -89,6 +101,7 @@ module MPW
def checkconfig
config = YAML::load_file(@file_config)
@key = config['config']['key']
@share_keys = config['config']['share_keys']
@lang = config['config']['lang']
@file_gpg = config['config']['file_gpg']
@timeout_pwd = config['config']['timeout_pwd'].to_i
@ -117,6 +130,7 @@ module MPW
# @rtrn: true is the file has been updated
def set_last_update
config = {'config' => {'key' => @key,
'share_keys' => @share_keys,
'lang' => @lang,
'file_gpg' => @file_gpg,
'timeout_pwd' => @timeout_pwd,

View file

@ -75,28 +75,37 @@ class Cli
puts '--------------------'
language = ask(I18n.t('form.setup.lang', :lang => lang)).to_s
key = ask(I18n.t('form.setup.gpg_key')).to_s
share_keys = ask(I18n.t('form.setup.share_gpg_keys')).to_s
file_gpg = ask(I18n.t('form.setup.gpg_file', :home => Dir.home)).to_s
timeout_pwd = ask(I18n.t('form.setup.timeout')).to_s
sync_type = ask(I18n.t('form.setup.sync_type')).to_s
if ['ssh', 'ftp', 'mpw'].include?(sync_type)
sync_host = ask(I18n.t('form.setup.sync_host')).to_s
sync_port = ask(I18n.t('form.setup.sync_port')).to_s
sync_user = ask(I18n.t('form.setup.sync_user')).to_s
sync_pwd = ask(I18n.t('form.setup.sync_pwd')).to_s
sync_path = ask(I18n.t('form.setup.sync_path')).to_s
end
if !language.nil? && !language.empty?
I18n.locale = language.to_sym
else
language = nil
end
sync_type = sync_type.empty? ? nil : sync_type
sync_host = sync_host.empty? ? nil : sync_host
sync_port = sync_port.empty? ? nil : sync_port.to_i
sync_user = sync_user.empty? ? nil : sync_user
sync_pwd = sync_pwd.empty? ? nil : sync_pwd
sync_path = sync_path.empty? ? nil : sync_path
sync_type = sync_type.nil? || sync_type.empty? ? nil : sync_type
sync_host = sync_host.nil? || sync_host.empty? ? nil : sync_host
sync_port = sync_port.nil? || sync_port.empty? ? nil : sync_port.to_i
sync_user = sync_user.nil? || sync_user.empty? ? nil : sync_user
sync_pwd = sync_pwd.nil? || sync_pwd.empty? ? nil : sync_pwd
sync_path = sync_path.nil? || sync_path.empty? ? nil : sync_path
if @config.setup(key, language, file_gpg, timeout_pwd, sync_type, sync_host, sync_port, sync_user, sync_pwd, sync_path)
if @config.setup(key, share_keys, language, file_gpg, timeout_pwd, sync_type, sync_host, sync_port, sync_user, sync_pwd, sync_path)
puts I18n.t('form.setup.valid')
else
puts "#{I18n.t('display.error')}: #{@config.error_msg}"
exit 2
end
if not @config.checkconfig

View file

@ -67,6 +67,7 @@ en:
title: "Setup a new config file"
lang: "Choose your language (en, fr, ...): "
gpg_key: "Enter the GPG key: "
share_gpg_key: "Enter the GPG keys with who you want to share the passwords: "
gpg_file: "Enter the path to encrypt file [default=%{home}/.mpw.gpg]: "
timeout: "Enter the timeout (in seconde) to GPG password [default=60]: "
sync_type: "Synchronization type (mpw, ssh, ftp, or nil): "

View file

@ -67,6 +67,7 @@ fr:
title: "Création d'un nouveau fichier de configuration"
lang: "Choisissez votre langue (en, fr, ...) [défaut=%{lang}]: "
gpg_key: "Entrez la clé GPG: "
share_gpg_key: "Entrez les clés GPG avec qui vous voulez partager les mots de passe: "
gpg_file: "Entrez le chemin du fichier qui sera chiffré [défaut=%{home}/.mpw.gpg]: "
timeout: "Entrez le temps (en seconde) du mot de passe GPG [défaut=60]: "
sync_type: "Type de synchronisation (mpw, ssh, ftp, or nil): "