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:
parent
9067a67d50
commit
477178ecdd
1 changed files with 22 additions and 17 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue