#!/usr/bin/perl
#
# This file depends on the following addition to
# /System/Library/SystemConfiguration/Kicker.bundle/Contents/Resources/Kicker.xml:
#
#
# execCommand
# /Library/VPNHack/vpn_fix.pl
# execUID
# 0
# keys
#
# Setup:/
# State:/Network/Global/IPv4
#
# name
# vpn-hack
#
$lanOK = 0;
$vpnGateway = "";
@lines = doCommand("ifconfig");
foreach $line (@lines) {
# Change the following to your usual LAN IP and network mask that you expect to have
# when your home network is up and running. I use a fixed IP address -- which makes
# this much easier -- for dependable port forwarding through my router.
if ($line =~ /inet 192\.168\.0\.\d{1,3} netmask 0xffffff00/) {
$lanOK = 1;
}
# Change the following to match the LAN you get connected to on your VPN.
elsif ($line =~ /inet 172\.16\.1\.\d{1,3} --> ([0-9\.]{7,15}) netmask 0xffff0000/) {
$vpnGateway = $1;
}
}
if ($lanOK && $vpnGateway) {
# Change the following to match the gateway on your home LAN.
doCommand("route change default 192.168.0.1");
# Change the following to match the LAN your VPN connects you to.
doCommand("route add 172.16.0.0 $vpnGateway 255.240.0.0");
}
sub doCommand
{
my $cmd = shift;
my @lines;
if (open(CMD, "$cmd|")) {
@lines = ;
close(CMD);
return @lines;
}
else {
return ();
}
}