#!/bin/sh

# This script will turn on and off ICMP ping "broadcasts".
# This is an evil thing to do.
#
# (You should not do it.)
#
#
# (Don't say I didn't warn you.)

enableresponse( )
{
    echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
}

disableresponse( )
{
    echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
}

# handle both passed in and read-from-sysinfo scenarios
if [ -z "$1" ]
then
    systemvalue=$(xmlcntrl /cfg/sysinfo/system.xml system pingBroadcast)
    if [ -n "$systemvalue" ]
    then
        value="$systemvalue"    
    else
        # it is not in the sysinfo object. die().
        exit 1
    fi
else
    value="$1"
fi

if [ "$value" == "on" ] || [ "$value" == "true" ]
then
    enableresponse
else
    disableresponse
fi

ping=$(cat /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts)
if [ "$ping" -eq "0" ]
then
    echo "Enabled"
else
    echo "Disabled"
fi

