mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-26 23:33:03 +00:00
translate Sync.rb
This commit is contained in:
parent
0598ec134f
commit
1a9fb07950
3 changed files with 34 additions and 9 deletions
|
@ -17,6 +17,10 @@ en:
|
|||
read: "Can't import, unable to read %{file}!"
|
||||
update:
|
||||
name_empty: "You must define a name!"
|
||||
sync:
|
||||
no_data: "Nothing data!"
|
||||
not_authorized: "You haven't the access to remote file!"
|
||||
unknown: "An unknown error is occured!"
|
||||
cli:
|
||||
option:
|
||||
usage: "Usage"
|
||||
|
|
|
@ -17,6 +17,10 @@ fr:
|
|||
read: "Impossible d'importer le fichier %{file}, car il n'est pas lisible!"
|
||||
update:
|
||||
name_empty: "Vous devez définir un nom!"
|
||||
sync:
|
||||
no_data: "Aucune data!"
|
||||
not_authorized: "Vous n'avez pas les autorisations d'accès au fichier distant!"
|
||||
unknown: "Une erreur inconnue est survenue!"
|
||||
cli:
|
||||
option:
|
||||
usage: "Utilisation"
|
||||
|
|
29
lib/Sync.rb
29
lib/Sync.rb
|
@ -14,14 +14,23 @@ class Sync
|
|||
|
||||
attr_accessor :error_msg
|
||||
|
||||
# Constructor
|
||||
def initialize()
|
||||
@error_msg = nil
|
||||
end
|
||||
|
||||
# Disable the sync
|
||||
def disable()
|
||||
@sync = false
|
||||
end
|
||||
|
||||
# Connect to server
|
||||
# @args: host -> the server host
|
||||
# port -> ther connection port
|
||||
# gpg_key -> the gpg key
|
||||
# password -> the remote password
|
||||
# suffix -> the suffix file
|
||||
# @rtrn: false if the connection fail
|
||||
def connect(host, port, gpg_key, password, suffix=nil)
|
||||
@gpg_key = gpg_key
|
||||
@password = password
|
||||
|
@ -31,13 +40,16 @@ class Sync
|
|||
@socket= TCPSocket.new(host, port)
|
||||
@sync = true
|
||||
rescue Exception => e
|
||||
@error_msg = "ERROR: Connection impossible\n#{e}"
|
||||
@error_msg = "#{I18n.t('error.sync.connection')}\n#{e}"
|
||||
@sync = false
|
||||
end
|
||||
|
||||
return @sync
|
||||
end
|
||||
|
||||
# Get data on server
|
||||
# @args: gpg_password -> the gpg password
|
||||
# @rtrn: nil if nothing data or error
|
||||
def get(gpg_password)
|
||||
if !@sync
|
||||
return nil
|
||||
|
@ -51,6 +63,7 @@ class Sync
|
|||
@socket.puts send_msg.to_json
|
||||
msg = JSON.parse(@socket.gets)
|
||||
|
||||
puts msg
|
||||
case msg['error']
|
||||
when nil, 'file_not_exist'
|
||||
tmp_file = "/tmp/mpw-#{MPW.generatePassword()}.gpg"
|
||||
|
@ -67,14 +80,17 @@ class Sync
|
|||
|
||||
return @mpw.search()
|
||||
when 'not_authorized'
|
||||
@error_msg = 'not authorized'
|
||||
@error_msg = "#{I18n.t('error.sync.not_authorized')}\n#{e}"
|
||||
else
|
||||
@error_msg = 'error unknow'
|
||||
@error_msg = "#{I18n.t('error.sync.unknown')}\n#{e}"
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
# Update the remote data
|
||||
# @args: data -> the data to send on server
|
||||
# @rtrn: false if there is a problem
|
||||
def update(data)
|
||||
if !@sync
|
||||
return true
|
||||
|
@ -93,11 +109,11 @@ class Sync
|
|||
when nil
|
||||
return true
|
||||
when 'not_authorized'
|
||||
@error_msg = 'not authorized'
|
||||
@error_msg = "#{I18n.t('error.sync.not_authorized')}\n#{e}"
|
||||
when 'no_data'
|
||||
@error_msg = 'no data'
|
||||
@error_msg = "#{I18n.t('error.sync.no_data')}\n#{e}"
|
||||
else
|
||||
@error_msg = 'error unknow'
|
||||
@error_msg = "#{I18n.t('error.sync.unknown')}\n#{e}"
|
||||
end
|
||||
|
||||
return false
|
||||
|
@ -106,6 +122,7 @@ class Sync
|
|||
def delete()
|
||||
end
|
||||
|
||||
# Close the connection
|
||||
def close()
|
||||
if !@sync
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue