forked from jbreams/gssvpn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac-client.pl
executable file
·72 lines (62 loc) · 1.37 KB
/
mac-client.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl
# This will handle network initialization for Mac OS X clients of GSSVPN.
# The parameters in argv will be the name of the tap device being used
# and the parameters passed back from the GSSVPN server. It will accept
# the following options
#
# ip <ip address>
# subnet <subnet mask>
# dhcp
# gateway <ip address>
# routenet <subnet address>/<cidr range>
# route <ip address>
#
# This script assumes it is running as the super-user
#
my $ipaddr = my $subnet = my $gateway = my $dhcp = undef;
my $tapdev = shift;
my $action = shift;
my @routenets = my @routehosts = ( );
$ENV{PATH} = "/sbin";
$action =~ /shutdown/ && exit 0;
while (@ARGV) {
$_ = shift;
if($_ =~ /ip/) {
$ipaddr = shift;
}
elsif($_ =~ /subnet/) {
$subnet = shift;
}
elsif($_ =~ /gateway/) {
$gateway = shift;
}
elsif($_ =~ /dhcp/) {
system "ipconfig set $tapdev DHCP";
$dhcp = 1;
}
elsif($_ =~ /netroute/) {
push @routenets, shift;
}
elsif($_ =~ /route/) {
push @routehosts, shift;
}
}
if(!$dhcp) {
if(!$ipaddr || !$subnet) {
exit 1;
}
system "/sbin/ifconfig $tapdev inet $ipaddr netmask $subnet";
}
if(!$gateway) {
exit 0;
}
system "/sbin/ping -o -q -n $gateway";
if($? != 0) {
die "Unable to ping gateway.";
}
foreach my $dest (@routenets) {
system "/sbin/route add -net $dest $gateway";
}
foreach my $dest (@routehosts) {
system "/sbin/route add -host $dest $gateway";
}