#!/bin/sh
source /etc/karoo.conf.d/config/redis-connect-info

REDIS_CMD="redis-cli -a ${REDIS_PASS} -h ${REDIS_HOST} -p ${REDIS_PORT}"

if [ -z "$1" ]; then
    echo "Please provide the IP address of the source to block."
    exit 1
else
    PUBLISH_CMD="{\"event-name\" : \"remove-whitelist-network\", \"event-args\" : \"$1\"}"
    if ${REDIS_CMD}  PUBLISH SBC-CHANNEL "${PUBLISH_CMD}" > /dev/null; then
        echo "Network $1 removed from white list"
        exit 0
    else
        echo "Is Karoo and Redis running?"
        exit 1
    fi
fi
