1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-02-21 10:20:05 +00:00

add last_update

This commit is contained in:
nishiki 2014-01-12 11:07:54 +01:00
parent 9067a67d50
commit 477178ecdd

View file

@ -61,26 +61,28 @@ class Server
end end
if File.exist?(file_gpg) if File.exist?(file_gpg)
gpg_data = YAML::load_file(file_gpg) gpg_data = YAML::load_file(file_gpg)
salt = gpg_data['gpg']['salt'] salt = gpg_data['gpg']['salt']
hash = gpg_data['gpg']['hash'] hash = gpg_data['gpg']['hash']
data = gpg_data['gpg']['data'] data = gpg_data['gpg']['data']
last_update = gpg_data['gpg']['last_update']
if self.isAuthorized?(msg['password'], salt, hash) if self.isAuthorized?(msg['password'], salt, hash)
send_msg = {:action => 'get', send_msg = {:action => 'get',
:gpg_key => msg['gpg_key'], :gpg_key => msg['gpg_key'],
:msg => 'get_done', :last_update => last_update,
:msg => 'done',
:data => data} :data => data}
else else
send_msg = {:action => 'get', send_msg = {:action => 'get',
:gpg_key => msg['gpg_key'], :gpg_key => msg['gpg_key'],
:msg => 'get_fail', :msg => 'fail',
:error => 'not_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'],
:msg => 'get_fail', :msg => 'fail',
:error => 'file_not_exist'} :error => 'file_not_exist'}
end end
@ -97,7 +99,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 => 'update_fail', :msg => 'fail',
:error => 'no_data'} :error => 'no_data'}
return send_msg.to_json return send_msg.to_json
@ -121,27 +123,30 @@ class Server
if self.isAuthorized?(msg['password'], salt, hash) if self.isAuthorized?(msg['password'], salt, hash)
begin begin
config = {'gpg' => {'salt' => salt, last_update = Time.now.to_i
'hash' => hash, config = {'gpg' => {'salt' => salt,
'data' => data}} 'hash' => hash,
'last_update' => last_update
'data' => data}}
File.open(file_gpg, 'w') do |file| File.open(file_gpg, 'w') do |file|
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 => 'update_done'} :last_update => last_update
:msg => 'done'}
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 => 'update_fail', :msg => 'fail',
:error => e} :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 => 'update_fail', :msg => 'fail',
:error => 'not_autorized'} :error => 'not_autorized'}
end end