diff --git a/OSX/netTHU b/OSX/netTHU index 15511d1..b253e2c 100755 --- a/OSX/netTHU +++ b/OSX/netTHU @@ -12,9 +12,12 @@ fi while getopts "odhrl" OPTION; do case $OPTION in o) - if [ -a netTHUservice ]; then - username=`awk 'NR==1 {print $2}' netTHUservice` - passmd5=`awk 'NR==2 {print $2}' netTHUservice` + if [ ! -d ~/.TsinghuaNet ]; then + mkdir ~/.TsinghuaNet + fi + if [ -a ~/.TsinghuaNet/netTHUservice ]; then + username=`awk 'NR==1 {print $2}' ~/.TsinghuaNet/netTHUservice` + passmd5=`awk 'NR==2 {print $2}' ~/.TsinghuaNet/netTHUservice` result=$(curl -sL net.tsinghua.edu.cn/do_login.php --data "action=login&username="$username"&password={MD5_HEX}"$passmd5"&ac_id=1") res=`echo $result |awk '{print $3}'` if [ $res != "successful." ]; then @@ -32,12 +35,12 @@ while getopts "odhrl" OPTION; do fi else echo "first use please input username" - read username - echo "username "$username > netTHUservice + read username + echo "username "$username > ~/.TsinghuaNet/netTHUservice echo "input password" read password passmd5=$(echo -n $password | md5) - echo "password "$passmd5 >> netTHUservice + echo "password "$passmd5 >> ~/.TsinghuaNet/netTHUservice result=$(curl -L net.tsinghua.edu.cn/do_login.php --data "action=login&username="$username"&password={MD5_HEX}"$passmd5"&ac_id=1") res=`echo $result |awk '{print $3}'` echo $result @@ -67,7 +70,7 @@ while getopts "odhrl" OPTION; do ;; r) - rm netTHUservice + rm ~/.TsinghuaNet/netTHUservice exit 0 ;; diff --git a/README.md b/README.md index 495001d..d31b7ad 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,12 @@ ##What's this This is a Command Line program writen in bash using Curl. You can use it to log in & out net.tsinghua.edu.cn -First time you use it, it will require your username and password. Then it saves the information locally and next time you are able to use short commands to control your status(login or logout). +First time you use it, it will require your username and password. Then it saves the information in **~/.TsinghuaNet/netTHUservice** and next time you are able to use short commands to control your status(login or logout). ##Setup cd ~ + #add PATH to your shell echo "PATH=/usr/local/bin:$PATH" >> .bashrc #or .zshrc git clone https://github.com/guzhaoyuan/net.tsinghua.git @@ -25,5 +26,7 @@ First time you use it, it will require your username and password. Then it saves ##TODO - [x] fix small bugs, recognize error type -- [ ] store password at other position +- [x] store password at other position - [x] added function: check current data usage +- [ ] write a install and uninstall script +- [ ] encrypt the information in netTHUservice for security \ No newline at end of file diff --git a/linux/netTHU b/linux/netTHU index b7a6339..2f2e00a 100755 --- a/linux/netTHU +++ b/linux/netTHU @@ -12,9 +12,12 @@ fi while getopts "odhrl" OPTION; do case $OPTION in o) - if [ -a netTHUservice ]; then - username=`awk 'NR==1 {print $2}' netTHUservice` - passmd5=`awk 'NR==2 {print $2}' netTHUservice` + if [ ! -d ~/.TsinghuaNet ]; then + mkdir ~/.TsinghuaNet + fi + if [ -a ~/.TsinghuaNet/netTHUservice ]; then + username=`awk 'NR==1 {print $2}' ~/.TsinghuaNet/netTHUservice` + passmd5=`awk 'NR==2 {print $2}' ~/.TsinghuaNet/netTHUservice` result=$(curl -sL net.tsinghua.edu.cn/do_login.php --data "action=login&username="$username"&password={MD5_HEX}"$passmd5"&ac_id=1") res=`echo $result |awk '{print $3}'` if [ $res != "successful." ]; then @@ -32,12 +35,12 @@ while getopts "odhrl" OPTION; do fi else echo "first use please input username" - read username - echo "username "$username > netTHUservice + read username + echo "username "$username > ~/.TsinghuaNet/netTHUservice echo "input password" read password passmd5=$(echo -n $password | md5sum | cut -d' ' -f1) - echo "password "$passmd5 >> netTHUservice + echo "password "$passmd5 >> ~/.TsinghuaNet/netTHUservice result=$(curl -L net.tsinghua.edu.cn/do_login.php --data "action=login&username="$username"&password={MD5_HEX}"$passmd5"&ac_id=1") res=`echo $result |awk '{print $3}'` echo $result @@ -67,7 +70,7 @@ while getopts "odhrl" OPTION; do ;; r) - rm netTHUservice + rm ~/.TsinghuaNet/netTHUservice exit 0 ;;