Sunday, August 4, 2013

Auto Login to Hathway Broadband Using Raspberry Pi

The 'Great' Hathway Captive Portal

As far as the broadband speed, billing, uptime and general experience is considered, I would say Hathway is a good ISP, at least here in Pune where I stay. But few years back this broadband internet provider suddenly introduced a bullshit, outdated captive portal mechanism for authentication. The system keeps logging you out every few hours. Once you are logged out, you can no more access internet until you open a browser and login to Hathway at login.hathway.com

The Problem

Well, one can simply login every time and use internet, whats the big deal? The biggest problem is when you have something in home that requires internet and it is not a computer or laptop! Why would someone require internet without a laptop or computer?

People do use internet radio, people do have home/shop remote monitoring systems which require continuous internet access. Imagine you install a remote monitoring camera in your home and are out of station, expecting to monitor your home over internet and within few hours you lose the connection just because Hathway has kicked your devices out and you now require to login to Hathway by physically going into your home! Totally sucks right? Does Hathway think that people use internet only for browsing?

The another issue is with large downloads. When you put something for download overnight, say using some torrent client expecting to finish the download by morning, and Hathway kicks you out of internet access late midnight. In the morning you only wake up to see that your download has stalled.

The biggest ever hurdle is for people using Linux based computers. The login mechanism does not work with most Linux versions including latest Ubuntu versions and even Android! That means when you lose connection you must log into a lovely Windows machine which can only take up to 10-20 minutes to boot and then login to Hathway!

Can't Hathway Fix This?

So many people are frustrated with Hathway login. Ideally Hathway should do away with something as stupid as this which is making their consumers totally unhappy. If you do a google search, you can find hundreds of complaints on various forums in this regard. It seems Hathway has turned a deaf ear to all of them, not sure if this is ignorance or strategy. Many people, including myself, have tried to report the issues to customer care, it has turned pointless - the guy sitting over there is just some non-technical person, who hasn't even heard the word 'Linux' in his whole life and answers 'Sir, this is for your security sir... '. I don't understand what kind of security they are trying to achieve with this login. Writing numerous mails to them hasn't got any response. I suspect Hathway has purposely introduced this nonsense, to avoid people doing long downloads etc. A fair-access policy implemented in unfair way.

My Solution

Hardware Requirements:
  1. Raspberry Pi - Model B. 
  2. In addition, I assume you are using Wired/Wireless home router.
The Raspberry Pi

While people out there have written some scripts, apps to automate Hathway login, most of them are for Windows and require a desktop/laptop which was not useful for me so I decided to go on my own way. Raspberry Pi came to the rescue. I have a Raspberry Pi model B which I ordered for $35. Nowadays it can be ordered online from many Indian sources including ebay.in. I have installed a Raspbian wheezy image on it on a 4GB SD card. There are hundreds of posts/guides available online that can help you quickly setup your Raspberry Pi. Once you have setup Raspberry Pi, plug it into your router using a LAN cable. You can keep it powered up 24 hours, it is very robust and very less power consuming. 

Setting up the hathway auto-login :

Get the IP Address of the Raspberry Pi, it can be obtained from your router's web UI. Do SSH to your Raspberry Pi using a terminal (or Putty if you are using Windows). In the home directory (say /home/pi) create a directory 'hathway' and in that create a file, say login.sh with contents as below. This script checks if internet is up and does an automatic login to the Hathway login portal only if the internet is not accessible. Make sure to replace the {yourusername} and password {yourpassword} with your Hathway username and password. [Please read the **Update below this script before using the script]

ping -c 1 -W 10 www.google.com 1> /dev/null 2> /dev/null
if [ $? -ne 0 ]; then
    echo `date` "Net not accessible. Logging into Hathway"
    wget --timeout=60 --tries=1 -S -nv "http://203.212.193.60/bsp/login.do?action=doLoginSubmit&flowId=UserLogin&username={yourusername}@hathway.com&password={yourpassword}"
else
    echo `date` "Net accessible"
fi
**Update: As mentioned by N Bhargav in comment below (Dated 2nd Feb, 2015) the Hathway login mechanism has changed and above script may not work anymore. Please use below script instead of above. Note that I personally could not test below script, as Hathway no more throws me to login page for my connection.  


ping -c 1 -W 10 www.google.com 1> /dev/null 2> /dev/null
if [ $? -ne 0 ]; then
    echo `date` "Net not accessible. Logging into Hathway"
    curl --data "username={yourusername}%40hathway.com&password={yourpassword}&Submit=++Login++" http://203.212.193.60/bsp/login.do?action=doLoginSubmit&flowId=UserLogin >> hathway_autologin.sh
