Skip to content

Instantly share code, notes, and snippets.

@noname77
Forked from sscarduzio/relog.sh
Last active May 25, 2022 11:09
Show Gist options
  • Save noname77/bf8f47ffe9a4eacfd3445d914f611e79 to your computer and use it in GitHub Desktop.
Save noname77/bf8f47ffe9a4eacfd3445d914f611e79 to your computer and use it in GitHub Desktop.
BTWiFi_with_FON automatic login written as a bash script. I have this running every 10 minutes on my openwrt router
#!/bin/ash
# CONF
DBG=true
RELOG_UNAME=your@email.com
RELOG_PASSW=xxxxxxxxxxxxxxx
#dns resolution not working atm, hardcode ip:
#TODO: maybe set dns for interface temporarilt
BTOPENZONE_IP=192.168.23.21
OK_MSG="now logged on to BT Wi-fi."
#TODO: check dynamically
IFACE=wlan0
CURL_OPTS=-ksL
# END CONF
#IS_LOGGED_IN=$(wget "https://www.btopenzone.com:8443/home" -O - 2>/dev/null | grep "$OK_MSG")
IS_LOGGED_IN=$(curl $CURL_OPTS --interface $IFACE "https://$BTOPENZONE_IP:8443/home" | grep "$OK_MSG")
if [ "$IS_LOGGED_IN" ]
then
[[ $DBG ]] && echo "Currently logged in. Nothing to do... :)"
[[ $DBG ]] && logger -t "logon_fon" "Currently logged in. Nothing to do... :)"
else
[[ $DBG ]] && echo "You're not logged in... will log in now!"
[[ $DBG ]] && logger -t "logon_fon" "You're not logged in... will log in now!"
#OUT=$(wget -qO - --no-check-certificate --no-cache --post-data "username=$RELOG_UNAME&password=$RELOG_PASSW&provider=tbb" "https://www.btopenzone.com:8443/tbbLogon")
# had to change to curl as wget on openwrt was complaining about too many redirects
#OUT=$(curl -kvsL --data "username=$RELOG_UNAME&password=$RELOG_PASSW&provider=tbb" "https://www.btopenzone.com:8443/tbbLogon")
OUT=$(curl $CURL_OPTS --interface $IFACE --data-ascii "username=$RELOG_UNAME&password=$RELOG_PASSW&provider=tbb" "https://$BTOPENZONE_IP:8443/tbbLogon")
ONLINE=$(echo $OUT | grep "$OK_MSG" )
if [ "$ONLINE" ]
then
[[ $DBG ]] && echo "You're online!"
[[ $DBG ]] && logger -t "logon_fon" "You're online!"
else
[[ $DBG ]] && echo "Could not login :("
[[ $DBG ]] && logger -t "logon_fon" "Could not login :("
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment