PPTP help - 10.3.3 behavior changes

agoltz

Registered
Hi Folks,

There were some excellent threads posted on how to automate the fixing of internet access when you have a pptp/vpn connection (Im at home, need to log onto work, but want to still use my home internet access to get to the web as work has blocked that)

in 10.3.2 i edited the file /System/Library/SystemConfiguration/Kicker.bundle/Contents/Resources/set-hostname as root and added a line at the end that called a script called vpn_route.sh

. /.../.../vpn_route.sh

This worked like a charm until last night when I upgraded to 10.3.3. Now it appears that set-hostname is not being called anymore (or at least that one) when I establish a vpn connection. That means I have to open terminal and run the script every time - a pain. Can anyone suggest where I need to add a line in 10.3.3 to get this to work.

I have also modified the script to better suit my needs and I thought I would post it here for every one. My modifications were
1) the PPP.log is not ginving me my own IP so I had to get it from netstat
2) in 10.3.3 I had to call awk twice to strip out an extra IP (see default_ and default_rt ) as I was getting two lines (I thought awk only printed the first line it matched) of ip addresses in the variable

ALSO - I have multiple locations - the one I am trying to connect from is HOME - does that mean that the script set-hostname is not being called as I am at a particular location?

So - help! Where can I call this script from???????

Thanks

----------------#!/bin/bash
################################################################################
# FIX VPN ROUTING . SH
# Author: Daniel Giribet
# Improvement over shell script published by 'Anonymous' on macosxhints.com
# 'silas' perl script did not work for me, so I use this one.
# Though the scipt is trivial, use at your own risk.
#
# 12/7/03 - modified by carbon14
# fixed mask to be derived from local ip
# fixed mask sed script. You can alter the mask size by changing "$3" to 0
# edited file set-hostname in /System/Library/SystemConfiguration/Kicker.bundle/Contents/Resources
# 3/15/04 - modified by agoltz
# fixed local Ip - derived from netstat and not ppp.log
# fixed local mask script (added default_rt to fix problem)
# added script to check to ppp0 being active - so you can call this from
# any script that initiates a network connection
# in 10.3.3 - set-hostname does not seem to work anymore
# can someone help?

PPTP_ISUP=$(/usr/sbin/netstat -nr | grep ppp0)
if [ "${PPTP_ISUP}" = "" ]; then exit 0 ; fi

PPP_LOG=/tmp/ppp.log

echo "calling vpn_route.sh to reset routing" >> $PPP_LOG

default_=$(/usr/sbin/netstat -nr | grep ' UHLW ' | awk '{print $1}')
default_rt=$(echo $default_ | awk '{print $1}')
remote_vpn_str=$(/usr/bin/tail -5 $PPP_LOG|/usr/bin/grep 'remote IP address')
local_vpn=$(/usr/sbin/netstat -nr | grep ' UHS ' | awk '{print $1}')
n=$(echo $remote_vpn_str |/usr/bin/wc -w|/usr/bin/tr -d 'n' |/usr/bin/tr -d ' ')
remote_vpn=$(echo $remote_vpn_str | awk '{print $'$n'}')
mask=$(echo $remote_vpn|/usr/bin/sed -e 's/\./ /g' | awk '{print $1"."$2"."$3}')

/usr/bin/logger 'fix_vpn_routing.sh: modifying routes...'

/sbin/route delete default $remote_vpn
/sbin/route add default $default_rt
/sbin/route -n add -net $mask $remote_vpn

/usr/bin/logger "fix_vpn_routing.sh: default: $default_irt mask: $mask"
echo "Removing default gateway (should be VPN remote gateway) " $remote_vpn >> $PPP_LOG
echo "Setting default gateway to (should be local gateway) " $default_rt >> $PPP_LOG
echo "Adding netmask " $mask " to connect through vpn gateway " $remote_vpn " to remote network " >> $PPP_LOG
echo "finished calling vpn_route.sh" >> /tmp/ppp.log

exit 1
 
Back
Top