mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-27 07:33:05 +00:00
rename function
This commit is contained in:
parent
174a028238
commit
1cabe202e7
6 changed files with 27 additions and 32 deletions
12
lib/Cli.rb
12
lib/Cli.rb
|
@ -23,8 +23,8 @@ class Cli
|
|||
@config = config
|
||||
end
|
||||
|
||||
# Destructor
|
||||
def finalize()
|
||||
# Close sync
|
||||
def sync_close()
|
||||
@sync.close()
|
||||
end
|
||||
|
||||
|
@ -47,7 +47,7 @@ class Cli
|
|||
puts "#{I18n.t('display.error')}: #{@mpw.error_msg}"
|
||||
elsif !@sync.update(File.open(@config.file_gpg).read)
|
||||
puts "#{I18n.t('display.error')}: #{@sync.error_msg}"
|
||||
elsif !@config.setLastUpdate()
|
||||
elsif !@config.set_last_update()
|
||||
puts "#{I18n.t('display.error')}: #{@config.error_msg}"
|
||||
else
|
||||
return true
|
||||
|
@ -188,7 +188,7 @@ class Cli
|
|||
# Update an item
|
||||
# @args: id -> the item's id
|
||||
def update(id)
|
||||
row = @mpw.searchById(id)
|
||||
row = @mpw.search_by_id(id)
|
||||
|
||||
if not row.empty?
|
||||
puts I18n.t('form.update.title')
|
||||
|
@ -222,7 +222,7 @@ class Cli
|
|||
# force -> no resquest a validation
|
||||
def remove(id, force=false)
|
||||
if not force
|
||||
result = @mpw.searchById(id)
|
||||
result = @mpw.search_by_id(id)
|
||||
|
||||
if result.length > 0
|
||||
displayFormat(result)
|
||||
|
@ -265,7 +265,7 @@ class Cli
|
|||
# @args: file -> the import file
|
||||
# force -> no resquest a validation
|
||||
def import(file, force=false)
|
||||
result = @mpw.importPreview(file)
|
||||
result = @mpw.import_preview(file)
|
||||
|
||||
if not force
|
||||
if result.is_a?(Array) && !result.empty?
|
||||
|
|
|
@ -105,7 +105,7 @@ class MPW
|
|||
# Search in some csv data
|
||||
# @args: id -> the id item
|
||||
# @rtrn: a row with the resultat of the search
|
||||
def searchById(id)
|
||||
def search_by_id(id)
|
||||
@data.each do |row|
|
||||
if row[ID] == id
|
||||
return row
|
||||
|
@ -243,7 +243,7 @@ class MPW
|
|||
# Return a preview import
|
||||
# @args: file -> path to file import
|
||||
# @rtrn: an array with the items to import, if there is an error return false
|
||||
def importPreview(file)
|
||||
def import_preview(file)
|
||||
begin
|
||||
result = Array.new()
|
||||
id = 0
|
||||
|
|
|
@ -110,7 +110,7 @@ class MPWConfig
|
|||
|
||||
# Set the last update when there is a sync
|
||||
# @rtrn: true is the file has been updated
|
||||
def setLastUpdate()
|
||||
def set_last_update()
|
||||
config = {'config' => {'key' => @key,
|
||||
'lang' => @lang,
|
||||
'file_gpg' => @file_gpg,
|
||||
|
|
|
@ -10,11 +10,6 @@ require "#{APP_ROOT}/lib/MPW.rb"
|
|||
|
||||
class Server
|
||||
|
||||
INFO = 0
|
||||
WARNING = 1
|
||||
ERROR = 2
|
||||
DEBUG = 3
|
||||
|
||||
attr_accessor :error_msg
|
||||
|
||||
# Constructor
|
||||
|
@ -37,37 +32,37 @@ class Server
|
|||
@log.info("#{client.peeraddr[3]} is connected")
|
||||
|
||||
while true do
|
||||
msg = getClientMessage(client)
|
||||
msg = get_client_msg(client)
|
||||
|
||||
if !msg
|
||||
next
|
||||
end
|
||||
|
||||
if msg['gpg_key'].nil? || msg['gpg_key'].empty? || msg['password'].nil? || msg['password'].empty?
|
||||
closeConnection(client)
|
||||
close_connection(client)
|
||||
next
|
||||
end
|
||||
|
||||
case msg['action']
|
||||
when 'get'
|
||||
@log.debug("#{client.peeraddr[3]} GET gpg_key=#{msg['gpg_key']} suffix=#{msg['suffix']}")
|
||||
client.puts getFile(msg)
|
||||
client.puts get_file(msg)
|
||||
when 'update'
|
||||
@log.debug("#{client.peeraddr[3]} UPDATE gpg_key=#{msg['gpg_key']} suffix=#{msg['suffix']}")
|
||||
client.puts updateFile(msg)
|
||||
client.puts update_file(msg)
|
||||
when 'delete'
|
||||
@log.debug("#{client.peeraddr[3]} DELETE gpg_key=#{msg['gpg_key']} suffix=#{msg['suffix']}")
|
||||
client.puts deleteFile(msg)
|
||||
client.puts delete_file(msg)
|
||||
when 'close'
|
||||
@log.info("#{client.peeraddr[3]} is disconnected")
|
||||
closeConnection(client)
|
||||
close_connection(client)
|
||||
else
|
||||
@log.warning("#{client.peeraddr[3]} is disconnected for unkwnow command")
|
||||
send_msg = {:action => 'unknown',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:error => 'server.error.client.unknown'}
|
||||
client.puts send_msg
|
||||
closeConnection(client)
|
||||
close_connection(client)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -77,7 +72,7 @@ class Server
|
|||
# Get a gpg file
|
||||
# @args: msg -> message puts by the client
|
||||
# @rtrn: json message
|
||||
def getFile(msg)
|
||||
def get_file(msg)
|
||||
gpg_key = msg['gpg_key'].sub('@', '_')
|
||||
|
||||
if msg['suffix'].nil? || msg['suffix'].empty?
|
||||
|
@ -92,7 +87,7 @@ class Server
|
|||
hash = gpg_data['gpg']['hash']
|
||||
data = gpg_data['gpg']['data']
|
||||
|
||||
if isAuthorized?(msg['password'], salt, hash)
|
||||
if is_authorized?(msg['password'], salt, hash)
|
||||
send_msg = {:action => 'get',
|
||||
:gpg_key => msg['gpg_key'],
|
||||
:data => data,
|
||||
|
@ -115,7 +110,7 @@ class Server
|
|||
# Update a file
|
||||
# @args: msg -> message puts by the client
|
||||
# @rtrn: json message
|
||||
def updateFile(msg)
|
||||
def update_file(msg)
|
||||
gpg_key = msg['gpg_key'].sub('@', '_')
|
||||
data = msg['data']
|
||||
|
||||
|
@ -143,7 +138,7 @@ class Server
|
|||
hash = Digest::SHA256.hexdigest(salt + msg['password'])
|
||||
end
|
||||
|
||||
if isAuthorized?(msg['password'], salt, hash)
|
||||
if is_authorized?(msg['password'], salt, hash)
|
||||
begin
|
||||
config = {'gpg' => {'salt' => salt,
|
||||
'hash' => hash,
|
||||
|
@ -173,7 +168,7 @@ class Server
|
|||
# Remove a gpg file
|
||||
# @args: msg -> message puts by the client
|
||||
# @rtrn: json message
|
||||
def deleteFile(msg)
|
||||
def delete_file(msg)
|
||||
gpg_key = msg['gpg_key'].sub('@', '_')
|
||||
|
||||
if msg['suffix'].nil? || msg['suffix'].empty?
|
||||
|
@ -194,7 +189,7 @@ class Server
|
|||
salt = gpg_data['gpg']['salt']
|
||||
hash = gpg_data['gpg']['hash']
|
||||
|
||||
if isAuthorized?(msg['password'], salt, hash)
|
||||
if is_authorized?(msg['password'], salt, hash)
|
||||
begin
|
||||
File.unlink(file_gpg)
|
||||
|
||||
|
@ -220,7 +215,7 @@ class Server
|
|||
# salt -> the salt
|
||||
# hash -> the hash of the password with the salt
|
||||
# @rtrn: true is is good, else false
|
||||
def isAuthorized?(password, salt, hash)
|
||||
def is_authorized?(password, salt, hash)
|
||||
if hash == Digest::SHA256.hexdigest(salt + password)
|
||||
return true
|
||||
else
|
||||
|
@ -231,7 +226,7 @@ class Server
|
|||
# Get message to client
|
||||
# @args: client -> client connection
|
||||
# @rtrn: array of the json string, or false if isn't json message
|
||||
def getClientMessage(client)
|
||||
def get_client_msg(client)
|
||||
begin
|
||||
msg = client.gets
|
||||
return JSON.parse(msg)
|
||||
|
@ -243,7 +238,7 @@ class Server
|
|||
|
||||
# Close the client connection
|
||||
# @args: client -> client connection
|
||||
def closeConnection(client)
|
||||
def close_connection(client)
|
||||
client.puts "Closing the connection. Bye!"
|
||||
client.close
|
||||
end
|
||||
|
|
2
mpw
2
mpw
|
@ -140,6 +140,6 @@ else
|
|||
end
|
||||
end
|
||||
|
||||
cli = nil
|
||||
cli.sync_close()
|
||||
|
||||
exit 0
|
||||
|
|
2
mpw-ssh
2
mpw-ssh
|
@ -66,6 +66,6 @@ else
|
|||
cli.ssh(search)
|
||||
end
|
||||
|
||||
cli = nil
|
||||
cli.sync_close()
|
||||
|
||||
exit 0
|
||||
|
|
Loading…
Reference in a new issue