-
-
Save erdoukki/61ac9befbd16d4c6cdb871034dc653c5 to your computer and use it in GitHub Desktop.
Telekom_FON Hotspot: auto-login bash script wget germany wispr client openwrt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# place this file at: /etc/hotplug.d/iface/99-login-telekom_fon | |
# based on source: https://gist.github.com/cusspvz/3ab1ea9110f4ef87f0d2e1cd134aca67 | |
# | |
# loginscript for german telekom_FON hotspot (NOT the general Telekom Hotspot) | |
# technic: uses HTTP POST formular; extract URLs from WIPSr | |
# | |
# Preparations | |
# for openwrt please install: "curl" "ca-certificates" | |
# | |
# | |
# In my case, this script was called every 5minutes (no cron job needed) | |
# | |
# Configurations | |
FON_USERNAME="username%40t-online.de" | |
# FON_USERNAME="498555555555%40t-mobile.de" | |
# must be url_encoded (e.g. @ = %40) | |
FON_PASSWORD="123456" | |
#must be url_encoded | |
FON_DELAY_UP=3 | |
COOKIE_JAR_PATH=/tmp/nos-fon-cookie-jar.$INTERFACE | |
. /lib/functions.sh | |
clean () { | |
[ -f $COOKIE_JAR_PATH ] && rm -f $COOKIE_JAR_PATH | |
} | |
logger -t FonLogin "Starting on $INTERFACE:$DEVICE -> $ACTION" | |
attempt () { | |
local INDICATOR="<LoginURL>" | |
local POST_URL="" | |
local TARGET="http://google.com" | |
logger -t FonLogin "Trying to fetch a website" | |
DATA="$(curl --insecure --interface $DEVICE --location --cookie-jar $COOKIE_JAR_PATH $TARGET)" | |
logger -t FonLogin "Trying to get post url" | |
POST_URL="$(echo "$DATA" | grep $INDICATOR | cut -d '<' -f 2 | cut -d '>' -f 2 | sed -r 's/\&/\&/g')" | |
if [ -n "$POST_URL" ]; then | |
logger -t FonLogin "Post URL found, trying to login" | |
DATA=`curl \ | |
--insecure \ | |
--interface $DEVICE \ | |
--location \ | |
--location-trusted \ | |
--cookie-jar $COOKIE_JAR_PATH \ | |
--header 'cache-control: no-cache' \ | |
--header 'content-type: application/x-www-form-urlencoded' \ | |
--data "UserName=${FON_USERNAME}&FNAME=0&button=Login&OriginatingServer=http%3A%2F%2Fgoogle.de&Password=${FON_PASSWORD}" \ | |
"$POST_URL"` | |
logger -t FonLogin "a Trying to get logoff url" | |
LOGOFF_URL="$(echo "$DATA" | grep "<LogoffURL>" | cut -d '<' -f 2 | cut -d '>' -f 2 | sed -r 's/\&/\&/g')" | |
echo "$LOGOFF_URL" | |
if [ -n "$LOGOFF_URL" ] | |
then | |
logger -t FonLogin "LogOff URL found; Login was successful" | |
logger -t FonLogin "...Login successfull" | |
else | |
logger -t FonLogin "LogOff URL -NOT- found" | |
logger -t FonLogin "...Login failed" | |
fi | |
else | |
logger -t FonLogin "Login not needed oder not possible" | |
fi | |
clean | |
} | |
case "$ACTION" in | |
ifup) | |
logger -t FonLogin "Waiting $FON_DELAY_UP seconds before attempt" | |
sleep $FON_DELAY_UP; | |
logger -t FonLogin "Attempting to login at FON" | |
attempt | |
;; | |
update) | |
logger -t FonLogin "Attempting to update login at FON" | |
attempt | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment