#!/bin/sh

#
# Hello, lovely FastNetMon customer! I'm really happy to see you here!
#  Pavel Odintsov, author 
#

# This script will get following params:
#  $1 client_ip_as_string
#  $2 data_direction
#  $3 pps_as_string
#  $4 action (ban or unban)

IP=$1
DATA_Dir=$2
PPS=$3
ACTION=$4
echo $IP
echo $DATA_Dir
echo $PPS
echo $ACTION

email_notify="alerts@example.com"
email_sender="fastnetmon@example.com"
#
# Please be carefult! You should not remove cat > 
#

if [ "$ACTION" = "unban" ]; then
    # No details arrived to stdin here

    # Unban actions if used
    /usr/bin/doas /usr/local/bin/unban.sh $1 
	exit 0
fi

#
# For ban and attack_details actions we will receive attack details to stdin
# if option notify_script_pass_details enabled in FastNetMon's configuration file
# 
# If you do not need this details, please set option notify_script_pass_details to "no".
#
# Please do not remove "cat" command if you have notify_script_pass_details enabled, because
# FastNetMon will crash in this case (it expect read of data from script side).
#

if [ "$ACTION" = "ban" ]; then
       cat | mail -r $email_sender -s "FastNetMon IP $IP blocked because $DATA_Dir attack with power $PPS pps" $email_notify;
    # You can add ban code here!
   /usr/bin/doas /usr/local/bin/ban.sh $1
echo post route 
   exit 0
fi
