#!/bin/sh

. /opt/autofreewifi/freewifi.conf

ESSID=\"$ESSID\"
WIFI=$(echo $(/sbin/iwgetid) | grep $INTERFACE | cut -d : -f 2)

if [ $ESSID = $WIFI ]; 
then
	if wget --ca-directory=/etc/certs/common-ca -q -O - --post-data="$POST_DATA" "$URL" 2> /dev/null | \
        grep "CONNEXION AU SERVICE REUSSIE" > /dev/null 2>&1
   then
        dbus-send --system --type=method_call \
            --dest=org.freedesktop.Notifications \
            /org/freedesktop/Notifications \
            org.freedesktop.Notifications.SystemNoteInfoprint \
            string:"AutoFreeWifi : authentification reussie"
   else
        dbus-send --system --type=method_call \
            --dest=org.freedesktop.Notifications \
            /org/freedesktop/Notifications \
            org.freedesktop.Notifications.SystemNoteInfoprint \
            string:"AutoFreeWifi : Echec de l'authentification"
   fi
fi
