Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Add a lot functions
Browse files Browse the repository at this point in the history
  • Loading branch information
satouriko committed Sep 16, 2016
1 parent 0ed7f90 commit 896cc7d
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 26 deletions.
7 changes: 5 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@ done
stty echo

mkdir /usr/local/neuipgw
cp ./ipgw.sh /usr/local/neuipgw/ipgw.sh
cp ./ipgw.sh /usr/local/neuipgw/ipgw
chmod 755 /usr/local/neuipgw/ipgw
#cp ./user.cfg /usr/local/neuipgw/user.cfg
echo "#!/bin/bash" > /usr/local/neuipgw/user.cfg
echo "USER_NAME=$username" >> /usr/local/neuipgw/user.cfg
echo "USER_PASS=$password" >> /usr/local/neuipgw/user.cfg
cp ./ipgw.png /usr/local/neuipgw/ipgw.png
rm -f /usr/bin/ipgw
ln -s /usr/local/neuipgw/ipgw /usr/bin/ipgw

echo [Desktop Entry]>/usr/share/applications/neuipgw.desktop
echo Name=NEU-IPGW>>/usr/share/applications/neuipgw.desktop
echo Comment=Speedier Internet Access>>/usr/share/applications/neuipgw.desktop
echo Exec=sh /usr/local/neuipgw/ipgw.sh>>/usr/share/applications/neuipgw.desktop
echo Exec=/usr/bin/ipgw>>/usr/share/applications/neuipgw.desktop
echo Icon=/usr/local/neuipgw/ipgw.png>>/usr/share/applications/neuipgw.desktop
echo Terminal=true>>/usr/share/applications/neuipgw.desktop
echo Type=Application>>/usr/share/applications/neuipgw.desktop
Expand Down
185 changes: 161 additions & 24 deletions ipgw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,84 @@
#########################################################################
#!/bin/bash

SOURCE="$0"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

source $DIR/user.cfg

LOGOUT=`curl -s -d "action=logout&ac_id=1&user_ip=&nas_ip=&user_mac=&url=&username=$USER_NAME&password=$USER_PASS&save_me=0" "http://ipgw.neu.edu.cn:803/srun_portal_pc.php?ac_id=1&" 2>&1`
LOGIN=`curl -s -d "action=login&ac_id=1&user_ip=&nas_ip=&user_mac=&url=&username=$USER_NAME&password=$USER_PASS&save_me=0" "http://ipgw.neu.edu.cn:803/srun_portal_pc.php?ac_id=1&" 2>&1`

k=$RANDOM


