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

new syntax

This commit is contained in:
nishiki 2014-08-31 10:58:34 +02:00
parent 07f7aa5b67
commit 4a564dd07e

View file

@ -52,9 +52,10 @@ module MPW
client.puts delete_file(msg) client.puts delete_file(msg)
else else
@log.warning("#{client.peeraddr[3]} is disconnected because unkwnow command") @log.warning("#{client.peeraddr[3]} is disconnected because unkwnow command")
send_msg = {:action => 'unknown', send_msg = {action: 'unknown',
:gpg_key => msg['gpg_key'], gpg_key: msg['gpg_key'],
:error => 'server.error.client.unknown'} error: 'server.error.client.unknown'
}
client.puts send_msg client.puts send_msg
close_connection(client) close_connection(client)
end end
@ -87,20 +88,23 @@ module MPW
data = gpg_data['gpg']['data'] data = gpg_data['gpg']['data']
if is_authorized?(msg['password'], salt, hash) if is_authorized?(msg['password'], salt, hash)
send_msg = {:action => 'get', send_msg = {action: 'get',
:gpg_key => msg['gpg_key'], gpg_key: msg['gpg_key'],
:data => data, data: data,
:error => nil} error: nil
}
else else
send_msg = {:action => 'get', send_msg = {action: 'get',
:gpg_key => msg['gpg_key'], gpg_key: msg['gpg_key'],
:error => 'server.error.client.no_authorized'} error: 'server.error.client.no_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: '',
:error => nil} error: nil
}
end end
return send_msg.to_json return send_msg.to_json
@ -114,9 +118,10 @@ module MPW
data = msg['data'] data = msg['data']
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'],
:error => 'server.error.client.no_data'} error: 'server.error.client.no_data'
}
return send_msg.to_json return send_msg.to_json
end end
@ -139,26 +144,31 @@ module MPW
if is_authorized?(msg['password'], salt, hash) if is_authorized?(msg['password'], salt, hash)
begin begin
config = {'gpg' => {'salt' => salt, config = {'gpg' => {'salt' => salt,
'hash' => hash, 'hash' => hash,
'data' => data}} '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'],
:error => nil} 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'],
:error => 'server.error.client.unknown'} error: 'server.error.client.unknown'
}
end end
else else
send_msg = {:action => 'update', send_msg = {action: 'update',
:gpg_key => msg['gpg_key'], gpg_key: msg['gpg_key'],
:error => 'server.error.client.no_authorized'} error: 'server.error.client.no_authorized'
}
end end
return send_msg.to_json return send_msg.to_json
@ -184,26 +194,29 @@ module MPW
return send_msg.to_json return send_msg.to_json
end end
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']
if is_authorized?(msg['password'], salt, hash) if is_authorized?(msg['password'], salt, hash)
begin begin
File.unlink(file_gpg) File.unlink(file_gpg)
send_msg = {:action => 'delete', send_msg = {action: 'delete',
:gpg_key => msg['gpg_key'], gpg_key: msg['gpg_key'],
:error => nil} 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'],
:error => 'server.error.client.unknown'} error: 'server.error.client.unknown'
}
end end
else else
send_msg = {:action => 'delete', send_msg = {action: 'delete',
:gpg_key => msg['gpg_key'], gpg_key: msg['gpg_key'],
:error => 'server.error.client.no_authorized'} error: 'server.error.client.no_authorized'
}
end end
return send_msg.to_json return send_msg.to_json
@ -296,10 +309,12 @@ module MPW
timeout = ask(I18n.t('form.setup.timeout')).to_s timeout = ask(I18n.t('form.setup.timeout')).to_s
config = {'config' => {'host' => host, config = {'config' => {'host' => host,
'port' => port, 'port' => port,
'data_dir' => data_dir, 'data_dir' => data_dir,
'log_file' => log_file, 'log_file' => log_file,
'timeout' => timeout}} 'timeout' => timeout
}
}
File.open(file_config, 'w') do |file| File.open(file_config, 'w') do |file|
file << config.to_yaml file << config.to_yaml