fix bug x3.

master
livejq 2 years ago
parent 207cd46900
commit 070773ba60
  1. 15
      chntunnel/chntunnel.sh

@ -42,7 +42,7 @@ Usage: chntunnel [OPTION...]
options: options:
-c, --collect genrate route files from apnic. -c, --collect genrate route files from apnic.
-g, --gre-tunnel create a gre tunnel. -g, --gre-tunnel create a gre tunnel.
-w, --white-list whitelist mode.[TODO] -w, --white-list whitelist mode, only manually.[TODO]
-f, --gfw-list gfwlist mode. -f, --gfw-list gfwlist mode.
EOF EOF
} }
@ -168,10 +168,13 @@ if [ $# != 0 ]; then
newGre $MY_INNER_IPADDR $PEER_INNER_IPADDR $PEER_OUTER_IPADDR ${TUNNEL_NAME:-tun0} newGre $MY_INNER_IPADDR $PEER_INNER_IPADDR $PEER_OUTER_IPADDR ${TUNNEL_NAME:-tun0}
ifup ${TUNNEL_NAME:-tun0} ifup ${TUNNEL_NAME:-tun0}
ping -c 3 $PEER_INNER_IPADDR >/dev/null && result=$? && [[ $result -eq 0 ]] && msg_pass "Tunnel created successfully!" && exit 0 ping -c 3 $PEER_INNER_IPADDR >/dev/null && result=$? && [[ $result -eq 0 ]] && msg_pass "Tunnel created successfully!" && exit 0
msg_err "Connection failed, please contact the administrator." && exit 1
elif [[ $param = '-f' || $param = '--gfw-list' ]]; then elif [[ $param = '-f' || $param = '--gfw-list' ]]; then
peer=$(ip addr | grep peer | grep inet | awk -F ' ' {'print $4'}) peer=$(ip addr | grep peer | grep inet | awk -F ' ' {'print $4'})
PEER_INNER_IPADDR=${peer%%/*} PEER_INNER_IPADDR=${peer%%/*}
:>/etc/sysconfig/static-routes :>/etc/sysconfig/static-routes
[[ ! -f $GFWLIST ]] && msg_err "Please run 'chntunnel -c' command first." && exit 1
msg "Generating, wait a while..."
cat $GFWLIST | while read line cat $GFWLIST | while read line
do do
ip route add $line via $PEER_INNER_IPADDR ip route add $line via $PEER_INNER_IPADDR
@ -179,7 +182,7 @@ if [ $# != 0 ]; then
done done
msg_pass "GFWlist is active, enjoy~" msg_pass "GFWlist is active, enjoy~"
elif [[ $param = '-w' || $param = '--white-list' ]]; then elif [[ $param = '-w' || $param = '--white-list' ]]; then
msg_err "TODO: not yet implemented, only manually." && exit 1 #msg_err "TODO: not yet implemented, only manually." && exit 1
local_gw=$(ip route | grep default | awk -F ' ' {'print $3'}) local_gw=$(ip route | grep default | awk -F ' ' {'print $3'})
#local_dev=$(ip route | grep src | awk -F ' ' {'print $3'}) #local_dev=$(ip route | grep src | awk -F ' ' {'print $3'})
#local_addr=$(ip route | grep src | awk -F ' ' {'print $9'}) #local_addr=$(ip route | grep src | awk -F ' ' {'print $9'})
@ -189,15 +192,17 @@ if [ $# != 0 ]; then
:>/etc/sysconfig/static-routes :>/etc/sysconfig/static-routes
grep $local_table /etc/iproute2/rt_tables && result=$? grep $local_table /etc/iproute2/rt_tables && result=$?
[[ $result != '0' ]] && echo "200 $local_table" >>/etc/iproute2/rt_tables [[ $result != '0' ]] && echo "200 $local_table" >>/etc/iproute2/rt_tables
grep $local_table /etc/rc.local && result=$? #grep $local_table /etc/rc.local && result=$?
[[ $result != '0' ]] && addRoutes $local_table $local_gw $local_dev $local_addr && chmod +x /etc/rc.local && /etc/rc.local && #[[ $result != '0' ]] && addRoutes $local_table $local_gw $local_dev $local_addr && chmod +x /etc/rc.local && /etc/rc.local
msg "Generating, wait a while..."
cat $WHITELIST | while read line cat $WHITELIST | while read line
do do
ip route add $line via $local_gw #ip route add $line via $local_gw
echo "any net $line gw $local_gw" >>/etc/sysconfig/static-routes || exit echo "any net $line gw $local_gw" >>/etc/sysconfig/static-routes || exit
done done
#ip route del default via $local_gw #ip route del default via $local_gw
#ip route add default via $PEER_INNER_IPADDR #ip route add default via $PEER_INNER_IPADDR
msg_pass "Whitelist is active, enjoy~"
else else
help help
fi fi

Loading…
Cancel
Save