#!/bin/sh

STATUS=$1
RET=0

log=/var/log/8021X_log.txt
if ! [ -f $log ]
then
touch $log
fi

#current status of authentication
auth_state=`CLISettings get CURRENT WPA8021XCFG_AUTHENTICATED 2>/dev/null`

if [ "$STATUS" == "SUCCESS" ]; then
    echo "802.1X Auth success">>$log
    echo "802.1X Auth success">/dev/console
    #only display success if different from last state
    #better in case of re-authentication
    if [ "$auth_state" == "false" ]; then
        displaypopup -t 4 -l notice 802.1X Auth Success
    fi
    CLISettings set CURRENT WPA8021XCFG_AUTHENTICATED true
elif [ "$STATUS" == "FAILURE" ]; then
    echo "802.1X Auth failure">>$log
    echo "802.1X Auth failure">/dev/console
    displaypopup -t 4 -l error 802.1X Auth failure
    CLISettings set CURRENT WPA8021XCFG_AUTHENTICATED false
elif [ "$STATUS" == "MAX_FAILURE" ]; then
    echo "802.1X Auth failure">>$log
    echo "802.1X Auth failure...rebooting">/dev/console
    displaypopup -t 4 -l error 802.1X Auth failure
    CLISettings set CURRENT WPA8021XCFG_AUTHENTICATED false
    reboot --owner wpa_state --reason "802.1X Auth failure"
else
    RET=1
fi
    exit $RET
