mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-27 07:33:05 +00:00
remove interactive mode
This commit is contained in:
parent
ac07b62992
commit
6290bfb3bb
3 changed files with 2 additions and 82 deletions
|
@ -18,7 +18,6 @@ module MPW
|
|||
attr_accessor :share_keys
|
||||
attr_accessor :lang
|
||||
attr_accessor :file_gpg
|
||||
attr_accessor :timeout_pwd
|
||||
attr_accessor :last_update
|
||||
attr_accessor :sync_type
|
||||
attr_accessor :sync_host
|
||||
|
@ -53,7 +52,6 @@ module MPW
|
|||
# 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
|
||||
# sync_type -> the type to synchronization
|
||||
# sync_host -> the server host for synchronization
|
||||
# sync_port -> the server port for synchronization
|
||||
|
@ -61,7 +59,7 @@ 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, share_keys, lang, file_gpg, timeout_pwd, sync_type, sync_host, sync_port, sync_user, sync_pwd, sync_path)
|
||||
def setup(key, share_keys, lang, file_gpg, 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')
|
||||
|
@ -76,13 +74,10 @@ module MPW
|
|||
file_gpg = "#{@dir_config}/db/default.gpg"
|
||||
end
|
||||
|
||||
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,
|
||||
'sync_type' => sync_type,
|
||||
'sync_host' => sync_host,
|
||||
'sync_port' => sync_port,
|
||||
|
@ -150,7 +145,6 @@ module MPW
|
|||
@share_keys = config['config']['share_keys']
|
||||
@lang = config['config']['lang']
|
||||
@file_gpg = config['config']['file_gpg']
|
||||
@timeout_pwd = config['config']['timeout_pwd'].to_i
|
||||
@sync_type = config['config']['sync_type']
|
||||
@sync_host = config['config']['sync_host']
|
||||
@sync_port = config['config']['sync_port']
|
||||
|
@ -216,7 +210,6 @@ module MPW
|
|||
'share_keys' => @share_keys,
|
||||
'lang' => @lang,
|
||||
'file_gpg' => @file_gpg,
|
||||
'timeout_pwd' => @timeout_pwd,
|
||||
'sync_type' => @sync_type,
|
||||
'sync_host' => @sync_host,
|
||||
'sync_port' => @sync_port,
|
||||
|
|
|
@ -78,7 +78,6 @@ class Cli
|
|||
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: @conf.dir_config)).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)
|
||||
|
@ -101,7 +100,7 @@ class Cli
|
|||
sync_pwd = sync_pwd.nil? or sync_pwd.empty? ? nil : sync_pwd
|
||||
sync_path = sync_path.nil? or sync_path.empty? ? nil : 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)
|
||||
if @config.setup(key, share_keys, language, file_gpg, sync_type, sync_host, sync_port, sync_user, sync_pwd, sync_path)
|
||||
puts I18n.t('form.setup.valid')
|
||||
else
|
||||
puts "#{I18n.t('display.error')} #8: #{@config.error_msg}"
|
||||
|
@ -347,69 +346,4 @@ class Cli
|
|||
end
|
||||
end
|
||||
|
||||
# Interactive mode
|
||||
def interactive
|
||||
group = nil
|
||||
last_access = Time.now.to_i
|
||||
|
||||
while buf = Readline.readline('<mpw> ', true)
|
||||
|
||||
if @config.timeout_pwd < Time.now.to_i - last_access
|
||||
passwd_confirm = ask(I18n.t('interactive.ask_password')) {|q| q.echo = false}
|
||||
|
||||
if @passwd.eql?(passwd_confirm)
|
||||
last_access = Time.now.to_i
|
||||
else
|
||||
puts I18n.t('interactive.bad_password')
|
||||
next
|
||||
end
|
||||
else
|
||||
last_access = Time.now.to_i
|
||||
end
|
||||
|
||||
command = buf.split(' ')
|
||||
|
||||
case command[0]
|
||||
when 'display', 'show', 'd', 's'
|
||||
if not command[1].nil? and not command[1].empty?
|
||||
display(command[1], group, command[2])
|
||||
end
|
||||
when 'add', 'a'
|
||||
add
|
||||
when 'update', 'u'
|
||||
if not command[1].nil? and not command[1].empty?
|
||||
update(command[1])
|
||||
end
|
||||
when 'remove', 'delete', 'r', 'd'
|
||||
if not command[1].nil? and not command[1].empty?
|
||||
remove(command[1])
|
||||
end
|
||||
when 'group', 'g'
|
||||
if not command[1].nil? and not command[1].empty?
|
||||
group = command[1]
|
||||
else
|
||||
group = nil
|
||||
end
|
||||
when 'help', 'h', '?'
|
||||
puts I18n.t('interactive.option.title')
|
||||
puts '--------------------'
|
||||
puts "display, show, d, s SEARCH #{I18n.t('interactive.option.show')}"
|
||||
puts "group, g #{I18n.t('interactive.option.group')}"
|
||||
puts "add, a #{I18n.t('interactive.option.add')}"
|
||||
puts "update, u ID #{I18n.t('interactive.option.update')}"
|
||||
puts "remove, delete, r, d ID #{I18n.t('interactive.option.remove')}"
|
||||
puts "help, h, ? #{I18n.t('interactive.option.help')}"
|
||||
puts "quit, exit, q #{I18n.t('interactive.option.quit')}"
|
||||
when 'quit', 'exit', 'q'
|
||||
puts I18n.t('interactive.goodbye')
|
||||
break
|
||||
else
|
||||
if not command[0].nil? and not command[0].empty?
|
||||
puts I18n.t('interactive.unknown_command')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
7
mpw
7
mpw
|
@ -156,13 +156,6 @@ elsif not options[:import].nil?
|
|||
cli.import(options[:import], options[:type], options[:force])
|
||||
|
||||
# Interactive mode
|
||||
else
|
||||
begin
|
||||
cli.interactive
|
||||
rescue SystemExit, Interrupt
|
||||
cli = nil
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
cli = nil
|
||||
|
|
Loading…
Reference in a new issue