Skip to content

Instantly share code, notes, and snippets.

@danny-source
Forked from JustinTW/login-cht-wifi.sh
Created February 4, 2020 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danny-source/f745d641a8fa2a1001ad689518e8b1cd to your computer and use it in GitHub Desktop.
Save danny-source/f745d641a8fa2a1001ad689518e8b1cd to your computer and use it in GitHub Desktop.
Auto login cht-wifi for dd-wrt
#!/bin/sh
# description: check cht-wifi login status, and auto login if no login.
# default script path: /mnt/sda1/mnt/scripts/login-cht-wifi.sh
# author: JustinTWD <justintwd@gmail.com>
# date: 2016/03/12
USERNAME=YOUR_CHT_ACCOUNT
PASSWD=YOUR_CHT_PASSWORD
LOGFILE=/mnt/sda1/log/cht-wifi.log
TMPSESSION=/tmp/cht_session.tmp
login_v1(){
/opt/bin/curl -d cht_user=$USERNAME -d passwd=$PASSWD -d username=$USERNAME%40hinet.net -d password=$PASSWD -d custom=cht -d session=$(/opt/bin/curl -I www.google.com.tw | grep Location | cut -d "&" -f 1 | cut -d "=" -f 2) https://wlanac.hinet.net/loginpages/userlogin.shtml
}
login_v2(){
rm -f $TMPSESSION
R1=$(/opt/bin/curl -c $TMPSESSION -k \
$(/opt/bin/curl -Ls -o /dev/null -w %{url_effective} http://google.com) 2>&1 \
| grep redirect_url= \
| awk -F"'" '{print $2}')
R2=$(/opt/bin/curl -b $TMPSESSION -c $TMPSESSION -k -i $R1 2>&1 \
| grep Location \
| awk '{print $2}')
/opt/bin/curl -b $TMPSESSION -c $TMPSESSION -k \
-H "Referer: $R2" \
-d cht_user=$USERNAME -d passwd=$PASSWD -d username=$USERNAME%40hinet.net -d password=$PASSWD -d custom=cht \
https://wlangw.hinet.net/v2_0/cht_auth/auth_page.php
}
main(){
testing=$(/opt/bin/curl -I www.google.com.tw | grep "200 OK")
echo "============================================="
if [ "$testing" != "" ]; then
echo "wifi logined."
elif [ "$1" == "" ]; then
echo "`date` You need login CHT Wi-Fi PWLAN." | tee $LOGFILE
login_v2;
fi
}
main;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment