Skip to content

Commit

Permalink
put password in other place done
Browse files Browse the repository at this point in the history
  • Loading branch information
guzhaoyuan committed Oct 21, 2016
1 parent b4a615a commit f869240
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
17 changes: 10 additions & 7 deletions OSX/netTHU
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -67,7 +70,7 @@ while getopts "odhrl" OPTION; do
;;

r)
rm netTHUservice
rm ~/.TsinghuaNet/netTHUservice
exit 0
;;

Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
17 changes: 10 additions & 7 deletions linux/netTHU
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -67,7 +70,7 @@ while getopts "odhrl" OPTION; do
;;

r)
rm netTHUservice
rm ~/.TsinghuaNet/netTHUservice
exit 0
;;

Expand Down

0 comments on commit f869240

Please sign in to comment.