if [[ "$LOGIN" =~ "网络已连接" ]];
then
echo "连接成功!"
INFO=`curl -s -d "action=get_online_info&key=$k" "http://ipgw.neu.edu.cn:803/include/auth_action.php?k=$k" 2>&1`
usage()
{
echo "Usage: `basename $0` [-c | -d] [-q] [-f] [-m] [-u <username>] [-p <password>]"
echo "Options:"
echo -e "-c, --connect\tConnect Neu ip gateway"
echo -e "-d, --disconnect\tDisconnect Neu ip gateway"
echo -e "-f, --force\tPerform force connection"
echo -e "-m, --mobile\tConnect as mobile device"
echo -e "-q, --query\tQuery use of flow, balance, etc"
echo -e "-u, --username VALUE\tSpecify username"
echo -e "-p, --password VALUE\tSpecify password"
}
invalidargs()
{
echo "Invaild Options!"
echo ""
usage
exit 1
}
requireuinfo()
{
if [ ! -n "$USER_NAME" ];
then
echo "请输入校园网账号:"
read USER_NAME
fi
if [ ! -n "$USER_PASS" ];
then
echo "请输入校园网密码:"
stty -echo
read USER_PASS
stty echo
fi
}
disconnect()
{
requireuinfo
LOGOUT=`curl -s -d "action=logout&ac_id=1&user_ip=&nas_ip=&user_mac=&url=&username=$USER_NAME&password=$USER_PASS&save_me=0" "http://ipgw.neu.edu.cn:"${p}"/srun_portal_pc.php?ac_id=1&" 2>&1`
if [[ "$LOGOUT" =~ "网络已断开" ]];
then
echo "断开连接成功!"
else
echo "断开连接失败!"
TEMP=${LOGOUT#*<td height=\"40\" style=\"font-weight:bold;color:orange;\">}
echo ${TEMP%%</td>*}
fi
}
connectasphone()
{
requireuinfo
LOGIN=`curl -H "Content-type: application/x-www-form-urlencoded" -A "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4" -s -d "action=login&ac_id=1&user_ip=&nas_ip=&user_mac=&url=&username=$USER_NAME&password=$USER_PASS&save_me=0" "http://ipgw.neu.edu.cn:"${p}"/srun_portal_pc.php?ac_id=1&" 2>&1`
if [[ "$LOGIN" =~ "网络已连接" ]];
then
echo "网络连接成功!"
else
echo "网络连接失败!"
TEMP=${LOGIN#*<p>}
echo ${TEMP%%</p>*}
fi
query
}
connect()
{
requireuinfo
LOGIN=`curl -H "Content-type: application/x-www-form-urlencoded" -A "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36" -s -d "action=login&ac_id=1&user_ip=&nas_ip=&user_mac=&url=&username=$USER_NAME&password=$USER_PASS&save_me=0" "http://ipgw.neu.edu.cn:"${p}"/srun_portal_pc.php?ac_id=1&" 2>&1`
if [[ "$LOGIN" =~ "网络已连接" ]];
then
echo "网络连接成功!"
else
echo "网络连接失败!"
TEMP=${LOGIN#*<p>}
echo ${TEMP%%</p>*}
fi
query
}
query()
{
INFO=`curl -s -d "action=get_online_info&key=$k" "http://ipgw.neu.edu.cn:"${p}"/include/auth_action.php?k=$k" 2>&1`
#echo $k;
#echo $INFO;
DATA=${INFO%%,*}
Expand All @@ -49,13 +107,92 @@ then
echo "账户余额:$BALANCE"
IP=${INFO##*,}
echo "IP地址:$IP"
}

opt=""

else
echo "连接失败!"
TEMP=${LOGIN#*<p>}
echo ${TEMP%%</p>*}
SOURCE="$0"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

source $DIR/user.cfg

temp=$(getopt -q -o qcdfmu:p:h --long connect,disconnect,force,mobile,query,username:,password:,help -- "$@")
if [ $? != 0 ]
then
invalidargs
fi

eval set -- "$temp"

while [ -n "$1" ]
do
case $1 in
-c|--connect) OPT_CONNECT=true
OPT_QUERY=false
shift
;;
-d|--disconnect) OPT_DISCONNECT=true
shift
;;
-f|--force) OPT_FORCE=true
shift
;;
-m|--mobile) OPT_MOBILE=true
shift
;;
-q|--query) OPT_QUERY=true
OPT_DISCONNECT=false
shift
;;
-u|--username) USER_NAME=$2
unset USER_PASS
shift 2
;;
-p|--password) USER_PASS=$2
shift 2
;;
-h|--help) usage
exit 0
;;
--)
shift
;;
*) usage
;;
esac
done


k=$RANDOM
p=$(($RANDOM % 4 + 801))

if [[ $OPT_CONNECT = true ]] || [ ! -n "$OPT_DISCONNECT" ];
then
if [[ $OPT_FORCE = true ]];
then
disconnect
fi
if [[ $OPT_MOBILE = true ]];
then
connectasphone
else
connect
fi
elif [[ $OPT_DISCONNECT = true ]];
then
disconnect
fi
if [[ $OPT_QUERY = true ]];
then
query
fi

#echo $p
#echo $LOGOUT
#echo $LOGIN

Expand Down

0 comments on commit 896cc7d

Please sign in to comment.