Skip to content

Commit

Permalink
update OpenWRT scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
clowwindy committed Oct 6, 2014
1 parent f4837c3 commit bd74ae8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 32 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.65])
AC_INIT([shadowvpn],[0.1.0],[[email protected]])
AC_INIT([shadowvpn],[0.1.1],[[email protected]])
AC_CONFIG_AUX_DIR([.])

AC_CONFIG_SRCDIR([src/main.c])
Expand Down
4 changes: 3 additions & 1 deletion openwrt/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=ShadowVPN
PKG_VERSION:=0.1.0
PKG_VERSION:=0.1.1
PKG_RELEASE=$(PKG_SOURCE_VERSION)

PKG_SOURCE_URL:=https://github.com/clowwindy/ShadowVPN/releases/download/$(PKG_VERSION)
Expand Down Expand Up @@ -42,9 +42,11 @@ endef
define Package/ShadowVPN/install
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DIR) $(1)/etc/shadowvpn
$(INSTALL_DIR) $(1)/etc/hotplug.d/iface
$(INSTALL_CONF) $(PKG_BUILD_DIR)/samples/client.conf $(1)/etc/shadowvpn/client.conf
$(INSTALL_CONF) $(PKG_BUILD_DIR)/samples/client_up.sh $(1)/etc/shadowvpn/client_up.sh
$(INSTALL_CONF) $(PKG_BUILD_DIR)/samples/client_down.sh $(1)/etc/shadowvpn/client_down.sh
$(INSTALL_CONF) $(PKG_BUILD_DIR)/samples/30-shadowvpn $(1)/etc/hotplug.d/iface/30-shadowvpn
$(INSTALL_BIN) ./files/shadowvpn.init $(1)/etc/init.d/shadowvpn
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/shadowvpn $(1)/usr/bin
Expand Down
12 changes: 12 additions & 0 deletions samples/30-shadowvpn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# hotplug.d for OpenWRT

[ ifup = "$ACTION" ] && {
[ wan = "$INTERFACE" ] && {
/etc/init.d/shadowvpn start
}
}
[ ifdown = "$ACTION" ] && {
[ wan = "$INTERFACE" ] && {
/etc/init.d/shadowvpn stop
}
}
3 changes: 2 additions & 1 deletion samples/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ shadowvpnconf_DATA = client.conf \
server_down.sh \
server_up.sh

EXTRA_DIST = $(shadowvpnconf_DATA)
EXTRA_DIST = $(shadowvpnconf_DATA) \
30-shadowvpn
9 changes: 3 additions & 6 deletions samples/client_down.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ iptables -D FORWARD -i eth0 -o $intf -j ACCEPT
# get old gateway
echo reading old gateway from /tmp/old_gw
old_gw=`cat /tmp/old_gw` || ( echo "can not read gateway, check up.sh" && exit 1 )
rm /tmp/old_gw

# change routing table
echo changing default route
route del $server gw $old_gw
route del $server $old_gw
route del default
route add default gw $old_gw
route add default $old_gw
echo default route changed to $old_gw

############################################
# remove chnroutes rules here if you need! #
############################################

echo $0 done
42 changes: 19 additions & 23 deletions samples/client_up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,25 @@ iptables -t nat -A POSTROUTING -o $intf -j MASQUERADE
iptables -A FORWARD -i $intf -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -o $intf -j ACCEPT

# get current gateway
echo reading old gateway from route table
old_gw=`ip route show | grep '^default' | sed -e 's/default via \([^ ]*\).*/\1/'`

# if current gateway is 10.7.0.1, it indicates that our gateway is already changed
# read from saved file
if [ $old_gw == 10.7.0.1 ]; then
echo reading old gateway from /tmp/old_gw
# get current gateway
echo reading old gateway from route table
old_gw=`ip route show | grep '^default' | sed -e 's/.* dev \([^ ]*\).*/\1/'`
# if current gateway is tun, it indicates that our gateway is already changed
# read from saved file
if [ $old_gw == "$intf" ]; then
echo reading old gateway from /tmp/old_gw
old_gw=`cat /tmp/old_gw` || ( echo "can not read gateway, check up.sh" && exit 1 )
fi

echo saving old gateway to /tmp/old_gw
echo $old_gw > /tmp/old_gw

# change routing table
echo changing default route
route add $server gw $old_gw
route del default
route add default gw 10.7.0.1
fi
echo saving old gateway to /tmp/old_gw
echo $old_gw > /tmp/old_gw
# change routing table
echo changing default route
route add $server $old_gw
route del default
route add default gw 10.7.0.1
echo default route changed to 10.7.0.1

############################################
# insert chnroutes rules here if you need! #
############################################


echo $0 done

0 comments on commit bd74ae8

Please sign in to comment.