#!/usr/local/bin/bash

#ROOTOID=".1.3.6.1.3.2"
ROOTOID=".1.3.6.1.4.1.1"

SNMPTYPE="$1"
OIDIN="$2"

export PATH=/bin:/usr/bin:/sbin:/usr/sbin

#OIDOUT is the OID we will return, != REQUESTEDOID if GETNEXT

#run as "./pass.sh -s .1.3.6.1.3.2.blah string garbage"

#handle GET and bail
if  [ "$SNMPTYPE" = "-s" ]; then
    logger "SET request $*"
    exit 0
fi

#determine OIDOUT for GETNEXT
#next next valid OID AFTER the one requested

if [ "$SNMPTYPE" = "-n" ]; then
    case "$OIDIN" in
	#these are before first OID, 1.1
	    $ROOTOID| \
	    $ROOTOID.0| \
	    $ROOTOID.0.*|\
	    $ROOTOID.1 )
		OIDOUT=$ROOTOID.1.1;;
	    #the first OID and later must return second OID
	    $ROOTOID.1.1 |\
	    $ROOTOID.1.1.* )\
		OIDOUT=$ROOTOID.1.2;;
	    #the second OID and later must return third OID
	    $ROOTOID.1.2 |\
	    $ROOTOID.1.2.*|\
	    $ROOTOID.2 )\
		OIDOUT=$ROOTOID.2.1;;
	    #the third OID and later must return the fourth OID
	    $ROOTOID.2.1 |\
	    $ROOTOID.2.1.*) \
		OIDOUT=$ROOTOID.2.2;;
	
	#we got handed an OID this script doesn't do, shit
	*) logger "GETNEXT received with $*"
	   exit 0 ;;
    esac
else

    #It's not a SET or GETNEXT, must be a GET
    #Make sure we didn't pass garbage here

    case "$OIDIN" in
	$ROOTOID.1.1| \
	    $ROOTOID.1.2| \
	    $ROOTOID.2.1| \
	    $ROOTOID.2.2) OIDOUT=$OIDIN;;
	*)  logger "GET received with $*"
	    exit 0;
    esac
fi

echo "$OIDOUT"

case "$OIDOUT" in
    $ROOTOID.1.1)
	echo "string";
	echo "firewall state table size";
	exit 0;;
    $ROOTOID.1.2)
	echo "integer";
	#BSD
	pfctl -ss | wc -l | sed 's/^ *//g'
	#Linux
	#insert command here
	exit 0;;

    $ROOTOID.2.1)
	echo "string";
	echo "application state from /tmp/appstatus";
	exit 0;;
    $ROOTOID.2.2)
	echo "string";
	head -1 /tmp/appstatus
	exit 0;;

    *)
	logger "Reached invalid OID at end with $*"
	echo "string";
	echo "All Hail Nyarlathotep!"
esac
