|
|
@ -77,7 +77,7 @@ def parse_snippet(s: Tuple[str, str]) -> Sequence[Command]:
|
|
|
|
parts = line.split(maxsplit=5)
|
|
|
|
parts = line.split(maxsplit=5)
|
|
|
|
assert parts[3] == '-H', "Insecure sudo?"
|
|
|
|
assert parts[3] == '-H', "Insecure sudo?"
|
|
|
|
user = parts[2]
|
|
|
|
user = parts[2]
|
|
|
|
directory = f'~{user}' # This actually works with SSH. That is nice, since we don't need to know the mapping of
|
|
|
|
directory = f'~{user}' # This actually works with SSH. That is nice, since we don't need to know the target's /etc/passwd
|
|
|
|
cmd = parts[4]
|
|
|
|
cmd = parts[4]
|
|
|
|
elif line.startswith('sudo'):
|
|
|
|
elif line.startswith('sudo'):
|
|
|
|
parts = line.split(maxsplit=2)
|
|
|
|
parts = line.split(maxsplit=2)
|
|
|
@ -112,6 +112,7 @@ def user_action(hunk: Sequence[Command], context=None) -> Sequence[Command]:
|
|
|
|
for cmd in hunk:
|
|
|
|
for cmd in hunk:
|
|
|
|
global host
|
|
|
|
global host
|
|
|
|
result += f'SSH: {cmd.user}@{host} {cmd.directory} $ {cmd.command}\n'
|
|
|
|
result += f'SSH: {cmd.user}@{host} {cmd.directory} $ {cmd.command}\n'
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: Print context in color (gray?)
|
|
|
|
# TODO: Print context in color (gray?)
|
|
|
@ -124,7 +125,7 @@ def user_action(hunk: Sequence[Command], context=None) -> Sequence[Command]:
|
|
|
|
answer = input("What to do: edit(e), run(y), skip(n)?")
|
|
|
|
answer = input("What to do: edit(e), run(y), skip(n)?")
|
|
|
|
if answer.startswith(('e', 'E')):
|
|
|
|
if answer.startswith(('e', 'E')):
|
|
|
|
import tempfile
|
|
|
|
import tempfile
|
|
|
|
with tempfile.NamedTemporaryFile() as tmpfile:
|
|
|
|
with tempfile.NamedTemporaryFile(mode='r+') as tmpfile:
|
|
|
|
# Fill the file with data
|
|
|
|
# Fill the file with data
|
|
|
|
for cmd in hunk:
|
|
|
|
for cmd in hunk:
|
|
|
|
tmpfile.file.write(f"{cmd.user}\t{cmd.directory}\t{cmd.command}\n")
|
|
|
|
tmpfile.file.write(f"{cmd.user}\t{cmd.directory}\t{cmd.command}\n")
|
|
|
@ -180,7 +181,7 @@ def process_file(fn: str):
|
|
|
|
snippets = extract_snippets(pd)
|
|
|
|
snippets = extract_snippets(pd)
|
|
|
|
for snip in snippets:
|
|
|
|
for snip in snippets:
|
|
|
|
cmds = parse_snippet(snip)
|
|
|
|
cmds = parse_snippet(snip)
|
|
|
|
cmds = user_action(cmds)
|
|
|
|
cmds = user_action(cmds, context=cmds[0].context)
|
|
|
|
for cmd in cmds:
|
|
|
|
for cmd in cmds:
|
|
|
|
run_command(cmd)
|
|
|
|
run_command(cmd)
|
|
|
|
|
|
|
|
|
|
|
|