mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-27 07:33:05 +00:00
beautiful code
This commit is contained in:
parent
1f5b37ed3c
commit
dbfe118490
2 changed files with 51 additions and 57 deletions
|
@ -17,13 +17,8 @@ class Server
|
|||
|
||||
# Start the server
|
||||
def start()
|
||||
begin
|
||||
server = TCPServer.open(@host, @port)
|
||||
@log.info("The server is started on #{@host}:#{@port}")
|
||||
rescue Exception => e
|
||||
@log.error("Impossible to start the server: #{e}")
|
||||
exit 2
|
||||
end
|
||||
|
||||
loop do
|
||||
Thread.start(server.accept) do |client|
|
||||
|
@ -68,6 +63,10 @@ class Server
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
rescue Exception => e
|
||||
@log.error("Impossible to start the server: #{e}")
|
||||
exit 2
|
||||
end
|
||||
|
||||
# Get a gpg file
|
||||
|
@ -228,14 +227,12 @@ class Server
|
|||
# @args: client -> client connection
|
||||
# @rtrn: array of the json string, or false if isn't json message
|
||||
def get_client_msg(client)
|
||||
begin
|
||||
msg = client.gets
|
||||
return JSON.parse(msg)
|
||||
rescue
|
||||
closeConnection(client)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
# Close the client connection
|
||||
# @args: client -> client connection
|
||||
|
@ -248,7 +245,6 @@ class Server
|
|||
# @args: file_config -> the configuration file
|
||||
# @rtrn: true if the config file is correct
|
||||
def checkconfig(file_config)
|
||||
begin
|
||||
config = YAML::load_file(file_config)
|
||||
@host = config['config']['host']
|
||||
@port = config['config']['port'].to_i
|
||||
|
@ -282,14 +278,12 @@ class Server
|
|||
end
|
||||
end
|
||||
|
||||
return true
|
||||
rescue Exception => e
|
||||
puts "#{I18n.t('checkconfig.fail')}\n#{e}"
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
# Create a new config file
|
||||
# @args: file_config -> the configuration file
|
||||
# @rtrn: true if le config file is create
|
||||
|
@ -308,18 +302,16 @@ class Server
|
|||
'log_file' => log_file,
|
||||
'timeout' => timeout}}
|
||||
|
||||
begin
|
||||
File.open(file_config, 'w') do |file|
|
||||
file << config.to_yaml
|
||||
end
|
||||
|
||||
return true
|
||||
rescue Exception => e
|
||||
puts "#{I18n.t('form.setup.not_valid')}\n#{e}"
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
# Generate a random salt
|
||||
# @args: length -> the length salt
|
||||
# @rtrn: a random string
|
||||
|
|
2
mpw
2
mpw
|
@ -135,11 +135,13 @@ else
|
|||
begin
|
||||
cli.interactive()
|
||||
rescue SystemExit, Interrupt
|
||||
cli.sync_close()
|
||||
cli = nil
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
cli.sync_close()
|
||||
cli = nil
|
||||
|
||||
exit 0
|
||||
|
|
Loading…
Reference in a new issue