summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-04-04 14:02:05 +0200
committerAnton Khirnov <anton@khirnov.net>2020-04-04 14:02:05 +0200
commit8c9a69297efaafe42f1826e1764e45b2006a9447 (patch)
tree98f26f1d6d2eb0787333e6b5c0835e86da2dd276
parent233815932553bdf9781e6bbde9976abfe458b93a (diff)
sshban: use shlex to parse the action
Allows to use more complex commands as actions.
-rwxr-xr-xsshban.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/sshban.py b/sshban.py
index dd2a5f2..8d160f5 100755
--- a/sshban.py
+++ b/sshban.py
@@ -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))