Commit c17458fc authored by Daniel STAN's avatar Daniel STAN
Browse files

displays qr code

parent 36fe39a5
......@@ -648,18 +648,6 @@ def saveclipboard(restore=False, old_clipboard=None):
if not restore:
old_clipboard = proc.stdout.read()
else:
if True:
print(u"Password is in clipboard.".encode('utf-8'))
try:
for i in range(SHOW_TIMEOUT):
print(u"Will disappear in %d" % (SHOW_TIMEOUT - i))
time.sleep(1)
sys.stdout.write("\033[F") # Cursor up one line
sys.stdout.write("\033[K") # Clear to the end of line
except KeyboardInterrupt:
pass
else:
raw_input(u"Appuyez sur Entrée pour récupérer le contenu précédent du presse papier.".encode("utf-8"))
proc.stdin.write(old_clipboard)
proc.stdin.close()
proc.stdout.close()
......@@ -707,16 +695,19 @@ def show_file(options):
old_clipboard = None
# Essaie de planquer le mot de passe
secret = None
for line in texte.split('\n'):
catchPass = None
# On essaie de trouver le pass pour le cacher dans le clipboard
# si ce n'est déjà fait et si c'est voulu
if not is_hidden and options.clipboard:
if not is_hidden and (options.clipboard or options.qrcode):
catchPass = pass_regexp.match(line)
if catchPass != None:
is_hidden = True
secret = catchPass.group(1)
# On met le mdp dans le clipboard en mémorisant son ancien contenu
old_clipboard = clipboard(catchPass.group(1))
if options.clipboard:
old_clipboard = clipboard(secret)
# Et donc on override l'affichage
line = u"[Le mot de passe a été mis dans le presse papier]"
filtered += line + '\n'
......@@ -743,6 +734,8 @@ def show_file(options):
pub_file.flush()
subprocess.check_call(['ssh-add', '-d', pub_file.name])
elif options.qrcode and secret != None:
showqr(secret)
else:
# Le binaire à utiliser
showbin = "cat" if is_hidden else "less"
......@@ -751,11 +744,32 @@ def show_file(options):
out.write(shown.encode("utf-8"))
out.close()
os.waitpid(proc.pid, 0)
# Repope ancien pass
if old_clipboard is not None:
print(u"Password is in clipboard.".encode('utf-8'))
try:
for i in range(SHOW_TIMEOUT):
print(u"Will disappear in %d" % (SHOW_TIMEOUT - i))
time.sleep(1)
sys.stdout.write("\033[F") # Cursor up one line
sys.stdout.write("\033[K") # Clear to the end of line
except KeyboardInterrupt:
pass
saveclipboard(restore=True, old_clipboard=old_clipboard)
def showqr(secret):
qrencode = subprocess.Popen(['/usr/bin/qrencode', '-o', '-'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
feh = subprocess.Popen(['/usr/bin/feh', '--zoom', 'fill', '-'],
stdin=qrencode.stdout)
qrencode.stdin.write(secret)
qrencode.stdin.flush()
qrencode.stdin.close()
feh.wait()
@need_filename
def edit_file(options):
"""Modifie/Crée un fichier"""
......@@ -997,6 +1011,9 @@ if __name__ == "__main__":
parser.add_argument('--no-clip', '--noclip', '--noclipboard', action='store_false', default=None,
dest='clipboard',
help="Ne PAS stocker le mot de passe dans le presse papier")
parser.add_argument('--qr', action='store_true', default=None,
dest='qrcode',
help="Afficher un QR code à scanner")
parser.add_argument('-f', '--force', action='store_true', default=False,
help="Ne pas demander confirmation")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment