#!/usr/bin/perl $iface=$ARGV[0]; $proto=$ARGV[1]; $localip=$ARGV[2]; $remoteip=$ARGV[3]; $logfile="/usr/local/etc/mpd/gamevpn.log"; $date=`date`; chomp($date); #routes are defined in the following manner: #[VPN-assigned ip address]:[user's internal lan ip] #in the first case, the vpn ip is 192.168.1.102 and that user's local lan ip is 10.10.10.2 @routes=("192.168.1.102:10.10.10.2", "192.168.1.103:192.168.44.2"); open(LOGFILE,">$logfile"); #if not executed by mpd itself, it's likely some parameters will be missing if ($iface eq "" or $proto eq "" or $localip eq "" or $remoteip eq "") { print "Not enough parameters supplied.\n"; exit; } #log the connection print LOGFILE "$date : $iface is $localip <---> $remoteip\n"; #find which vpn client connected to us and set his route. foreach (@routes) { @current=split(/:/, $_, 2); if ($remoteip eq $current[0]) { #log and execute the routing command. print LOGFILE "$date : Executing route add " . $current[1] . " " . $current[0] ."\n"; exec("route add ". $current[1] . " ". $current[0]); exit; } } #if no route is defined for the vpn user, log this. print LOGFILE "$date : This client will not be configured.\n";