1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-30 08:53:05 +00:00

fix sync MPW

This commit is contained in:
nishiki 2015-02-08 21:57:15 +01:00
parent b7b56c306d
commit cdf2de0fb4
2 changed files with 15 additions and 22 deletions

View file

@ -6,6 +6,7 @@
require 'rubygems' require 'rubygems'
require 'i18n' require 'i18n'
require 'yaml' require 'yaml'
require 'tempfile'
require "#{APP_ROOT}/lib/Item" require "#{APP_ROOT}/lib/Item"
require "#{APP_ROOT}/lib/MPW" require "#{APP_ROOT}/lib/MPW"

View file

@ -55,8 +55,8 @@ module MPW
# Get data on server # Get data on server
# @args: gpg_password -> the gpg password # @args: gpg_password -> the gpg password
# @rtrn: nil if nothing data or error # @rtrn: nil if nothing data or error
def get(gpg_key, gpg_password) def get(file_tmp)
return nil if not @enable return false if not @enable
msg = nil msg = nil
TCPSocket.open(@host, @port) do |socket| TCPSocket.open(@host, @port) do |socket|
@ -72,38 +72,30 @@ module MPW
if not defined?(msg['error']) if not defined?(msg['error'])
@error_msg = I18n.t('error.sync.communication') @error_msg = I18n.t('error.sync.communication')
return nil return false
elsif not msg['error'].nil? elsif not msg['error'].nil?
@error_msg = I18n.t(msg['error']) @error_msg = I18n.t(msg['error'])
return nil return false
elsif msg['data'].nil? or msg['data'].empty? end
return {}
else
file_tmp = Tempfile.new('mpw-')
File.open(file_tmp, 'w') do |file| File.open(file_tmp, 'w') do |file|
file << msg['data'] file << msg['data']
end end
mpw = MPW.new(file_tmp, gpg_key) return true
raise mpw.error_msg if not mpw.decrypt(gpg_password)
file_tmp.close(true)
puts 'test'
return mpw.list
end
rescue Exception => e rescue Exception => e
@error_msg = "#{I18n.t('error.sync.download')}\n#{e}" @error_msg = "#{I18n.t('error.sync.download')}\n#{e}"
file_tmp.close(true) return false
return nil
end end
# Update the remote data # Update the remote data
# @args: data -> the data to send on server # @args: data -> the data to send on server
# @rtrn: false if there is a problem # @rtrn: false if there is a problem
def update(data) def update(file_gpg)
return true if not @enable return true if not @enable
data = File.open(file_gpg, 'r').read
msg = nil msg = nil
TCPSocket.open(@host, @port) do |socket| TCPSocket.open(@host, @port) do |socket|
send_msg = {action: 'update', send_msg = {action: 'update',