diff --git a/i18n/en.yml b/i18n/en.yml index 2f1f476..c97ac5c 100644 --- a/i18n/en.yml +++ b/i18n/en.yml @@ -77,8 +77,9 @@ en: comment: "Enter a comment (optional): " valid: "Item has been added!" clipboard: + choice: "What do you want to copy ? [q = quit, p = password, l = login]: " clean: "The clipboard has been cleaned." - login: "The login has been copied in clipboard, press any key to continue." + login: "The login has been copied in clipboard." password: "The password has been copied in clipboard for 30s!" delete_key: valid: "Key has been deleted!" diff --git a/i18n/fr.yml b/i18n/fr.yml index da91af0..993a809 100644 --- a/i18n/fr.yml +++ b/i18n/fr.yml @@ -77,8 +77,9 @@ fr: comment: "Entrez un commentaire (optionnel): " valid: "L'élément a bien été ajouté!" clipboard: + choice: "Que voulez-vous copier ? [q = quitter, p = mot de passe, l = identifiant]: " clean: "Le presse papier a été nettoyé." - login: "L'identifiant a été copié dans le presse papier, pressez n'importe quelle touche pour continuer." + login: "L'identifiant a été copié dans le presse papier" password: "Le mot de passe a été copié dans le presse papier pour 30s!" delete_key: valid: "La clé a bien été supprimée!" diff --git a/lib/mpw/cli.rb b/lib/mpw/cli.rb index 0b06724..ce1b9ec 100644 --- a/lib/mpw/cli.rb +++ b/lib/mpw/cli.rb @@ -217,20 +217,69 @@ class Cli end # Copy in clipboard the login and password + # @args: item -> the item def clipboard(item) - Clipboard.copy(item.user) - print "\n#{I18n.t('form.clipboard.login')}".green - gets + pid = nil - Clipboard.copy(@mpw.get_password(item.id)) - puts I18n.t('form.clipboard.password').yellow + # Security: force quit after 90s + pid_s = Process.fork do + begin + sleep 90 + Process.kill(3, Process.ppid) + rescue Interrupt + exit + end + end + + while true + choice = ask(I18n.t('form.clipboard.choice')).to_s + + if not pid.nil? + Clipboard.clear + Process.kill(9, pid) - sleep(30) + pid = nil + end + + case choice + when 'q', 'quit' + break + + when 'l', 'login' + Clipboard.copy(item.user) + puts I18n.t('form.clipboard.login').green + + when 'p', 'password' + Clipboard.copy(@mpw.get_password(item.id)) + puts I18n.t('form.clipboard.password').yellow + + pid = Process.fork do + begin + sleep 30 + + Clipboard.clear + puts I18n.t('form.clipboard.clean').green + rescue Interrupt + exit + end + end + + else + puts I18n.t('warning.select').yellow + next + end + end Clipboard.clear puts I18n.t('form.clipboard.clean').green + rescue SystemExit, Interrupt Clipboard.clear + puts I18n.t('form.clipboard.clean').green + + ensure + Process.kill('HUP', pid) if not pid.nil? + Process.kill('HUP', pid_s) end # Display the wallet @@ -259,6 +308,7 @@ class Cli @wallet_file = wallets[choice-1] else puts "#{I18n.t('display.warning')}: #{I18n.t('warning.select')}".yellow + exit 2 end end else