#!/bin/sh
#
# Script invoked by the fail2ban action secinfo-xmpp.conf
# to pass information about a ban to secinfo-xmpp, via a
# local tcp port.
#
# This version uses secinfo-client if the port is 0


CONFFILE=/etc/secinfo-xmpp/config.ini

PORT=$(grep -i "Port"  ${CONFFILE} | grep -v '#' | grep "=" | cut -d= -f2)

MESSAGE=$1

# for debug
#   echo "command will be printf  \"${MESSAGE}\" | nc localhost ${PORT} || true"

if [ ${PORT} -ne 0 ]; then
   printf %b  "${MESSAGE}" | nc localhost ${PORT} &
 exit
 fi

DIRNAME=$(dirname "$0")

${DIRNAME}/secinfo-client ${MESSAGE} &


