mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-21 10:20:05 +00:00
fix when sync with the server
This commit is contained in:
parent
c654dac532
commit
66f07e907c
3 changed files with 19 additions and 9 deletions
20
lib/Cli.rb
20
lib/Cli.rb
|
@ -34,6 +34,8 @@ class Cli
|
||||||
elsif !@sync.connect(@config.sync_host, @config.sync_port, @config.key, @config.sync_pwd, @config.sync_suffix)
|
elsif !@sync.connect(@config.sync_host, @config.sync_port, @config.key, @config.sync_pwd, @config.sync_suffix)
|
||||||
puts "#{I18n.t('cli.sync.not_connect')}:\n#{@sync.error_msg}"
|
puts "#{I18n.t('cli.sync.not_connect')}:\n#{@sync.error_msg}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sync()
|
||||||
end
|
end
|
||||||
|
|
||||||
# Destructor
|
# Destructor
|
||||||
|
@ -44,9 +46,17 @@ class Cli
|
||||||
# Sync the data with the server
|
# Sync the data with the server
|
||||||
def sync()
|
def sync()
|
||||||
begin
|
begin
|
||||||
@mpw.sync(@sync.get(@passwd), @config.last_update)
|
if !@mpw.sync(@sync.get(@passwd), @config.last_update)
|
||||||
@sync.update(File.open(@config.file_gpg).read)
|
puts "#{I18n.t('cli.display.error')}: #{@mpw.error_msg}"
|
||||||
@config.setLastUpdate()
|
end
|
||||||
|
|
||||||
|
if !@sync.update(File.open(@config.file_gpg).read)
|
||||||
|
puts "#{I18n.t('cli.display.error')}: #{@sync.error_msg}"
|
||||||
|
end
|
||||||
|
|
||||||
|
if !@config.setLastUpdate()
|
||||||
|
puts "#{I18n.t('cli.display.error')}: #{@config.error_msg}"
|
||||||
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
puts "#{I18n.t('cli.sync.error')}:\n#{e}"
|
puts "#{I18n.t('cli.sync.error')}:\n#{e}"
|
||||||
end
|
end
|
||||||
|
@ -150,6 +160,7 @@ class Cli
|
||||||
|
|
||||||
if @mpw.update(name, group, server, protocol, login, passwd, port, comment)
|
if @mpw.update(name, group, server, protocol, login, passwd, port, comment)
|
||||||
if @mpw.encrypt()
|
if @mpw.encrypt()
|
||||||
|
sync()
|
||||||
puts I18n.t('cli.form.add.valid')
|
puts I18n.t('cli.form.add.valid')
|
||||||
else
|
else
|
||||||
puts "#{I18n.t('cli.display.error')}: #{@mpw.error_msg}"
|
puts "#{I18n.t('cli.display.error')}: #{@mpw.error_msg}"
|
||||||
|
@ -178,6 +189,7 @@ class Cli
|
||||||
|
|
||||||
if @mpw.update(name, group, server, protocol, login, passwd, port, comment, id)
|
if @mpw.update(name, group, server, protocol, login, passwd, port, comment, id)
|
||||||
if @mpw.encrypt()
|
if @mpw.encrypt()
|
||||||
|
sync()
|
||||||
puts I18n.t('cli.form.update.valid')
|
puts I18n.t('cli.form.update.valid')
|
||||||
else
|
else
|
||||||
puts "#{I18n.t('cli.display.error')}: #{@mpw.error_msg}"
|
puts "#{I18n.t('cli.display.error')}: #{@mpw.error_msg}"
|
||||||
|
@ -212,6 +224,7 @@ class Cli
|
||||||
if force
|
if force
|
||||||
if @mpw.remove(id)
|
if @mpw.remove(id)
|
||||||
if @mpw.encrypt()
|
if @mpw.encrypt()
|
||||||
|
sync()
|
||||||
puts I18n.t('cli.form.delete.valid', :id => id)
|
puts I18n.t('cli.form.delete.valid', :id => id)
|
||||||
else
|
else
|
||||||
puts "#{I18n.t('cli.display.error')}: #{@mpw.error_msg}"
|
puts "#{I18n.t('cli.display.error')}: #{@mpw.error_msg}"
|
||||||
|
@ -256,6 +269,7 @@ class Cli
|
||||||
|
|
||||||
if force
|
if force
|
||||||
if @mpw.import(file) && @mpw.encrypt()
|
if @mpw.import(file) && @mpw.encrypt()
|
||||||
|
sync()
|
||||||
puts I18n.t('cli.form.import.valid')
|
puts I18n.t('cli.form.import.valid')
|
||||||
else
|
else
|
||||||
puts "#{I18n.t('cli.display.error')}: #{@mpw.error_msg}"
|
puts "#{I18n.t('cli.display.error')}: #{@mpw.error_msg}"
|
||||||
|
|
3
mpw
3
mpw
|
@ -97,7 +97,6 @@ config = MPWConfig.new(options[:config])
|
||||||
check_error = config.checkconfig()
|
check_error = config.checkconfig()
|
||||||
|
|
||||||
cli = Cli.new(lang, config)
|
cli = Cli.new(lang, config)
|
||||||
cli.sync()
|
|
||||||
|
|
||||||
# Setup a new config
|
# Setup a new config
|
||||||
if !check_error || !options[:setup].nil?
|
if !check_error || !options[:setup].nil?
|
||||||
|
@ -132,13 +131,11 @@ else
|
||||||
begin
|
begin
|
||||||
cli.interactive()
|
cli.interactive()
|
||||||
rescue SystemExit, Interrupt
|
rescue SystemExit, Interrupt
|
||||||
cli.sync()
|
|
||||||
cli = nil
|
cli = nil
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
cli.sync()
|
|
||||||
cli = nil
|
cli = nil
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
5
mpw-ssh
5
mpw-ssh
|
@ -55,8 +55,6 @@ cli.port = options[:port]
|
||||||
|
|
||||||
search = ARGV[0]
|
search = ARGV[0]
|
||||||
|
|
||||||
cli.sync()
|
|
||||||
|
|
||||||
# Setup a new config
|
# Setup a new config
|
||||||
if !check_error
|
if !check_error
|
||||||
cli.setup(lang)
|
cli.setup(lang)
|
||||||
|
@ -64,9 +62,10 @@ if !check_error
|
||||||
elsif ARGV.length < 1
|
elsif ARGV.length < 1
|
||||||
puts "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]"
|
puts "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]"
|
||||||
exit 2
|
exit 2
|
||||||
|
else
|
||||||
|
cli.ssh(search)
|
||||||
end
|
end
|
||||||
|
|
||||||
cli.ssh(search)
|
|
||||||
cli = nil
|
cli = nil
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue