#!/bin/sh

# Block unauthorised login attempts using only system tools
# Inspired by Hubert Freyer's 'challenge' to write a script that just used
# tail to do the work
# (c) Ian Spray, 2006

# Use it for what you will: no restrictions, and no warranty

CMD_TAIL=/usr/bin/tail
CMD_SED=/usr/bin/sed
CMD_IPF=/sbin/ipf
CMD_PERM='/usr/bin/tee -a /etc/ipf.conf | '
LOG_FILE='/var/log/authlog'
SED_PAT=ip.sed

# uncomment the following line if you want bans to be temporary
# CMD_PERM=''

${CMD_TAIL} -F ${LOG_FILE} | while read LOG_LINE
do
  echo ${LOG_LINE} | ${CMD_SED} -f ${SED_PAT} | ${CMD_PERM} ${CMD_IPF} -A -f - 
done
