#!/bin/sh

if [ -z "$1" ]; then
    echo "$0: called with no interface" 1>&2
    exit 1;
fi

# Fake ifupdown environment
export IFACE="$1"

[ "$2" != "up" ] && exit 0

# Env
[ ! -x /sbin/iwconfig ] && exit 0
. /etc/freewifi.conf || exit 0

logger "FreeWifi $LOGIN"
! /sbin/iwconfig "$IFACE" 2>&1|grep -i freewifi 2>&1 && logger "Ce n'est pas FreeWifi ..." && exit 0

#priv=`wget -O - "https://wifi.free.fr/" 2>/dev/null|grep 'input name="priv"'|awk -F'"' '{print $8}'`
#wget -O - --post-data="login=$LOGIN&password=$PASSWORD&priv=$priv" "https://wifi.free.fr/" 2>/dev/null|grep "CONNEXION AU SE
RVICE REUSSIE" 1>/dev/null 2>&1 && logger "Connection FreeWifi OK" && exit 0

# 2012-01-02 Adaptation au service
wget -O - --post-data="login=$LOGIN&password=$PASSWORD" "https://wifi.free.fr/Auth" 2>/dev/null|grep "CONNEXION AU SERVICE RE
USSIE" 1>/dev/null 2>&1 && logger "Connection FreeWifi OK" && exit 0
logger "Erreur de connection FreeWifi"
exit 1
