Skip to content

Instantly share code, notes, and snippets.

@vDorst
Created September 22, 2015 17:46
Show Gist options
  • Save vDorst/9d20ce76344c26ef65bd to your computer and use it in GitHub Desktop.
Save vDorst/9d20ce76344c26ef65bd to your computer and use it in GitHub Desktop.
#!/bin/sh
DEV="wlan0"
[ "$ACTION" = ifup -o "$ACTION" = ifupdate ] || exit 0
[ "$DEVICE" = "${DEV}" ] || exit 0
[ "$(iw dev ${DEV} link | grep SSID: | egrep -o "KPN")" = "KPN" ] || exit 0
USERNAME="xxxxx@kpn-fon.nl"
PASSWORD="xxxxxx"
PORTAL_FILE=/tmp/portal.html
COOKIE_FILE=/tmp/cookie
CA_FILE=/etc/config/ssl/fon.com.crt
if [ -f ${COOKIE_FILE} ]; then
rm ${COOKIE_FILE};
fi
echo "Connect To www.fon.com"
wget -qO- -T 10 --output-document=${PORTAL_FILE} --ca-certificate=${CA_FILE} --save-cookies=${COOKIE_FILE} --keep-session-cookies http://www.fon.com
WGET_RES=$?
if [ ${WGET_RES} -eq 5 ]; then
echo "SSL Error, it is unsafe to go on. QUIT!"
exit 1
fi
if [ ${WGET_RES} -eq 4 ]; then
echo "Time Out? Try to reconnect."
iw dev ${DEV} disconnect
sleep 5
wget -qO- -T 10 --output-document=${PORTAL_FILE} --ca-certificate=${CA_FILE} --save-cookies=${COOKIE_FILE} --keep-session-cookies http://www.fon.com
WGET_RES=$?
fi
if [ ${WGET_RES} -ne 0 ]; then
echo "WGET ERRROR ${WGET_RES}"
fi
WISP_DATA=$(cat ${PORTAL_FILE} |awk "/<WISPAccessGatewayParam/,/<\/WISPAccessGatewayParam>/")
rm ${PORTAL_FILE}
if [ -z "${WISP_DATA}" ]; then
echo "No WISP DATA!\nProbely we have internet."
exit 1
fi
POST_URL=$(echo ${WISP_DATA} | egrep -io "<LoginURL>[^<]+</LoginURL>" | egrep -io "https://[^<]+" | sed "s/\&amp;/\&/" )
if [ -z "$POST_URL" ]; then
echo "No LoginURL found."
exit 1
fi
echo "Logging at ${POST_URL}"
POST_DATA="WISPrVersion=1.0&UserName=${USERNAME}&Password=${PASSWORD}"
wget -qO- --output-document=${PORTAL_FILE} --ca-certificate=${CA_FILE} --load-cookies=${COOKIE_FILE} --keep-session-cookies -U "WISPR!client_software_identi
WISP_DATA=$(cat ${PORTAL_FILE} | awk "/<WISPAccessGatewayParam/,/<\/WISPAccessGatewayParam>/")
rm ${PORTAL_FILE}
if [ -z "${WISP_DATA}" ]; then
echo "No WISP DATA!"
exit 1
fi
RESPONSE_CODE=$(echo ${WISP_DATA} | egrep -o '<ResponseCode>[0-9]+<\/ResponseCode>' | egrep -o '[0-9]+')
if [ ${RESPONSE_CODE} -eq 50 ]; then
echo "We got internet!"
echo "Logout URL: $(echo ${WISP_DATA} | egrep -o '<LogoffURL>[^<]+<\/LogoffURL>')"
else
echo "print error ${RESPONSE_CODE}"
fi
rm ${COOKIE_FILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment