Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #DEBUG= # uncomment/comment to enable/disable debug mode
- # name: merlin-pptp-gw-override.sh
- # version: 1.0.1, 27-jun-2024, by eibgrad
- # purpose: replace pptp default gateway w/ pptp static routing
- # type(s): init-start
- # href: https://tinyurl.com/2yekbh7e
- # installation:
- # 1. enable jffs custom scripts and configs (administration->system)
- # 2. ssh to router and copy/paste the following command:
- # curl -kLs bit.ly/merlin-installer|tr -d '\r'|sh -s MLtSBb6E
- # 3. modify script w/ your preferred options using nano editor:
- # nano /jffs/scripts/merlin-pptp-gw-override.sh
- # 4. reboot
- SCRIPTS_DIR='/jffs/scripts'
- SCRIPT1="$SCRIPTS_DIR/merlin-pptp-gw-override.sh"
- SCRIPT2="$SCRIPTS_DIR/init-start"
- mkdir -p $SCRIPTS_DIR
- # ---------------------- begin merlin-pptp-gw-override ----------------------- #
- cat << 'EOF' > $SCRIPT1
- #!/bin/sh
- #set -x # comment/uncomment to disable/enable debug mode
- {
- # ------------------------------ BEGIN OPTIONS ------------------------------- #
- # remote ip(s)/network(s) reachable over vpn (space separated)
- REMOTE_NET='192.168.2.0/24 192.168.3.0/24 192.168.10.100'
- # how often (in secs) between each check for pptp default gateway
- INTERVAL=30
- # comment/uncomment to enable/disable continous monitoring
- STOP_AFTER_SUCCESS=
- # ------------------------------- END OPTIONS -------------------------------- #
- # ---------------------- DO NOT CHANGE BELOW THIS LINE ----------------------- #
- while sleep $INTERVAL; do
- VPN_IP="$(nvram get vpnc_ipaddr)"
- VPN_GW="$(nvram get vpnc_gateway)"
- VPN_IF="$(nvram get vpnc_pppoe_ifname)"
- # verify appearance of pptp client configuration in nvram
- [[ $VPN_IP && $VPN_GW && $VPN_IF ]] || continue
- # verify appearance of pptp client in process table
- pidof 'pppd' &>/dev/null || continue
- # verify appearance of pptp client default gateway in routing table
- ip route | grep -Eq "^0\.0\.0\.0/1\s.*$VPN_IF(\s|$)" || continue
- ip route | grep -Eq "^128\.0\.0\.0/1\s.*$VPN_IF(\s|$)" || continue
- # delete pptp client default gateway
- ip route del 0.0.0.0/1 dev $VPN_IF
- ip route del 128.0.0.0/1 dev $VPN_IF
- # create static routes to remote ip(s)/network(s) over vpn
- for i in $REMOTE_NET; do
- ip route add $i via $VPN_IP dev $VPN_IF
- done
- # force routing system to recognize changes
- ip route flush cache
- # continue monitoring or quit?
- [ ${STOP_AFTER_SUCCESS+x} ] && exit 0
- done
- } 2>&1 | logger -t $(basename $0 .sh)[$$]
- EOF
- [ ${DEBUG+x} ] && sed -ri '2 s/^#(set -x)/\1/' $SCRIPT1
- chmod +x $SCRIPT1
- echo "installed: $SCRIPT1"
- # ----------------------- end merlin-pptp-gw-override ------------------------ #
- # ----------------------------- begin init-start ----------------------------- #
- create_script() {
- cat << 'EOF' > $SCRIPT2
- #!/bin/sh
- #set -x # comment/uncomment to disable/enable debug mode
- {
- nohup $SCRIPT1 &>/dev/null &
- } 2>&1 | logger -t $(basename $0)[$$]
- EOF
- [ ${DEBUG+x} ] && sed -ri '2 s/^#(set -x)/\1/' $SCRIPT2
- sed "s:\$SCRIPT1:$SCRIPT1:g" -i $SCRIPT2
- chmod +x $SCRIPT2
- }
- if [ -f $SCRIPT2 ]; then
- echo "error: $SCRIPT2 already exists; requires manual installation"
- else
- create_script
- echo "installed: $SCRIPT2"
- fi
- # ------------------------------ end init-start ------------------------------ #
Add Comment
Please, Sign In to add comment