#!/bin/sh

OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3

HOST="127.0.0.1"
CONFIG="/etc/peap-mschapv2.conf"
SECRET="testing123"

usage() {
	echo "Usage: $0 [-H server] [-c configfile] [-s secret]" >&2
	exit 3
}

OPTS=`getopt -o H:c:s: -n "$0" -- "$@"` || usage

eval set -- "$OPTS"

while :; do
	case "$1" in
		-H)
			HOST=$2
			shift 2
			;;
		-c)
			CONFIG=$2
			shift 2
			;;
		-s)
			SECRET=$2
			shift 2
			;;
		--)
			shift
			break
			;;
		*)
			usage
			;;
	esac
done

if $(/usr/bin/eapol_test -c ${CONFIG} -a ${HOST} -s ${SECRET} > /dev/null 2>&1)
then
	echo "Radius authentication working."
	exit ${OK}
else
	echo "Radius authentication failed."
	exit ${CRITICAL}
fi
