diff options
author | Anton Khirnov <anton@khirnov.net> | 2020-04-04 14:02:05 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2020-04-04 14:02:05 +0200 |
commit | 8c9a69297efaafe42f1826e1764e45b2006a9447 (patch) | |
tree | 98f26f1d6d2eb0787333e6b5c0835e86da2dd276 /sshban.py | |
parent | 233815932553bdf9781e6bbde9976abfe458b93a (diff) |
sshban: use shlex to parse the action
Allows to use more complex commands as actions.
Diffstat (limited to 'sshban.py')
-rwxr-xr-x | sshban.py | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -6,6 +6,7 @@ import logging.handlers import os import re import select +import shlex import sys import subprocess import time @@ -160,6 +161,7 @@ parser.add_argument('action', help = 'Executable to run. It will get two paramet args = parser.parse_args(sys.argv[1:]) progname = os.path.basename(sys.argv[0]) +action = shlex.split(args.action) logger = logging.getLogger(progname) loglevel = logging.DEBUG if args.debug else logging.INFO @@ -211,7 +213,7 @@ with open(fifofd) as fifo: logger.info('Action %s for: %s' % (verdict, host)) # TODO: rate-limit actions? - cmdline = [args.action, verdict, host] + cmdline = action + [verdict, host] res = subprocess.run(cmdline, capture_output = True, text = True) if res.returncode != 0: logger.error('Error running action "%s": return code %d' % (str(cmdline), res.returncode)) |