else
    echo `date` "Net accessible"
fi

Ensure that the file is executable by setting up the correct permissions. Use below command to make the file executable.
chmod +x login.sh 
The above script checks for internet and does login only once. You need to do this periodically, say every 5 minutes. For that you must set up a cron job that will execute the login script every 5 minutes. To setup cron job use command - 
sudo crontab -e
and at the end of file, add a line as below -
*/5 * * * * /home/pi/hathway/login.sh 1>> /home/pi/hathway/hathway-log.txt 2>> /home/pi/hathway/hathway-log.txt
Save and exit. This will update and start cron jobs that will cause the script to be executed every 5 minutes. The job will run even after you restart the Raspberry Pi. You may change the time interval by changing the '5' to whatever interval in minutes you want. This script also generates a nice log file hathway/hathway-log.txt listing actions taken by the script every time it runs.This will give you a complete history showing when your internet was working fine and when you were kicked out by Hathway.

I have the Raspberry Pi running at least two weeks now, up 24 hours and I have never had to do a single manual login into Hathway internet. Pleasure!

Do More with the Raspberry Pi

Using the Raspberry Pi only for doing the stupid Hathway login is probably not so optimal use of the Raspberry Pi. It is very powerful device and can do lot many things in parallel. So don't waste its capacity. My Raspberry Pi while serving as auto-login for Hathway captive portal is also serving as NAS (file sharing), automated backups and home media server as well. Not going to write how that can be done, as there are already many contents out there on how to do that which I have followed.

12 comments:

  1. "and at the end of file, add a line as below -

    */5 * * * * /home/pi/hathway/login.sh 1>> /home/pi/hathway/hathway-log.txt 2>> /home/pi/hathway/hathway-log.txt
    "
    Can you please tell at the end of which file I need to add this line? if possible can you attach hathway-login.sh file

    ReplyDelete
    Replies
    1. If you execute previous command 'sudo crontab -e' it opens a screen where you can see the cron tab configuration file, just put this line at the end of it.

      I will attach the script soon.

      Delete
  2. Good one. I hope someday I will start using this Raspberry Pi :-)

    ReplyDelete
  3. for windows you can use the following app : Hathway Auto Connect from http://hathwayautoconnect.blogspot.in/

    ReplyDelete
  4. Brillant. Thanks a lot. Those money sucking Hathway idiots don't allow login from Linux/Firefox browser let alone automatic logout. Your wisdom saved me. Thanks Thanks thanks.

    ReplyDelete
  5. Thanks for the script and I see passing the credentials via the URL is not working anymore. I have written a script to fix it. You can validate and update your post :)

    #!/bin/bash

    ping -c 1 -W 10 www.google.com 1> /dev/null 2> /dev/null

    if [ $? -ne 0 ]; then
    echo `date` "Net not accessible. Logging into Hathway"
    curl --data "username={USERNAME}%40hathway.com&password={PASSWORD}&Submit=++Login++" http://203.212.193.60/bsp/login.do?action=doLoginSubmit&flowId=UserLogin >> hathway_autologin.sh
    else
    echo `date` "Net accessible"
    fi

    ReplyDelete
    Replies
    1. Thanks Bhargav! I see Hathway has assigned my connection with a static IP address and the login page never appears anymore. So I did not face this issue. Thanks for updating. I have updated my blog with your script. Thanks again!

      Delete
    2. thanks for sharing it, working perfectly in delhi (even the old script)

      Delete
  6. :START
    @ECHO OFF
    CLS
    ECHO Waiting...
    PING -n 60 127.0.0.1 > NUL
    :AGAIN
    PING -n 1 www.google.com|find "Reply from " >NUL
    IF NOT ERRORLEVEL 1 goto START
    ECHO Not Working!
    ECHO.
    ECHO Logging Back in...
    E:\WGET\WGET -qO- --post-data="username=USER%40hathway.com&password=PASSWORD" "http://203.212.193.61/bsp/login.do?action=doLoginSubmit&flowId=UserLogin"
    ECHO Checking Internet...
    PING -n 1 www.google.com|find "Reply from " >NUL
    IF NOT ERRORLEVEL 1 goto AGAIN
    GOTO START


    ^for windows

    ReplyDelete
  7. Hey, I used to use the AutoHathwayAuthenticator earlier. Then for years the problem was solved and I didn't need to use it.

    Now since a few weeks the issue is back & the old s/w doesn't work any more. Hoping for someone to help me fix this issue!

    Thanks!

    ReplyDelete