diff --git a/lib/Config.rb b/lib/Config.rb index 8dbbc8b..aaab3ac 100644 --- a/lib/Config.rb +++ b/lib/Config.rb @@ -43,7 +43,7 @@ module MPW end @file_config = "#{@dir_config}/conf/default.cfg" - if !file_config.nil? && !file_config.empty? + if not file_config.nil? and not file_config.empty? @file_config = file_config end end @@ -68,7 +68,7 @@ module MPW return false end - if !check_public_gpg_key(share_keys) + if not check_public_gpg_key(share_keys) return false end @@ -112,10 +112,10 @@ module MPW # expire -> the time of expire to GPG key # @rtrn: true if the GPG key is create, else false def setup_gpg_key(password, name, length = 2048, expire = 0) - if name.nil? || name.empty? + if name.nil? or name.empty? @error_msg = "#{I18n.t('error.config.genkey_gpg.name')}" return false - elsif password.nil? || password.empty? + elsif password.nil? or password.empty? @error_msg = "#{I18n.t('error.config.genkey_gpg.password')}" return false end @@ -159,7 +159,7 @@ module MPW @sync_path = config['config']['sync_path'] @last_update = config['config']['last_update'].to_i - if @key.empty? || @file_gpg.empty? + if @key.empty? or @file_gpg.empty? @error_msg = I18n.t('error.config.check') return false end @@ -190,7 +190,7 @@ module MPW ctx = GPGME::Ctx.new share_keys = share_keys.nil? ? '' : share_keys - if !share_keys.empty? + if not share_keys.empty? share_keys.split.each do |k| if not k =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/ @error_msg = I18n.t('error.config.key_bad_format') diff --git a/lib/MPW.rb b/lib/MPW.rb index f262a9d..0b0fafb 100644 --- a/lib/MPW.rb +++ b/lib/MPW.rb @@ -59,7 +59,7 @@ module MPW recipients = [] recipients.push(@key) - if !@share_keys.nil? + if not @share_keys.nil? @share_keys.split.each { |k| recipients.push(k) } end @@ -81,7 +81,7 @@ module MPW def search(search='', group=nil, protocol=nil) result = [] - if !search.nil? + if not search.nil? search = search.downcase end search = search.force_encoding('ASCII-8BIT') @@ -91,8 +91,8 @@ module MPW server = row[:host].nil? ? nil : row[:host].downcase comment = row[:comment].nil? ? nil : row[:comment].downcase - if name =~ /^.*#{search}.*$/ || server =~ /^.*#{search}.*$/ || comment =~ /^.*#{search}.*$/ - if (protocol.nil? || protocol.eql?(row[:protocol])) && (group.nil? || group.eql?(row[:group])) + if name =~ /^.*#{search}.*$/ or server =~ /^.*#{search}.*$/ or comment =~ /^.*#{search}.*$/ + if (protocol.nil? or protocol.eql?(row[:protocol])) and (group.nil? or group.eql?(row[:group])) result.push(row) end end @@ -146,15 +146,15 @@ module MPW row_update = {} row_update[:date] = Time.now.to_i - row_update[:id] = id.nil? || id.empty? ? MPW.password(16) : id - row_update[:name] = name.nil? || name.empty? ? row[:name] : name - row_update[:group] = group.nil? || group.empty? ? row[:group] : group - row_update[:host] = server.nil? || server.empty? ? row[:host] : server - row_update[:protocol] = protocol.nil? || protocol.empty? ? row[:protocol] : protocol - row_update[:login] = login.nil? || login.empty? ? row[:login] : login - row_update[:password] = passwd.nil? || passwd.empty? ? row[:password] : passwd - row_update[:port] = port.nil? || port.empty? ? row[:port] : port - row_update[:comment] = comment.nil? || comment.empty? ? row[:comment] : comment + row_update[:id] = id.nil? or id.empty? ? MPW.password(16) : id + row_update[:name] = name.nil? or name.empty? ? row[:name] : name + row_update[:group] = group.nil? or group.empty? ? row[:group] : group + row_update[:host] = server.nil? or server.empty? ? row[:host] : server + row_update[:protocol] = protocol.nil? or protocol.empty? ? row[:protocol] : protocol + row_update[:login] = login.nil? or login.empty? ? row[:login] : login + row_update[:password] = passwd.nil? or passwd.empty? ? row[:password] : passwd + row_update[:port] = port.nil? or port.empty? ? row[:port] : port + row_update[:comment] = comment.nil? or comment.empty? ? row[:comment] : comment row_update[:name] = row_update[:name].nil? ? nil : row_update[:name].force_encoding('ASCII-8BIT') row_update[:group] = row_update[:group].nil? ? nil : row_update[:group].force_encoding('ASCII-8BIT') @@ -164,7 +164,7 @@ module MPW row_update[:password] = row_update[:password].nil? ? nil : row_update[:password].force_encoding('ASCII-8BIT') row_update[:comment] = row_update[:comment].nil? ? nil : row_update[:comment].force_encoding('ASCII-8BIT') - if row_update[:name].nil? || row_update[:name].empty? + if row_update[:name].nil? or row_update[:name].empty? @error_msg = I18n.t('error.update.name_empty') return false end @@ -277,9 +277,9 @@ module MPW # last_update -> last update # @rtrn: false if data_remote is nil def sync(data_remote, last_update) - if !data_remote.instance_of?(Array) + if not data_remote.instance_of?(Array) return false - else !data_remote.nil? && !data_remote.empty? + else not data_remote.nil? and not data_remote.empty? @data.each do |l| j = 0 update = false @@ -298,7 +298,7 @@ module MPW end # Delete an old item - if !update && l[:date].to_i < last_update + if not update and l[:date].to_i < last_update remove(l[:id]) end end diff --git a/lib/UI/Cli.rb b/lib/UI/Cli.rb index c84df63..3b74105 100644 --- a/lib/UI/Cli.rb +++ b/lib/UI/Cli.rb @@ -24,7 +24,7 @@ class Cli # Sync the data with the server # @rtnr: true if the synchro is finish def sync - if !defined?(@sync) + if not defined?(@sync) case @config.sync_type when 'mpw' require "#{APP_ROOT}/lib/Sync/MPWSync" @@ -40,21 +40,21 @@ class Cli end end - if !@config.sync_host.nil? && !@config.sync_port.nil? - if !@sync.connect(@config.sync_host, @config.sync_user, @config.sync_pwd, @config.sync_path, @config.sync_port) + if not @config.sync_host.nil? and not @config.sync_port.nil? + if not @sync.connect(@config.sync_host, @config.sync_user, @config.sync_pwd, @config.sync_path, @config.sync_port) puts "#{I18n.t('display.error')} #1: #{@sync.error_msg}" end end if @sync.enable - if !@mpw.sync(@sync.get(@passwd), @config.last_update) + if not @mpw.sync(@sync.get(@passwd), @config.last_update) puts "#{I18n.t('display.error')} #2: #{@mpw.error_msg}" if !@mpw.error_msg.nil? puts "#{I18n.t('display.error')} #3: #{@sync.error_msg}" if !@sync.error_msg.nil? - elsif !@sync.update(File.open(@config.file_gpg).read) + elsif not @sync.update(File.open(@config.file_gpg).read) puts "#{I18n.t('display.error')} #4: #{@sync.error_msg}" - elsif !@config.set_last_update + elsif not @config.set_last_update puts "#{I18n.t('display.error')} #5: #{@config.error_msg}" - elsif !@mpw.encrypt + elsif not @mpw.encrypt puts "#{I18n.t('display.error')} #6: #{@mpw.error_msg}" else return true @@ -89,17 +89,17 @@ class Cli sync_path = ask(I18n.t('form.setup.sync_path')).to_s end - if language.nil? || language.empty? + if language.nil? or language.empty? language = lang end I18n.locale = language.to_sym - sync_type = sync_type.nil? || sync_type.empty? ? nil : sync_type - sync_host = sync_host.nil? || sync_host.empty? ? nil : sync_host - sync_port = sync_port.nil? || sync_port.empty? ? nil : sync_port.to_i - sync_user = sync_user.nil? || sync_user.empty? ? nil : sync_user - sync_pwd = sync_pwd.nil? || sync_pwd.empty? ? nil : sync_pwd - sync_path = sync_path.nil? || sync_path.empty? ? nil : sync_path + sync_type = sync_type.nil? or sync_type.empty? ? nil : sync_type + sync_host = sync_host.nil? or sync_host.empty? ? nil : sync_host + sync_port = sync_port.nil? or sync_port.empty? ? nil : sync_port.to_i + sync_user = sync_user.nil? or sync_user.empty? ? nil : sync_user + sync_pwd = sync_pwd.nil? or sync_pwd.empty? ? nil : sync_pwd + sync_path = sync_path.nil? or sync_path.empty? ? nil : sync_path if @config.setup(key, share_keys, language, file_gpg, timeout_pwd, sync_type, sync_host, sync_port, sync_user, sync_pwd, sync_path) puts I18n.t('form.setup.valid') @@ -120,7 +120,7 @@ class Cli puts '--------------------' ask = ask(I18n.t('form.setup_gpg_key.ask')).to_s - if !['Y', 'y', 'O', 'o'].include?(ask) + if not ['Y', 'y', 'O', 'o'].include?(ask) puts I18n.t('form.setup_gpg_key.no_create') exit 2 end @@ -138,8 +138,8 @@ class Cli expire = ask(I18n.t('form.setup_gpg_key.expire')).to_s password = password.to_s - length = length.nil? || length.empty? ? 2048 : length.to_i - expire = expire.nil? || expire.empty? ? 0 : expire.to_i + length = length.nil? or length.empty? ? 2048 : length.to_i + expire = expire.nil? or expire.empty? ? 0 : expire.to_i puts I18n.t('form.setup_gpg_key.wait') @@ -153,12 +153,12 @@ class Cli # Request the GPG password and decrypt the file def decrypt - if !defined?(@mpw) + if not defined?(@mpw) @mpw = MPW::MPW.new(@config.file_gpg, @config.key, @config.share_keys) end @passwd = ask(I18n.t('display.gpg_password')) {|q| q.echo = false} - if !@mpw.decrypt(@passwd) + if not @mpw.decrypt(@passwd) puts "#{I18n.t('display.error')} #11: #{@mpw.error_msg}" exit 2 end @@ -203,7 +203,7 @@ class Cli def displayFormatAlt(item) port = item[:port].nil? ? '' : ":#{item[:port]}" - if item[:password].nil? || item[:password].empty? + if item[:password].nil? or item[:password].empty? if item[:login].include('@') puts "# #{item[:id]} #{item[:protocol]}://#{item[:login]}@#{item[:host]}#{port}" else @@ -338,7 +338,7 @@ class Cli end if force - if @mpw.import(file) && @mpw.encrypt + if @mpw.import(file) and @mpw.encrypt sync puts I18n.t('form.import.valid') else @@ -371,21 +371,21 @@ class Cli case command[0] when 'display', 'show', 'd', 's' - if !command[1].nil? && !command[1].empty? + if not command[1].nil? and not command[1].empty? display(command[1], group, command[2]) end when 'add', 'a' add when 'update', 'u' - if !command[1].nil? && !command[1].empty? + if not command[1].nil? and not command[1].empty? update(command[1]) end when 'remove', 'delete', 'r', 'd' - if !command[1].nil? && !command[1].empty? + if not command[1].nil? and not command[1].empty? remove(command[1]) end when 'group', 'g' - if !command[1].nil? && !command[1].empty? + if not command[1].nil? and not command[1].empty? group = command[1] else group = nil @@ -404,7 +404,7 @@ class Cli puts I18n.t('interactive.goodbye') break else - if !command[0].nil? && !command[0].empty? + if not command[0].nil? and not command[0].empty? puts I18n.t('interactive.unknown_command') end end diff --git a/lib/UI/CliSSH.rb b/lib/UI/CliSSH.rb index c982a28..b32097e 100644 --- a/lib/UI/CliSSH.rb +++ b/lib/UI/CliSSH.rb @@ -22,7 +22,7 @@ class CliSSH < Cli passwd = r[:password] - if port.nil? || port.empty? + if port.nil? and port.empty? port = 22 end diff --git a/mpw b/mpw index 9056610..309f910 100755 --- a/mpw +++ b/mpw @@ -21,14 +21,14 @@ require "#{APP_ROOT}/lib/MPW" 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 end I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) -I18n.load_path = Dir["#{APP_ROOT}/i18n/cli/*.yml"] +I18n.load_path = Dir["#{APP_ROOT}/i18n/cli/*.yml"] I18n.default_locale = :en -I18n.locale = lang.to_sym +I18n.locale = lang.to_sym # --------------------------------------------------------- # # Options @@ -122,9 +122,9 @@ check_error = config.checkconfig cli = Cli.new(config) # Setup a new config -if !check_error || !options[:setup].nil? +if not check_error or not options[:setup].nil? cli.setup(lang) -elsif !config.check_gpg_key? +elsif not config.check_gpg_key? cli.setup_gpg_key end diff --git a/mpw-ssh b/mpw-ssh index 5674b1e..89a8c99 100755 --- a/mpw-ssh +++ b/mpw-ssh @@ -19,14 +19,14 @@ lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1] # Set local # --------------------------------------------------------- # -if defined? I18n.enforce_available_locales +if defined?(I18n.enforce_available_locales) I18n.enforce_available_locales = true end I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) -I18n.load_path = Dir["#{APP_ROOT}/i18n/cli/*.yml"] +I18n.load_path = Dir["#{APP_ROOT}/i18n/cli/*.yml"] I18n.default_locale = :en -I18n.locale = lang.to_sym +I18n.locale = lang.to_sym # --------------------------------------------------------- # # Options @@ -73,7 +73,7 @@ cli.port = options[:port] search = ARGV[0] # Setup a new config -if !check_error +if not check_error cli.setup(lang) elsif ARGV.length < 1