mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-21 02:10:04 +00:00
update syntax
This commit is contained in:
parent
4aa4a750cd
commit
3e2c8eef0c
2 changed files with 16 additions and 17 deletions
|
@ -30,11 +30,9 @@ module MPW
|
||||||
while true do
|
while true do
|
||||||
msg = get_client_msg(client)
|
msg = get_client_msg(client)
|
||||||
|
|
||||||
if !msg
|
next if not msg
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
if msg['gpg_key'].nil? || msg['gpg_key'].empty? || msg['password'].nil? || msg['password'].empty?
|
if msg['gpg_key'].nil? or msg['gpg_key'].empty? or msg['password'].nil? or msg['password'].empty?
|
||||||
@log.warning("#{client.peeraddr[3]} is disconnected because no password or no gpg_key")
|
@log.warning("#{client.peeraddr[3]} is disconnected because no password or no gpg_key")
|
||||||
close_connection(client)
|
close_connection(client)
|
||||||
next
|
next
|
||||||
|
@ -75,7 +73,7 @@ module MPW
|
||||||
def get_file(msg)
|
def get_file(msg)
|
||||||
gpg_key = msg['gpg_key'].sub('@', '_')
|
gpg_key = msg['gpg_key'].sub('@', '_')
|
||||||
|
|
||||||
if msg['suffix'].nil? || msg['suffix'].empty?
|
if msg['suffix'].nil? or msg['suffix'].empty?
|
||||||
file_gpg = "#{@data_dir}/#{gpg_key}.yml"
|
file_gpg = "#{@data_dir}/#{gpg_key}.yml"
|
||||||
else
|
else
|
||||||
file_gpg = "#{@data_dir}/#{gpg_key}-#{msg['suffix']}.yml"
|
file_gpg = "#{@data_dir}/#{gpg_key}-#{msg['suffix']}.yml"
|
||||||
|
@ -117,7 +115,7 @@ module MPW
|
||||||
gpg_key = msg['gpg_key'].sub('@', '_')
|
gpg_key = msg['gpg_key'].sub('@', '_')
|
||||||
data = msg['data']
|
data = msg['data']
|
||||||
|
|
||||||
if data.nil? || data.empty?
|
if data.nil? or 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'
|
||||||
|
@ -126,7 +124,7 @@ module MPW
|
||||||
return send_msg.to_json
|
return send_msg.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
if msg['suffix'].nil? || msg['suffix'].empty?
|
if msg['suffix'].nil? or msg['suffix'].empty?
|
||||||
file_gpg = "#{@data_dir}/#{gpg_key}.yml"
|
file_gpg = "#{@data_dir}/#{gpg_key}.yml"
|
||||||
else
|
else
|
||||||
file_gpg = "#{@data_dir}/#{gpg_key}-#{msg['suffix']}.yml"
|
file_gpg = "#{@data_dir}/#{gpg_key}-#{msg['suffix']}.yml"
|
||||||
|
@ -180,16 +178,17 @@ module MPW
|
||||||
def delete_file(msg)
|
def delete_file(msg)
|
||||||
gpg_key = msg['gpg_key'].sub('@', '_')
|
gpg_key = msg['gpg_key'].sub('@', '_')
|
||||||
|
|
||||||
if msg['suffix'].nil? || msg['suffix'].empty?
|
if msg['suffix'].nil? or msg['suffix'].empty?
|
||||||
file_gpg = "#{@data_dir}/#{gpg_key}.yml"
|
file_gpg = "#{@data_dir}/#{gpg_key}.yml"
|
||||||
else
|
else
|
||||||
file_gpg = "#{@data_dir}/#{gpg_key}-#{msg['suffix']}.yml"
|
file_gpg = "#{@data_dir}/#{gpg_key}-#{msg['suffix']}.yml"
|
||||||
end
|
end
|
||||||
|
|
||||||
if !File.exist?(file_gpg)
|
if not File.exist?(file_gpg)
|
||||||
send_msg = {:action => 'delete',
|
send_msg = {:action => 'delete',
|
||||||
:gpg_key => msg['gpg_key'],
|
:gpg_key => msg['gpg_key'],
|
||||||
:error => nil}
|
:error => nil
|
||||||
|
}
|
||||||
|
|
||||||
return send_msg.to_json
|
return send_msg.to_json
|
||||||
end
|
end
|
||||||
|
@ -264,19 +263,19 @@ module MPW
|
||||||
@log_file = config['config']['log_file']
|
@log_file = config['config']['log_file']
|
||||||
@timeout = config['config']['timeout'].to_i
|
@timeout = config['config']['timeout'].to_i
|
||||||
|
|
||||||
if @host.empty? || @port <= 0 || @data_dir.empty?
|
if @host.empty? or @port <= 0 or @data_dir.empty?
|
||||||
puts I18n.t('checkconfig.fail')
|
puts I18n.t('checkconfig.fail')
|
||||||
puts I18n.t('checkconfig.empty')
|
puts I18n.t('checkconfig.empty')
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if !Dir.exist?(@data_dir)
|
if not Dir.exist?(@data_dir)
|
||||||
puts I18n.t('checkconfig.fail')
|
puts I18n.t('checkconfig.fail')
|
||||||
puts I18n.t('checkconfig.datadir')
|
puts I18n.t('checkconfig.datadir')
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if @log_file.nil? || @log_file.empty?
|
if @log_file.nil? or @log_file.empty?
|
||||||
puts I18n.t('checkconfig.fail')
|
puts I18n.t('checkconfig.fail')
|
||||||
puts I18n.t('checkconfig.log_file_empty')
|
puts I18n.t('checkconfig.log_file_empty')
|
||||||
return false
|
return false
|
||||||
|
@ -330,7 +329,7 @@ module MPW
|
||||||
# @args: length -> the length salt
|
# @args: length -> the length salt
|
||||||
# @rtrn: a random string
|
# @rtrn: a random string
|
||||||
def generate_salt(length=4)
|
def generate_salt(length=4)
|
||||||
if length.to_i <= 0 || length.to_i > 16
|
if length.to_i <= 0 or length.to_i > 16
|
||||||
length = 4
|
length = 4
|
||||||
else
|
else
|
||||||
length = length.to_i
|
length = length.to_i
|
||||||
|
|
|
@ -18,7 +18,7 @@ require "#{APP_ROOT}/lib/Server.rb"
|
||||||
|
|
||||||
lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
|
lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
|
||||||
|
|
||||||
if defined? I18n.enforce_available_locales
|
if defined?(I18n.enforce_available_locales)
|
||||||
I18n.enforce_available_locales = true
|
I18n.enforce_available_locales = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ end.parse!
|
||||||
# Main
|
# Main
|
||||||
# --------------------------------------------------------- #
|
# --------------------------------------------------------- #
|
||||||
|
|
||||||
if options[:config].nil? || options[:config].empty?
|
if options[:config].nil? or options[:config].empty?
|
||||||
puts "#{I18n.t('option.usage')}: mpw-server -c CONFIG [options]"
|
puts "#{I18n.t('option.usage')}: mpw-server -c CONFIG [options]"
|
||||||
exit 2
|
exit 2
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue