Tuesday, December 21, 2010

truewifi auto connect with wrt54gl

this article for people who live in thailand and currently apply truewifi service from true internet company.

the modify script allow you to feel free to serv internet via true wifi hotpot without reconnect manully every 90 minute.

Are you ready? okay let do this.
first of all you need to install openwrt firmware you can found here.

! IMPORTANT USE THIS WITH YOUR OWN RISK NO ANY WARRANTY

http://downloads.openwrt.org/kamikaze/8.09/brcm-2.4/openwrt-wrt54g-squashfs.bin

for anyone who prefer complete modify fimware you can download at link at the buttom of page which is recommend for who is not have experience or have no time with this.

after upgrade firmware is complete you can test by access to the router with no password (default)

telnet 192.168.1.1

if your prefer ssh make password first by

passwd

and type password you want to make
after that you can ssh

ssh root@192.168.1.1

after login success you will see like this

















add this script to /usr/bin/truecond

vi /usr/bin/truecond

paste this scirpt
change username and password to your

change domain to "truewifi" is look like "truehisp" don't work any more (may be only my account)
thank you to pok1800@hotmail.com for inform.

#!/bin/sh
utime=`echo ICT-7 > /etc/TZ` # set time zone to asia bangkok

sleep 300 # delay 5 minute for start up make sure wifi is connect config already put into /etc/config/wireless

# true wifi user and password
trueusername="test"
truepassword="test"
truedomain="truewifi" # change to "truewifi"
trueyourmac="AA:BB:CC:DD:EE:FF"


# optional for update dyndns
dyndnsuser="test"
dyndnspass="test"
dyndnshost="test.dyndns.tv"

url="www.whatismyip.com" # url for check wan ip

log_in=`wget -O /tmp/log_in.txt --user-agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" --auth-no-challenge --no-cookies --no-check-certificate --post-data 'domain='$truedomain'&textuname='$trueusername'&password='$truepassword'&vlan=851&mac='$trueyourmac'&remember=1&type=desktop' https://portal.trueinternet.co.th/wifiauthen/login_result.php`

sleep 30 # give it some time to authentication

while [ 1 ]; do

up=`ping -c 2 $url | grep '100%'` # test ping external site
if [ -z "$up" ]; then

ip=`wget -O /tmp/ip.txt http://www.whatismyip.com/automation/n09230945.asp`
extip=`cat /tmp/ip.txt`
update=`ez-ipupdate -S dyndns -a $extip -u "$dyndnsuser":"$dyndnspass" -h "$dyndnshost"`

# synctime to avoid crontab time missing
sync=`ntpdate ntp.ubuntu.com`

sleep 4800 # delay for 80 minute which is default truewifi disconnect every 90 minute

log_out=`wget -O /tmp/log_out.txt --user-agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" --auth-no-challenge --no-cookies --no-check-certificate https://portal.trueinternet.co.th/wifiauthen/logout_result.php`

else

# retry login until sucess
log_in=`wget -O /tmp/log_in.txt --user-agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" --auth-no-challenge --no-cookies --no-check-certificate --post-data 'domain='truedomain'&textuname='$trueusername'&password='$truepassword'&vlan=851&mac='$trueyourmac'&remember=1&type=desktop' https://portal.trueinternet.co.th/wifiauthen/login_result.php`

fi

sleep 45

done

for save file in vi type :wq

:wq

change script to executable

chmod a+x /usr/bin/truecond

because original wget from Openwrt didn't support https so we have to get GNU wget

opkg update

before use this command make sure your router can connect to internet
and your have to authentication manually through trueinternet redirect site for the first time

http://192.168.1.1

scan and connect to true wifi
now change to @TRUEWIFI






















login to router again

ssh root@192.168.1.1

test internet access

ping google.com

























okay when router can access to internet
let update package list again

opkg update













get ez-ipupdate for dyndns update

opkg install ez-ipupdate

get ntp-update for time correct

opkg install ntpdate

now get GNU wget

wget http://downloads.openwrt.org/kamikaze/8.09/brcm-2.4/packages/wget_1.11.4-1_mipsel.ipk

and install it , we have to force install because it alredy exist form busy-box build in

opkg -force-overwrite install wget_1.11.4-1_mipsel.ipk

now you will get GNU wget















now we prepare all thing done
next is make is run as startup when start router

vi /etc/init.d/truenet

#!/bin/sh /etc/rc.common

START=99

start() {
/usr/bin/truecond > /dev/null 2>&1 &
}

stop() {
killall -9 truecond
killall -9 sleep
}

for save file in vi type :wq
:wq

chmod a+x /etc/init.d/truenet

now make is run as init (start up)

ln -s /etc/init.d/truenet /etc/rc.d/S99truenet


reboot


after reboot try browsing internet from your computer(after wait 5 minute) because we sleep 300 second

when timeout(in this case 80 minute) and your are browsing webpage found redirect to truewifi authentication page don't have to enter username and password
just wait for 45 second and router will connect it self

Have some fun.

! IMPORTANT USE THIS WITH YOUR OWN RISK NO ANY WARRANTY