mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-27 07:33:05 +00:00
clean error message with the server
This commit is contained in:
parent
a8b4ca29c9
commit
e2839d136c
4 changed files with 58 additions and 54 deletions
|
@ -19,6 +19,7 @@ en:
|
||||||
name_empty: "You must define a name!"
|
name_empty: "You must define a name!"
|
||||||
sync:
|
sync:
|
||||||
connection: "Connection fail!"
|
connection: "Connection fail!"
|
||||||
|
communication: "A communication problem with the server is appeared!"
|
||||||
no_data: "Nothing data!"
|
no_data: "Nothing data!"
|
||||||
not_authorized: "You haven't the access to remote file!"
|
not_authorized: "You haven't the access to remote file!"
|
||||||
unknown: "An unknown error is occured!"
|
unknown: "An unknown error is occured!"
|
||||||
|
@ -117,6 +118,11 @@ en:
|
||||||
connect: "Connection to:"
|
connect: "Connection to:"
|
||||||
nothing: "Nothing result!"
|
nothing: "Nothing result!"
|
||||||
server:
|
server:
|
||||||
|
error:
|
||||||
|
client:
|
||||||
|
unknown: "An unknown error is appeared!"
|
||||||
|
no_authorized: "You haven't access to remote file!"
|
||||||
|
no_data: "Nothing data has been sent!"
|
||||||
option:
|
option:
|
||||||
usage: "Usage"
|
usage: "Usage"
|
||||||
config: "Specifie the configuration file"
|
config: "Specifie the configuration file"
|
||||||
|
|
10
i18n/fr.yml
10
i18n/fr.yml
|
@ -18,8 +18,9 @@ fr:
|
||||||
update:
|
update:
|
||||||
name_empty: "Vous devez définir un nom!"
|
name_empty: "Vous devez définir un nom!"
|
||||||
sync:
|
sync:
|
||||||
connection: "La connexion n'a pu être établie"
|
connection: "La connexion n'a pu être établie!"
|
||||||
no_data: "Aucune data!"
|
communication: "Un problème de communication avec le serveur est apparu!"
|
||||||
|
no_data: "Aucune donnée!"
|
||||||
not_authorized: "Vous n'avez pas les autorisations d'accès au fichier distant!"
|
not_authorized: "Vous n'avez pas les autorisations d'accès au fichier distant!"
|
||||||
unknown: "Une erreur inconnue est survenue!"
|
unknown: "Une erreur inconnue est survenue!"
|
||||||
cli:
|
cli:
|
||||||
|
@ -117,6 +118,11 @@ fr:
|
||||||
connect: "Connexion à:"
|
connect: "Connexion à:"
|
||||||
nothing: "Aucun résultat!"
|
nothing: "Aucun résultat!"
|
||||||
server:
|
server:
|
||||||
|
error:
|
||||||
|
client:
|
||||||
|
unknown: "Une erreur inconnue est apparue!"
|
||||||
|
no_authorized: "Vous n'avez pas les accès au fichier distant!"
|
||||||
|
no_data: "Aucune donnée n'a été transmise!"
|
||||||
option:
|
option:
|
||||||
usage: "Utilisation"
|
usage: "Utilisation"
|
||||||
config: "Spécifie le fichier de configuration"
|
config: "Spécifie le fichier de configuration"
|
||||||
|
|
|
@ -43,7 +43,10 @@ class Server
|
||||||
when 'close'
|
when 'close'
|
||||||
closeConnection(client)
|
closeConnection(client)
|
||||||
else
|
else
|
||||||
client.puts 'Unknown command'
|
send_msg = {:action => 'unknown',
|
||||||
|
:gpg_key => msg['gpg_key'],
|
||||||
|
:error => 'server.error.client.unknown'}
|
||||||
|
client.puts send_msg
|
||||||
closeConnection(client)
|
closeConnection(client)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -72,20 +75,18 @@ class Server
|
||||||
if isAuthorized?(msg['password'], salt, hash)
|
if isAuthorized?(msg['password'], salt, hash)
|
||||||
send_msg = {:action => 'get',
|
send_msg = {:action => 'get',
|
||||||
:gpg_key => msg['gpg_key'],
|
:gpg_key => msg['gpg_key'],
|
||||||
:msg => 'done',
|
:data => data,
|
||||||
:data => data}
|
:error => nil}
|
||||||
else
|
else
|
||||||
send_msg = {:action => 'get',
|
send_msg = {:action => 'get',
|
||||||
:gpg_key => msg['gpg_key'],
|
:gpg_key => msg['gpg_key'],
|
||||||
:msg => 'fail',
|
:error => 'server.error.client.no_authorized'}
|
||||||
:error => 'not_authorized'}
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
send_msg = {:action => 'get',
|
send_msg = {:action => 'get',
|
||||||
:gpg_key => msg['gpg_key'],
|
:gpg_key => msg['gpg_key'],
|
||||||
:data => '',
|
:data => '',
|
||||||
:msg => 'fail',
|
:error => nil}
|
||||||
:error => 'file_not_exist'}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return send_msg.to_json
|
return send_msg.to_json
|
||||||
|
@ -101,8 +102,7 @@ class Server
|
||||||
if data.nil? || data.empty?
|
if data.nil? || data.empty?
|
||||||
send_msg = {:action => 'update',
|
send_msg = {:action => 'update',
|
||||||
:gpg_key => msg['gpg_key'],
|
:gpg_key => msg['gpg_key'],
|
||||||
:msg => 'fail',
|
:error => 'server.error.client.no_data'}
|
||||||
:error => 'no_data'}
|
|
||||||
|
|
||||||
return send_msg.to_json
|
return send_msg.to_json
|
||||||
end
|
end
|
||||||
|
@ -133,20 +133,18 @@ class Server
|
||||||
file << config.to_yaml
|
file << config.to_yaml
|
||||||
end
|
end
|
||||||
|
|
||||||
send_msg = {:action => 'update',
|
send_msg = {:action => 'update',
|
||||||
:gpg_key => msg['gpg_key'],
|
:gpg_key => msg['gpg_key'],
|
||||||
:msg => 'done'}
|
:error => nil}
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
send_msg = {:action => 'update',
|
send_msg = {:action => 'update',
|
||||||
:gpg_key => msg['gpg_key'],
|
:gpg_key => msg['gpg_key'],
|
||||||
:msg => 'fail',
|
:error => 'server.error.client.unknown'}
|
||||||
:error => 'server_error'}
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
send_msg = {:action => 'update',
|
send_msg = {:action => 'update',
|
||||||
:gpg_key => msg['gpg_key'],
|
:gpg_key => msg['gpg_key'],
|
||||||
:msg => 'fail',
|
:error => 'server.error.client.no_authorized'}
|
||||||
:error => 'not_autorized'}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return send_msg.to_json
|
return send_msg.to_json
|
||||||
|
@ -167,8 +165,7 @@ class Server
|
||||||
if !File.exist?(file_gpg)
|
if !File.exist?(file_gpg)
|
||||||
send_msg = {:action => 'delete',
|
send_msg = {:action => 'delete',
|
||||||
:gpg_key => msg['gpg_key'],
|
:gpg_key => msg['gpg_key'],
|
||||||
:msg => 'delete_fail',
|
:error => nil}
|
||||||
:error => 'file_not_exist'}
|
|
||||||
|
|
||||||
return send_msg.to_json
|
return send_msg.to_json
|
||||||
end
|
end
|
||||||
|
@ -183,18 +180,16 @@ class Server
|
||||||
|
|
||||||
send_msg = {:action => 'delete',
|
send_msg = {:action => 'delete',
|
||||||
:gpg_key => msg['gpg_key'],
|
:gpg_key => msg['gpg_key'],
|
||||||
:msg => 'delete_done'}
|
:error => nil}
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
send_msg = {:action => 'delete',
|
send_msg = {:action => 'delete',
|
||||||
:gpg_key => msg['gpg_key'],
|
:gpg_key => msg['gpg_key'],
|
||||||
:msg => 'delete_fail',
|
:error => 'server.error.client.unknown'}
|
||||||
:error => e}
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
send_msg = {:action => 'delete',
|
send_msg = {:action => 'delete',
|
||||||
:gpg_key => msg['gpg_key'],
|
:gpg_key => msg['gpg_key'],
|
||||||
:msg => 'delete_fail',
|
:error => 'server.error.client.no_authorized'}
|
||||||
:error => 'not_autorized'}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return send_msg.to_json
|
return send_msg.to_json
|
||||||
|
@ -285,7 +280,7 @@ class Server
|
||||||
file << config.to_yaml
|
file << config.to_yaml
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
puts "#{I18n.t('server.formsetup.not_valid')}\n#{e}"
|
puts "#{I18n.t('server.form.setup.not_valid')}\n#{e}"
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
47
lib/Sync.rb
47
lib/Sync.rb
|
@ -55,16 +55,18 @@ class Sync
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
send_msg = {:action => 'get',
|
send_msg = {:action => 'get',
|
||||||
:gpg_key => @gpg_key,
|
:gpg_key => @gpg_key,
|
||||||
:password => @password,
|
:password => @password,
|
||||||
:suffix => @suffix}
|
:suffix => @suffix}
|
||||||
|
|
||||||
@socket.puts send_msg.to_json
|
@socket.puts send_msg.to_json
|
||||||
msg = JSON.parse(@socket.gets)
|
msg = JSON.parse(@socket.gets)
|
||||||
|
|
||||||
case msg['error']
|
if !msg['error']
|
||||||
when nil, 'file_not_exist'
|
@error_msg = I18n.t('error.sync.communication')
|
||||||
|
return nil
|
||||||
|
elsif msg['error'].nil?
|
||||||
tmp_file = "/tmp/mpw-#{MPW.generatePassword()}.gpg"
|
tmp_file = "/tmp/mpw-#{MPW.generatePassword()}.gpg"
|
||||||
File.open(tmp_file, 'w') do |file|
|
File.open(tmp_file, 'w') do |file|
|
||||||
file << msg['data']
|
file << msg['data']
|
||||||
|
@ -76,15 +78,12 @@ class Sync
|
||||||
end
|
end
|
||||||
|
|
||||||
File.unlink(tmp_file)
|
File.unlink(tmp_file)
|
||||||
|
|
||||||
return @mpw.search()
|
return @mpw.search()
|
||||||
when 'not_authorized'
|
|
||||||
@error_msg = "#{I18n.t('error.sync.not_authorized')}\n#{e}"
|
|
||||||
else
|
else
|
||||||
@error_msg = "#{I18n.t('error.sync.unknown')}\n#{e}"
|
@error_msg = I18n.t(msg['error'])
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update the remote data
|
# Update the remote data
|
||||||
|
@ -95,29 +94,27 @@ class Sync
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
send_msg = {:action => 'update',
|
send_msg = {:action => 'update',
|
||||||
:gpg_key => @gpg_key,
|
:gpg_key => @gpg_key,
|
||||||
:password => @password,
|
:password => @password,
|
||||||
:suffix => @suffix,
|
:suffix => @suffix,
|
||||||
:data => data}
|
:data => data}
|
||||||
|
|
||||||
@socket.puts send_msg.to_json
|
@socket.puts send_msg.to_json
|
||||||
msg = JSON.parse(@socket.gets)
|
msg = JSON.parse(@socket.gets)
|
||||||
|
|
||||||
case msg['error']
|
if !msg['error']
|
||||||
when nil
|
@error_msg = I18n.t('error.sync.communication')
|
||||||
|
return false
|
||||||
|
elsif msg['error'].nil?
|
||||||
return true
|
return true
|
||||||
when 'not_authorized'
|
|
||||||
@error_msg = "#{I18n.t('error.sync.not_authorized')}\n#{e}"
|
|
||||||
when 'no_data'
|
|
||||||
@error_msg = "#{I18n.t('error.sync.no_data')}\n#{e}"
|
|
||||||
else
|
else
|
||||||
@error_msg = "#{I18n.t('error.sync.unknown')}\n#{e}"
|
@error_msg = I18n.t(msg['error'])
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO
|
||||||
def delete()
|
def delete()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue