Skip to content
Snippets Groups Projects
Commit 37cba098 authored by Maxime Bombar's avatar Maxime Bombar
Browse files

Minimal cpasswords, to be used in external scripts.

parent 7468b5c7
No related branches found
No related tags found
1 merge request!12Minimal cpasswords, to be used in external scripts.
Pipeline #4070 passed with warnings with stages
in 5 minutes and 1 second
...@@ -447,6 +447,41 @@ def show_file(options): ...@@ -447,6 +447,41 @@ def show_file(options):
if old_clipboard is not None: if old_clipboard is not None:
saveclipboard(restore=True, old_clipboard=old_clipboard) saveclipboard(restore=True, old_clipboard=old_clipboard)
@need_filename
def show_minimal(options):
"""
Action that decrypt file content and only prints the password
"""
fname = options.filename
gotit, value = get_file(options, fname)
if not gotit:
log.warn(value) # value contient le message d'erreur
return
passfile = value
content = passfile['contents']
# Kludge (broken db ?)
if type(content) == list:
log.warn("Eau dans le gaz")
content = content[-1]
# Déchiffre le contenu
texte = decrypt(content)
found = None
# Essaie de planquer le mot de passe
for line in texte.split('\n'):
catch_pass = None
if not found:
catch_pass = pass_regexp.match(line)
if catch_pass is not None:
found = True
passwd = catch_pass.group(1)
break
print(passwd)
@need_filename @need_filename
def edit_file(options): def edit_file(options):
...@@ -816,6 +851,13 @@ def main(): ...@@ -816,6 +851,13 @@ def main():
const=recrypt_files, const=recrypt_files,
help=_("recrypt all files having a role listed in --roles"), help=_("recrypt all files having a role listed in --roles"),
) )
action_grp.add_argument(
'--minimal',
action='store_const',
dest='action',
const=show_minimal,
help=_("just print the password in a file, for use in an external script."),
)
action_grp.set_defaults(action=show_file) action_grp.set_defaults(action=show_file)
# On parse les options fournies en commandline # On parse les options fournies en commandline
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment