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

add login and password in clipboard

This commit is contained in:
nishiki 2016-07-09 14:06:49 +02:00
parent bbeeb68065
commit e068a2758c
7 changed files with 54 additions and 11 deletions

View file

@ -6,3 +6,4 @@ gem 'gpgme'
gem 'colorize' gem 'colorize'
gem 'net-ssh' gem 'net-ssh'
gem 'net-scp' gem 'net-scp'
gem 'clipboard'

View file

@ -8,6 +8,7 @@ MPW can synchronize your password with SSH or FTP.
This program work with ruby >= 2.0 This program work with ruby >= 2.0
* install ruby and rubygems on your computer * install ruby and rubygems on your computer
* install xclip
* gem install mpw * gem install mpw
# How to use # How to use

19
bin/mpw
View file

@ -48,12 +48,13 @@ I18n.locale = lang.to_sym
# Options # Options
# --------------------------------------------------------- # # --------------------------------------------------------- #
options = {} options = {}
options[:force] = false options[:force] = false
options[:sync] = true options[:sync] = true
options[:group] = nil options[:clipboard] = true
options[:config] = nil options[:group] = nil
options[:wallet] = nil options[:config] = nil
options[:wallet] = nil
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "#{I18n.t('option.usage')}: mpw [options]" opts.banner = "#{I18n.t('option.usage')}: mpw [options]"
@ -71,6 +72,10 @@ OptionParser.new do |opts|
options[:config] = config options[:config] = config
end end
opts.on('-C', '--no-clipboard', I18n.t('option.clipboard')) do
options[:clipboard] = false
end
opts.on('-d', '--delete', I18n.t('option.remove')) do opts.on('-d', '--delete', I18n.t('option.remove')) do
options[:delete] = true options[:delete] = true
end end
@ -144,7 +149,7 @@ end.parse!
begin begin
config = MPW::Config.new(options[:config]) config = MPW::Config.new(options[:config])
cli = MPW::Cli.new(config, options[:sync]) cli = MPW::Cli.new(config, options[:clipboard], options[:sync])
# Setup a new config # Setup a new config
if not options[:setup].nil? if not options[:setup].nil?

View file

@ -38,6 +38,7 @@ en:
option: option:
add: "Add an item or key" add: "Add an item or key"
config: "Specify the configuration file to use" config: "Specify the configuration file to use"
clipboard: "Disable the clipboard feature"
export: "Export a wallet in an yaml file" export: "Export a wallet in an yaml file"
file: "Specify a file, to use with the options [--import | --export | --add]" file: "Specify a file, to use with the options [--import | --export | --add]"
force: "No ask to confirm when you delete an item" force: "No ask to confirm when you delete an item"
@ -72,6 +73,10 @@ en:
port: "Enter the connection port (optional): " port: "Enter the connection port (optional): "
comment: "Enter a comment (optional): " comment: "Enter a comment (optional): "
valid: "Item has been added!" valid: "Item has been added!"
clipboard:
clean: "The clipboard has been cleaned."
login: "The login has been copied in clipboard, press any key to continue."
password: "The password has been copied in clipboard for 30s!"
delete_key: delete_key:
valid: "Key has been deleted!" valid: "Key has been deleted!"
delete_item: delete_item:

View file

@ -38,6 +38,7 @@ fr:
option: option:
add: "Ajoute un élément ou une clé" add: "Ajoute un élément ou une clé"
config: "Spécifie le fichier de configuration à utiliser" config: "Spécifie le fichier de configuration à utiliser"
clipboard: "Désactive la fonction presse papier"
export: "Exporte un portefeuille dans un fichier yaml" export: "Exporte un portefeuille dans un fichier yaml"
file: "Spécifie un fichier, à utiliser avec les options [--import | --export | --add]" file: "Spécifie un fichier, à utiliser avec les options [--import | --export | --add]"
force: "Ne demande pas de confirmation pour la suppression d'un élément" force: "Ne demande pas de confirmation pour la suppression d'un élément"
@ -72,6 +73,10 @@ fr:
port: "Entrez le port de connexion (optionnel): " port: "Entrez le port de connexion (optionnel): "
comment: "Entrez un commentaire (optionnel): " comment: "Entrez un commentaire (optionnel): "
valid: "L'élément a bien été ajouté!" valid: "L'élément a bien été ajouté!"
clipboard:
clean: "Le presse papier a été nettoyé."
login: "L'identifiant a été copié dans le presse papier, pressez n'importe quelle touche pour continuer."
password: "Le mot de passe a été copié dans le presse papier pour 30s!"
delete_key: delete_key:
valid: "La clé a bien été supprimée!" valid: "La clé a bien été supprimée!"
delete_item: delete_item:

View file

@ -20,6 +20,7 @@ require 'readline'
require 'i18n' require 'i18n'
require 'colorize' require 'colorize'
require 'highline/import' require 'highline/import'
require 'clipboard'
#TODO #TODO
require "#{APP_ROOT}/../lib/mpw/item.rb" require "#{APP_ROOT}/../lib/mpw/item.rb"
@ -31,9 +32,10 @@ class Cli
# Constructor # Constructor
# @args: config -> the config # @args: config -> the config
# sync -> boolean for sync or not # sync -> boolean for sync or not
def initialize(config, sync=true) def initialize(config, clipboard=true, sync=true)
@config = config @config = config
@sync = sync @clipboard = clipboard
@sync = sync
end end
# Create a new config file # Create a new config file
@ -184,11 +186,34 @@ class Cli
print "#{I18n.t('display.login')}: ".cyan print "#{I18n.t('display.login')}: ".cyan
puts item.user puts item.user
print "#{I18n.t('display.password')}: ".cyan print "#{I18n.t('display.password')}: ".cyan
puts @mpw.get_password(item.id) if @clipboard
puts '***********'
else
puts @mpw.get_password(item.id)
end
print "#{I18n.t('display.port')}: ".cyan print "#{I18n.t('display.port')}: ".cyan
puts item.port puts item.port
print "#{I18n.t('display.comment')}: ".cyan print "#{I18n.t('display.comment')}: ".cyan
puts item.comment puts item.comment
clipboard(item) if @clipboard
end
# Copy in clipboard the login and password
def clipboard(item)
Clipboard.copy(item.user)
print "\n#{I18n.t('form.clipboard.login')}".green
gets
Clipboard.copy(@mpw.get_password(item.id))
puts I18n.t('form.clipboard.password').yellow
sleep(30)
Clipboard.clear
puts I18n.t('form.clipboard.clean').green
rescue SystemExit, Interrupt
Clipboard.clear
end end
# Display the wallet # Display the wallet

View file

@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
spec.add_dependency "colorize" spec.add_dependency "colorize"
spec.add_dependency "net-ssh" spec.add_dependency "net-ssh"
spec.add_dependency "net-scp" spec.add_dependency "net-scp"
spec.add_dependency "clipboard"
end end