@@ -21,8 +21,8 @@ EXTRA_IFACE_LIST='' # 'vwan1 vwan2 vwan3' the extra interface list (Recommended
2121
2222GW_PORT=' 8060'
2323
24- IS_MAGIC_PRO=1 # 0 is disable
25- MAGIC_PRO_TIME=240 # will make magic when ${MAGIC_PRO_TIME} > $(ONLINE_TIME)
24+ IS_MAGIC_PRO=1 # 0 is disable
25+ MAGIC_PRO_TIME=240 # will make magic when ${MAGIC_PRO_TIME} > $(ONLINE_TIME)
2626
2727PRE_BUILD_TOKEN_NUM=5
2828TOKEN_BUILD_SPEED=5
@@ -177,22 +177,21 @@ get_nic_gateway() {
177177}
178178
179179displaytime () {
180- local T=$1
181- local D=$(( T/ 60 / 60 / 24 ))
182- local H=$(( T/ 60 / 60 % 24 ))
183- local M=$(( T/ 60 % 60 ))
184- local S=$(( T% 60 ))
185- [ $D -gt 0 ] && printf ' %d days ' $D
186- [ $H -gt 0 ] && printf ' %d hours ' $H
187- [ $M -gt 0 ] && printf ' %d minutes ' $M
188- [ $S -ge 0 ] && printf ' %d seconds\n' $S
180+ local T=$1
181+ local D=$(( T / 60 / 60 / 24 ))
182+ local H=$(( T / 60 / 60 % 24 ))
183+ local M=$(( T / 60 % 60 ))
184+ local S=$(( T % 60 ))
185+ [ $D -gt 0 ] && printf ' %d days ' $D
186+ [ $H -gt 0 ] && printf ' %d hours ' $H
187+ [ $M -gt 0 ] && printf ' %d minutes ' $M
188+ [ $S -ge 0 ] && printf ' %d seconds\n' $S
189189}
190190
191191# ############################################
192192# # Json Handle
193193# ############################################
194194
195-
196195cat_json_value () {
197196 ${AWK_TOOL} -v json=" $1 " -v key=" $2 " -v defaultValue=" $3 " ' BEGIN{
198197 foundKeyCount = 0
@@ -501,7 +500,6 @@ gw_auth_token() {
501500# # Parts
502501# ############################################
503502
504-
505503get_auth_state () {
506504 AUTH_STATE_RTE=" $( gw_get_auth_state) "
507505 # #{"resultCode":0,"data":"{\"auth_state\":1,\"gw_id\":\"GWIFI-luoyangligong4\",\"access_type\":\"1\",\"authStaType\":\"0\",\"station_sn\":\"c400ada4a45a\",\"client_ip\":\"172.21.219.234\",\"client_mac\":\"60:F1:89:4A:5C:CB\",\"online_time\":680,\"logout_reason\":32,\"contact_phone\":\"400-038-5858\",\"suggest_phone\":\"400-038-5858\",\"station_cloud\":\"login.gwifi.com.cn\",\"orgId\":\"930\",\"timestamp\":\"1619174989\",\"sign\":\"29C2348DCE52C1E47C9B52076DE26C32\"}"}
@@ -668,7 +666,6 @@ web_rebindmac() {
668666 [ " $WEB_REBINDMAC_RTE_STATUS " = ' 1' ] && logcat " $WEB_REBINDMAC_RTE_INFO " || { logcat " $WEB_REBINDMAC_RTE_INFO " ' E' && exit 1; }
669667}
670668
671-
672669desktop_rebindmac () {
673670 DESKTOP_REBINDMAC_RTE=" $( printf " $( gw_desktop_rebindmac " $DESKTOP_LOGIN_DATA " ) " | sed " s@\\\\ @@g" ) "
674671
@@ -698,8 +695,8 @@ mobile_rebindmac() {
698695}
699696
700697web_get_token () {
701- # login to get the auth token
702- WEB_LOGIN_DATA=" " " \
698+ # login to get the auth token
699+ WEB_LOGIN_DATA=" " " \
703700access_type=" $ACCESS_TYPE " \
704701&acsign=" $SIGN " \
705702&btype=" $AUTH_TYPE " \
@@ -724,70 +721,71 @@ access_type="$ACCESS_TYPE"\
724721&user_agent=" " \
725722&link_data=" " \
726723" " "
727- [ " $AUTH_TYPE " = ' staff' ] && WEB_LOGIN_DATA=" account_type=1&" $WEB_LOGIN_DATA " "
724+ [ " $AUTH_TYPE " = ' staff' ] && WEB_LOGIN_DATA=" account_type=1&" $WEB_LOGIN_DATA " "
728725
729- [ $ISLOG ] && echo " " && \
730- echo " WEB_LOGIN_DATA:" && \
731- echo " --> " $WEB_LOGIN_DATA " " && \
732- echo ' '
726+ [ $ISLOG ] && echo " " && \
727+ echo " WEB_LOGIN_DATA:" && \
728+ echo " --> " $WEB_LOGIN_DATA " " && \
729+ echo ' '
733730
734- if [ $ISBIND ]; then
735- web_rebindmac
736- logcat " exit"
737- exit
738- fi
731+ if [ $ISBIND ]; then
732+ web_rebindmac
733+ logcat " exit"
734+ exit
735+ fi
739736
740- WEB_LOGIN_RTE=" $( printf " $( gw_web_loginaction " $WEB_LOGIN_DATA " ) " | sed " s@\\\\ @@g" ) "
737+ WEB_LOGIN_RTE=" $( printf " $( gw_web_loginaction " $WEB_LOGIN_DATA " ) " | sed " s@\\\\ @@g" ) "
741738
742- [ $ISLOG ] && echo " " && \
743- echo " WEB_LOGIN_RTE:" && \
744- echo " --> " $WEB_LOGIN_RTE " " && \
745- echo ' '
739+ [ $ISLOG ] && echo " " && \
740+ echo " WEB_LOGIN_RTE:" && \
741+ echo " --> " $WEB_LOGIN_RTE " " && \
742+ echo ' '
746743
747- WEB_LOGIN_RTE_STATUS=" $( get_json_value " $WEB_LOGIN_RTE " ' status' ) "
748- WEB_LOGIN_RTE_INFO=" $( str_str " $WEB_LOGIN_RTE " ' "info":"' ' ","' ) "
749- WEB_LOGIN_RTE_DATA=" $( get_json_value " $WEB_LOGIN_RTE " ' data' ) "
750- WEB_LOGIN_RTE_DATA_REASONCODE=" $( get_json_value " $WEB_LOGIN_RTE_DATA " ' reasoncode' ) "
751-
752- if [ ! " $WEB_LOGIN_RTE_STATUS " = ' 1' ]; then
753- logcat " $WEB_LOGIN_RTE_INFO " ' E'
754- if [ " $WEB_LOGIN_RTE_DATA_REASONCODE " = ' 43' ]; then
755- printf ' %s' ' Are you sure to rebind your device? [Y/n] '
756- read input
757- case $input in
758- [yY][eE][sS] | [yY])
759- web_rebindmac
760- logcat " exit"
761- exit
762- ;;
763-
764- [nN][oO] | [nN])
765- logcat " Ok, is ending..."
766- ;;
767-
768- * )
769- logcat " Invalid input..."
770- ;;
771- esac
772- elif [ " $WEB_LOGIN_RTE_DATA_REASONCODE " = ' 55' ]; then
773- [ $ISDAEMON ] && {
774-
775- [ " $AUTH_TOKEN_LIST " ] && auth_token_magic
776-
777- logcat " The state of the user is being banned..."
778- logcat " Will try again after $BANNED_WAIT_TIME seconds..."
779- sleep $BANNED_WAIT_TIME
780- # restart main
781- logcat " restart..."
782- main
783- }
784- fi
744+ WEB_LOGIN_RTE_STATUS=" $( get_json_value " $WEB_LOGIN_RTE " ' status' ) "
745+ WEB_LOGIN_RTE_INFO=" $( str_str " $WEB_LOGIN_RTE " ' "info":"' ' ","' ) "
746+ WEB_LOGIN_RTE_DATA=" $( get_json_value " $WEB_LOGIN_RTE " ' data' ) "
747+ WEB_LOGIN_RTE_DATA_REASONCODE=" $( get_json_value " $WEB_LOGIN_RTE_DATA " ' reasoncode' ) "
785748
786- [ ! $ISDAEMON ] && logcat " exit" && exit 0
749+ if [ ! " $WEB_LOGIN_RTE_STATUS " = ' 1' ]; then
750+ logcat " $WEB_LOGIN_RTE_INFO " ' E'
751+ if [ " $WEB_LOGIN_RTE_DATA_REASONCODE " = ' 43' ]; then
752+ printf ' %s' ' Are you sure to rebind your device? [Y/n] '
753+ local input
754+ read -t 20 input
755+ case $input in
756+ [yY][eE][sS] | [yY])
757+ web_rebindmac
758+ logcat " exit"
759+ exit
760+ ;;
787761
762+ [nN][oO] | [nN])
763+ logcat " Ok, is ending..."
764+ ;;
765+
766+ * )
767+ logcat " Invalid input..."
768+ ;;
769+ esac
770+ elif [ " $WEB_LOGIN_RTE_DATA_REASONCODE " = ' 55' ]; then
771+ [ $ISDAEMON ] && {
772+
773+ [ " $AUTH_TOKEN_LIST " ] && auth_token_magic
774+
775+ logcat " The state of the user is being banned..."
776+ logcat " Will try again after $BANNED_WAIT_TIME seconds..."
777+ sleep $BANNED_WAIT_TIME
778+ # restart main
779+ logcat " restart..."
780+ main
781+ }
788782 fi
789783
790- [ " $( echo " $WEB_LOGIN_RTE_INFO " | grep ' token' ) " ] && AUTH_TOKEN=" $( str_str " $WEB_LOGIN_RTE_INFO " ' token=' ' &' ) " || AUTH_TOKEN=' '
784+ [ ! $ISDAEMON ] && logcat " exit" && exit 0
785+
786+ fi
787+
788+ [ " $( echo " $WEB_LOGIN_RTE_INFO " | grep ' token' ) " ] && AUTH_TOKEN=" $( str_str " $WEB_LOGIN_RTE_INFO " ' token=' ' &' ) " || AUTH_TOKEN=' '
791789
792790}
793791
@@ -834,7 +832,8 @@ ap_mac="$AP_MAC"\
834832 logcat " $DESKTOP_LOGIN_RTE_MSG " ' E'
835833 if [ " $DESKTOP_LOGIN_RTE_CODE " = ' 43' ]; then
836834 printf ' %s' ' Are you sure to rebind your device? [Y/n] '
837- read input
835+ local input
836+ read -t 20 input
838837 case $input in
839838 [yY][eE][sS] | [yY])
840839 desktop_rebindmac
@@ -863,7 +862,7 @@ ap_mac="$AP_MAC"\
863862 main
864863 }
865864 fi
866-
865+
867866 [ ! $ISDAEMON ] && logcat " exit" && exit 0
868867
869868 fi
@@ -926,7 +925,8 @@ mobile_get_token() {
926925 logcat " $MOBILE_LOGIN_RTE_MSG " ' E'
927926 if [ " $MOBILE_LOGIN_RTE_CODE " = ' 43' ]; then
928927 printf ' %s' ' Are you sure to rebind your device? [Y/n] '
929- read input
928+ local input
929+ read -t 20 input
930930 case $input in
931931 [yY][eE][sS] | [yY])
932932 mobile_rebindmac
@@ -944,11 +944,11 @@ mobile_get_token() {
944944 esac
945945 elif [ " $MOBILE_LOGIN_RTE_CODE " = ' 55' ]; then
946946 [ $ISDAEMON ] && {
947-
947+
948948 [ " $AUTH_TOKEN_LIST " ] && auth_token_magic
949949
950950 logcat " The state of the user is being banned..."
951-
951+
952952 logcat " Will try again after $BANNED_WAIT_TIME seconds..."
953953 sleep $BANNED_WAIT_TIME
954954 # restart main
@@ -1041,7 +1041,7 @@ do_auth() {
10411041 # login and get token...
10421042 case " $AUTH_MODE " in
10431043 ' web' )
1044- web_build_data
1044+ web_build_data
10451045 web_get_token
10461046 ;;
10471047 ' desktop' )
@@ -1224,10 +1224,10 @@ Info: "$([ "$AUTH_INFO" ] && echo "$AUTH_INFO" || echo 'none')"
12241224Logged: yes
12251225--------------------------------------------\
12261226" " "
1227- } || { logcat " Fail to auth by the token!" ' E' && [ ! $ISDAEMON ] && exit 1; }
1227+ } || { logcat " Fail to auth by the token!" ' E' && [ ! $ISDAEMON ] && exit 1; }
12281228
12291229 } || {
1230- logcat " Fail to get the token!" ' E'
1230+ logcat " Fail to get the token!" ' E'
12311231 [ ! $ISDAEMON ] && exit 1
12321232 }
12331233
@@ -1258,7 +1258,7 @@ Logged: yes
12581258 logcat " Heartache: $fail_iota " ' E' && fail_iota=$(( fail_iota + 1 ))
12591259 auth_token_magic
12601260 }
1261-
1261+
12621262 [ $iota -le $PRE_BUILD_TOKEN_NUM ] && data_iota=$TOKEN_BUILD_SPEED || data_iota=$(( data_iota + 1 ))
12631263
12641264 [ $fail_iota -gt $HEART_BROKEN_TIME ] && {
@@ -1290,20 +1290,19 @@ Logged: yes
12901290 }
12911291
12921292 [ $ISLOG ] && {
1293- echo " $( date " +%H:%M:%S" ) $AUTH_TOKEN $AUTH_INFO " >> " gg-$GW_USER -$AUTH_TYPE -$CLIENT_MAC "
1293+ echo " $( date " +%H:%M:%S" ) $AUTH_TOKEN $AUTH_INFO " >> " gg-$GW_USER -$AUTH_TYPE -$CLIENT_MAC "
12941294 }
12951295
12961296 TOKEN_IOTA=$(( TOKEN_IOTA + 1 ))
12971297 data_iota=1
12981298 }
12991299
1300-
13011300 [ $IS_MAGIC_PRO ] && {
13021301 [ $ONLINE_TIME -ge $MAGIC_PRO_TIME ] && {
13031302 auth_token_magic
13041303 }
13051304 }
1306-
1305+
13071306 # max AUTH_TOKEN_LIST limit
13081307 [ $TOKEN_IOTA -ge $MAX_TOKEN_LIST_LEN ] && {
13091308
@@ -1322,7 +1321,7 @@ Logged: yes
13221321 }
13231322 }
13241323
1325- TOKEN_IOTA=$(( MAX_TOKEN_LIST_LEN- 1 ))
1324+ TOKEN_IOTA=$(( MAX_TOKEN_LIST_LEN - 1 ))
13261325 }
13271326 }
13281327
0 commit comments